mirror of https://github.com/spf13/cobra.git
Merge pull request #85 from eparis/more-simplification
More simplification
This commit is contained in:
commit
7c7837e882
38
command.go
38
command.go
|
@ -432,19 +432,18 @@ func (c *Command) execute(a []string) (err error) {
|
||||||
c.Usage()
|
c.Usage()
|
||||||
r.SetOutput(out)
|
r.SetOutput(out)
|
||||||
return err
|
return err
|
||||||
} else {
|
}
|
||||||
// If help is called, regardless of other flags, we print that.
|
// If help is called, regardless of other flags, we print that.
|
||||||
// Print help also if c.Run is nil.
|
// Print help also if c.Run is nil.
|
||||||
if c.helpFlagVal || !c.Runnable() {
|
if c.helpFlagVal || !c.Runnable() {
|
||||||
c.Help()
|
c.Help()
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
c.preRun()
|
|
||||||
argWoFlags := c.Flags().Args()
|
|
||||||
c.Run(c, argWoFlags)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.preRun()
|
||||||
|
argWoFlags := c.Flags().Args()
|
||||||
|
c.Run(c, argWoFlags)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) preRun() {
|
func (c *Command) preRun() {
|
||||||
|
@ -495,20 +494,9 @@ func (c *Command) Execute() (err error) {
|
||||||
args = c.args
|
args = c.args
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) == 0 {
|
cmd, flags, err := c.Find(args)
|
||||||
// Only the executable is called and the root is runnable, run it
|
if err == nil {
|
||||||
if c.Runnable() {
|
err = cmd.execute(flags)
|
||||||
err = c.execute([]string(nil))
|
|
||||||
} else {
|
|
||||||
c.Help()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cmd, flags, e := c.Find(args)
|
|
||||||
if e != nil {
|
|
||||||
err = e
|
|
||||||
} else {
|
|
||||||
err = cmd.execute(flags)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue