fix: suppress misleading "Did you mean" suggestions#17
Open
anmarhindi wants to merge 1 commit into
Open
Conversation
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.
Summary
suggestCommandpreviously printed a suggestion for every unknown subcommand, even when the best jaro-winkler match was barely related. Two visible failure modes:Add a minimum similarity threshold below which
suggestCommandreturns"". The upstreamurfave/clierror formatter already omits the suggestion clause when the function returns an empty string, so the user just seesNo help topic for 'X'.cleanly.After
Why 0.7
I measured jaro-winkler scores against the real top-level commands. Real typos score 0.78-1.00 (e.g.
creat->create= 0.97,comp->completions= 0.87,lst->list= 0.93). Unrelated input scores at most 0.557 (totallybogus->completions). A threshold of 0.7 sits in the gap, and conveniently matches the existingboostThresholdconstant insidejaroWinkleritself — the prefix boost only kicks in past 0.7, so it's a natural "plausibly the same word" cutoff.Verification
go test ./pkg/cmd/ -run TestSuggest— new table-driven coverage of close typos, exact matches, unrelated input, low-similarity input, empty input, and empty command lists.Closes #16