Skip to content

fix(cli): unknown flags exit 2 and list valid flags - #370

Merged
ankitranjan7 merged 2 commits into
mainfrom
fix/unknown-flag-exit
Aug 19, 2026
Merged

fix(cli): unknown flags exit 2 and list valid flags#370
ankitranjan7 merged 2 commits into
mainfrom
fix/unknown-flag-exit

Conversation

@ankitranjan7

Copy link
Copy Markdown
Contributor

Unknown flags printed error: unknown option '--foo' and exited 1. Agents treat 1 as a runtime error and still have to call --help to learn the valid set.

After

$ webcmd list --unknown-flag
error: unknown option '--unknown-flag'
help: valid flags for `webcmd list`: -f, --format, --tag
# exit 2
  • First line stays Commander's unknown option so existing parsers keep working
  • Second line enumerates that command's flags
  • Exit code is 2 (USAGE_ERROR), same as a missing required flag
  • --help before or after an unknown option still shows help and exits 0
  • Local runCli, hosted adapter parse, and hosted built-in surfaces share structuralErrorFromCommander

Hosted impact

Hosted impact: B — rides the pin bump
Trigger: none
Why: CLI presentation of Commander usage errors only. Cloud HTTP is unchanged. Hosted thin client uses the same helper, so local/hosted stay aligned.
Sequencing: none. Behaviour reaches hosted CLI users at the next bump:webcmd.

Verification

  • npx tsc --noEmit — clean
  • npx vitest run --project unit src/command-surface.test.ts src/hosted/root-command-surface.test.ts src/hosted/runner.test.ts src/cli.test.ts src/fetch/command.test.ts src/hosted/browser-args.test.ts src/plugin-create-cli.test.ts — 529 passed

Commander still rejects unknown options by name. The usage path now
exits 2 and appends the command's valid flags so an agent can retry
without a second --help call.
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🟠 Maintainer review suggested — low confidence

The automated review could not reach a fully supported conclusion.

This review is advisory and does not block merging.

exitOverride made --help throw commander.helpDisplayed. runCli now
keeps that as a display exit so webcmd web --help stays exit 0.
@ankitranjan7
ankitranjan7 merged commit 9cd0d5a into main Aug 19, 2026
37 checks passed
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