From b9e25fa4a06011fa3a4e3ea9a2b5d5b416f924cb Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Mon, 6 Apr 2015 14:54:26 -0400 Subject: [PATCH 1/2] Slight formatting change, to make next commit more readable --- command.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/command.go b/command.go index 7e52d34f..9c3a7013 100644 --- a/command.go +++ b/command.go @@ -422,19 +422,18 @@ func (c *Command) execute(a []string) (err error) { c.Usage() r.SetOutput(out) return err - } else { - // If help is called, regardless of other flags, we print that. - // Print help also if c.Run is nil. - if c.helpFlagVal || !c.Runnable() { - c.Help() - return nil - } - - c.preRun() - argWoFlags := c.Flags().Args() - c.Run(c, argWoFlags) + } + // If help is called, regardless of other flags, we print that. + // Print help also if c.Run is nil. + if c.helpFlagVal || !c.Runnable() { + c.Help() return nil } + + c.preRun() + argWoFlags := c.Flags().Args() + c.Run(c, argWoFlags) + return nil } func (c *Command) preRun() { From 794a36280887640cc246dfcd279bd85dfd91f433 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Mon, 6 Apr 2015 15:24:36 -0400 Subject: [PATCH 2/2] Remove specail casing in Execute() We had some stuff that created a new empty []string if args was already and empty string (why?) We had some stuff that called Help() if it wasn't runnable (but .execute() already does that) Just remove the special case stuff. --- command.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/command.go b/command.go index 9c3a7013..d05e05ea 100644 --- a/command.go +++ b/command.go @@ -476,20 +476,9 @@ func (c *Command) Execute() (err error) { args = c.args } - if len(args) == 0 { - // Only the executable is called and the root is runnable, run it - if c.Runnable() { - 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) - } + cmd, flags, err := c.Find(args) + if err == nil { + err = cmd.execute(flags) } if err != nil {