mirror of
https://github.com/spf13/cobra
synced 2025-07-07 11:37:17 +00:00
use findAndParseFlag instead of ParseFlags
This commit is contained in:
parent
7a0f61e6a5
commit
d2e2d77694
1 changed files with 9 additions and 7 deletions
16
command.go
16
command.go
|
@ -726,8 +726,10 @@ func (c *Command) findAndParseFlag(args []string) (*Command, error) {
|
||||||
// return c.FlagErrorFunc()(c, err)
|
// return c.FlagErrorFunc()(c, err)
|
||||||
// }
|
// }
|
||||||
return innerfind(cmd, afterArgs)
|
return innerfind(cmd, afterArgs)
|
||||||
|
} else {
|
||||||
|
c.ParseFlags(innerArgs)
|
||||||
|
return c, innerArgs
|
||||||
}
|
}
|
||||||
return c, innerArgs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
commandFound, a := innerfind(c, args)
|
commandFound, a := innerfind(c, args)
|
||||||
|
@ -870,13 +872,13 @@ func (c *Command) execute(a []string) (err error) {
|
||||||
|
|
||||||
// initialize help and version flag at the last point possible to allow for user
|
// initialize help and version flag at the last point possible to allow for user
|
||||||
// overriding
|
// overriding
|
||||||
c.InitDefaultHelpFlag()
|
// c.InitDefaultHelpFlag()
|
||||||
c.InitDefaultVersionFlag()
|
// c.InitDefaultVersionFlag()
|
||||||
|
|
||||||
err = c.ParseFlags(a)
|
// err = c.ParseFlags(a)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return c.FlagErrorFunc()(c, err)
|
// return c.FlagErrorFunc()(c, err)
|
||||||
}
|
// }
|
||||||
|
|
||||||
// If help is called, regardless of other flags, return we want help.
|
// If help is called, regardless of other flags, return we want help.
|
||||||
// Also say we need help if the command isn't runnable.
|
// Also say we need help if the command isn't runnable.
|
||||||
|
|
Loading…
Add table
Reference in a new issue