MCPcopy
hub / github.com/cli/cli / nestedSuggestFunc

Function nestedSuggestFunc

pkg/cmd/root/help.go:62–84  ·  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

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

Callers 1

rootHelpFuncFunction · 0.85

Calls 1

rootUsageFuncFunction · 0.85

Tested by

no test coverage detected