Modify the logic of Command execute function

Signed-off-by: Dong Gang <dong.gang@daocloud.io>
This commit is contained in:
Dong Gang 2020-07-13 11:34:19 +08:00
parent 01ce53c87a
commit f5ce802946

View file

@ -801,12 +801,6 @@ func (c *Command) execute(a []string) (err error) {
} }
} }
if !c.Runnable() {
return flag.ErrHelp
}
c.preRun()
argWoFlags := c.Flags().Args() argWoFlags := c.Flags().Args()
if c.DisableFlagParsing { if c.DisableFlagParsing {
argWoFlags = a argWoFlags = a
@ -816,6 +810,12 @@ func (c *Command) execute(a []string) (err error) {
return err return err
} }
if !c.Runnable() {
return flag.ErrHelp
}
c.preRun()
for p := c; p != nil; p = p.Parent() { for p := c; p != nil; p = p.Parent() {
if p.PersistentPreRunE != nil { if p.PersistentPreRunE != nil {
if err := p.PersistentPreRunE(c, argWoFlags); err != nil { if err := p.PersistentPreRunE(c, argWoFlags); err != nil {