Skip to content
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

cmd: Expand cobra support, add short flags #5379

Merged
merged 5 commits into from
Feb 24, 2023
Merged

Conversation

francislavoie
Copy link
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
cmd/commands.go Outdated Show resolved Hide resolved
Co-authored-by: Emily Lange <[email protected]>
Copy link
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!

cmd/commands.go Outdated Show resolved Hide resolved
cmd/commands.go Outdated Show resolved Hide resolved
cmd/commands.go Outdated Show resolved Hide resolved
cmd/commands.go Outdated Show resolved Hide resolved
cmd/commands.go Outdated Show resolved Hide resolved
modules/caddyhttp/staticresp.go Show resolved Hide resolved
modules/caddypki/command.go Outdated Show resolved Hide resolved
modules/caddypki/command.go Outdated Show resolved Hide resolved
modules/caddypki/command.go Outdated Show resolved Hide resolved
modules/caddypki/command.go Outdated Show resolved Hide resolved
Copy link
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