Skip to content
Myr

Correctly print the unknown command name

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

by now, if someone calls: `program --validflag unknowncommand` the output will be: ``` Error: unknown command "--validflag" Run 'program help' for usage. ``` This patch strips out flags so the unknown command is printed: ``` Error: unknown command "unknowncommand" Run 'program help' for usage. ```

authored by Simone Gotti · committed by Simone Gotti · parent 3120920 · Browse files · 2 files+6 added−1 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+6 added−1 removed

  • other:+6 added−1 removed

2 files+6 added−1 removed

modified:cobra_test.go+5 added
753 unmodified lines
754755 if r.Output != s {756 t.Errorf("Unexpected response.\nExpecting to be:\n %q\nGot:\n %q\n", s, r.Output)757 }758759 r = noRRSetupTest("--strtwo=a bogus")760 if r.Output != s {761 t.Errorf("Unexpected response.\nExpecting to be:\n %q\nGot:\n %q\n", s, r.Output)762 }763}764765func TestFlagsBeforeCommand(t *testing.T) {766 // short without space
181 unmodified lines
modified:command.go+1 added-1 removed
422 unmodified lines
423 commandFound, a := innerfind(c, args)424425 // If we matched on the root, but we asked for a subcommand, return an error426 if commandFound.Name() == c.Name() && len(stripFlags(args, c)) > 0 && commandFound.Name() != args[0] {427 return nil, a, fmt.Errorf("unknown command %q", a[0])427 return nil, a, fmt.Errorf("unknown command %q", stripFlags(args, c)[0])428 }429430 return commandFound, a, nil431}
600 unmodified lines