-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix: remove NoArgs positional arguments validation #3573
base: main
Are you sure you want to change the base?
fix: remove NoArgs positional arguments validation #3573
Conversation
Signed-off-by: Yashvardhan Kukreja <[email protected]>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yashvardhan-kukreja The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @yashvardhan-kukreja. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
what happen now if I pass arguments that are not going to be used? |
Can you give a more specific example which might be going through your mind? Meanwhile I did try providing unusable args/flag (all of these correlate to "bad" with the present release of KinD) ❯ ./bin/kind get clusters -v3 --a3 -b3 > /dev/null && echo good || echo bad
ERROR: unknown flag: --a3
bad ❯ kind get clusters -v3 --a3 -b3 > /dev/null && echo good || echo bad
ERROR: unknown flag: --a3
bad ❯ ./bin/kind get clust clusters > /dev/null && echo good || echo bad
ERROR: Subcommand is required
bad ❯ ./bin/kind get clusters clust > /dev/null && echo good || echo bad
ERROR: unknown command "clust" for "kind get clusters"
bad |
I'm not familiar enough with cobra, I was wondering what change on behavior is causing the removal of this option |
Sure, let me elaborate on what I found when diggin originally into this issue, which ultimately led to the solution this PR suggests. Cobra calls Here you can see the A more graceful way would have been to already have a Finally, it would have been much nicer if cobra returned an error here instead of just returning a (It almost looks like a bug/mistake to me that they added a |
The only change I noticed was the change in how things were logged when wrong subcommands were provided. Previously, But after this PR, any wrong subcommands would fail much before i.e. here only Also, Any non-leaf commands provided with unknown arguments or no arguments will lead to a different error For example: Old behaviour of KinD ❯ kind get clust x > /dev/null && echo good || echo bad
ERROR: unknown command "clust" for "kind get"
bad New behaviour of KinD ❯ ./bin/kind get clust x > /dev/null && echo good || echo bad
ERROR: Subcommand is required
bad And, any leaf subcommands like For example ❯ kind get clusters cl
ERROR: unknown command "cl" for "kind get clusters" New behaviour of KinD ❯ ./bin/kind get clusters cl
ERROR: unknown command "cl" for "kind get clusters" |
@aojea mind taking a look at this once you get free? |
In this case, being less explicit does seem to be the better option so we get the appropriate non-zero return code. /lgtm |
fixes #3466