diff --git a/args.go b/args.go index 92e1dde..c86b1bb 100644 --- a/args.go +++ b/args.go @@ -33,7 +33,7 @@ func legacyArgs(cmd *Command, args []string) error { // root command with subcommands, do subcommand checking. if !cmd.HasParent() && len(args) > 0 { - return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.SuggestFunc()(args[0])) + return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.SuggestFunc(args[0])) } return nil } @@ -58,7 +58,7 @@ func OnlyValidArgs(cmd *Command, args []string) error { } for _, v := range args { if !stringInSlice(v, validArgs) { - return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.SuggestFunc()(args[0])) + return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.SuggestFunc(args[0])) } } } diff --git a/command.go b/command.go index abf3f06..1b3a687 100644 --- a/command.go +++ b/command.go @@ -483,16 +483,16 @@ func (c *Command) Help() error { return nil } -// SuggestFunc returns either the function set by SetSuggestFunc for this command -// or a parent, or it returns a function with default suggestion behavior. -func (c *Command) SuggestFunc() func(string) string { +// SuggestFunc returns suggestions for the provided typedName using either +// the function set by SetSuggestFunc for this command, parent's or a default one. +func (c *Command) SuggestFunc(typedName string) string { if c.suggestFunc != nil && !c.DisableSuggestions { - return c.suggestFunc + return c.suggestFunc(typedName) } if c.HasParent() { - return c.Parent().SuggestFunc() + return c.Parent().SuggestFunc(typedName) } - return c.findSuggestions + return c.findSuggestions(typedName) } // UsageString returns usage string.