File tree 2 files changed +6
-5
lines changed
2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -536,9 +536,10 @@ func (f *FlagSet) PrintDefaults() {
536
536
// defaultIsZeroValue returns true if the default value for this flag represents
537
537
// a zero value.
538
538
func (f * Flag ) defaultIsZeroValue () bool {
539
- switch f .Value .(type ) {
540
- case boolFlag :
539
+ if bf , ok := f .Value .(boolFlag ); ok && bf .IsBoolFlag () {
541
540
return f .DefValue == "false"
541
+ }
542
+ switch f .Value .(type ) {
542
543
case * durationValue :
543
544
// Beginning in Go 1.7, duration zero values are "0s"
544
545
return f .DefValue == "0" || f .DefValue == "0s"
Original file line number Diff line number Diff line change @@ -1134,7 +1134,6 @@ func TestMultipleNormalizeFlagNameInvocations(t *testing.T) {
1134
1134
}
1135
1135
}
1136
1136
1137
- //
1138
1137
func TestHiddenFlagInUsage (t * testing.T ) {
1139
1138
f := NewFlagSet ("bob" , ContinueOnError )
1140
1139
f .Bool ("secretFlag" , true , "shhh" )
@@ -1149,7 +1148,6 @@ func TestHiddenFlagInUsage(t *testing.T) {
1149
1148
}
1150
1149
}
1151
1150
1152
- //
1153
1151
func TestHiddenFlagUsage (t * testing.T ) {
1154
1152
f := NewFlagSet ("bob" , ContinueOnError )
1155
1153
f .Bool ("secretFlag" , true , "shhh" )
@@ -1202,6 +1200,8 @@ func (cv *customValue) Set(s string) error {
1202
1200
1203
1201
func (cv * customValue ) Type () string { return "custom" }
1204
1202
1203
+ func (cv * customValue ) IsBoolFlag () bool { return false }
1204
+
1205
1205
func TestPrintDefaults (t * testing.T ) {
1206
1206
fs := NewFlagSet ("print defaults test" , ContinueOnError )
1207
1207
var buf bytes.Buffer
@@ -1239,7 +1239,7 @@ func TestPrintDefaults(t *testing.T) {
1239
1239
got := buf .String ()
1240
1240
if got != defaultOutput {
1241
1241
fmt .Println ("\n " + got )
1242
- fmt .Println ("\n " + defaultOutput )
1242
+ fmt .Print ("\n " + defaultOutput )
1243
1243
t .Errorf ("got %q want %q\n " , got , defaultOutput )
1244
1244
}
1245
1245
}
You can’t perform that action at this time.
0 commit comments