diff options
| author | Marco Molteni <[email protected]> | 2020-01-19 19:40:53 +0100 |
|---|---|---|
| committer | Marco Molteni <[email protected]> | 2020-01-19 19:40:53 +0100 |
| commit | cfd894f446f356ed1c0fb37d88aee8c34bb4e40c (patch) | |
| tree | 007b6c8a2ef3ff41729dbd6b165dfea4dae3cb91 | |
| parent | 33db14a48bf1893422ba8ee2f0b898760a9d1737 (diff) | |
usage: if the program supports subcommands, mention it
| -rw-r--r-- | example_test.go | 2 | ||||
| -rw-r--r-- | usage.go | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/example_test.go b/example_test.go index ea123e4..be3cd12 100644 --- a/example_test.go +++ b/example_test.go @@ -193,7 +193,7 @@ func Example_helpTextWithSubcommand() { MustParse(&args) // output: - // Usage: example [--verbose] + // Usage: example [--verbose] <command> [<args>] // // Options: // --verbose @@ -88,6 +88,13 @@ func (p *Parser) writeUsageForCommand(w io.Writer, cmd *command) { fmt.Fprint(w, spec.placeholder) } } + + // if the program supports subcommands and the command-line doesn't contain any, + // give a hint to the user about the existence of these subcommands. + if len(p.cmd.subcommands) > 0 && p.cmd == cmd { + fmt.Fprint(w, " <command> [<args>]") + } + fmt.Fprint(w, "\n") } |
