-
Notifications
You must be signed in to change notification settings - Fork 4
Use preset path directly if it exists #44
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,7 +23,7 @@ struct Cli { | |||||||||||||||||||||||||||||||||||||||
| enum Subcommand { | ||||||||||||||||||||||||||||||||||||||||
| /// Load a preset configuration. | ||||||||||||||||||||||||||||||||||||||||
| Load { | ||||||||||||||||||||||||||||||||||||||||
| /// Name of the preset to load. Must correspond to a file in the `presets/` directory without the `.toml` extension. | ||||||||||||||||||||||||||||||||||||||||
| /// Name of the preset to load. Can either be a path, or the name of a file in the `presets/` directory without the `.toml` extension. | ||||||||||||||||||||||||||||||||||||||||
| preset: String, | ||||||||||||||||||||||||||||||||||||||||
| /// Do not ask for confirmation. | ||||||||||||||||||||||||||||||||||||||||
| #[arg(long, default_value_t = false)] | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -79,8 +79,14 @@ fn ask_confirmation(prompt: &str) -> bool { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| fn run_load_preset(preset_name: &str, no_confirm: bool, current_dir: &Path) -> Result<(), Error> { | ||||||||||||||||||||||||||||||||||||||||
| // Load the preset file from the `presets/` directory. | ||||||||||||||||||||||||||||||||||||||||
| let preset_path = PathBuf::from("presets").join(format!("{preset_name}.toml")); | ||||||||||||||||||||||||||||||||||||||||
| // Load the file, or get it from the `presets/` directory | ||||||||||||||||||||||||||||||||||||||||
| let pb = PathBuf::from(preset_name); | ||||||||||||||||||||||||||||||||||||||||
| let preset_path = if pb.is_file() { | ||||||||||||||||||||||||||||||||||||||||
| pb | ||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||
| PathBuf::from("presets").join(format!("{preset_name}.toml")) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+82
to
+87
|
||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+83
to
+88
|
||||||||||||||||||||||||||||||||||||||||
| let pb = PathBuf::from(preset_name); | |
| let preset_path = if pb.is_file() { | |
| pb | |
| } else { | |
| PathBuf::from("presets").join(format!("{preset_name}.toml")) | |
| }; | |
| // Resolve the preset path relative to `current_dir` (the `--root`), unless `preset_name` is absolute. | |
| let candidate = if Path::new(preset_name).is_absolute() { | |
| PathBuf::from(preset_name) | |
| } else { | |
| current_dir.join(preset_name) | |
| }; | |
| let preset_path = if candidate.is_file() { | |
| candidate | |
| } else { | |
| current_dir | |
| .join("presets") | |
| .join(format!("{preset_name}.toml")) | |
| }; |
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.
Imo in this case it makes sense to do this relative? As user I just expect to pass a path and have that read
Uh oh!
There was an error while loading. Please reload this page.