Merge pull request #104 from marco-m/subcommands-usage-simple

Subcommands usage simple
This commit is contained in:
Alex Flint 2020-01-23 11:07:40 -08:00 committed by GitHub
commit f5d3733c0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 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

@ -129,7 +129,7 @@ type Parser struct {
version string
description string
// the following fields change curing processing of command line arguments
// the following field changes during processing of command line arguments
lastCmd *command
}

View File

@ -88,6 +88,12 @@ func (p *Parser) writeUsageForCommand(w io.Writer, cmd *command) {
fmt.Fprint(w, spec.placeholder)
}
}
// if the program supports subcommands, give a hint to the user about their existence
if len(cmd.subcommands) > 0 {
fmt.Fprint(w, " <command> [<args>]")
}
fmt.Fprint(w, "\n")
}