summaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/pflag/uint.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/github.com/spf13/pflag/uint.go (renamed from vendor/github.com/victorhaggqvist/pflag/uint.go)36
1 files changed, 27 insertions, 9 deletions
diff --git a/vendor/github.com/victorhaggqvist/pflag/uint.go b/vendor/github.com/spf13/pflag/uint.go
index 40b9ebb..dcbc2b7 100644
--- a/vendor/github.com/victorhaggqvist/pflag/uint.go
+++ b/vendor/github.com/spf13/pflag/uint.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// -- uint Value
type uintValue uint
@@ -19,7 +16,28 @@ func (i *uintValue) Set(s string) error {
return err
}
-func (i *uintValue) String() string { return fmt.Sprintf("%v", *i) }
+func (i *uintValue) Type() string {
+ return "uint"
+}
+
+func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) }
+
+func uintConv(sval string) (interface{}, error) {
+ v, err := strconv.ParseUint(sval, 0, 0)
+ if err != nil {
+ return 0, err
+ }
+ return uint(v), nil
+}
+
+// GetUint return the uint value of a flag with the given name
+func (f *FlagSet) GetUint(name string) (uint, error) {
+ val, err := f.getFlagType(name, "uint", uintConv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(uint), nil
+}
// UintVar defines a uint flag with specified name, default value, and usage string.
// The argument p points to a uint variable in which to store the value of the flag.
@@ -27,7 +45,7 @@ func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) {
f.VarP(newUintValue(value, p), name, "", usage)
}
-// Like UintVar, but accepts a shorthand letter that can be used after a single dash.
+// UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) {
f.VarP(newUintValue(value, p), name, shorthand, usage)
}
@@ -38,7 +56,7 @@ func UintVar(p *uint, name string, value uint, usage string) {
CommandLine.VarP(newUintValue(value, p), name, "", usage)
}
-// Like UintVar, but accepts a shorthand letter that can be used after a single dash.
+// UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
func UintVarP(p *uint, name, shorthand string, value uint, usage string) {
CommandLine.VarP(newUintValue(value, p), name, shorthand, usage)
}
@@ -51,7 +69,7 @@ func (f *FlagSet) Uint(name string, value uint, usage string) *uint {
return p
}
-// Like Uint, but accepts a shorthand letter that can be used after a single dash.
+// UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint {
p := new(uint)
f.UintVarP(p, name, shorthand, value, usage)
@@ -64,7 +82,7 @@ func Uint(name string, value uint, usage string) *uint {
return CommandLine.UintP(name, "", value, usage)
}
-// Like Uint, but accepts a shorthand letter that can be used after a single dash.
+// UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
func UintP(name, shorthand string, value uint, usage string) *uint {
return CommandLine.UintP(name, shorthand, value, usage)
}