feat(cli): point to --help when a command/option typo has no suggestion#383
Merged
Merged
Conversation
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.
Contributor
E2E Test Pass · ❌ FAILTag:
❌ Failed tests (1)
Sentry traces: view spans for this run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 howgitalways ends its "not a command" error withSee 'git --help'.Why
Commander v12 already ships idiomatic Levenshtein suggestions (
showSuggestionAfterError, on by default), so near-miss typos likeloign→loginand--yse→--yesalready worked. The gap was the no-suggestion case: a far-off typo printed a bareerror: unknown command 'xyzzy'with no next step.Behavior
playground xyzzyerror: unknown command 'xyzzy'+Run 'playground --help' to see available commands.playground login --zzzzzzerror: unknown option '--zzzzzz'+Run 'playground --help' to see available options.playground loign(Did you mean login?)— unchangedplayground login --yse(Did you mean --yes?)— unchangedThe 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'sconfigureOutputto subcommands attached viaaddCommand(the formsrc/index.tsuses), so a root-only hook would miss option typos onlogin,deploy, etc. The walk wraps every command. It must run after alladdCommandcalls (documented at the call site).Testing
deploylazy-load passthrough.format:check,lint:license,typecheck,test(956 passing).