diff --git a/command.go b/command.go index 49889318..6ce78642 100644 --- a/command.go +++ b/command.go @@ -127,6 +127,9 @@ type Command struct { // Disable the flag parsing. If this is true all flags will be passed to the command as arguments. DisableFlagParsing bool + + // If set, it will be called if the command requested can not be found + UnknownCommandFunc func([]string) (*Command, []string, error) } // os.Args[1:] by default, if desired, can be overridden @@ -509,6 +512,9 @@ func (c *Command) Find(args []string) (*Command, []string, error) { } } } + if c.UnknownCommandFunc != nil { + return c.UnknownCommandFunc(args) + } return commandFound, a, fmt.Errorf("unknown command %q for %q%s", argsWOflags[0], commandFound.CommandPath(), suggestionsString) }