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

Allow for command line argument groups #36

Closed
nderjung opened this issue Jul 23, 2022 · 2 comments
Closed

Allow for command line argument groups #36

nderjung opened this issue Jul 23, 2022 · 2 comments
Assignees
Labels
good-first-issue Good for newcomers kind/enhancement New feature or request

Comments

@nderjung
Copy link
Member

nderjung commented Jul 23, 2022

This issue tracks the ability to add command line argument groups. This is useful to help displaly information on any invocation of the --help flag and to show flags which are part of either a common area, subsystem or category.

For example, all configuration options for KraftKit should be grouped together (see #35) as "global options".

// TODO: Introduce flag groupings (e.g. "Global Flags" and "Subcommand Flags")
flagUsages := command.LocalFlags().FlagUsagesWrapped(80)
if flagUsages != "" {
command.Println("\n\nFlags:")
command.Print(text.Indent(dedent(flagUsages), " "))
}

@nderjung nderjung added good-first-issue Good for newcomers kind/enhancement New feature or request labels Jul 23, 2022
@gabrielmocanu
Copy link
Member

For this one, we should have something similar with this?

@nderjung
Copy link
Member Author

nderjung commented Jul 27, 2022

The output should look similar to this, yes. :D

You can use pflag.SetAnnotation against a flag to attribute it to a group:

https://github.com/spf13/pflag/blob/85dd5c8bc61cfa382fecd072378089d4e856579d/flag.go#L497-L511

to annotate a flag against a group alias name. E.g. the annotation group:global would be the annotation and the "key" would be "global". When the help command is invoked, the key could be looked up against an index of group names, where "global" would correspond to the string "Global flags".

Not sure where group names should be saved though. Perhaps it should be possible via the cmdutil library to register a new group, e.g. a publicaly exposed API cmdutil.RegisterNewFlagGroup(key, title string) which saves to a local variable map which is then referenced (in the same vein as cmdutil.RegisterFlag).

nderjung added a commit to nderjung/kraftkit that referenced this issue Nov 30, 2022
This commit allows us to specify which group a subcommand belongs to
which allows for an easier-to-navigate help command output.  For now, 3
groups are provided: "build", "pkg" and "run" which display a set of
subcommands (and sub-sub-commands) which are part of the same group.  A
modificaiton to all current subcommand programs in KraftKit are made,
using this new system based on cobra's annotation system.

GitHub-Fixes: unikraft#36
Signed-off-by: Alexander Jung <alex@unikraft.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue Good for newcomers kind/enhancement New feature or request
Projects
Status: 🚀 Done
Development

No branches or pull requests

2 participants