-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 vtctldclient
's Root command to return an error on unknown command
#12481
Fix vtctldclient
's Root command to return an error on unknown command
#12481
Conversation
… unknown command Closes vitessio#12480. Signed-off-by: Andrew Mason <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
If a new flag is being introduced:
If a workflow is added or modified:
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test to verify that it indeed returns an error?
Signed-off-by: Andrew Mason <[email protected]>
Done! |
Sweet! 🥇 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
// From this we conclude that the user was trying to either run a | ||
// command that doesn't exist (e.g. "vtctldclient delete-my-data") or | ||
// has misspelled a legitimate command (e.g. "vtctldclient StapReplication"). | ||
// If we think this has happened, return an error, which will get | ||
// displayed to the user in main.go along with the usage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not something that I'm suggesting we bring in here but we could at some point use the "did you mean X" functionality that cobra provides via the command.SuggestionsMinimumDistance = X
option. Maybe you explored it and there were downsides?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i never explored it but i definitely want to at some point!
Signed-off-by: Andrew Mason <[email protected]>
I was unable to backport this Pull Request to the following branches: |
…nd (vitessio#12481) * Add a Run func to `vtctldclient`'s Root command to return an error on unknown command Closes vitessio#12480. Signed-off-by: Andrew Mason <[email protected]> * Add test Signed-off-by: Andrew Mason <[email protected]> * flags test data Signed-off-by: Andrew Mason <[email protected]> --------- Signed-off-by: Andrew Mason <[email protected]>
…nd (vitessio#12481) * Add a Run func to `vtctldclient`'s Root command to return an error on unknown command Closes vitessio#12480. Signed-off-by: Andrew Mason <[email protected]> * Add test Signed-off-by: Andrew Mason <[email protected]> * flags test data Signed-off-by: Andrew Mason <[email protected]> --------- Signed-off-by: Andrew Mason <[email protected]>
…nd (#12481) (#12532) * Add a Run func to `vtctldclient`'s Root command to return an error on unknown command Closes #12480. * Add test * flags test data --------- Signed-off-by: Andrew Mason <[email protected]>
…nd (#12481) (#12531) * Add a Run func to `vtctldclient`'s Root command to return an error on unknown command Closes #12480. * Add test * flags test data --------- Signed-off-by: Andrew Mason <[email protected]>
Description
Add a Run func to
vtctldclient
's Root command to return an error on unknown command.Cobra can't (and shouldn't!) be distinguish between "we didn't find a subcommand because the user made an error" and "we didn't find a subcommand because the user is trying to invoke a parent command with positional arguments", so we specify a run function (what cobra invokes when executing the command) on the root (top-level parent) and check if there are any positional arguments, which in our case we assume means the user was trying to run a subcommand that doesn't exist.
Related Issue(s)
Closes #12480.
Checklist
Deployment Notes