MCPcopy Create free account
hub / github.com/cli/cli / nestedSuggestFunc

Function nestedSuggestFunc

pkg/cmd/root/help.go:64–86  ·  view source on GitHub ↗

Display helpful error message in case subcommand name was mistyped. This matches Cobra's behavior for root command, which Cobra confusingly doesn't apply to nested commands.

(w io.Writer, command *cobra.Command, arg string)

Source from the content-addressed store, hash-verified

62// This matches Cobra's behavior for root command, which Cobra
63// confusingly doesn't apply to nested commands.
64func nestedSuggestFunc(w io.Writer, command *cobra.Command, arg string) {
65 fmt.Fprintf(w, "unknown command %q for %q\n", arg, command.CommandPath())
66
67 var candidates []string
68 if arg == "help" {
69 candidates = []string{"--help"}
70 } else {
71 if command.SuggestionsMinimumDistance <= 0 {
72 command.SuggestionsMinimumDistance = 2
73 }
74 candidates = command.SuggestionsFor(arg)
75 }
76
77 if len(candidates) > 0 {
78 fmt.Fprint(w, "\nDid you mean this?\n")
79 for _, c := range candidates {
80 fmt.Fprintf(w, "\t%s\n", c)
81 }
82 }
83
84 fmt.Fprint(w, "\n")
85 _ = rootUsageFunc(w, command)
86}
87
88func isRootCmd(command *cobra.Command) bool {
89 return command != nil && !command.HasParent()

Callers 1

rootHelpFuncFunction · 0.85

Calls 1

rootUsageFuncFunction · 0.85

Tested by

no test coverage detected