Skip to content

cmd: Expand cobra support, add short flags#5379

Merged
mholt merged 5 commits intomasterfrom
expand-cobra-support
Feb 24, 2023
Merged

cmd: Expand cobra support, add short flags#5379
mholt merged 5 commits intomasterfrom
expand-cobra-support

Conversation

@francislavoie
Copy link
Copy Markdown
Member

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.Command which allows configuring the command using the full power of Cobra's APIs while keeping backwards compatibility and ergonomics of our RegisterCommand setup.

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 😂

@francislavoie francislavoie added the feature ⚙️ New feature or request label Feb 17, 2023
@francislavoie francislavoie added this to the v2.7.0 milestone Feb 17, 2023
Comment thread cmd/commands.go Outdated
Co-authored-by: Emily Lange <[email protected]>
Copy link
Copy Markdown
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment thread cmd/commands.go Outdated
Comment thread cmd/commands.go Outdated
Comment thread cmd/commands.go Outdated
Comment thread cmd/commands.go Outdated
Comment thread cmd/commands.go Outdated
Comment thread modules/caddyhttp/staticresp.go
Comment thread modules/caddypki/command.go Outdated
Comment thread modules/caddypki/command.go Outdated
Comment thread modules/caddypki/command.go Outdated
Comment thread modules/caddypki/command.go Outdated
@francislavoie francislavoie requested a review from mholt February 24, 2023 19:42
Copy link
Copy Markdown
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

@mholt mholt merged commit 9e69195 into master Feb 24, 2023
@mholt mholt deleted the expand-cobra-support branch February 24, 2023 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants