Suggestions when “unknown command” happens
Cobra will print automatic suggestions when “unknown command” errors happen. This allows Cobra to behave similarly to the git
command when a typo happens. For example:
$ hugo srever
Error: unknown command "srever" for "hugo"
Did you mean this?
server
Run 'hugo --help' for usage.
Suggestions are automatic based on every subcommand registered and use an implementation of Levenshtein distance. Every registered command that matches a minimum distance of 2 (ignoring case) will be displayed as a suggestion.
If you need to disable suggestions or tweak the string distance in your command, use:
command.DisableSuggestions = true
or
command.SuggestionsMinimumDistance = 1
You can also explicitly set names for which a given command will be suggested using the SuggestFor
attribute. This allows suggestions for strings that are not close in terms of string distance, but makes sense in your set of commands and for some which you don’t want aliases. Example:
$ kubectl remove
Error: unknown command "remove" for "kubectl"
Did you mean this?
delete
Run 'kubectl help' for usage.