feat: suggest similar flags for an unknown flag

tea issue list --lable bug now fails with "unknown flag: --lable; did
you mean --label?". Suggestions are the command's visible flags that
start with the typed name or are at most two edits away from it.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-11 22:55:27 +02:00
1 parent f03d0fdf54
commit 04d5f2aed0
2 files changed
+57 -1

No files matched your search

+16
View File
@@ -196,6 +196,22 @@ func TestRawJSONCommandsKeepJQToThemselves(t *testing.T) {
require.ErrorContains(t, root.Execute(), "raw prints text; --json is not supported")
}
func TestUnknownFlagsSuggestSimilarFlags(t *testing.T) {
requireUsageBeforeRequests(t, "unknown flag: --lable; did you mean --label?", "issue", "list", "--lable", "bug")
requireUsageBeforeRequests(t, "unknown flag: --stat; did you mean --state?", "issue", "list", "--stat", "open")
requireUsageBeforeRequests(t, "unknown flag: --add-label; did you mean --add-labels?", "issue", "edit", "1", "--add-label", "bug")
deps, _, _ := testDeps(t)
err := Execute(context.Background(), deps, []string{"issue", "list", "--zzzzzz"})
require.Equal(t, clierr.Usage, clierr.ExitCode(err))
require.EqualError(t, err, "unknown flag: --zzzzzz")
for _, tc := range []struct {
a, b string
distance int
}{{"kitten", "sitting", 3}, {"", "abc", 3}, {"label", "label", 0}, {"lable", "label", 2}} {
require.Equal(t, tc.distance, editDistance(tc.a, tc.b), tc)
}
}
func TestRootHelpGroupsCommandsAndTopics(t *testing.T) {
deps, out, _ := testDeps(t)
require.NoError(t, Execute(context.Background(), deps, []string{"alias", "set", "co", "pr checkout"}))