Skip to content

Use preset path directly if it exists#44

Open
xarantolus wants to merge 1 commit intomainfrom
fix/preset-path
Open

Use preset path directly if it exists#44
xarantolus wants to merge 1 commit intomainfrom
fix/preset-path

Conversation

@xarantolus
Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings April 1, 2026 11:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 preset argument as a file path if it points to an existing file.
  • Fallback to presets/<preset_name>.toml when 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"))
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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"))
}

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +84
let pb = PathBuf::from(preset_name);
let preset_path = if pb.is_file() {
pb
} else {
PathBuf::from("presets").join(format!("{preset_name}.toml"))
};
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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"))
};

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +83
// 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"))
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

LCOV of commit fe0ba87 during Osiris CI #395

Total coverage: 14.04%

lcov: WARNING: lcov: WARNING: RC option 'lcov_branch_coverage' is deprecated.  Consider using 'branch_coverage. instead.  (Backward-compatible support will be removed in the future
Summary coverage rate:
  lines......: 14.0% (232 of 1653 lines)
  functions..: 16.7% (39 of 233 functions)
  branches...: no data found

Files changed coverage rate: n/a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants