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

Separate subcommand flags from global flags #68

Open
freb opened this issue May 14, 2020 · 1 comment
Open

Separate subcommand flags from global flags #68

freb opened this issue May 14, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@freb
Copy link

freb commented May 14, 2020

I asked about this on the slack channel a while back. Since it is one of only two issues I have with flaggy, I thought I'd ask about it here.

When exploring a CLI program I start by viewing the help at the root command, I figure out which subcommand I want to use, then I view its available options. Currently in the help output flaggy groups all flags together in the Flags section. It is often difficult to figure out which flags apply specifically to the subcommand, especially when you have many global flags.

This is the default output:

go run main.go policy delete mypolicy -h
delete

  Usage:
    delete [policy_name]

  Positional Variables: 
    policy_name   (Required)

  Flags: 
       --version      Displays the program version string.
    -h --help         Displays help with available flag, subcommand, and positional value parameters.
    -a --associated-data   also delete associated data
       --addr         address of server

I'd like to see something like this instead:

delete

  Usage:
    delete [policy_name]

  Positional Variables: 
    policy_name   (Required)

  Subcommand Flags:
    -a --associated-data   also delete associated data

  Flags: 
       --version      Displays the program version string.
    -h --help         Displays help with available flag, subcommand, and positional value parameters.
       --addr         address of server

Here is some output from the Dgraph command line, which I believe uses Cobra. The root help shows a Flags section, but the help for a subcommand moves that flags section to Global Flags and uses the Flags section for the subcommand:

> $ dgraph acl --help
[Decoder]: Using assembly version of decoder
Run the Dgraph acl tool

Usage:
  dgraph acl [command]

Available Commands:
  add         Run Dgraph acl tool to add a user or group
  del         Run Dgraph acl tool to delete a user or group
  info        Show info about a user or group
  mod         Run Dgraph acl tool to modify a user's password, a user's group list, or agroup's predicate permissions

Flags:
  -a, --alpha string               Dgraph Alpha gRPC server address (default "127.0.0.1:9080")
  -h, --help                       help for acl
      --tls_cacert string          The CA Cert file used to verify server certificates.
      --tls_use_system_ca          Include System CA into CA Certs. (default true)

Global Flags:
      --alsologtostderr                  log to standard error as well as files
      --bindall                          Use 0.0.0.0 instead of localhost to bind to all addresses on local machine. (default true)
      --block_rate int                   Block profiling rate. Must be used along with block profile_mode
      --config string                    Configuration file.

Use "dgraph acl [command] --help" for more information about a command.

It's been a while since I've dug into the code. I'm curious if the required information is available to do this in a template (which I don't think it is). And how hard you think it would be make that expose that to the help template.

@integrii
Copy link
Owner

This looks really useful and should be do-able by simply adding some more metadata to our flags and editing the default help template.

@integrii integrii added the enhancement New feature or request label Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants