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

Function nestedSuggestFunc

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

(IOStreams *iostreams.IOStreams, command *cobra.Command, arg string)

Source from the content-addressed store, hash-verified

35// This matches Cobra's behavior for root command, which Cobra
36// confusingly doesn't apply to nested commands.
37func nestedSuggestFunc(IOStreams *iostreams.IOStreams, command *cobra.Command, arg string) {
38 w := IOStreams.ErrOut
39 fmt.Fprintf(w, "unknown command %q for %q\n", arg, command.CommandPath())
40
41 var candidates []string
42 if arg == "help" {
43 candidates = []string{"--help"}
44 } else {
45 if command.SuggestionsMinimumDistance <= 0 {
46 command.SuggestionsMinimumDistance = 2
47 }
48 candidates = command.SuggestionsFor(arg)
49 }
50
51 if len(candidates) > 0 {
52 fmt.Fprint(w, "\nDid you mean this?\n")
53 for _, c := range candidates {
54 fmt.Fprintf(w, "\t%s\n", c)
55 }
56 }
57
58 fmt.Fprint(w, "\n")
59 _ = rootUsageFunc(IOStreams, command)(command)
60}
61
62func isRootCmd(command *cobra.Command) bool {
63 return command != nil && !command.HasParent()

Callers 1

rootHelpFuncFunction · 0.85

Calls 1

rootUsageFuncFunction · 0.85

Tested by

no test coverage detected