docopt / docopt.go

A command-line arguments parser that will make you smile.
http://docopt.org/
MIT License
1.43k stars 111 forks source link

Parse docopt even if no args are passed #72

Open kindermax opened 4 years ago

kindermax commented 4 years ago

Hi. I am looking for a future to parse docopt even if no args were given for parser.

Real use-case - I want to get all flags (by flag I mean all options a command can receive) and use them in autocomplete.

Basically I need only keys from opts map[string]interface{} map of flags. I then filter them as I need.

Example:

doc = `Usage: somecli run [--debug] [--config=<config>] <app>
Options:
  --debug                   Run app with debug
  --config=<config>         Run with a config file
  <app>                     An app to run
`
onlyFlage := true
opts, err := docopt.ParseDoc(doc, onlyFlags)

The values of flags doesn't matter in this case and can be default values (bool, empty string, nil, etc)

I am ready to implement this feature if you are okay with an idea. Thanks!