Skip to content

Commit 3927b71

Browse files
authored
Merge pull request #342 from sv99/help-pos-required
Help for positional args without allcmd.ArgsRequired dependent from arg.Required
2 parents 4d0b7bb + 0259d21 commit 3927b71

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

help.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ func (p *Parser) WriteHelp(writer io.Writer) {
334334
}
335335

336336
if !allcmd.ArgsRequired {
337-
fmt.Fprintf(wr, "[%s]", name)
337+
if arg.Required > 0 {
338+
fmt.Fprintf(wr, "%s", name)
339+
} else {
340+
fmt.Fprintf(wr, "[%s]", name)
341+
}
338342
} else {
339343
fmt.Fprintf(wr, "%s", name)
340344
}

help_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestHelp(t *testing.T) {
107107

108108
if runtime.GOOS == "windows" {
109109
expected = `Usage:
110-
TestHelp [OPTIONS] [filename] [num] [hidden-in-help] <bommand | command | parent>
110+
TestHelp [OPTIONS] [filename] [num] hidden-in-help <bommand | command | parent>
111111
112112
Application Options:
113113
/v, /verbose Show verbose debug information
@@ -156,7 +156,7 @@ Available commands:
156156
`
157157
} else {
158158
expected = `Usage:
159-
TestHelp [OPTIONS] [filename] [num] [hidden-in-help] <bommand | command | parent>
159+
TestHelp [OPTIONS] [filename] [num] hidden-in-help <bommand | command | parent>
160160
161161
Application Options:
162162
-v, --verbose Show verbose debug information

0 commit comments

Comments
 (0)