Skip to content

Reject unknown CLI commands with help or version flags - #9264

Open
aspeddro wants to merge 2 commits into
rescript-lang:masterfrom
aspeddro:fix/unknown-command-help
Open

aspeddro wants to merge 2 commits into
rescript-lang:masterfrom
aspeddro:fix/unknown-command-help

Conversation

@aspeddro

@aspeddro aspeddro commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

rescript invalid --help and rescript unkdnow --version previously discarded the unknown command, printed help or version, and exited with code 0. Validate positional command names before either display request so unknown commands report an error and exit with code 2.

Includes regression coverage for long, short, leading, formatted, and clustered help/version flags, plus a changelog fragment.

Validation: toolchain build, 55 unit tests, 103 command-validation cases, OCaml formatting, changelog validation, and manual checks through the Node CLI launcher.

Checklist

  • Added a changelog fragment.
  • Added tests for the fix.
  • Gave every commit a description below its subject.
  • Signed off every commit for the DCO.

Why:
    Argument normalization discarded unknown command names when help was
    requested, so misspelled commands printed root help and exited with 0.

Representation modified (Cli.normalize_argv routing):
Before (text):
    rescript invalid --help -> rescript --help=plain
After (text):
    rescript invalid --help -> rescript help invalid

Diagnostic modified (unknown command help):
Before (text):
    rescript invalid --help
    Root help on stdout; exit status 0.
After (text):
    rescript invalid --help
    rescript: unknown command "invalid"
    Exit status 2.

Signed-off-by: Pedro Castro <aspeddro@gmail.com>
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Report a usage error and exit with code 2 for unknown CLI commands even when help or version is requested.

Semantic Diff

2 commits · Full page

Reject unknown CLI commands when help is requested

413e8bd · aspeddro · Nov 07, 2026, 17:50 UTC

Why

Argument normalization discarded unknown command names when help was requested, so misspelled commands printed root help and exited with 0.

Representation modified (Cli.normalize_argv routing)

text

-rescript invalid --help -> rescript --help=plain
+rescript invalid --help -> rescript help invalid

Diagnostic modified (unknown command help)

text

 rescript invalid --help
-Root help on stdout; exit status 0.
+rescript: unknown command "invalid"
+Exit status 2.
✨ Reject unknown CLI commands when version is requested

6be17f5 · aspeddro · Nov 07, 2026, 18:09 UTC · new

Why

The help fix still let version requests discard unknown subcommands and exit successfully. Validate command topics for both display flags.

Representation modified (Cli.normalize_argv routing)

text

-rescript unkdnow --version -> rescript --version
+rescript unkdnow --version -> rescript help unkdnow

Diagnostic modified (unknown command version)

text

 rescript unkdnow --version
-rescript 13.0.0-alpha.8
-Exit status 0.
+rescript: unknown command "unkdnow"
+Exit status 2.

@pkg-pr-new

pkg-pr-new Bot commented Nov 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9264

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9264

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9264

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9264

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9264

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9264

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9264

commit: 413e8bd

Why:
    The help fix still let version requests discard unknown subcommands
    and exit successfully. Validate command topics for both display flags.

Representation modified (Cli.normalize_argv routing):
Before (text):
    rescript unkdnow --version -> rescript --version
After (text):
    rescript unkdnow --version -> rescript help unkdnow

Diagnostic modified (unknown command version):
Before (text):
    rescript unkdnow --version
    rescript 13.0.0-alpha.8
    Exit status 0.
After (text):
    rescript unkdnow --version
    rescript: unknown command "unkdnow"
    Exit status 2.

Signed-off-by: Pedro Castro <aspeddro@gmail.com>
@aspeddro aspeddro changed the title Fix exit status for unknown CLI commands with help Reject unknown CLI commands with help or version flags Nov 7, 2026

This branch has not been deployed

No deployments
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.

1 participant