hashicorp / hcp

HCP Command-Line Interface
Mozilla Public License 2.0
8 stars 0 forks source link

Feature: Group flags by feature (essentially FlagSets) #12

Open briancain opened 4 months ago

briancain commented 4 months ago

Currently, there's no way in this project to define group flags in a command where flags are related. For example, with mitchell/cli you could define groups of flags known as FlagSets so the help shows them together as related fields.

With the current project, it groups all flags as equal under FLAGS. Any commands that take a lot of options will become pretty messy and hard to understand what is related to what without grouping flags.

brian@brian-LNQ0KYW6HD:hcp λ ./bin/hcp waypoint action-config create -help ±[●][waypoint/add-action-config-cli]
USAGE
  hcp waypoint action-config create [Optional Flags]

DESCRIPTION
  Create a new action configuration.

FLAGS
  -d, --description
    The description of the action configuration.

  -n, --name
    The name of the action configuration.

  -u, --url
    The URL of the action configuration.

  -x, --example-feature-1
    My cool feature unrelated to the other thing.

  -y, --example-feature-A
    My cool feature unrelated to the other thing.

GLOBAL FLAGS
  --format=FORMAT, --profile=NAME, --project=ID, --quiet

  For more global flag details, run $ hcp --help

With flag sets, help becomes much more useful:

brian@brian-LNQ0KYW6HD:hcp λ ./bin/hcp waypoint action-config create -help ±[●][waypoint/add-action-config-cli]
USAGE
  hcp waypoint action-config create [Optional Flags]

DESCRIPTION
  Create a new action configuration.

FLAGS
  -d, --description
    The description of the action configuration.

  -n, --name
    The name of the action configuration.

CUSTOM REQUEST FLAGS
  -u, --url
    The URL of the action configuration.

FEATURE 1 FLAGS

  -x, --example-feature-1
    My cool feature unrelated to the other thing.

FEATURE 2 FLAGS

  -y, --example-feature-A
    My cool feature unrelated to the other thing.

GLOBAL FLAGS
  --format=FORMAT, --profile=NAME, --project=ID, --quiet

  For more global flag details, run $ hcp --help

This CLI project should support FlagSets so that commands with lots of configurations can group flags together for easier understanding.

dadgar commented 4 months ago

How would you imagine capturing required vs non required. I was planning on having flag groups live under the respective categories that exist today.

USAGE
  hcp waypoint action-config create [Optional Flags]

DESCRIPTION
  Create a new action configuration.

REQUIRED FLAGS
  -d, --description
    The description of the action configuration.

  -n, --name
    The name of the action configuration.

OPTIONAL FLAGS
  -u, --url
    The URL of the action configuration.

  Flags for example Feature 1:

  -x, --example-feature-1
    My cool feature unrelated to the other thing.

  -y, --example-feature-A
    My cool feature unrelated to the other thing.

GLOBAL FLAGS
  --format=FORMAT, --profile=NAME, --project=ID, --quiet

  For more global flag details, run $ hcp --help

Thoughts?

briancain commented 4 months ago

In all honesty I'd probably do whatever mitchell/cli or spf13/cobra does since they are pretty established CLI tools 😅 Just based on what I've experienced, I think I'd expect to see a Required string on the flag description, maybe after the flag definition.

  -n, --name
    The name of the action configuration. (Required, Defaults to "example")

You could also show required flags by auto-generating the usage and auto-including required flags

USAGE
  hcp waypoint action-config create -name="your-action-name" [Optional Flags]