From 921818bca208f0c70e85ec670074cb3905cbbc82 Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Sat, 27 Aug 2016 01:32:30 +0100 Subject: Update dependencies --- vendor/github.com/spf13/pflag/flag.go | 51 ++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'vendor/github.com/spf13/pflag/flag.go') diff --git a/vendor/github.com/spf13/pflag/flag.go b/vendor/github.com/spf13/pflag/flag.go index 965df13..eb143d7 100644 --- a/vendor/github.com/spf13/pflag/flag.go +++ b/vendor/github.com/spf13/pflag/flag.go @@ -419,20 +419,26 @@ func (f *FlagSet) PrintDefaults() { fmt.Fprintf(f.out(), "%s", usages) } -// isZeroValue guesses whether the string represents the zero -// value for a flag. It is not accurate but in practice works OK. -func isZeroValue(value string) bool { - switch value { - case "false": - return true - case "": - return true - case "": - return true - case "0": +// defaultIsZeroValue returns true if the default value for this flag represents +// a zero value. +func (f *Flag) defaultIsZeroValue() bool { + switch f.Value.(type) { + case boolFlag: + return f.DefValue == "false" + case *durationValue: + // Beginning in Go 1.7, duration zero values are "0s" + return f.DefValue == "0" || f.DefValue == "0s" + case *intValue, *int8Value, *int32Value, *int64Value, *uintValue, *uint8Value, *uint16Value, *uint32Value, *uint64Value, *countValue, *float32Value, *float64Value: + return f.DefValue == "0" + case *stringValue: + return f.DefValue == "" + case *ipValue, *ipMaskValue, *ipNetValue: + return f.DefValue == "" + case *intSliceValue, *stringSliceValue: + return f.DefValue == "[]" + default: return true } - return false } // UnquoteUsage extracts a back-quoted name from the usage @@ -455,22 +461,19 @@ func UnquoteUsage(flag *Flag) (name string, usage string) { break // Only one back quote; use type name. } } - // No explicit name, so use type if we can find one. - name = "value" - switch flag.Value.(type) { - case boolFlag: + + name = flag.Value.Type() + switch name { + case "bool": name = "" - case *durationValue: - name = "duration" - case *float64Value: + case "float64": name = "float" - case *intValue, *int64Value: + case "int64": name = "int" - case *stringValue: - name = "string" - case *uintValue, *uint64Value: + case "uint64": name = "uint" } + return } @@ -519,7 +522,7 @@ func (f *FlagSet) FlagUsages() string { } line += usage - if !isZeroValue(flag.DefValue) { + if !flag.defaultIsZeroValue() { if flag.Value.Type() == "string" { line += fmt.Sprintf(" (default %q)", flag.DefValue) } else { -- cgit v1.2.3