fix(args): suggest alternatives for the invalid arg, not the first one
OnlyValidArgs reports the offending argument correctly ("invalid
argument %q") but computed the "Did you mean this?" suggestion from
args[0]. When the invalid argument is not the first one, the suggestion
was therefore based on an unrelated (valid) argument, so it was missing
or pointed at the wrong token.
Compute the suggestion from the argument actually being reported, so it
always matches the invalid argument regardless of its position.
This commit is contained in:
1 parent
53d1818651
commit
3caf507246
2 files changed
+26
-1
No files matched your search
@@ -58,7 +58,7 @@ func OnlyValidArgs(cmd *Command, args []string) error {
|
||||
}
|
||||
for _, v := range args {
|
||||
if !stringInSlice(v, validArgs) {
|
||||
return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0]))
|
||||
return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user