aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Paris <[email protected]>2015-08-16 23:30:14 -0700
committerEric Paris <[email protected]>2015-08-16 23:30:14 -0700
commit4412b61d0a5498abc79464bfcbfb71c762c0e44e (patch)
tree3cca9f496f466373ccfb33a2ad069ddf12fe5a7a
parent79cd27658176c2e62f6fafb8104f2b487633019b (diff)
Do not trust golang flag's DefValue
Apparently it is wrong :-(. Use the current value instead. It is at least the default at the moment that pflag learned about the flag.
-rw-r--r--golangflag.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/golangflag.go b/golangflag.go
index 7b36f87..5213dc3 100644
--- a/golangflag.go
+++ b/golangflag.go
@@ -63,10 +63,12 @@ func (v *flagValueWrapper) Type() string {
func PFlagFromGoFlag(goflag *goflag.Flag) *Flag {
// Remember the default value as a string; it won't change.
flag := &Flag{
- Name: goflag.Name,
- Usage: goflag.Usage,
- Value: wrapFlagValue(goflag.Value),
- DefValue: goflag.DefValue,
+ Name: goflag.Name,
+ Usage: goflag.Usage,
+ Value: wrapFlagValue(goflag.Value),
+ // Looks like golang flags don't set DefValue correctly :-(
+ //DefValue: goflag.DefValue,
+ DefValue: goflag.Value.String(),
}
if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() {
flag.NoOptDefVal = "true"