diff --git a/command.go b/command.go index 58980bc2..5fefb58d 100644 --- a/command.go +++ b/command.go @@ -685,7 +685,7 @@ func (c *Command) execute(a []string) (err error) { return err } - if helpVal || !c.Runnable() { + if helpVal { return flag.ErrHelp } @@ -705,6 +705,10 @@ func (c *Command) execute(a []string) (err error) { } } + if !c.Runnable() { + return flag.ErrHelp + } + c.preRun() argWoFlags := c.Flags().Args() diff --git a/command_test.go b/command_test.go index 142203f1..d3dde152 100644 --- a/command_test.go +++ b/command_test.go @@ -867,7 +867,7 @@ func TestVersionTemplate(t *testing.T) { } func TestVersionFlagExecutedOnSubcommand(t *testing.T) { - rootCmd := &Command{Use: "root", Version: "1.0.0", Run: emptyRun} + rootCmd := &Command{Use: "root", Version: "1.0.0"} rootCmd.AddCommand(&Command{Use: "sub", Run: emptyRun}) output, err := executeCommand(rootCmd, "--version", "sub")