@@ -75,7 +75,7 @@ func TestBoolFuncCompat(t *testing.T) {
7575 args := []string {"--bflag" , "--bflag=false" , "--bflag=1" , "--bflag=bar" , "--bflag=" }
7676
7777 // It turns out that, even though the function is called "BoolFunc",
78- // the stanard flag package does not try to parse the value assigned to
78+ // the standard flag package does not try to parse the value assigned to
7979 // that cli flag as a boolean. The string provided on the command line is
8080 // passed as is to the callback.
8181 // e.g: with "--bflag=not_a_bool" on the command line, the FlagSet does not
@@ -106,7 +106,7 @@ func TestBoolFuncCompat(t *testing.T) {
106106 flagName := "bflag"
107107 args := []string {"--bflag" , "--bflag=err" , "--bflag=after" }
108108
109- // test behavior of standard flag.Fset with an error triggere by the callback:
109+ // test behavior of standard flag.Fset with an error triggered by the callback:
110110 // (note: as can be seen in 'runCase()', if the callback sees "err" as a value
111111 // for the bool flag, it will return an error)
112112 stdFSet := flag .NewFlagSet ("std test" , flag .ContinueOnError )
@@ -145,3 +145,33 @@ func TestBoolFuncCompat(t *testing.T) {
145145 }
146146 })
147147}
148+
149+ func TestBoolFuncUsage (t * testing.T ) {
150+ t .Run ("regular func flag" , func (t * testing.T ) {
151+ // regular boolfunc flag:
152+ // expect to see '--flag1' followed by the usageMessage, and no mention of a default value
153+ fset := NewFlagSet ("unittest" , ContinueOnError )
154+ fset .BoolFunc ("flag1" , "usage message" , func (s string ) error { return nil })
155+ usage := fset .FlagUsagesWrapped (80 )
156+
157+ usage = strings .TrimSpace (usage )
158+ expected := "--flag1 usage message"
159+ if usage != expected {
160+ t .Fatalf ("unexpected generated usage message\n expected: %s\n got: %s" , expected , usage )
161+ }
162+ })
163+
164+ t .Run ("func flag with placeholder name" , func (t * testing.T ) {
165+ // func flag, with a placeholder name:
166+ // if usageMesage contains a placeholder, expect '--flag2 {placeholder}'; still expect no mention of a default value
167+ fset := NewFlagSet ("unittest" , ContinueOnError )
168+ fset .BoolFunc ("flag2" , "usage message with `name` placeholder" , func (s string ) error { return nil })
169+ usage := fset .FlagUsagesWrapped (80 )
170+
171+ usage = strings .TrimSpace (usage )
172+ expected := "--flag2 name usage message with name placeholder"
173+ if usage != expected {
174+ t .Fatalf ("unexpected generated usage message\n expected: %s\n got: %s" , expected , usage )
175+ }
176+ })
177+ }
0 commit comments