Skip to content

Commit

Permalink
adapt: mention the command name in argument errors
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Mar 18, 2024
1 parent e71de40 commit 1c6d122
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions adapt.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func checkAdapt(fn any) (func(*Env) error, error) {
if fz, ok := fn.(func(*Env) error); ok {
return func(env *Env) error {
if len(env.Args) != 0 {
return env.Usagef("extra arguments after command: %q", env.Args)
return env.Usagef("extra arguments after command %q: %q",
env.Command.Name, env.Args)
}
return fz(env)
}, nil
Expand Down Expand Up @@ -90,7 +91,8 @@ func checkAdapt(fn any) (func(*Env) error, error) {
if hasRest {
return func(env *Env) error {
if len(env.Args) < argc-1 {
return env.Usagef("wrong number of arguments: got %d, want at least %d", len(env.Args), argc-1)
return env.Usagef("wrong number of arguments for %q: got %d, want at least %d",
env.Command.Name, len(env.Args), argc-1)
}
args := append(packValues(env, argc-1), reflect.ValueOf(env.Args[argc-1:]))
return unpackError(call(args))
Expand All @@ -100,7 +102,8 @@ func checkAdapt(fn any) (func(*Env) error, error) {
// Case 3: A fixed-positional function.
return func(env *Env) error {
if len(env.Args) != argc {
return env.Usagef("wrong number of arguments: got %d, want %d", len(env.Args), argc)
return env.Usagef("wrong number of arguments for %q: got %d, want %d",
env.Command.Name, len(env.Args), argc)
}
args := packValues(env, argc)
return unpackError(call(args))
Expand Down

0 comments on commit 1c6d122

Please sign in to comment.