Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the xtask config load flow to accept a direct preset file path when it exists, while retaining the previous behavior of loading a named preset from presets/ when no file is found.
Changes:
- Treat the
presetargument as a file path if it points to an existing file. - Fallback to
presets/<preset_name>.tomlwhen the provided path doesn’t exist.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let preset_path = if pb.is_file() { | ||
| pb | ||
| } else { | ||
| PathBuf::from("presets").join(format!("{preset_name}.toml")) |
There was a problem hiding this comment.
Fallback path construction uses the entire preset_name string in format!("{preset_name}.toml"). If the user passes a filename that already ends with .toml (common with shell completion) or includes path components (e.g. presets/foo.toml), the fallback becomes presets/foo.toml.toml / presets/presets/foo.toml.toml and will never match the intended preset. Consider deriving the preset key from Path::new(preset_name).file_stem() (and/or file_name()) before appending .toml for the presets/ lookup.
| PathBuf::from("presets").join(format!("{preset_name}.toml")) | |
| { | |
| // Derive a preset key (file stem) to avoid double `.toml` or duplicated path segments. | |
| let preset_stem = Path::new(preset_name) | |
| .file_stem() | |
| .and_then(|s| s.to_str()) | |
| .unwrap_or(preset_name); | |
| PathBuf::from("presets").join(format!("{preset_stem}.toml")) | |
| } |
| let pb = PathBuf::from(preset_name); | ||
| let preset_path = if pb.is_file() { | ||
| pb | ||
| } else { | ||
| PathBuf::from("presets").join(format!("{preset_name}.toml")) | ||
| }; |
There was a problem hiding this comment.
pb.is_file() (and the fallback PathBuf::from("presets")...) resolve paths relative to the process working directory, not the current_dir/--root passed into this function. Since just config invokes the xtask with --root {{justfile_directory()}}, running just from a different directory can cause existing preset paths to be missed and the wrong fallback path to be used. Consider resolving relative preset_names (and the presets/ directory) against current_dir to make --root consistently control where presets are found.
| 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")) | |
| }; |
| // 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")) |
There was a problem hiding this comment.
The Load.preset CLI help text still says the argument "must correspond to a file in the presets/ directory without the .toml extension", but this function now accepts direct file paths as well. Update the clap docstring (and any related docs) so users discover the new behavior and don't get misled about what values are valid.
LCOV of commit
|
I usually run
just config load <filename>, which is nice because it works with shell completions. This makes that actually work, and falls back to the preset basename if no file with that name exists.