mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
allow suggestions for non-root commands
This commit is contained in:
parent
f368244301
commit
658b0c71fb
1 changed files with 5 additions and 5 deletions
10
command.go
10
command.go
|
@ -430,13 +430,13 @@ func (c *Command) Find(args []string) (*Command, []string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// root command with subcommands, do subcommand checking
|
// root command with subcommands, do subcommand checking
|
||||||
if commandFound == c && len(argsWOflags) > 0 {
|
if commandFound != nil && len(argsWOflags) > 0 {
|
||||||
suggestionsString := ""
|
suggestionsString := ""
|
||||||
if !c.DisableSuggestions {
|
if !commandFound.DisableSuggestions {
|
||||||
if c.SuggestionsMinimumDistance <= 0 {
|
if commandFound.SuggestionsMinimumDistance <= 0 {
|
||||||
c.SuggestionsMinimumDistance = 2
|
commandFound.SuggestionsMinimumDistance = 2
|
||||||
}
|
}
|
||||||
if suggestions := c.SuggestionsFor(argsWOflags[0]); len(suggestions) > 0 {
|
if suggestions := commandFound.SuggestionsFor(argsWOflags[0]); len(suggestions) > 0 {
|
||||||
suggestionsString += "\n\nDid you mean this?\n"
|
suggestionsString += "\n\nDid you mean this?\n"
|
||||||
for _, s := range suggestions {
|
for _, s := range suggestions {
|
||||||
suggestionsString += fmt.Sprintf("\t%v\n", s)
|
suggestionsString += fmt.Sprintf("\t%v\n", s)
|
||||||
|
|
Loading…
Reference in a new issue