Added an UnknownCommandFunc to allow for custom handling of unknown

commands
This commit is contained in:
Mark Bates 2016-12-13 18:27:32 -05:00
parent 9495bc009a
commit 3c49a47b3c

View file

@ -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)
}