Skip to content

fix(#585): invocation-name-aware help - bash/sh --help print the GNU usage contract - #596

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/585-invocation-aware-help
Oct 13, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/585-invocation-aware-help

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fix(#585): invocation-name-aware help — bash/sh --help print the GNU usage contract

Problem

Under the bash/sh invocation names, --help printed the product help
(setup/font/doctor/plugin/self-update verbs — none of them bash options),
byte-identical to niu --help. GNU bash answers --help with the
show_shell_usage(stdout, extra=1) contract: a version line, the usage
pair naming the invoked shell, the long-option table, the shell-options
block, and the footer (shell.c:477-482, 2057-2103), rc 0, on stdout.

The fork (engine layer, keyed off argv[0])

  • parse_long_options's help arm now forks on the invocation name
    (argv[0] basename, .exe stripped, - login marker kept in the
    display name):
    • bash / -bash → the GNU usage contract with bash (resp. -bash)
      in the usage and `Type ...' lines,
    • sh / -sh → the same shape with the sh name (GNU prints the
      invoked name; oracle: exec -a sh bash --help → Usage:\tsh ...),
    • any other name (rubash, niu, ...) → the product help, byte-identical
      to before (owner constraint: niu --help keeps the full product
      help; the GNU usage appears ONLY under the bash/sh names).
  • The version line honestly carries the engine's own strings in GNU's
    GNU bash, version %s-(%s) shape (shell.c:2071): today
    GNU bash, version 5.3.0(1)-release-(x86_64-pc-msys).
  • The long-option table is the engine's accepted LONG_OPTIONS set —
    the same 16 entries the usage-error block already prints; no
    aspirational entries. The Shell options block is byte-identical to the
    existing usage-error contract.
  • The shim layer needs no change (src/bin/bash.rs untouched): the fork
    lives entirely in the engine, keyed off argv[0], exactly where the
    fix(shim): forward the sh invocation name so the host honors its GNU contract #504/[bug] script-file argument open failure exits 1 instead of 127 (ENOENT) / 126 (EISDIR etc.) — shell.c open_shell_script EX_NOTFOUND/EX_NOINPUT unmapped #262 execution-contract forwarding lands once the host resolves
    the invocation name.
  • No Windows-only resources are referenced by the new code: the unix
    cross-compile lanes (cargo check --target x86_64-unknown-linux-gnu
    etc.) compile the same plain-string tables.

Why -h is unchanged

-h stays GNU hashall. Oracle (WSL bash 5.3.0(1)-release):
bash -h -c 'echo hi' executes the command (rc 0, prints hi) and
bash -h with a stdin script runs it — GNU's -h is not a help word
(only the long option --help sets want_initial_help, shell.c:477).
Making -h print usage would break bash -h -c ...-style invocations;
the launcher-owned -h surface (product help under niu) is unchanged
per the owner constraint.

Verification

  • tests/issue585_invocation_aware_help_regressions.rs: bash/-bash/sh
    invocations assert the exact GNU form (byte-for-byte against the WSL
    5.3.0(1)-release oracle shape, version line excepted), rc 0, stdout
    not stderr; rubash and a niu-named binary assert the product help
    stays byte-identical.
  • Full suite (RUST_TEST_THREADS=1 cargo test --no-fail-fast) failure
    set vs the master baseline: bidirectional comm empty (the 10
    pre-existing cli_tests/regression failures match one-to-one).
  • RUSTFLAGS=-D warnings cargo check clean; test-crate warning set
    identical to master (windows and linux targets).
  • cargo fmt clean; UTF-8 boundary hygiene lane clean.

closes #585

…ract

GNU bash answers --help with the show_shell_usage(stdout, extra=1)
contract - version line, usage pair naming the invoked shell, long-option
table, shell-options block, footer (shell.c:477-482, 2057-2103) - while
rubash printed the product help under every name. The help surface now
forks on argv[0]: bash/-bash and sh/-sh spellings print the GNU usage
form (rc 0, stdout; the login dash and the sh-vs-bash name reach the
usage lines, oracle-verified against WSL bash 5.3.0(1)-release), and any
other invocation name (rubash, niu, ...) keeps the product help byte for
byte. The version line honestly carries the engine's own BASH_VERSION +
machtype in GNU's `version %s-(%s)` shape, and the long-option table is
the engine's accepted LONG_OPTIONS set - no aspirational entries. -h
stays GNU hashall (oracle: bash -h -c 'echo hi' executes; GNU -h is not
a help word). The fork lives entirely in the engine keyed off argv[0],
so the niubash bash/sh forwarder shims need no change, and no
Windows-only resources are referenced on the unix cross-compile lanes.

tests: tests/issue585_invocation_aware_help_regressions.rs pins the
bash/-bash/sh GNU forms (exact bytes vs the oracle shape), the rc and
stream contract, and the rubash/niu product-help regression.

closes #585
@caomengxuan666
caomengxuan666 merged commit 306c001 into master Oct 13, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/585-invocation-aware-help branch October 13, 2026 06:04
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.

[cli] invocation-name-aware help is forked: bash --help / sh --help print the niu product help instead of the GNU usage contract

1 participant