Skip to content

feat(cli): point to --help when a command/option typo has no suggestion#383

Merged
UtkarshBhardwaj007 merged 1 commit into
mainfrom
feat/help-hint-unknown-command
Jun 13, 2026
Merged

feat(cli): point to --help when a command/option typo has no suggestion#383
UtkarshBhardwaj007 merged 1 commit into
mainfrom
feat/help-hint-unknown-command

Conversation

@UtkarshBhardwaj007

Copy link
Copy Markdown
Member

What

When a mistyped command or option is too far off for commander's built-in "Did you mean …?" suggestion, the error now tails with a pointer to playground --help — matching how git always ends its "not a command" error with See 'git --help'.

Why

Commander v12 already ships idiomatic Levenshtein suggestions (showSuggestionAfterError, on by default), so near-miss typos like loignlogin and --yse--yes already worked. The gap was the no-suggestion case: a far-off typo printed a bare error: unknown command 'xyzzy' with no next step.

Behavior

Input Output
playground xyzzy error: unknown command 'xyzzy' + Run 'playground --help' to see available commands.
playground login --zzzzzz error: unknown option '--zzzzzz' + Run 'playground --help' to see available options.
playground loign (Did you mean login?) — unchanged
playground login --yse (Did you mean --yes?) — unchanged

The hint is appended only for unknown-command/option errors that commander left without a suggestion. Already-suggested errors, missing-required-option, and invalid-argument errors pass through untouched.

Implementation notes

  • appendHelpHint() is a pure string→string function (fully unit-tested).
  • installHelpHint() walks the whole command tree. Commander does not propagate the root program's configureOutput to subcommands attached via addCommand (the form src/index.ts uses), so a root-only hook would miss option typos on login, deploy, etc. The walk wraps every command. It must run after all addCommand calls (documented at the call site).

Testing

  • 10 new tests (TDD, written failing first), including real-commander integration tests that pin the actual error wording — so an upstream commander wording change fails the tests rather than silently dropping the hint.
  • Verified end-to-end against the real CLI, including the deploy lazy-load passthrough.
  • All four gates pass: format:check, lint:license, typecheck, test (956 passing).

Commander already suggests near-miss commands/options, but when a typo is
too far for a suggestion it emits a bare "unknown command/option" error
with no next step. Tail those with a pointer to `playground --help`,
matching git's behavior. Walks the command tree because commander does not
propagate the root output config to addCommand'd subcommands.
@UtkarshBhardwaj007 UtkarshBhardwaj007 merged commit 77df2b8 into main Jun 13, 2026
18 of 20 checks passed
@UtkarshBhardwaj007 UtkarshBhardwaj007 deleted the feat/help-hint-unknown-command branch June 13, 2026 14:56
@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Pass · ❌ FAIL

Tag: e2e-ci-pr · Branch: feat/help-hint-unknown-command · Commit: 60d1a7a · Run logs

Cell Result Time
pr-login-session ✅ PASS 2m57s
pr-deploy-foundry ✅ PASS 0m50s
pr-preflight ❌ FAIL 6m36s
pr-deploy-cdm ✅ PASS 3m38s
pr-deploy-frontend ✅ PASS 8m59s
pr-install ✅ PASS 0m50s
pr-mod ✅ PASS 1m28s
${{ matrix.cell }} ⏭️ SKIP 0m-9s
${{ matrix.cell }} ⏭️ SKIP 0m-9s
❌ Failed tests (1)
  • e2e/cli/build.test.ts › dot build > exits non-zero when no build strategy can be detected
    expected '\n✖ No package.json found in /tmp/dot…' to contain 'No build strategy detected'

Sentry traces: view spans for this run

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