Skip to content

fix(launcher): list the GNU short invocation options in --help (#385) - #388

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/385-help-gnu-short-options
Oct 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/385-help-gnu-short-options

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #385.

niu --help advertised only -h -V -c -C plus the generated long options, 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 later hand-written block listed a few of them, but it could drift from the parser at any time.

What changed

  • The "Bash-compatible invocation options" block is now generated from 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 pipefail repro end to end, plus -euo and -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_OPTIONS table added in unixwin/rubash#697 (fix/382-option-cluster). The local [patch] in Cargo.toml points rubash at the sibling checkout, so refresh/merge rubash first or CI will not see the new API.

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 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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-written const GNU_SHORT_OPTIONS is 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.

@caomengxuan666

Copy link
Copy Markdown
Member Author

The all-red checks are expected and understood, no code problem: CI compiles niubash against the pinned rubash subrepo, which lives on origin/master without rubash::usage::SHORT_OPTIONS yet — that symbol ships with open PR unixwin/rubash#697 (fix/382-option-cluster, review R-A already end-to-end-built #388's head against exactly that worktree and both test files pass with it: issue382... 3, issue385... 3).

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).

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.

docs: --help omits the working GNU-bash invocation options (-e, -o, -u, -x, --noprofile, --norc)

1 participant