docopt / docopt.go

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

Printing the entire usage string when running command without parameters #39

Closed c4milo closed 6 years ago

c4milo commented 7 years ago

Is there a way to print the entire usage string as opposed to only the Usage section parsed by docopt?

aviddiviner commented 7 years ago

This is possible on a fork that I have: https://github.com/aviddiviner/docopt-go#api

You can do it by setting a custom HelpHandler as follows:

usage := `...`

parser := &docopt.Parser{
  HelpHandler: func(err error, short string) {
    fmt.Fprintln(os.Stderr, usage)  // Print full usage every time.
    os.Exit(0)
  },
}
opts, err := parser.ParseArgs(usage, argv, "")

flag, _ := opts.Bool("--flag")
secs, _ := opts.Int("<seconds>")