Merge pull request #116 from sgotti/fix_flag_as_unknown_command_in_output

Correctly print the unknown command name
This commit is contained in:
Eric Paris 2015-06-22 16:52:47 -05:00
commit ddd4c82b82
2 changed files with 6 additions and 1 deletions

View File

@ -755,6 +755,11 @@ func TestRootUnknownCommand(t *testing.T) {
if r.Output != s { if r.Output != s {
t.Errorf("Unexpected response.\nExpecting to be:\n %q\nGot:\n %q\n", s, r.Output) t.Errorf("Unexpected response.\nExpecting to be:\n %q\nGot:\n %q\n", s, r.Output)
} }
r = noRRSetupTest("--strtwo=a bogus")
if r.Output != s {
t.Errorf("Unexpected response.\nExpecting to be:\n %q\nGot:\n %q\n", s, r.Output)
}
} }
func TestFlagsBeforeCommand(t *testing.T) { func TestFlagsBeforeCommand(t *testing.T) {

View File

@ -424,7 +424,7 @@ func (c *Command) Find(args []string) (*Command, []string, error) {
// If we matched on the root, but we asked for a subcommand, return an error // If we matched on the root, but we asked for a subcommand, return an error
if commandFound.Name() == c.Name() && len(stripFlags(args, c)) > 0 && commandFound.Name() != args[0] { if commandFound.Name() == c.Name() && len(stripFlags(args, c)) > 0 && commandFound.Name() != args[0] {
return nil, a, fmt.Errorf("unknown command %q", a[0]) return nil, a, fmt.Errorf("unknown command %q", stripFlags(args, c)[0])
} }
return commandFound, a, nil return commandFound, a, nil