diff --git a/cobra_test.go b/cobra_test.go index 576c97d3..9f48ee32 100644 --- a/cobra_test.go +++ b/cobra_test.go @@ -925,6 +925,11 @@ func TestRootSuggestions(t *testing.T) { cmd := initializeWithRootCmd() cmd.AddCommand(cmdTimes) + origCmdRun := cmd.Run + defer func() { + cmd.Run = origCmdRun + }() + cmd.Run = nil tests := map[string]string{ "time": "times", @@ -986,6 +991,12 @@ func TestFlagsBeforeCommand(t *testing.T) { func TestRemoveCommand(t *testing.T) { versionUsed = 0 c := initializeWithRootCmd() + origCmdRun := c.Run + defer func() { + c.Run = origCmdRun + }() + c.Run = nil + c.AddCommand(cmdVersion1) c.RemoveCommand(cmdVersion1) x := fullTester(c, "version") diff --git a/command.go b/command.go index e85bf51a..faa2dae8 100644 --- a/command.go +++ b/command.go @@ -521,7 +521,7 @@ func (c *Command) Find(args []string) (*Command, []string, error) { } // root command with subcommands, do subcommand checking - if commandFound == c && len(argsWOflags) > 0 { + if commandFound == c && !c.Runnable() && len(argsWOflags) > 0 { suggestionsString := "" if !c.DisableSuggestions { if c.SuggestionsMinimumDistance <= 0 {