-
Notifications
You must be signed in to change notification settings - Fork 4
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
Group glazed flags together in cobra help section #59
Comments
Link to cobra topic here: spf13/cobra#1327 |
See also this for command groups, just out of curiosity: spf13/cobra#1003 |
See that flags can be marked as required in groups, which is interesting: https://github.com/spf13/cobra/releases |
Here's an actual implementation of flag groups: aquasecurity/trivy#2488 |
The implementation in trivy uses each cobra.Command to call SetUsageTemplate, and fills in the help for its flags straight in there. We could do two things, we could have each command to the same, passing in some glazed structure with the ParameterDefinitionGroups of some sort, which then also calls AddFlags, or we could have the HelpSystem UsageFunc do the lookup itself. |
There's also the fact that we can set the Annotations of a cobra command to stuff we can use to our leisure. For example, the rendered flags help. |
See func GetCobraHelpUsageFuncs(hs *HelpSystem) (HelpFunc, UsageFunc) {
helpFunc := func(c *cobra.Command, args []string) {
qb := NewSectionQuery().
ReturnAllTypes()
options := &RenderOptions{
Query: qb,
ShowAllSections: false,
ShowShortTopic: false,
HelpCommand: c.Root().CommandPath() + " help",
}
cobra.CheckErr(renderCommandHelpPage(c, options, hs))
}
usageFunc := func(c *cobra.Command) error {
qb := NewSectionQuery().
ReturnExamples()
options := &RenderOptions{
Query: qb,
ShowAllSections: false,
ShowShortTopic: true,
HelpCommand: c.Root().CommandPath() + " help",
}
// TODO(manuel, 2023-02-19) Here is where we would compute grouped flags
// See #59
return renderCommandHelpPage(c, options, hs)
}
return helpFunc, usageFunc
} |
One way could be to use flagGroup:XXX annotations. I think this is actually quite a slick solutions, as it allows for the most flexibility. |
When adding all the glazed flags to normal commands, the actual relevant flags for the command get drowned out in the noise:
The text was updated successfully, but these errors were encountered: