-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add resources directory validation for init and install commands #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ pub mod registry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use clap::{Args, Parser, Subcommand}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::env; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::path::Path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[derive(Debug, Parser)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[command(name = "fxpkg")] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -44,6 +45,32 @@ struct InstallArgs { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn find_resources_directory(current_path: &Path) -> Result<String, String> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut path = current_path.to_path_buf(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if current directory is already "resources" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if path.file_name().and_then(|n| n.to_str()) == Some("resources") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Ok(path.to_string_lossy().to_string()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Traverse upwards to find "resources" directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| loop { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let resources_path = path.join("resources"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if resources_path.exists() && resources_path.is_dir() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Ok(resources_path.to_string_lossy().to_string()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+48
to
+60
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn find_resources_directory(current_path: &Path) -> Result<String, String> { | |
| let mut path = current_path.to_path_buf(); | |
| // Check if current directory is already "resources" | |
| if path.file_name().and_then(|n| n.to_str()) == Some("resources") { | |
| return Ok(path.to_string_lossy().to_string()); | |
| } | |
| // Traverse upwards to find "resources" directory | |
| loop { | |
| let resources_path = path.join("resources"); | |
| if resources_path.exists() && resources_path.is_dir() { | |
| return Ok(resources_path.to_string_lossy().to_string()); | |
| fn find_resources_directory(current_path: &Path) -> Result<PathBuf, String> { | |
| let mut path = current_path.to_path_buf(); | |
| // Check if current directory is already "resources" | |
| if path.file_name().and_then(|n| n.to_str()) == Some("resources") { | |
| return Ok(path); | |
| } | |
| // Traverse upwards to find "resources" directory | |
| loop { | |
| let resources_path = path.join("resources"); | |
| if resources_path.exists() && resources_path.is_dir() { | |
| return Ok(resources_path); |
Copilot
AI
May 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling logic for both commands is duplicated; extract the match block into a helper to reduce repetition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a doc comment explaining the lookup strategy and error cases for find_resources_directory to improve readability and maintainability.