Expand description
pathlint sort --dry-run — propose a PATH order that satisfies
every applicable [[expect]] rule, without touching the real PATH.
Pure: the public entry point sort_path takes the current
entries, the expectation set, the merged source catalog, and the
current OS, and returns a SortPlan. Callers print it and
decide on the exit code.
Read-only by design — PRD §4 forbids PATH mutation. Any future
--apply mode would live behind its own subcommand and a flag
the user has to pass explicitly.
See PRD §7.8 for the role this plays in the four-role model (R5 — repair, the inverse of R1 resolve order).
§Algorithm (0.0.8 MVP)
- For every PATH entry, find which
[source.X]names match it viacrate::source_match::find. - For every
[[expect]]rule whoseosfilter applies, mark the entries matching itspreferset as “preferred forcommand”. Entries matchingavoidare marked too. - Compute a stable reordering: preferred entries float ahead of avoided entries for the same command, while every other entry’s relative order is preserved.
- Diff the original and sorted vectors to populate
moves.
Stability matters: pathlint must not rearrange entries it has no opinion on, so sysadmins reading the diff see only the changes they need to think about.
§Examples
use pathlint::config::Config;
use pathlint::os_detect::Os;
use pathlint::path_entry::PathEntry;
use pathlint::sort;
let cfg = Config::default();
let sources = pathlint::catalog::merge_with_user(&cfg.source);
let relations = pathlint::catalog::merge_with_user_relations(&cfg.relations);
let null_env = |_: &str| -> Option<String> { None };
let entries = vec![
PathEntry::from_raw("/usr/local/bin", null_env),
PathEntry::from_raw("/usr/bin", null_env),
];
let plan = sort::sort_path(&entries, &cfg.expectations, &sources, &relations, Os::Linux);
// No expectations → no moves proposed.
assert!(plan.moves.is_empty());Structs§
- Entry
Move - One entry’s movement from old to new index. Only emitted when
the entry actually moved; entries that stayed in place do not
generate a
EntryMove. - Sort
Plan - Proposed PATH reordering from
pathlint sort --dry-run, carrying the original and sorted entries plus the move list.
Enums§
- Sort
Note - Non-blocking observation about a
[[expect]]rule. The current PATH cannot satisfyprefer(no PATH entry matches any preferred source), sosortcannot fix it by reordering — the user has to install the missing tool or adjust the rule. Surfaced so the human view can include it as an “fyi” line below the diff.
Functions§
- sort_
path - Compute a sort plan. Pure.