cmd: Expand cobra support, add short flags#5379
Merged
Conversation
8753b2a to
7bafa9d
Compare
7bafa9d to
e1f8531
Compare
emilylange
suggested changes
Feb 17, 2023
Co-authored-by: Emily Lange <[email protected]>
mholt
requested changes
Feb 24, 2023
Member
mholt
left a comment
There was a problem hiding this comment.
Thanks for this change!
Overall I like it. I wish we didn't have to hack in the Cobra API like that, but oh well.
I made many suggestions regarding short flags. I lean toward what you suggested: let's start with fewer short flags, until we determine where additional ones would be useful. I suggested removing them on the less-common flags, or ones where there was a difficult conflict and where I could see multiple different letters being good options, or where a clear choice wasn't obvious.
Hope that's OK. Let me know what you think!
Co-authored-by: Matt Holt <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We've had Cobra in for a few versions now, and it's worked pretty well. Now, it's time to make it possible to use more of its features.
For that, I'm adding a new CobraFunc field to
caddycmd.Commandwhich allows configuring the command using the full power of Cobra's APIs while keeping backwards compatibility and ergonomics of ourRegisterCommandsetup.In addition, I ported every built-in command to use this new API (making sure commands still worked after the first commit), and added shorthands for most flags. Some of them are a bit funky due to the english language only having so many letters in the alphabet, but I think it should be reasonable. Let me know if you find any of them too weird. We could also just play it safe and enable less shorthands to start, not to paint ourselves into a corner with exhausting letters ahead of time 😂