mirror of
https://github.com/spf13/cobra
synced 2025-05-05 21:07:24 +00:00
Merge 7c32580196
into dc208f4211
This commit is contained in:
commit
f29c8eaf0f
1 changed files with 17 additions and 3 deletions
20
command.go
20
command.go
|
@ -678,17 +678,31 @@ func (c *Command) errorMsgFromParse() string {
|
||||||
// and run through the command tree finding appropriate matches
|
// and run through the command tree finding appropriate matches
|
||||||
// for commands and then corresponding flags.
|
// for commands and then corresponding flags.
|
||||||
func (c *Command) Execute() error {
|
func (c *Command) Execute() error {
|
||||||
|
if c.HasParent() {
|
||||||
|
_, err := c.Root().ExecuteC()
|
||||||
|
return err
|
||||||
|
}
|
||||||
_, err := c.ExecuteC()
|
_, err := c.ExecuteC()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) ExecuteC() (cmd *Command, err error) {
|
func (c *Command) ExecuteSolo() error {
|
||||||
|
_, err := c.executeC()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||||
// Regardless of what command execute is called on, run on Root only
|
// Regardless of what command execute is called on, run on Root only
|
||||||
if c.HasParent() {
|
if c.HasParent() {
|
||||||
return c.Root().ExecuteC()
|
return c.Root().ExecuteC()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd, err = c.executeC()
|
||||||
|
return cmd, err
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (c *Command) executeC() (cmd *Command, err error) {
|
||||||
// windows hook
|
// windows hook
|
||||||
if preExecHookFn != nil {
|
if preExecHookFn != nil {
|
||||||
preExecHookFn(c)
|
preExecHookFn(c)
|
||||||
|
|
Loading…
Add table
Reference in a new issue