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

Support variable categories #14

Open
stevenroose opened this issue Nov 20, 2017 · 1 comment
Open

Support variable categories #14

stevenroose opened this issue Nov 20, 2017 · 1 comment

Comments

@stevenroose
Copy link
Owner

I was thinking it would be nice to have support for categories. Especially for the --help output.

The problem, however, is that pflag does not support them right now and we rely on them to generate the usage string: https://github.com/spf13/pflag/blob/master/flag.go#L649

I thought about refactoring that function in pflag to an auxiliary one that returns the individual lines in a []string and then grouping and formatting ourselves from there.

@stevenroose
Copy link
Owner Author

e609545 implements our own help printing function.

I'm wondering how variable categories could be implemented.

First of all, a HelpCategoriesForStructs would allow a 1-line header for a set of flags that is nested in a struct. Like this:

var config = struct {
	IntVar int `id:"intvar" desc:"some random integer" default:"42"`
	DbVars struct {
		Name string `id:"name" desc:"database name"`
		User string `id:"user" desc:"database user"`
	} `id:"db" desc:"Database variables"`
}{}

The current output

Usage of test:
      --intvar int       some random integer (default 42)
      --db.name string   database name
      --db.user string   database user
  -h, --help             print this help menu

Could become then something like this:

Usage of test:
      --intvar int       some random integer (default 42)

Database variables:
      --db.name string   database name
      --db.user string   database user

  -h, --help             print this help menu

A second approach could be to allow more control f.e. with a cat:"db" in the tag and then a HelpCategories map[string]string option in the config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant