-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpk: add error for unknown command execution #18650
Conversation
Cobra won't recognize unknown commands unless cobra.NoArg is set as an Arg validation parameter in the command definition. This means that running 'rpk cluster unknowncommand' won't return a 'unknown command' error, therefore, exit as a successful command execution. Now, cobra will return an 'unknown error' and exit with code 1.
Another option rather than walking is to add a test that fails if Args is empty. <-This may be better for the future, to enforce at code-writing-time that all new commands have Args carefully chosen to be NoArgs vs. something else. |
But this is good too |
Going ahead with this one since adding a test like this would force commands with optional arguments to have: cobra.MinimumArgs(0) which can be confusing. We can revisit this back in the future since adding it would be fairly easy. |
/backport v24.1.x |
In redpanda-data#18650 we added Arg validations for every comman and an automatic "walk" through the command space to add cobra.NoArgs. Plugins were not taken into account, this commit explicitly set the cobra.MinimumArg(0) to avoid adding "NoArgs" on execution.
In redpanda-data#18650 we added Arg validations for every comman and an automatic "walk" through the command space to add cobra.NoArgs. Plugins were not taken into account, this commit explicitly set the cobra.MinimumArg(0) to avoid adding "NoArgs" on execution. (cherry picked from commit 0c9a20b)
In redpanda-data#18650 we added Arg validations for every comman and an automatic "walk" through the command space to add cobra.NoArgs. Plugins were not taken into account, this commit explicitly set the cobra.MinimumArg(0) to avoid adding "NoArgs" on execution.
In redpanda-data#18650 we added Arg validations for every comman and an automatic "walk" through the command space to add cobra.NoArgs. Plugins were not taken into account, this commit explicitly set the cobra.MinimumArg(0) to avoid adding "NoArgs" on execution.
In redpanda-data#18650 we added Arg validations for every comman and an automatic "walk" through the command space to add cobra.NoArgs. Plugins were not taken into account, this commit explicitly set the cobra.MinimumArg(0) to avoid adding "NoArgs" on execution.
Cobra won't recognize unknown commands unless
cobra.NoArg is set as an Arg validation parameter
in the command definition.
This means that running 'rpk cluster unknowncommand'
won't return an 'unknown command' error, therefore,
exit as a successful command execution.
See: spf13/cobra#706
Now, cobra will return an 'unknown error' and exit
with code 1.
Fixes #18627
Backports Required
Release Notes
Improvements