This commit is contained in:
Mark Bates 2017-05-08 21:03:16 +00:00 committed by GitHub
commit 3052272ba5

View file

@ -135,6 +135,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)
}
// SetArgs sets arguments for the command. It is set to 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)
}