From 4412b61d0a5498abc79464bfcbfb71c762c0e44e Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Sun, 16 Aug 2015 23:30:14 -0700 Subject: 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. --- golangflag.go | 10 ++++++---- 1 file 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" -- cgit v1.2.3