You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are two simple ways that I see to solve this. One is to use Flag.DefValue instead of Flag.Value.String() in the nested switch statement in the default case. This appears to be the most consistent way to program this as all of the other cases are comparing Flag.DefValue with their type's zero value. Of course Flag.DefValue is set from Flag.Value.String() when the flag is first initialized, so this should have no effect on existing code.
I personally feel that the use of Flag.Value.String() in the nested switch statement is incorrect code, but it's a bit subjective.
Using Flag.DefValue instead is a small change, but it will allow a user to override Flag.DefValue to the empty string if they wish to hide the "(default %v)" in the usage description for the flag.
The other way, more obtrusive but also more flexible way, to achieve this is by adding an explicit option to the Flag struct that will hide the default value and skip the zero value check altogether.
Currently default values that are zero are not displayed in usage.
Value
interfaces whoseString() string
method doesn't output "0", "", "", or "false" for their uninitialized value aren't considered zero valued.pflag/flag.go
Lines 519 to 547 in 298182f
There are two simple ways that I see to solve this. One is to use
Flag.DefValue
instead ofFlag.Value.String()
in the nested switch statement in thedefault
case. This appears to be the most consistent way to program this as all of the other cases are comparingFlag.DefValue
with their type's zero value. Of courseFlag.DefValue
is set fromFlag.Value.String()
when the flag is first initialized, so this should have no effect on existing code.pflag/flag.go
Line 817 in 298182f
I personally feel that the use of
Flag.Value.String()
in the nested switch statement is incorrect code, but it's a bit subjective.Using
Flag.DefValue
instead is a small change, but it will allow a user to override Flag.DefValue to the empty string if they wish to hide the "(default %v)" in the usage description for the flag.The other way, more obtrusive but also more flexible way, to achieve this is by adding an explicit option to the Flag struct that will hide the default value and skip the zero value check altogether.
pflag/flag.go
Line 712 in 298182f
Something like
The text was updated successfully, but these errors were encountered: