mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
Added an UnknownCommandFunc to allow for custom handling of unknown
commands
This commit is contained in:
parent
9495bc009a
commit
3c49a47b3c
1 changed files with 6 additions and 0 deletions
|
@ -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.
|
// Disable the flag parsing. If this is true all flags will be passed to the command as arguments.
|
||||||
DisableFlagParsing bool
|
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
|
// 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)
|
return commandFound, a, fmt.Errorf("unknown command %q for %q%s", argsWOflags[0], commandFound.CommandPath(), suggestionsString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue