Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,12 @@ func (f *FlagSet) FlagUsagesWrapped(cols int) string {
}

varname, usage := UnquoteUsage(flag)
if varname != "" {
if flag.Value.Type() == "bool" {
line += "[=true|false]"
} else if varname != "" {
line += " " + varname
}

if flag.NoOptDefVal != "" {
switch flag.Value.Type() {
case "string":
Expand Down
44 changes: 22 additions & 22 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1271,28 +1271,28 @@ func TestHiddenFlagUsage(t *testing.T) {
}
}

const defaultOutput = ` --A for bootstrapping, allow 'any' type
--Alongflagname disable bounds checking
-C, --CCC a boolean defaulting to true (default true)
--D path set relative path for local imports
-E, --EEE num[=1234] a num with NoOptDefVal (default 4321)
--F number a non-zero number (default 2.7)
--G float a float that defaults to zero
--IP ip IP address with no default
--IPMask ipMask Netmask address with no default
--IPNet ipNet IP network with no default
--Ints ints int slice with zero default
--N int a non-zero int (default 27)
--ND1 string[="bar"] a string with NoOptDefVal (default "foo")
--ND2 num[=4321] a num with NoOptDefVal (default 1234)
--StringArray stringArray string array with zero default
--StringSlice strings string slice with zero default
--Z int an int that defaults to zero
--custom custom custom Value implementation
--custom-with-val custom custom value which has been set from command line while help is shown
--customP custom a VarP with default (default 10)
--maxT timeout set timeout for dial
-v, --verbose count verbosity
const defaultOutput = ` --A[=true|false] for bootstrapping, allow 'any' type
--Alongflagname[=true|false] disable bounds checking
-C, --CCC[=true|false] a boolean defaulting to true (default true)
--D path set relative path for local imports
-E, --EEE num[=1234] a num with NoOptDefVal (default 4321)
--F number a non-zero number (default 2.7)
--G float a float that defaults to zero
--IP ip IP address with no default
--IPMask ipMask Netmask address with no default
--IPNet ipNet IP network with no default
--Ints ints int slice with zero default
--N int a non-zero int (default 27)
--ND1 string[="bar"] a string with NoOptDefVal (default "foo")
--ND2 num[=4321] a num with NoOptDefVal (default 1234)
--StringArray stringArray string array with zero default
--StringSlice strings string slice with zero default
--Z int an int that defaults to zero
--custom custom custom Value implementation
--custom-with-val custom custom value which has been set from command line while help is shown
--customP custom a VarP with default (default 10)
--maxT timeout set timeout for dial
-v, --verbose count verbosity
`

// Custom value that satisfies the Value interface.
Expand Down
22 changes: 11 additions & 11 deletions printusage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"testing"
)

const expectedOutput = ` --long-form Some description
--long-form2 Some description
with multiline
-s, --long-name Some description
-t, --long-name2 Some description with
multiline
const expectedOutput = ` --long-form[=true|false] Some description
--long-form2[=true|false] Some description
with multiline
-s, --long-name[=true|false] Some description
-t, --long-name2[=true|false] Some description with
multiline
`

func setUpPFlagSet(buf io.Writer) *FlagSet {
Expand Down Expand Up @@ -47,11 +47,11 @@ func setUpPFlagSet2(buf io.Writer) *FlagSet {
return f
}

const expectedOutput2 = ` --long-form Some description
--long-form2 Some description
const expectedOutput2 = ` --long-form[=true|false] Some description
--long-form2[=true|false] Some description
with multiline
-s, --long-name Some description
-t, --long-name2 Some description with
-s, --long-name[=true|false] Some description
-t, --long-name2[=true|false] Some description with
multiline
-o, --other-very-long-arg string Some very long description having
break the limit (default
Expand All @@ -69,6 +69,6 @@ func TestPrintUsage_2(t *testing.T) {
f := setUpPFlagSet2(&buf)
res := f.FlagUsagesWrapped(80)
if res != expectedOutput2 {
t.Errorf("Expected \n%q \nActual \n%q", expectedOutput2, res)
t.Errorf("Expected \n%s \nActual \n%s", expectedOutput2, res)
}
}
Loading