From 3c49a47b3c4c5c94dc0a65b5593a63d8d7745177 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 13 Dec 2016 18:27:32 -0500 Subject: [PATCH] Added an UnknownCommandFunc to allow for custom handling of unknown commands --- command.go | 6 ++++++ 1 file changed, 6 insertions(+) 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) }