usage: if the program supports subcommands, mention it

This commit is contained in:
Marco Molteni 2020-01-19 19:40:53 +01:00
parent 33db14a48b
commit cfd894f446
2 changed files with 8 additions and 1 deletions

View File

@ -193,7 +193,7 @@ func Example_helpTextWithSubcommand() {
MustParse(&args)
// output:
// Usage: example [--verbose]
// Usage: example [--verbose] <command> [<args>]
//
// Options:
// --verbose

View File

@ -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")
}