Skip to content

Commit ad99c53

Browse files
committed
Show 'correct' explicit bool value syntax in help
1 parent be274af commit ad99c53

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

flag.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,16 @@ func (f *FlagSet) FlagUsagesWrapped(cols int) string {
723723
}
724724

725725
varname, usage := UnquoteUsage(flag)
726-
if varname != "" {
726+
if flag.Value.Type() == "bool" {
727+
if varname != "" {
728+
line += "[=" + varname + "]"
729+
} else {
730+
line += "[=value]"
731+
}
732+
} else if varname != "" {
727733
line += " " + varname
728734
}
735+
729736
if flag.NoOptDefVal != "" {
730737
switch flag.Value.Type() {
731738
case "string":

flag_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,9 +1271,9 @@ func TestHiddenFlagUsage(t *testing.T) {
12711271
}
12721272
}
12731273

1274-
const defaultOutput = ` --A for bootstrapping, allow 'any' type
1275-
--Alongflagname disable bounds checking
1276-
-C, --CCC a boolean defaulting to true (default true)
1274+
const defaultOutput = ` --A[=value] for bootstrapping, allow 'any' type
1275+
--Alongflagname[=value] disable bounds checking
1276+
-C, --CCC[=value] a boolean defaulting to true (default true)
12771277
--D path set relative path for local imports
12781278
-E, --EEE num[=1234] a num with NoOptDefVal (default 4321)
12791279
--F number a non-zero number (default 2.7)

printusage_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"testing"
77
)
88

9-
const expectedOutput = ` --long-form Some description
10-
--long-form2 Some description
11-
with multiline
12-
-s, --long-name Some description
13-
-t, --long-name2 Some description with
14-
multiline
9+
const expectedOutput = ` --long-form[=value] Some description
10+
--long-form2[=value] Some description
11+
with multiline
12+
-s, --long-name[=value] Some description
13+
-t, --long-name2[=value] Some description with
14+
multiline
1515
`
1616

1717
func setUpPFlagSet(buf io.Writer) *FlagSet {
@@ -47,11 +47,11 @@ func setUpPFlagSet2(buf io.Writer) *FlagSet {
4747
return f
4848
}
4949

50-
const expectedOutput2 = ` --long-form Some description
51-
--long-form2 Some description
50+
const expectedOutput2 = ` --long-form[=value] Some description
51+
--long-form2[=value] Some description
5252
with multiline
53-
-s, --long-name Some description
54-
-t, --long-name2 Some description with
53+
-s, --long-name[=value] Some description
54+
-t, --long-name2[=value] Some description with
5555
multiline
5656
-o, --other-very-long-arg string Some very long description having
5757
break the limit (default

0 commit comments

Comments
 (0)