cobra icon indicating copy to clipboard operation
cobra copied to clipboard

Proposal: Make command suggestion messages configurable

Open MarvinJWendt opened this issue 3 years ago • 4 comments

Hi, we have a project where clear definitions were made, what the output of the CLI has to look like. We appreciate the automatic suggestions if a command was misspelled. Sadly it seems like we cannot customize the suggestion message and the default message doesn't really fit with the rest of the CLI.

Is there a possibility to make a SetSuggestFunc() like it's been done with SetHelpFunc()?

This could be used to change the suggestion message:

rootCmd.SetSuggestFunc(func(suggestedCommands []*cobra.Command) {
    var commandNames string
    for _, command := range suggestedCommands {
        	commandNames += command.Use + " "
    }
    fmt.Printf("Did you mean any of [%s]", commandNames)
})

MarvinJWendt avatar May 10 '21 08:05 MarvinJWendt