Skip to content
Myr

Merge pull request #83 from adammck/fix_double_output_on_unknown_command

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix redundant error for unknown root commands

authored by Eric Paris · committed by Eric Paris · parents be3cf39, 2c370cd · Browse files · 2 files+12 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−3 removed

  • other:+12 added−3 removed

2 files+12 added−3 removed

modified:cobra_test.go+9 added
552 unmodified lines
553 t.Errorf("--help shouldn't trigger an error, Got: \n %s", x.Output)554 }555}556557func TestRootUnknownCommand(t *testing.T) {558 r := noRRSetupTest("bogus")559 s := "Error: unknown command \"bogus\"\nRun 'cobra-test help' for usage.\n"560561 if r.Output != s {562 t.Errorf("Unexpected response.\nExpecting to be:\n %q\nGot:\n %q\n", s, r.Output)563 }564}565566func TestFlagsBeforeCommand(t *testing.T) {567 // short without space568 x := fullSetupTest("-i10 echo")569 if x.Error != nil {
49 unmodified lines
modified:command.go+3 added-3 removed
376 unmodified lines
377378 // if commander returned and the first argument (if it exists) doesn't379 // match the command name, return nil & error380 if commandFound.Name() == c.Name() && len(arrs[0]) > 0 && commandFound.Name() != arrs[0] {381 return nil, a, fmt.Errorf("unknown command %q\nRun 'help' for usage.\n", a[0])381 return nil, a, fmt.Errorf("unknown command %q", a[0])382 }383384 return commandFound, a, nil385}
152 unmodified lines
538539 if err != nil {540 if err == flag.ErrHelp {541 c.Help()542543 } else {544 c.Println("Error:", err.Error())544 c.Printf("%v: invalid command %#q\n", c.Root().Name(), os.Args[1:])545 c.Printf("Run '%v help' for usage\n", c.Root().Name())545 c.Printf("Run '%v help' for usage.\n", c.Root().Name())546 }547 }548549 return
409 unmodified lines