use findAndParseFlag instead of ParseFlags

This commit is contained in:
luyanbo 2021-10-11 22:59:14 +08:00
parent 7a0f61e6a5
commit d2e2d77694

View file

@ -726,9 +726,11 @@ 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)
if commandFound.Args == nil { if commandFound.Args == nil {
@ -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.