Skip to content

Commit

Permalink
Merge pull request #342 from sv99/help-pos-required
Browse files Browse the repository at this point in the history
Help for positional args without allcmd.ArgsRequired dependent from arg.Required
  • Loading branch information
jessevdk authored Jun 7, 2021
2 parents 4d0b7bb + 0259d21 commit 3927b71
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion help.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ func (p *Parser) WriteHelp(writer io.Writer) {
}

if !allcmd.ArgsRequired {
fmt.Fprintf(wr, "[%s]", name)
if arg.Required > 0 {
fmt.Fprintf(wr, "%s", name)
} else {
fmt.Fprintf(wr, "[%s]", name)
}
} else {
fmt.Fprintf(wr, "%s", name)
}
Expand Down
4 changes: 2 additions & 2 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestHelp(t *testing.T) {

if runtime.GOOS == "windows" {
expected = `Usage:
TestHelp [OPTIONS] [filename] [num] [hidden-in-help] <bommand | command | parent>
TestHelp [OPTIONS] [filename] [num] hidden-in-help <bommand | command | parent>
Application Options:
/v, /verbose Show verbose debug information
Expand Down Expand Up @@ -156,7 +156,7 @@ Available commands:
`
} else {
expected = `Usage:
TestHelp [OPTIONS] [filename] [num] [hidden-in-help] <bommand | command | parent>
TestHelp [OPTIONS] [filename] [num] hidden-in-help <bommand | command | parent>
Application Options:
-v, --verbose Show verbose debug information
Expand Down

0 comments on commit 3927b71

Please sign in to comment.