Skip to content

Commit a4c71bc

Browse files
committed
Changes NoArgs to report invalid argument
NoArgs currently reports "unknown command", which is a little misleading to the user. Change it to report "invalid argument" as a more appropriate return error. This should be appropriate for both root and sub-commands.
1 parent 4dab30c commit a4c71bc

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

args.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func legacyArgs(cmd *Command, args []string) error {
2626
// NoArgs returns an error if any args are included.
2727
func NoArgs(cmd *Command, args []string) error {
2828
if len(args) > 0 {
29-
return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath())
29+
return fmt.Errorf("invalid argument %q for %q", args[0], cmd.CommandPath())
3030
}
3131
return nil
3232
}

args_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestNoArgsWithArgs(t *testing.T) {
2626
}
2727

2828
got := err.Error()
29-
expected := `unknown command "illegal" for "c"`
29+
expected := `invalid argument "illegal" for "c"`
3030
if got != expected {
3131
t.Errorf("Expected: %q, got: %q", expected, got)
3232
}
@@ -223,7 +223,7 @@ func TestChildTakesNoArgs(t *testing.T) {
223223
}
224224

225225
got := err.Error()
226-
expected := `unknown command "illegal" for "root child"`
226+
expected := `invalid argument "illegal" for "root child"`
227227
if !strings.Contains(got, expected) {
228228
t.Errorf("expected %q, got %q", expected, got)
229229
}

0 commit comments

Comments
 (0)