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
cilium: export intermediate cobra.Commands #26265
Conversation
/test |
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.
@lmb Tx for this PR!
Could be totally out of context here but not sure if I am missing the intent here...
It would be great to highlight some of the use cases this pr would enable to further understand the motivation?
Especially the part about without allowing modifications to individual commands
?
Isn't it the case that if we make these package globals then one can override the entire command structure since cobra exports all the interesting bits?
Especially in light that rootCmd would now be exported.
Am I wrong about that?
The use case is to build a binary which exposes a superset
You can't change arbitrary subcommands from what I can tell (since those are unexported), but other bits are up for grabs, yes! I have two ideas if you think this level of openness is problematic:
type MyCommandType interface{
AddCommand(...)
// Prevent others from implementing the interface. May not be needed.
unexported()
} |
@derailed thoughts? |
After discussing on Slack, it turns out that exporting the root command is equivalent to exporting all cobra commands anyways, due to https://pkg.go.dev/github.com/spf13/cobra#Command.Commands So I think we're not making anything worse by exporting intermediate commands here. |
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.
@lmb LGTM
/test |
Export all cobra.Command which do not have a Run function set. This allows extending the CLI behaviour from outside the package without allowing modifications to individual commands. Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
/test |
Export all cobra.Command which do not have a Run function set. This allows extending the CLI behaviour from outside the package without allowing modifications to individual commands.