Skip to content

Commit

Permalink
Merge pull request #104 from marco-m/subcommands-usage-simple
Browse files Browse the repository at this point in the history
Subcommands usage simple
  • Loading branch information
alexflint authored Jan 23, 2020
2 parents ced05bf + 9f55226 commit f5d3733
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func Example_helpTextWithSubcommand() {
MustParse(&args)

// output:
// Usage: example [--verbose]
// Usage: example [--verbose] <command> [<args>]
//
// Options:
// --verbose
Expand Down
2 changes: 1 addition & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit f5d3733

Please sign in to comment.