Repository navigation
fix(launcher): list the GNU short invocation options in --help (#385) - #388
Conversation
The product help advertised only -h -V -c -C plus the long-option table, while the engine parser accepts -e, -o, -u, -x, -l, -i, -s and the rest of the GNU short set (that is why an invalid-looking cluster produced a parser error rather than an unknown-option error). A hand-written block had since listed a few of them, but it could drift from the parser at any time. Generate the whole short-option list from rubash::usage::SHORT_OPTIONS — the same table is_short_option_letter derives from — so every accepted option appears with a one-line description, its value placeholder (-c <command>, -o <option>, -O <shopt>) and any long alias (-l, --login). Depends on the SHORT_OPTIONS table added in unixwin/rubash#382. Regression: tests/issue385_help_short_options.rs asserts every table entry is printed, names the options from the report, and keeps the generated long list; tests/issue382_clustered_short_options.rs pins the `-eo pipefail` repro end to end.
caomengxuan666
left a comment
There was a problem hiding this comment.
Independent review — --help short-option list. Cross-checked the launcher help against the parser's accepted set, the rubash #697 table, and the engine's invalid-option check.
verified-ok — the short table is genuinely the single source. In rubash #697 (fix/382-option-cluster, OPEN, head 0f2d5d5) src/usage.rs adds SHORT_OPTIONS + is_short_option_letter, and the parser derives from it in both places:
src/main.rs:let invalid = script[1..].chars().find(|ch| !rubash::usage::is_short_option_letter(*ch));— the hand-writtenconst GNU_SHORT_OPTIONSis deleted.src/invocation.rs:known_cluster = … letters.iter().all(|flag| crate::usage::is_short_option_letter(*flag)).
The table is exactly the 27 GNU letters c i l r s D o O a b e f h k m n p t u v x B C E H P T. Spot check: niu -lc 'echo hi' → hi (rc 0). No option in the table is rejected by the parser, and every accepted short letter is in the table.
verified-ok — dependency and merge order. rubash::usage::SHORT_OPTIONS does not exist on rubash master (D:/repo/rubash at 8f596779 has only LONG_OPTIONS, LONG_OPTIONS_WITH_VALUE), so this PR does not build or pass CI until rubash #697 lands. Merge rubash #697 first, exactly as the PR body states.
non-blocking — two generated lines are wrong on the niu product face, and --help now contradicts itself. The launcher claims -h/-C before the engine sees them, but the generated block prints the engine meanings next to the launcher meanings in one output:
$ niu -h # product help, rc 0
$ niu -C 'echo hi' # hi
so the new help contains both
-h, --help Show this help
-h hashall: remember the location of executed commands
-C, --repl-command <cmd> Execute one non-interactive REPL command
-C noclobber: refuse to overwrite existing files with >
-c <command> is likewise listed twice. The engine face (bash -h/-C) is correct, so this is a product-help wording issue, not a parser defect; a one-line note above the generated block ("engine short options; the launcher owns -h/-C") or filtering those two letters would remove it.
non-blocking — a second hand-written copy survives (long options). src/main.rs show_shell_usage() still prints its own const LONG_OPTIONS (≈ lines 1364-1372) instead of rubash::usage::LONG_OPTIONS; identical today (16 entries) but free to drift — the failure mode this PR closes for the short set.
Recommendation: merge after rubash #697 merges. The two non-blocking notes are optional.
|
The all-red checks are expected and understood, no code problem: CI compiles niubash against the pinned rubash subrepo, which lives on Sequence therefore stays: rubash #697 merges → bump the pin in this branch → checks go green. No hard-coding of the option list in niubash (that would undo #385's single-source goal). |
Fixes #385.
niu --helpadvertised only-h -V -c -Cplus the generated long options, while the engine parser accepts-e,-o,-u,-x,-l,-i,-sand the rest of the GNU short set (that is why an invalid-looking cluster produced a parser error rather than an unknown-option error). A later hand-written block listed a few of them, but it could drift from the parser at any time.What changed
rubash::usage::SHORT_OPTIONS(letter, value placeholder, long alias, one-line description) instead of hand-written. Every accepted short option is listed, and the help cannot drift from the parser again.Tests
cargo test --test issue385_help_short_options— 3 passed (every table entry is printed; the options named in the report; the generated long-option list is still present).cargo test --test issue382_clustered_short_options— 3 passed (the-eo pipefailrepro end to end, plus-euoand-eO).cargo test --test host_contract --test closed_pipe— 47 passed, 2 ignored.cargo test --test repl_command— 11 passed.Dependency
Requires the
rubash::usage::SHORT_OPTIONStable added in unixwin/rubash#697 (fix/382-option-cluster). The local[patch]inCargo.tomlpoints rubash at the sibling checkout, so refresh/merge rubash first or CI will not see the new API.