summaryrefslogtreecommitdiff
path: root/vendor/github.com/victorhaggqvist/pflag
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/github.com/spf13/pflag/LICENSE (renamed from vendor/github.com/victorhaggqvist/pflag/LICENSE)0
-rw-r--r--vendor/github.com/spf13/pflag/bool.go (renamed from vendor/github.com/victorhaggqvist/pflag/bool.go)51
-rw-r--r--vendor/github.com/spf13/pflag/duration.go (renamed from vendor/github.com/victorhaggqvist/pflag/duration.go)32
-rw-r--r--vendor/github.com/spf13/pflag/float32.go (renamed from vendor/github.com/victorhaggqvist/pflag/float32.go)36
-rw-r--r--vendor/github.com/spf13/pflag/float64.go (renamed from vendor/github.com/victorhaggqvist/pflag/float64.go)32
-rw-r--r--vendor/github.com/spf13/pflag/int.go (renamed from vendor/github.com/victorhaggqvist/pflag/int.go)32
-rw-r--r--vendor/github.com/spf13/pflag/int32.go (renamed from vendor/github.com/victorhaggqvist/pflag/int32.go)36
-rw-r--r--vendor/github.com/spf13/pflag/int64.go (renamed from vendor/github.com/victorhaggqvist/pflag/int64.go)32
-rw-r--r--vendor/github.com/spf13/pflag/int8.go (renamed from vendor/github.com/victorhaggqvist/pflag/int8.go)36
-rw-r--r--vendor/github.com/spf13/pflag/ip.go (renamed from vendor/github.com/victorhaggqvist/pflag/ip.go)33
-rw-r--r--vendor/github.com/spf13/pflag/ipmask.go (renamed from vendor/github.com/victorhaggqvist/pflag/ipmask.go)53
-rw-r--r--vendor/github.com/spf13/pflag/string.go (renamed from vendor/github.com/victorhaggqvist/pflag/string.go)28
-rw-r--r--vendor/github.com/spf13/pflag/uint.go (renamed from vendor/github.com/victorhaggqvist/pflag/uint.go)36
-rw-r--r--vendor/github.com/spf13/pflag/uint16.go (renamed from vendor/github.com/victorhaggqvist/pflag/uint16.go)39
-rw-r--r--vendor/github.com/spf13/pflag/uint32.go (renamed from vendor/github.com/victorhaggqvist/pflag/uint32.go)41
-rw-r--r--vendor/github.com/spf13/pflag/uint64.go (renamed from vendor/github.com/victorhaggqvist/pflag/uint64.go)36
-rw-r--r--vendor/github.com/spf13/pflag/uint8.go (renamed from vendor/github.com/victorhaggqvist/pflag/uint8.go)36
-rw-r--r--vendor/github.com/victorhaggqvist/pflag/README.md157
-rw-r--r--vendor/github.com/victorhaggqvist/pflag/flag.go644
19 files changed, 435 insertions, 955 deletions
diff --git a/vendor/github.com/victorhaggqvist/pflag/LICENSE b/vendor/github.com/spf13/pflag/LICENSE
index 63ed1cf..63ed1cf 100644
--- a/vendor/github.com/victorhaggqvist/pflag/LICENSE
+++ b/vendor/github.com/spf13/pflag/LICENSE
diff --git a/vendor/github.com/victorhaggqvist/pflag/bool.go b/vendor/github.com/spf13/pflag/bool.go
index 617971a..c4c5c0b 100644
--- a/vendor/github.com/victorhaggqvist/pflag/bool.go
+++ b/vendor/github.com/spf13/pflag/bool.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// optional interface to indicate boolean flags that can be
// supplied without "=value" text
@@ -26,41 +23,58 @@ func (b *boolValue) Set(s string) error {
return err
}
-func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) }
+func (b *boolValue) Type() string {
+ return "bool"
+}
+
+func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) }
func (b *boolValue) IsBoolFlag() bool { return true }
+func boolConv(sval string) (interface{}, error) {
+ return strconv.ParseBool(sval)
+}
+
+// GetBool return the bool value of a flag with the given name
+func (f *FlagSet) GetBool(name string) (bool, error) {
+ val, err := f.getFlagType(name, "bool", boolConv)
+ if err != nil {
+ return false, err
+ }
+ return val.(bool), nil
+}
+
// BoolVar defines a bool flag with specified name, default value, and usage string.
// The argument p points to a bool variable in which to store the value of the flag.
func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) {
- f.VarP(newBoolValue(value, p), name, "", usage)
+ f.BoolVarP(p, name, "", value, usage)
}
-// Like BoolVar, but accepts a shorthand letter that can be used after a single dash.
+// BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
- f.VarP(newBoolValue(value, p), name, shorthand, usage)
+ flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage)
+ flag.NoOptDefVal = "true"
}
// BoolVar defines a bool flag with specified name, default value, and usage string.
// The argument p points to a bool variable in which to store the value of the flag.
func BoolVar(p *bool, name string, value bool, usage string) {
- CommandLine.VarP(newBoolValue(value, p), name, "", usage)
+ BoolVarP(p, name, "", value, usage)
}
-// Like BoolVar, but accepts a shorthand letter that can be used after a single dash.
+// BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
func BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
- CommandLine.VarP(newBoolValue(value, p), name, shorthand, usage)
+ flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage)
+ flag.NoOptDefVal = "true"
}
// Bool defines a bool flag with specified name, default value, and usage string.
// The return value is the address of a bool variable that stores the value of the flag.
func (f *FlagSet) Bool(name string, value bool, usage string) *bool {
- p := new(bool)
- f.BoolVarP(p, name, "", value, usage)
- return p
+ return f.BoolP(name, "", value, usage)
}
-// Like Bool, but accepts a shorthand letter that can be used after a single dash.
+// BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool {
p := new(bool)
f.BoolVarP(p, name, shorthand, value, usage)
@@ -70,10 +84,11 @@ func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool
// Bool defines a bool flag with specified name, default value, and usage string.
// The return value is the address of a bool variable that stores the value of the flag.
func Bool(name string, value bool, usage string) *bool {
- return CommandLine.BoolP(name, "", value, usage)
+ return BoolP(name, "", value, usage)
}
-// Like Bool, but accepts a shorthand letter that can be used after a single dash.
+// BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
func BoolP(name, shorthand string, value bool, usage string) *bool {
- return CommandLine.BoolP(name, shorthand, value, usage)
+ b := CommandLine.BoolP(name, shorthand, value, usage)
+ return b
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/duration.go b/vendor/github.com/spf13/pflag/duration.go
index db59463..e9debef 100644
--- a/vendor/github.com/victorhaggqvist/pflag/duration.go
+++ b/vendor/github.com/spf13/pflag/duration.go
@@ -1,6 +1,8 @@
package pflag
-import "time"
+import (
+ "time"
+)
// -- time.Duration Value
type durationValue time.Duration
@@ -16,13 +18,23 @@ func (d *durationValue) Set(s string) error {
return err
}
+func (d *durationValue) Type() string {
+ return "duration"
+}
+
func (d *durationValue) String() string { return (*time.Duration)(d).String() }
-// Value is the interface to the dynamic value stored in a flag.
-// (The default value is represented as a string.)
-type Value interface {
- String() string
- Set(string) error
+func durationConv(sval string) (interface{}, error) {
+ return time.ParseDuration(sval)
+}
+
+// GetDuration return the duration value of a flag with the given name
+func (f *FlagSet) GetDuration(name string) (time.Duration, error) {
+ val, err := f.getFlagType(name, "duration", durationConv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(time.Duration), nil
}
// DurationVar defines a time.Duration flag with specified name, default value, and usage string.
@@ -31,7 +43,7 @@ func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration
f.VarP(newDurationValue(value, p), name, "", usage)
}
-// Like DurationVar, but accepts a shorthand letter that can be used after a single dash.
+// DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) {
f.VarP(newDurationValue(value, p), name, shorthand, usage)
}
@@ -42,7 +54,7 @@ func DurationVar(p *time.Duration, name string, value time.Duration, usage strin
CommandLine.VarP(newDurationValue(value, p), name, "", usage)
}
-// Like DurationVar, but accepts a shorthand letter that can be used after a single dash.
+// DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) {
CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage)
}
@@ -55,7 +67,7 @@ func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time
return p
}
-// Like Duration, but accepts a shorthand letter that can be used after a single dash.
+// DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration {
p := new(time.Duration)
f.DurationVarP(p, name, shorthand, value, usage)
@@ -68,7 +80,7 @@ func Duration(name string, value time.Duration, usage string) *time.Duration {
return CommandLine.DurationP(name, "", value, usage)
}
-// Like Duration, but accepts a shorthand letter that can be used after a single dash.
+// DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration {
return CommandLine.DurationP(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/float32.go b/vendor/github.com/spf13/pflag/float32.go
index a0041e2..a243f81 100644
--- a/vendor/github.com/victorhaggqvist/pflag/float32.go
+++ b/vendor/github.com/spf13/pflag/float32.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// -- float32 Value
type float32Value float32
@@ -19,7 +16,28 @@ func (f *float32Value) Set(s string) error {
return err
}
-func (f *float32Value) String() string { return fmt.Sprintf("%v", *f) }
+func (f *float32Value) Type() string {
+ return "float32"
+}
+
+func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) }
+
+func float32Conv(sval string) (interface{}, error) {
+ v, err := strconv.ParseFloat(sval, 32)
+ if err != nil {
+ return 0, err
+ }
+ return float32(v), nil
+}
+
+// GetFloat32 return the float32 value of a flag with the given name
+func (f *FlagSet) GetFloat32(name string) (float32, error) {
+ val, err := f.getFlagType(name, "float32", float32Conv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(float32), nil
+}
// Float32Var defines a float32 flag with specified name, default value, and usage string.
// The argument p points to a float32 variable in which to store the value of the flag.
@@ -27,7 +45,7 @@ func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage strin
f.VarP(newFloat32Value(value, p), name, "", usage)
}
-// Like Float32Var, but accepts a shorthand letter that can be used after a single dash.
+// Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
f.VarP(newFloat32Value(value, p), name, shorthand, usage)
}
@@ -38,7 +56,7 @@ func Float32Var(p *float32, name string, value float32, usage string) {
CommandLine.VarP(newFloat32Value(value, p), name, "", usage)
}
-// Like Float32Var, but accepts a shorthand letter that can be used after a single dash.
+// Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
func Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage)
}
@@ -51,7 +69,7 @@ func (f *FlagSet) Float32(name string, value float32, usage string) *float32 {
return p
}
-// Like Float32, but accepts a shorthand letter that can be used after a single dash.
+// Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 {
p := new(float32)
f.Float32VarP(p, name, shorthand, value, usage)
@@ -64,7 +82,7 @@ func Float32(name string, value float32, usage string) *float32 {
return CommandLine.Float32P(name, "", value, usage)
}
-// Like Float32, but accepts a shorthand letter that can be used after a single dash.
+// Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
func Float32P(name, shorthand string, value float32, usage string) *float32 {
return CommandLine.Float32P(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/float64.go b/vendor/github.com/spf13/pflag/float64.go
index 8d79be0..04b5492 100644
--- a/vendor/github.com/victorhaggqvist/pflag/float64.go
+++ b/vendor/github.com/spf13/pflag/float64.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// -- float64 Value
type float64Value float64
@@ -19,7 +16,24 @@ func (f *float64Value) Set(s string) error {
return err
}
-func (f *float64Value) String() string { return fmt.Sprintf("%v", *f) }
+func (f *float64Value) Type() string {
+ return "float64"
+}
+
+func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) }
+
+func float64Conv(sval string) (interface{}, error) {
+ return strconv.ParseFloat(sval, 64)
+}
+
+// GetFloat64 return the float64 value of a flag with the given name
+func (f *FlagSet) GetFloat64(name string) (float64, error) {
+ val, err := f.getFlagType(name, "float64", float64Conv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(float64), nil
+}
// Float64Var defines a float64 flag with specified name, default value, and usage string.
// The argument p points to a float64 variable in which to store the value of the flag.
@@ -27,7 +41,7 @@ func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage strin
f.VarP(newFloat64Value(value, p), name, "", usage)
}
-// Like Float64Var, but accepts a shorthand letter that can be used after a single dash.
+// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
f.VarP(newFloat64Value(value, p), name, shorthand, usage)
}
@@ -38,7 +52,7 @@ func Float64Var(p *float64, name string, value float64, usage string) {
CommandLine.VarP(newFloat64Value(value, p), name, "", usage)
}
-// Like Float64Var, but accepts a shorthand letter that can be used after a single dash.
+// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
func Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage)
}
@@ -51,7 +65,7 @@ func (f *FlagSet) Float64(name string, value float64, usage string) *float64 {
return p
}
-// Like Float64, but accepts a shorthand letter that can be used after a single dash.
+// Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 {
p := new(float64)
f.Float64VarP(p, name, shorthand, value, usage)
@@ -64,7 +78,7 @@ func Float64(name string, value float64, usage string) *float64 {
return CommandLine.Float64P(name, "", value, usage)
}
-// Like Float64, but accepts a shorthand letter that can be used after a single dash.
+// Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
func Float64P(name, shorthand string, value float64, usage string) *float64 {
return CommandLine.Float64P(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/int.go b/vendor/github.com/spf13/pflag/int.go
index cb85e14..1474b89 100644
--- a/vendor/github.com/victorhaggqvist/pflag/int.go
+++ b/vendor/github.com/spf13/pflag/int.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// -- int Value
type intValue int
@@ -19,7 +16,24 @@ func (i *intValue) Set(s string) error {
return err
}
-func (i *intValue) String() string { return fmt.Sprintf("%v", *i) }
+func (i *intValue) Type() string {
+ return "int"
+}
+
+func (i *intValue) String() string { return strconv.Itoa(int(*i)) }
+
+func intConv(sval string) (interface{}, error) {
+ return strconv.Atoi(sval)
+}
+
+// GetInt return the int value of a flag with the given name
+func (f *FlagSet) GetInt(name string) (int, error) {
+ val, err := f.getFlagType(name, "int", intConv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(int), nil
+}
// IntVar defines an int flag with specified name, default value, and usage string.
// The argument p points to an int variable in which to store the value of the flag.
@@ -27,7 +41,7 @@ func (f *FlagSet) IntVar(p *int, name string, value int, usage string) {
f.VarP(newIntValue(value, p), name, "", usage)
}
-// Like IntVar, but accepts a shorthand letter that can be used after a single dash.
+// IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) {
f.VarP(newIntValue(value, p), name, shorthand, usage)
}
@@ -38,7 +52,7 @@ func IntVar(p *int, name string, value int, usage string) {
CommandLine.VarP(newIntValue(value, p), name, "", usage)
}
-// Like IntVar, but accepts a shorthand letter that can be used after a single dash.
+// IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
func IntVarP(p *int, name, shorthand string, value int, usage string) {
CommandLine.VarP(newIntValue(value, p), name, shorthand, usage)
}
@@ -51,7 +65,7 @@ func (f *FlagSet) Int(name string, value int, usage string) *int {
return p
}
-// Like Int, but accepts a shorthand letter that can be used after a single dash.
+// IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int {
p := new(int)
f.IntVarP(p, name, shorthand, value, usage)
@@ -64,7 +78,7 @@ func Int(name string, value int, usage string) *int {
return CommandLine.IntP(name, "", value, usage)
}
-// Like Int, but accepts a shorthand letter that can be used after a single dash.
+// IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
func IntP(name, shorthand string, value int, usage string) *int {
return CommandLine.IntP(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/int32.go b/vendor/github.com/spf13/pflag/int32.go
index 2e1a317..9b95944 100644
--- a/vendor/github.com/victorhaggqvist/pflag/int32.go
+++ b/vendor/github.com/spf13/pflag/int32.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// -- int32 Value
type int32Value int32
@@ -19,7 +16,28 @@ func (i *int32Value) Set(s string) error {
return err
}
-func (i *int32Value) String() string { return fmt.Sprintf("%v", *i) }
+func (i *int32Value) Type() string {
+ return "int32"
+}
+
+func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) }
+
+func int32Conv(sval string) (interface{}, error) {
+ v, err := strconv.ParseInt(sval, 0, 32)
+ if err != nil {
+ return 0, err
+ }
+ return int32(v), nil
+}
+
+// GetInt32 return the int32 value of a flag with the given name
+func (f *FlagSet) GetInt32(name string) (int32, error) {
+ val, err := f.getFlagType(name, "int32", int32Conv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(int32), nil
+}
// Int32Var defines an int32 flag with specified name, default value, and usage string.
// The argument p points to an int32 variable in which to store the value of the flag.
@@ -27,7 +45,7 @@ func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) {
f.VarP(newInt32Value(value, p), name, "", usage)
}
-// Like Int32Var, but accepts a shorthand letter that can be used after a single dash.
+// Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) {
f.VarP(newInt32Value(value, p), name, shorthand, usage)
}
@@ -38,7 +56,7 @@ func Int32Var(p *int32, name string, value int32, usage string) {
CommandLine.VarP(newInt32Value(value, p), name, "", usage)
}
-// Like Int32Var, but accepts a shorthand letter that can be used after a single dash.
+// Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
func Int32VarP(p *int32, name, shorthand string, value int32, usage string) {
CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage)
}
@@ -51,7 +69,7 @@ func (f *FlagSet) Int32(name string, value int32, usage string) *int32 {
return p
}
-// Like Int32, but accepts a shorthand letter that can be used after a single dash.
+// Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 {
p := new(int32)
f.Int32VarP(p, name, shorthand, value, usage)
@@ -64,7 +82,7 @@ func Int32(name string, value int32, usage string) *int32 {
return CommandLine.Int32P(name, "", value, usage)
}
-// Like Int32, but accepts a shorthand letter that can be used after a single dash.
+// Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
func Int32P(name, shorthand string, value int32, usage string) *int32 {
return CommandLine.Int32P(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/int64.go b/vendor/github.com/spf13/pflag/int64.go
index 43aeced..0026d78 100644
--- a/vendor/github.com/victorhaggqvist/pflag/int64.go
+++ b/vendor/github.com/spf13/pflag/int64.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// -- int64 Value
type int64Value int64
@@ -19,7 +16,24 @@ func (i *int64Value) Set(s string) error {
return err
}
-func (i *int64Value) String() string { return fmt.Sprintf("%v", *i) }
+func (i *int64Value) Type() string {
+ return "int64"
+}
+
+func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) }
+
+func int64Conv(sval string) (interface{}, error) {
+ return strconv.ParseInt(sval, 0, 64)
+}
+
+// GetInt64 return the int64 value of a flag with the given name
+func (f *FlagSet) GetInt64(name string) (int64, error) {
+ val, err := f.getFlagType(name, "int64", int64Conv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(int64), nil
+}
// Int64Var defines an int64 flag with specified name, default value, and usage string.
// The argument p points to an int64 variable in which to store the value of the flag.
@@ -27,7 +41,7 @@ func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) {
f.VarP(newInt64Value(value, p), name, "", usage)
}
-// Like Int64Var, but accepts a shorthand letter that can be used after a single dash.
+// Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) {
f.VarP(newInt64Value(value, p), name, shorthand, usage)
}
@@ -38,7 +52,7 @@ func Int64Var(p *int64, name string, value int64, usage string) {
CommandLine.VarP(newInt64Value(value, p), name, "", usage)
}
-// Like Int64Var, but accepts a shorthand letter that can be used after a single dash.
+// Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
func Int64VarP(p *int64, name, shorthand string, value int64, usage string) {
CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage)
}
@@ -51,7 +65,7 @@ func (f *FlagSet) Int64(name string, value int64, usage string) *int64 {
return p
}
-// Like Int64, but accepts a shorthand letter that can be used after a single dash.
+// Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 {
p := new(int64)
f.Int64VarP(p, name, shorthand, value, usage)
@@ -64,7 +78,7 @@ func Int64(name string, value int64, usage string) *int64 {
return CommandLine.Int64P(name, "", value, usage)
}
-// Like Int64, but accepts a shorthand letter that can be used after a single dash.
+// Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
func Int64P(name, shorthand string, value int64, usage string) *int64 {
return CommandLine.Int64P(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/int8.go b/vendor/github.com/spf13/pflag/int8.go
index 539c4eb..4da9222 100644
--- a/vendor/github.com/victorhaggqvist/pflag/int8.go
+++ b/vendor/github.com/spf13/pflag/int8.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// -- int8 Value
type int8Value int8
@@ -19,7 +16,28 @@ func (i *int8Value) Set(s string) error {
return err
}
-func (i *int8Value) String() string { return fmt.Sprintf("%v", *i) }
+func (i *int8Value) Type() string {
+ return "int8"
+}
+
+func (i *int8Value) String() string { return strconv.FormatInt(int64(*i), 10) }
+
+func int8Conv(sval string) (interface{}, error) {
+ v, err := strconv.ParseInt(sval, 0, 8)
+ if err != nil {
+ return 0, err
+ }
+ return int8(v), nil
+}
+
+// GetInt8 return the int8 value of a flag with the given name
+func (f *FlagSet) GetInt8(name string) (int8, error) {
+ val, err := f.getFlagType(name, "int8", int8Conv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(int8), nil
+}
// Int8Var defines an int8 flag with specified name, default value, and usage string.
// The argument p points to an int8 variable in which to store the value of the flag.
@@ -27,7 +45,7 @@ func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) {
f.VarP(newInt8Value(value, p), name, "", usage)
}
-// Like Int8Var, but accepts a shorthand letter that can be used after a single dash.
+// Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) {
f.VarP(newInt8Value(value, p), name, shorthand, usage)
}
@@ -38,7 +56,7 @@ func Int8Var(p *int8, name string, value int8, usage string) {
CommandLine.VarP(newInt8Value(value, p), name, "", usage)
}
-// Like Int8Var, but accepts a shorthand letter that can be used after a single dash.
+// Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
func Int8VarP(p *int8, name, shorthand string, value int8, usage string) {
CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage)
}
@@ -51,7 +69,7 @@ func (f *FlagSet) Int8(name string, value int8, usage string) *int8 {
return p
}
-// Like Int8, but accepts a shorthand letter that can be used after a single dash.
+// Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 {
p := new(int8)
f.Int8VarP(p, name, shorthand, value, usage)
@@ -64,7 +82,7 @@ func Int8(name string, value int8, usage string) *int8 {
return CommandLine.Int8P(name, "", value, usage)
}
-// Like Int8, but accepts a shorthand letter that can be used after a single dash.
+// Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
func Int8P(name, shorthand string, value int8, usage string) *int8 {
return CommandLine.Int8P(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/ip.go b/vendor/github.com/spf13/pflag/ip.go
index 3a411fc..3d414ba 100644
--- a/vendor/github.com/victorhaggqvist/pflag/ip.go
+++ b/vendor/github.com/spf13/pflag/ip.go
@@ -3,6 +3,7 @@ package pflag
import (
"fmt"
"net"
+ "strings"
)
// -- net.IP value
@@ -15,15 +16,33 @@ func newIPValue(val net.IP, p *net.IP) *ipValue {
func (i *ipValue) String() string { return net.IP(*i).String() }
func (i *ipValue) Set(s string) error {
- ip := net.ParseIP(s)
+ ip := net.ParseIP(strings.TrimSpace(s))
if ip == nil {
return fmt.Errorf("failed to parse IP: %q", s)
}
*i = ipValue(ip)
return nil
}
-func (i *ipValue) Get() interface{} {
- return net.IP(*i)
+
+func (i *ipValue) Type() string {
+ return "ip"
+}
+
+func ipConv(sval string) (interface{}, error) {
+ ip := net.ParseIP(sval)
+ if ip != nil {
+ return ip, nil
+ }
+ return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval)
+}
+
+// GetIP return the net.IP value of a flag with the given name
+func (f *FlagSet) GetIP(name string) (net.IP, error) {
+ val, err := f.getFlagType(name, "ip", ipConv)
+ if err != nil {
+ return nil, err
+ }
+ return val.(net.IP), nil
}
// IPVar defines an net.IP flag with specified name, default value, and usage string.
@@ -32,7 +51,7 @@ func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) {
f.VarP(newIPValue(value, p), name, "", usage)
}
-// Like IPVar, but accepts a shorthand letter that can be used after a single dash.
+// IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
f.VarP(newIPValue(value, p), name, shorthand, usage)
}
@@ -43,7 +62,7 @@ func IPVar(p *net.IP, name string, value net.IP, usage string) {
CommandLine.VarP(newIPValue(value, p), name, "", usage)
}
-// Like IPVar, but accepts a shorthand letter that can be used after a single dash.
+// IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
CommandLine.VarP(newIPValue(value, p), name, shorthand, usage)
}
@@ -56,7 +75,7 @@ func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP {
return p
}
-// Like IP, but accepts a shorthand letter that can be used after a single dash.
+// IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP {
p := new(net.IP)
f.IPVarP(p, name, shorthand, value, usage)
@@ -69,7 +88,7 @@ func IP(name string, value net.IP, usage string) *net.IP {
return CommandLine.IPP(name, "", value, usage)
}
-// Like IP, but accepts a shorthand letter that can be used after a single dash.
+// IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
func IPP(name, shorthand string, value net.IP, usage string) *net.IP {
return CommandLine.IPP(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/ipmask.go b/vendor/github.com/spf13/pflag/ipmask.go
index b8a164a..5bd44bd 100644
--- a/vendor/github.com/victorhaggqvist/pflag/ipmask.go
+++ b/vendor/github.com/spf13/pflag/ipmask.go
@@ -3,6 +3,7 @@ package pflag
import (
"fmt"
"net"
+ "strconv"
)
// -- net.IPMask value
@@ -22,27 +23,63 @@ func (i *ipMaskValue) Set(s string) error {
*i = ipMaskValue(ip)
return nil
}
-func (i *ipMaskValue) Get() interface{} {
- return net.IPMask(*i)
+
+func (i *ipMaskValue) Type() string {
+ return "ipMask"
}
-// Parse IPv4 netmask written in IP form (e.g. 255.255.255.0).
+// ParseIPv4Mask written in IP form (e.g. 255.255.255.0).
// This function should really belong to the net package.
func ParseIPv4Mask(s string) net.IPMask {
mask := net.ParseIP(s)
if mask == nil {
- return nil
+ if len(s) != 8 {
+ return nil
+ }
+ // net.IPMask.String() actually outputs things like ffffff00
+ // so write a horrible parser for that as well :-(
+ m := []int{}
+ for i := 0; i < 4; i++ {
+ b := "0x" + s[2*i:2*i+2]
+ d, err := strconv.ParseInt(b, 0, 0)
+ if err != nil {
+ return nil
+ }
+ m = append(m, int(d))
+ }
+ s := fmt.Sprintf("%d.%d.%d.%d", m[0], m[1], m[2], m[3])
+ mask = net.ParseIP(s)
+ if mask == nil {
+ return nil
+ }
}
return net.IPv4Mask(mask[12], mask[13], mask[14], mask[15])
}
+func parseIPv4Mask(sval string) (interface{}, error) {
+ mask := ParseIPv4Mask(sval)
+ if mask == nil {
+ return nil, fmt.Errorf("unable to parse %s as net.IPMask", sval)
+ }
+ return mask, nil
+}
+
+// GetIPv4Mask return the net.IPv4Mask value of a flag with the given name
+func (f *FlagSet) GetIPv4Mask(name string) (net.IPMask, error) {
+ val, err := f.getFlagType(name, "ipMask", parseIPv4Mask)
+ if err != nil {
+ return nil, err
+ }
+ return val.(net.IPMask), nil
+}
+
// IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string.
// The argument p points to an net.IPMask variable in which to store the value of the flag.
func (f *FlagSet) IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) {
f.VarP(newIPMaskValue(value, p), name, "", usage)
}
-// Like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
+// IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) {
f.VarP(newIPMaskValue(value, p), name, shorthand, usage)
}
@@ -53,7 +90,7 @@ func IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) {
CommandLine.VarP(newIPMaskValue(value, p), name, "", usage)
}
-// Like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
+// IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
func IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) {
CommandLine.VarP(newIPMaskValue(value, p), name, shorthand, usage)
}
@@ -66,7 +103,7 @@ func (f *FlagSet) IPMask(name string, value net.IPMask, usage string) *net.IPMas
return p
}
-// Like IPMask, but accepts a shorthand letter that can be used after a single dash.
+// IPMaskP is like IPMask, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask {
p := new(net.IPMask)
f.IPMaskVarP(p, name, shorthand, value, usage)
@@ -79,7 +116,7 @@ func IPMask(name string, value net.IPMask, usage string) *net.IPMask {
return CommandLine.IPMaskP(name, "", value, usage)
}
-// Like IP, but accepts a shorthand letter that can be used after a single dash.
+// IPMaskP is like IP, but accepts a shorthand letter that can be used after a single dash.
func IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask {
return CommandLine.IPMaskP(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/string.go b/vendor/github.com/spf13/pflag/string.go
index 65c0cb7..04e0a26 100644
--- a/vendor/github.com/victorhaggqvist/pflag/string.go
+++ b/vendor/github.com/spf13/pflag/string.go
@@ -1,7 +1,5 @@
package pflag
-import "fmt"
-
// -- string Value
type stringValue string
@@ -14,8 +12,24 @@ func (s *stringValue) Set(val string) error {
*s = stringValue(val)
return nil
}
+func (s *stringValue) Type() string {
+ return "string"
+}
+
+func (s *stringValue) String() string { return string(*s) }
+
+func stringConv(sval string) (interface{}, error) {
+ return sval, nil
+}
-func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) }
+// GetString return the string value of a flag with the given name
+func (f *FlagSet) GetString(name string) (string, error) {
+ val, err := f.getFlagType(name, "string", stringConv)
+ if err != nil {
+ return "", err
+ }
+ return val.(string), nil
+}
// StringVar defines a string flag with specified name, default value, and usage string.
// The argument p points to a string variable in which to store the value of the flag.
@@ -23,7 +37,7 @@ func (f *FlagSet) StringVar(p *string, name string, value string, usage string)
f.VarP(newStringValue(value, p), name, "", usage)
}
-// Like StringVar, but accepts a shorthand letter that can be used after a single dash.
+// StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) {
f.VarP(newStringValue(value, p), name, shorthand, usage)
}
@@ -34,7 +48,7 @@ func StringVar(p *string, name string, value string, usage string) {
CommandLine.VarP(newStringValue(value, p), name, "", usage)
}
-// Like StringVar, but accepts a shorthand letter that can be used after a single dash.
+// StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
func StringVarP(p *string, name, shorthand string, value string, usage string) {
CommandLine.VarP(newStringValue(value, p), name, shorthand, usage)
}
@@ -47,7 +61,7 @@ func (f *FlagSet) String(name string, value string, usage string) *string {
return p
}
-// Like String, but accepts a shorthand letter that can be used after a single dash.
+// StringP is like String, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string {
p := new(string)
f.StringVarP(p, name, shorthand, value, usage)
@@ -60,7 +74,7 @@ func String(name string, value string, usage string) *string {
return CommandLine.StringP(name, "", value, usage)
}
-// Like String, but accepts a shorthand letter that can be used after a single dash.
+// StringP is like String, but accepts a shorthand letter that can be used after a single dash.
func StringP(name, shorthand string, value string, usage string) *string {
return CommandLine.StringP(name, shorthand, value, usage)
}
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)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/uint16.go b/vendor/github.com/spf13/pflag/uint16.go
index 182dc40..7e9914e 100644
--- a/vendor/github.com/victorhaggqvist/pflag/uint16.go
+++ b/vendor/github.com/spf13/pflag/uint16.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// -- uint16 value
type uint16Value uint16
@@ -12,14 +9,34 @@ func newUint16Value(val uint16, p *uint16) *uint16Value {
*p = val
return (*uint16Value)(p)
}
-func (i *uint16Value) String() string { return fmt.Sprintf("%d", *i) }
+
func (i *uint16Value) Set(s string) error {
v, err := strconv.ParseUint(s, 0, 16)
*i = uint16Value(v)
return err
}
-func (i *uint16Value) Get() interface{} {
- return uint16(*i)
+
+func (i *uint16Value) Type() string {
+ return "uint16"
+}
+
+func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
+
+func uint16Conv(sval string) (interface{}, error) {
+ v, err := strconv.ParseUint(sval, 0, 16)
+ if err != nil {
+ return 0, err
+ }
+ return uint16(v), nil
+}
+
+// GetUint16 return the uint16 value of a flag with the given name
+func (f *FlagSet) GetUint16(name string) (uint16, error) {
+ val, err := f.getFlagType(name, "uint16", uint16Conv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(uint16), nil
}
// Uint16Var defines a uint flag with specified name, default value, and usage string.
@@ -28,7 +45,7 @@ func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string)
f.VarP(newUint16Value(value, p), name, "", usage)
}
-// Like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
+// Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
f.VarP(newUint16Value(value, p), name, shorthand, usage)
}
@@ -39,7 +56,7 @@ func Uint16Var(p *uint16, name string, value uint16, usage string) {
CommandLine.VarP(newUint16Value(value, p), name, "", usage)
}
-// Like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
+// Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage)
}
@@ -52,7 +69,7 @@ func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 {
return p
}
-// Like Uint16, but accepts a shorthand letter that can be used after a single dash.
+// Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
p := new(uint16)
f.Uint16VarP(p, name, shorthand, value, usage)
@@ -65,7 +82,7 @@ func Uint16(name string, value uint16, usage string) *uint16 {
return CommandLine.Uint16P(name, "", value, usage)
}
-// Like Uint16, but accepts a shorthand letter that can be used after a single dash.
+// Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
func Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
return CommandLine.Uint16P(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/uint32.go b/vendor/github.com/spf13/pflag/uint32.go
index 165c8b2..d802453 100644
--- a/vendor/github.com/victorhaggqvist/pflag/uint32.go
+++ b/vendor/github.com/spf13/pflag/uint32.go
@@ -1,25 +1,42 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
-// -- uint16 value
+// -- uint32 value
type uint32Value uint32
func newUint32Value(val uint32, p *uint32) *uint32Value {
*p = val
return (*uint32Value)(p)
}
-func (i *uint32Value) String() string { return fmt.Sprintf("%d", *i) }
+
func (i *uint32Value) Set(s string) error {
v, err := strconv.ParseUint(s, 0, 32)
*i = uint32Value(v)
return err
}
-func (i *uint32Value) Get() interface{} {
- return uint32(*i)
+
+func (i *uint32Value) Type() string {
+ return "uint32"
+}
+
+func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
+
+func uint32Conv(sval string) (interface{}, error) {
+ v, err := strconv.ParseUint(sval, 0, 32)
+ if err != nil {
+ return 0, err
+ }
+ return uint32(v), nil
+}
+
+// GetUint32 return the uint32 value of a flag with the given name
+func (f *FlagSet) GetUint32(name string) (uint32, error) {
+ val, err := f.getFlagType(name, "uint32", uint32Conv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(uint32), nil
}
// Uint32Var defines a uint32 flag with specified name, default value, and usage string.
@@ -28,7 +45,7 @@ func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string)
f.VarP(newUint32Value(value, p), name, "", usage)
}
-// Like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
+// Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
f.VarP(newUint32Value(value, p), name, shorthand, usage)
}
@@ -39,7 +56,7 @@ func Uint32Var(p *uint32, name string, value uint32, usage string) {
CommandLine.VarP(newUint32Value(value, p), name, "", usage)
}
-// Like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
+// Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage)
}
@@ -52,7 +69,7 @@ func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 {
return p
}
-// Like Uint32, but accepts a shorthand letter that can be used after a single dash.
+// Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
p := new(uint32)
f.Uint32VarP(p, name, shorthand, value, usage)
@@ -65,7 +82,7 @@ func Uint32(name string, value uint32, usage string) *uint32 {
return CommandLine.Uint32P(name, "", value, usage)
}
-// Like Uint32, but accepts a shorthand letter that can be used after a single dash.
+// Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
func Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
return CommandLine.Uint32P(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/uint64.go b/vendor/github.com/spf13/pflag/uint64.go
index f41c5a2..f62240f 100644
--- a/vendor/github.com/victorhaggqvist/pflag/uint64.go
+++ b/vendor/github.com/spf13/pflag/uint64.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// -- uint64 Value
type uint64Value uint64
@@ -19,7 +16,28 @@ func (i *uint64Value) Set(s string) error {
return err
}
-func (i *uint64Value) String() string { return fmt.Sprintf("%v", *i) }
+func (i *uint64Value) Type() string {
+ return "uint64"
+}
+
+func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
+
+func uint64Conv(sval string) (interface{}, error) {
+ v, err := strconv.ParseUint(sval, 0, 64)
+ if err != nil {
+ return 0, err
+ }
+ return uint64(v), nil
+}
+
+// GetUint64 return the uint64 value of a flag with the given name
+func (f *FlagSet) GetUint64(name string) (uint64, error) {
+ val, err := f.getFlagType(name, "uint64", uint64Conv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(uint64), nil
+}
// Uint64Var defines a uint64 flag with specified name, default value, and usage string.
// The argument p points to a uint64 variable in which to store the value of the flag.
@@ -27,7 +45,7 @@ func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string)
f.VarP(newUint64Value(value, p), name, "", usage)
}
-// Like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
+// Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) {
f.VarP(newUint64Value(value, p), name, shorthand, usage)
}
@@ -38,7 +56,7 @@ func Uint64Var(p *uint64, name string, value uint64, usage string) {
CommandLine.VarP(newUint64Value(value, p), name, "", usage)
}
-// Like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
+// Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) {
CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage)
}
@@ -51,7 +69,7 @@ func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 {
return p
}
-// Like Uint64, but accepts a shorthand letter that can be used after a single dash.
+// Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 {
p := new(uint64)
f.Uint64VarP(p, name, shorthand, value, usage)
@@ -64,7 +82,7 @@ func Uint64(name string, value uint64, usage string) *uint64 {
return CommandLine.Uint64P(name, "", value, usage)
}
-// Like Uint64, but accepts a shorthand letter that can be used after a single dash.
+// Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
func Uint64P(name, shorthand string, value uint64, usage string) *uint64 {
return CommandLine.Uint64P(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/uint8.go b/vendor/github.com/spf13/pflag/uint8.go
index 174f99c..bb0e83c 100644
--- a/vendor/github.com/victorhaggqvist/pflag/uint8.go
+++ b/vendor/github.com/spf13/pflag/uint8.go
@@ -1,9 +1,6 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
// -- uint8 Value
type uint8Value uint8
@@ -19,7 +16,28 @@ func (i *uint8Value) Set(s string) error {
return err
}
-func (i *uint8Value) String() string { return fmt.Sprintf("%v", *i) }
+func (i *uint8Value) Type() string {
+ return "uint8"
+}
+
+func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
+
+func uint8Conv(sval string) (interface{}, error) {
+ v, err := strconv.ParseUint(sval, 0, 8)
+ if err != nil {
+ return 0, err
+ }
+ return uint8(v), nil
+}
+
+// GetUint8 return the uint8 value of a flag with the given name
+func (f *FlagSet) GetUint8(name string) (uint8, error) {
+ val, err := f.getFlagType(name, "uint8", uint8Conv)
+ if err != nil {
+ return 0, err
+ }
+ return val.(uint8), nil
+}
// Uint8Var defines a uint8 flag with specified name, default value, and usage string.
// The argument p points to a uint8 variable in which to store the value of the flag.
@@ -27,7 +45,7 @@ func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) {
f.VarP(newUint8Value(value, p), name, "", usage)
}
-// Like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
+// Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {
f.VarP(newUint8Value(value, p), name, shorthand, usage)
}
@@ -38,7 +56,7 @@ func Uint8Var(p *uint8, name string, value uint8, usage string) {
CommandLine.VarP(newUint8Value(value, p), name, "", usage)
}
-// Like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
+// Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {
CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage)
}
@@ -51,7 +69,7 @@ func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 {
return p
}
-// Like Uint8, but accepts a shorthand letter that can be used after a single dash.
+// Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 {
p := new(uint8)
f.Uint8VarP(p, name, shorthand, value, usage)
@@ -64,7 +82,7 @@ func Uint8(name string, value uint8, usage string) *uint8 {
return CommandLine.Uint8P(name, "", value, usage)
}
-// Like Uint8, but accepts a shorthand letter that can be used after a single dash.
+// Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
func Uint8P(name, shorthand string, value uint8, usage string) *uint8 {
return CommandLine.Uint8P(name, shorthand, value, usage)
}
diff --git a/vendor/github.com/victorhaggqvist/pflag/README.md b/vendor/github.com/victorhaggqvist/pflag/README.md
deleted file mode 100644
index d9b189f..0000000
--- a/vendor/github.com/victorhaggqvist/pflag/README.md
+++ /dev/null
@@ -1,157 +0,0 @@
-[![Build Status](https://travis-ci.org/ogier/pflag.png?branch=master)](https://travis-ci.org/ogier/pflag)
-
-## Description
-
-pflag is a drop-in replacement for Go's flag package, implementing
-POSIX/GNU-style --flags.
-
-pflag is compatible with the [GNU extensions to the POSIX recommendations
-for command-line options][1]. For a more precise description, see the
-"Command-line flag syntax" section below.
-
-[1]: http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
-
-pflag is available under the same style of BSD license as the Go language,
-which can be found in the LICENSE file.
-
-## Installation
-
-pflag is available using the standard `go get` command.
-
-Install by running:
-
- go get github.com/ogier/pflag
-
-Run tests by running:
-
- go test github.com/ogier/pflag
-
-## Usage
-
-pflag is a drop-in replacement of Go's native flag package. If you import
-pflag under the name "flag" then all code should continue to function
-with no changes.
-
-``` go
-import flag "github.com/ogier/pflag"
-```
-
-There is one exception to this: if you directly instantiate the Flag struct
-there is one more field "Shorthand" that you will need to set.
-Most code never instantiates this struct directly, and instead uses
-functions such as String(), BoolVar(), and Var(), and is therefore
-unaffected.
-
-Define flags using flag.String(), Bool(), Int(), etc.
-
-This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
-
-``` go
-var ip *int = flag.Int("flagname", 1234, "help message for flagname")
-```
-
-If you like, you can bind the flag to a variable using the Var() functions.
-
-``` go
-var flagvar int
-func init() {
- flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
-}
-```
-
-Or you can create custom flags that satisfy the Value interface (with
-pointer receivers) and couple them to flag parsing by
-
-``` go
-flag.Var(&flagVal, "name", "help message for flagname")
-```
-
-For such flags, the default value is just the initial value of the variable.
-
-After all flags are defined, call
-
-``` go
-flag.Parse()
-```
-
-to parse the command line into the defined flags.
-
-Flags may then be used directly. If you're using the flags themselves,
-they are all pointers; if you bind to variables, they're values.
-
-``` go
-fmt.Println("ip has value ", *ip)
-fmt.Println("flagvar has value ", flagvar)
-```
-
-After parsing, the arguments after the flag are available as the
-slice flag.Args() or individually as flag.Arg(i).
-The arguments are indexed from 0 through flag.NArg()-1.
-
-The pflag package also defines some new functions that are not in flag,
-that give one-letter shorthands for flags. You can use these by appending
-'P' to the name of any function that defines a flag.
-
-``` go
-var ip = flag.IntP("flagname", "f", 1234, "help message")
-var flagvar bool
-func init() {
- flag.BoolVarP("boolname", "b", true, "help message")
-}
-flag.VarP(&flagVar, "varname", "v", 1234, "help message")
-```
-
-Shorthand letters can be used with single dashes on the command line.
-Boolean shorthand flags can be combined with other shorthand flags.
-
-The default set of command-line flags is controlled by
-top-level functions. The FlagSet type allows one to define
-independent sets of flags, such as to implement subcommands
-in a command-line interface. The methods of FlagSet are
-analogous to the top-level functions for the command-line
-flag set.
-
-## Command line flag syntax
-
-```
---flag // boolean flags only
---flag=x
-```
-
-Unlike the flag package, a single dash before an option means something
-different than a double dash. Single dashes signify a series of shorthand
-letters for flags. All but the last shorthand letter must be boolean flags.
-
-```
-// boolean flags
--f
--abc
-
-// non-boolean flags
--n 1234
--Ifile
-
-// mixed
--abcs "hello"
--abcn1234
-```
-
-Flag parsing stops after the terminator "--". Unlike the flag package,
-flags can be interspersed with arguments anywhere on the command line
-before this terminator.
-
-Integer flags accept 1234, 0664, 0x1234 and may be negative.
-Boolean flags (in their long form) accept 1, 0, t, f, true, false,
-TRUE, FALSE, True, False.
-Duration flags accept any input valid for time.ParseDuration.
-
-## More info
-
-You can see the full reference documentation of the pflag package
-[at godoc.org][3], or through go's standard documentation system by
-running `godoc -http=:6060` and browsing to
-[http://localhost:6060/pkg/github.com/ogier/pflag][2] after
-installation.
-
-[2]: http://localhost:6060/pkg/github.com/ogier/pflag
-[3]: http://godoc.org/github.com/ogier/pflag
diff --git a/vendor/github.com/victorhaggqvist/pflag/flag.go b/vendor/github.com/victorhaggqvist/pflag/flag.go
deleted file mode 100644
index cb0c6eb..0000000
--- a/vendor/github.com/victorhaggqvist/pflag/flag.go
+++ /dev/null
@@ -1,644 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-/*
- pflag is a drop-in replacement for Go's flag package, implementing
- POSIX/GNU-style --flags.
-
- pflag is compatible with the GNU extensions to the POSIX recommendations
- for command-line options. See
- http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
-
- Usage:
-
- pflag is a drop-in replacement of Go's native flag package. If you import
- pflag under the name "flag" then all code should continue to function
- with no changes.
-
- import flag "github.com/ogier/pflag"
-
- There is one exception to this: if you directly instantiate the Flag struct
- there is one more field "Shorthand" that you will need to set.
- Most code never instantiates this struct directly, and instead uses
- functions such as String(), BoolVar(), and Var(), and is therefore
- unaffected.
-
- Define flags using flag.String(), Bool(), Int(), etc.
-
- This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
- var ip = flag.Int("flagname", 1234, "help message for flagname")
- If you like, you can bind the flag to a variable using the Var() functions.
- var flagvar int
- func init() {
- flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
- }
- Or you can create custom flags that satisfy the Value interface (with
- pointer receivers) and couple them to flag parsing by
- flag.Var(&flagVal, "name", "help message for flagname")
- For such flags, the default value is just the initial value of the variable.
-
- After all flags are defined, call
- flag.Parse()
- to parse the command line into the defined flags.
-
- Flags may then be used directly. If you're using the flags themselves,
- they are all pointers; if you bind to variables, they're values.
- fmt.Println("ip has value ", *ip)
- fmt.Println("flagvar has value ", flagvar)
-
- After parsing, the arguments after the flag are available as the
- slice flag.Args() or individually as flag.Arg(i).
- The arguments are indexed from 0 through flag.NArg()-1.
-
- The pflag package also defines some new functions that are not in flag,
- that give one-letter shorthands for flags. You can use these by appending
- 'P' to the name of any function that defines a flag.
- var ip = flag.IntP("flagname", "f", 1234, "help message")
- var flagvar bool
- func init() {
- flag.BoolVarP("boolname", "b", true, "help message")
- }
- flag.VarP(&flagVar, "varname", "v", 1234, "help message")
- Shorthand letters can be used with single dashes on the command line.
- Boolean shorthand flags can be combined with other shorthand flags.
-
- Command line flag syntax:
- --flag // boolean flags only
- --flag=x
-
- Unlike the flag package, a single dash before an option means something
- different than a double dash. Single dashes signify a series of shorthand
- letters for flags. All but the last shorthand letter must be boolean flags.
- // boolean flags
- -f
- -abc
- // non-boolean flags
- -n 1234
- -Ifile
- // mixed
- -abcs "hello"
- -abcn1234
-
- Flag parsing stops after the terminator "--". Unlike the flag package,
- flags can be interspersed with arguments anywhere on the command line
- before this terminator.
-
- Integer flags accept 1234, 0664, 0x1234 and may be negative.
- Boolean flags (in their long form) accept 1, 0, t, f, true, false,
- TRUE, FALSE, True, False.
- Duration flags accept any input valid for time.ParseDuration.
-
- The default set of command-line flags is controlled by
- top-level functions. The FlagSet type allows one to define
- independent sets of flags, such as to implement subcommands
- in a command-line interface. The methods of FlagSet are
- analogous to the top-level functions for the command-line
- flag set.
-*/
-package pflag
-
-import (
- "errors"
- "fmt"
- "io"
- "os"
- "runtime"
- "sort"
- "strings"
-)
-
-// ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.
-var ErrHelp = errors.New("pflag: help requested")
-
-// ErrorHandling defines how to handle flag parsing errors.
-type ErrorHandling int
-
-const (
- ContinueOnError ErrorHandling = iota
- ExitOnError
- PanicOnError
-)
-
-// A FlagSet represents a set of defined flags.
-type FlagSet struct {
- // Usage is the function called when an error occurs while parsing flags.
- // The field is a function (not a method) that may be changed to point to
- // a custom error handler.
- Usage func()
-
- name string
- parsed bool
- actual map[string]*Flag
- formal map[string]*Flag
- shorthands map[byte]*Flag
- args []string // arguments after flags
- exitOnError bool // does the program exit if there's an error?
- errorHandling ErrorHandling
- output io.Writer // nil means stderr; use out() accessor
- interspersed bool // allow interspersed option/non-option args
-}
-
-// A Flag represents the state of a flag.
-type Flag struct {
- Name string // name as it appears on command line
- Shorthand string // one-letter abbreviated flag
- Usage string // help message
- Value Value // value as set
- DefValue string // default value (as text); for usage message
-}
-
-// sortFlags returns the flags as a slice in lexicographical sorted order.
-func sortFlags(flags map[string]*Flag) []*Flag {
- list := make(sort.StringSlice, len(flags))
- i := 0
- for _, f := range flags {
- list[i] = f.Name
- i++
- }
- list.Sort()
- result := make([]*Flag, len(list))
- for i, name := range list {
- result[i] = flags[name]
- }
- return result
-}
-
-func (f *FlagSet) out() io.Writer {
- if f.output == nil {
- return os.Stderr
- }
- return f.output
-}
-
-// SetOutput sets the destination for usage and error messages.
-// If output is nil, os.Stderr is used.
-func (f *FlagSet) SetOutput(output io.Writer) {
- f.output = output
-}
-
-// VisitAll visits the flags in lexicographical order, calling fn for each.
-// It visits all flags, even those not set.
-func (f *FlagSet) VisitAll(fn func(*Flag)) {
- for _, flag := range sortFlags(f.formal) {
- fn(flag)
- }
-}
-
-// VisitAll visits the command-line flags in lexicographical order, calling
-// fn for each. It visits all flags, even those not set.
-func VisitAll(fn func(*Flag)) {
- CommandLine.VisitAll(fn)
-}
-
-// Visit visits the flags in lexicographical order, calling fn for each.
-// It visits only those flags that have been set.
-func (f *FlagSet) Visit(fn func(*Flag)) {
- for _, flag := range sortFlags(f.actual) {
- fn(flag)
- }
-}
-
-// Visit visits the command-line flags in lexicographical order, calling fn
-// for each. It visits only those flags that have been set.
-func Visit(fn func(*Flag)) {
- CommandLine.Visit(fn)
-}
-
-// Lookup returns the Flag structure of the named flag, returning nil if none exists.
-func (f *FlagSet) Lookup(name string) *Flag {
- return f.formal[name]
-}
-
-// Lookup returns the Flag structure of the named command-line flag,
-// returning nil if none exists.
-func Lookup(name string) *Flag {
- return CommandLine.formal[name]
-}
-
-// Set sets the value of the named flag.
-func (f *FlagSet) Set(name, value string) error {
- flag, ok := f.formal[name]
- if !ok {
- return fmt.Errorf("no such flag -%v", name)
- }
- err := flag.Value.Set(value)
- if err != nil {
- return err
- }
- if f.actual == nil {
- f.actual = make(map[string]*Flag)
- }
- f.actual[name] = flag
- return nil
-}
-
-// Set sets the value of the named command-line flag.
-func Set(name, value string) error {
- return CommandLine.Set(name, value)
-}
-
-// 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 "0":
- return true
- }
- return false
-}
-
-// UnquoteUsage extracts a back-quoted name from the usage
-// string for a flag and returns it and the un-quoted usage.
-// Given "a `name` to show" it returns ("name", "a name to show").
-// If there are no back quotes, the name is an educated guess of the
-// type of the flag's value, or the empty string if the flag is boolean.
-func UnquoteUsage(flag *Flag) (name string, usage string) {
- // Look for a back-quoted name, but avoid the strings package.
- usage = flag.Usage
- for i := 0; i < len(usage); i++ {
- if usage[i] == '`' {
- for j := i + 1; j < len(usage); j++ {
- if usage[j] == '`' {
- name = usage[i+1 : j]
- usage = usage[:i] + name + usage[j+1:]
- return name, usage
- }
- }
- 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 = ""
- case *durationValue:
- name = "duration"
- case *float64Value:
- name = "float"
- case *intValue, *int64Value:
- name = "int"
- case *stringValue:
- name = "string"
- case *uintValue, *uint64Value:
- name = "uint"
- }
- return
-}
-
-// PrintDefaults prints to standard error the default values of all
-// defined command-line flags in the set. See the documentation for
-// the global function PrintDefaults for more information.
-func (f *FlagSet) PrintDefaults() {
- f.VisitAll(func(flag *Flag) {
- s := ""
- if len(flag.Shorthand) > 0 {
- s = fmt.Sprintf(" -%s, --%s", flag.Shorthand, flag.Name)
- } else {
- s = fmt.Sprintf(" --%s", flag.Name)
- }
-
- name, usage := UnquoteUsage(flag)
- if len(name) > 0 {
- s += " " + name
- }
-
- s += "\n \t"
- s += usage
- if !isZeroValue(flag.DefValue) {
- if _, ok := flag.Value.(*stringValue); ok {
- // put quotes on the value
- s += fmt.Sprintf(" (default %q)", flag.DefValue)
- } else {
- s += fmt.Sprintf(" (default %v)", flag.DefValue)
- }
- }
- fmt.Fprint(f.out(), s, "\n")
- })
-}
-
-// PrintDefaults prints to standard error the default values of all defined command-line flags.
-func PrintDefaults() {
- CommandLine.PrintDefaults()
-}
-
-// defaultUsage is the default function to print a usage message.
-func defaultUsage(f *FlagSet) {
- if f.name == "" {
- fmt.Fprintf(f.out(), "Usage:\n")
- } else {
- fmt.Fprintf(f.out(), "Usage of %s:\n", f.name)
- }
- f.PrintDefaults()
-}
-
-// NOTE: Usage is not just defaultUsage(CommandLine)
-// because it serves (via godoc flag Usage) as the example
-// for how to write your own usage function.
-
-// Usage prints to standard error a usage message documenting all defined command-line flags.
-// The function is a variable that may be changed to point to a custom function.
-var Usage = func() {
- fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
- PrintDefaults()
-}
-
-// If defined, the flag --version will print version information
-var Version string
-
-// NFlag returns the number of flags that have been set.
-func (f *FlagSet) NFlag() int { return len(f.actual) }
-
-// NFlag returns the number of command-line flags that have been set.
-func NFlag() int { return len(CommandLine.actual) }
-
-// Arg returns the i'th argument. Arg(0) is the first remaining argument
-// after flags have been processed.
-func (f *FlagSet) Arg(i int) string {
- if i < 0 || i >= len(f.args) {
- return ""
- }
- return f.args[i]
-}
-
-// Arg returns the i'th command-line argument. Arg(0) is the first remaining argument
-// after flags have been processed.
-func Arg(i int) string {
- return CommandLine.Arg(i)
-}
-
-// NArg is the number of arguments remaining after flags have been processed.
-func (f *FlagSet) NArg() int { return len(f.args) }
-
-// NArg is the number of arguments remaining after flags have been processed.
-func NArg() int { return len(CommandLine.args) }
-
-// Args returns the non-flag arguments.
-func (f *FlagSet) Args() []string { return f.args }
-
-// Args returns the non-flag command-line arguments.
-func Args() []string { return CommandLine.args }
-
-// Var defines a flag with the specified name and usage string. The type and
-// value of the flag are represented by the first argument, of type Value, which
-// typically holds a user-defined implementation of Value. For instance, the
-// caller could create a flag that turns a comma-separated string into a slice
-// of strings by giving the slice the methods of Value; in particular, Set would
-// decompose the comma-separated string into the slice.
-func (f *FlagSet) Var(value Value, name string, usage string) {
- f.VarP(value, name, "", usage)
-}
-
-// Like Var, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) VarP(value Value, name, shorthand, usage string) {
- // Remember the default value as a string; it won't change.
- flag := &Flag{name, shorthand, usage, value, value.String()}
- _, alreadythere := f.formal[name]
- if alreadythere {
- msg := fmt.Sprintf("%s flag redefined: %s", f.name, name)
- fmt.Fprintln(f.out(), msg)
- panic(msg) // Happens only if flags are declared with identical names
- }
- if f.formal == nil {
- f.formal = make(map[string]*Flag)
- }
- f.formal[name] = flag
-
- if len(shorthand) == 0 {
- return
- }
- if len(shorthand) > 1 {
- fmt.Fprintf(f.out(), "%s shorthand more than ASCII character: %s\n", f.name, shorthand)
- panic("shorthand is more than one character")
- }
- if f.shorthands == nil {
- f.shorthands = make(map[byte]*Flag)
- }
- c := shorthand[0]
- old, alreadythere := f.shorthands[c]
- if alreadythere {
- fmt.Fprintf(f.out(), "%s shorthand reused: %q for %s already used for %s\n", f.name, c, name, old.Name)
- panic("shorthand redefinition")
- }
- f.shorthands[c] = flag
-}
-
-// Var defines a flag with the specified name and usage string. The type and
-// value of the flag are represented by the first argument, of type Value, which
-// typically holds a user-defined implementation of Value. For instance, the
-// caller could create a flag that turns a comma-separated string into a slice
-// of strings by giving the slice the methods of Value; in particular, Set would
-// decompose the comma-separated string into the slice.
-func Var(value Value, name string, usage string) {
- CommandLine.VarP(value, name, "", usage)
-}
-
-// Like Var, but accepts a shorthand letter that can be used after a single dash.
-func VarP(value Value, name, shorthand, usage string) {
- CommandLine.VarP(value, name, shorthand, usage)
-}
-
-// failf prints to standard error a formatted error and usage message and
-// returns the error.
-func (f *FlagSet) failf(format string, a ...interface{}) error {
- err := fmt.Errorf(format, a...)
- fmt.Fprintln(f.out(), err)
- f.usage()
- return err
-}
-
-// usage calls the Usage method for the flag set, or the usage function if
-// the flag set is CommandLine.
-func (f *FlagSet) usage() {
- if f == CommandLine {
- Usage()
- } else if f.Usage == nil {
- defaultUsage(f)
- } else {
- f.Usage()
- }
-}
-
-func (f *FlagSet) version() {
- if Version != "" {
- fmt.Fprintf(os.Stderr, "%s v%s (%s/%s/%s)\n", os.Args[0], Version, runtime.GOOS, runtime.GOARCH, runtime.Version())
- }
-}
-
-func PrintVersion() {
- CommandLine.version()
-}
-
-func (f *FlagSet) setFlag(flag *Flag, value string, origArg string) error {
- if err := flag.Value.Set(value); err != nil {
- return f.failf("invalid argument %q for %s: %v", value, origArg, err)
- }
- // mark as visited for Visit()
- if f.actual == nil {
- f.actual = make(map[string]*Flag)
- }
- f.actual[flag.Name] = flag
-
- return nil
-}
-
-func (f *FlagSet) parseArgs(args []string) error {
- for len(args) > 0 {
- s := args[0]
- args = args[1:]
- if len(s) == 0 || s[0] != '-' || len(s) == 1 {
- if !f.interspersed {
- f.args = append(f.args, s)
- f.args = append(f.args, args...)
- return nil
- }
- f.args = append(f.args, s)
- continue
- }
-
- if s[1] == '-' {
- if len(s) == 2 { // "--" terminates the flags
- f.args = append(f.args, args...)
- return nil
- }
- name := s[2:]
- if len(name) == 0 || name[0] == '-' || name[0] == '=' {
- return f.failf("bad flag syntax: %s", s)
- }
- split := strings.SplitN(name, "=", 2)
- name = split[0]
- m := f.formal
- flag, alreadythere := m[name] // BUG
- if !alreadythere {
- if name == "help" { // special case for nice help message.
- f.usage()
- return ErrHelp
- } else if name == "version" { // special case for nice version string
- f.version()
- return ErrHelp
- }
- return f.failf("unknown flag: --%s", name)
- }
- if len(split) == 1 {
- if bv, ok := flag.Value.(boolFlag); !ok || !bv.IsBoolFlag() {
- return f.failf("flag needs an argument: %s", s)
- }
- f.setFlag(flag, "true", s)
- } else {
- if err := f.setFlag(flag, split[1], s); err != nil {
- return err
- }
- }
- } else {
- shorthands := s[1:]
- for i := 0; i < len(shorthands); i++ {
- c := shorthands[i]
- flag, alreadythere := f.shorthands[c]
- if !alreadythere {
- if c == 'h' { // special case for nice help message.
- f.usage()
- return ErrHelp
- } else if c == 'V' { // special case for nice version string
- f.version()
- return ErrHelp
- }
- return f.failf("unknown shorthand flag: %q in -%s", c, shorthands)
- }
- if bv, ok := flag.Value.(boolFlag); ok && bv.IsBoolFlag() {
- f.setFlag(flag, "true", s)
- continue
- }
- if i < len(shorthands)-1 {
- if err := f.setFlag(flag, shorthands[i+1:], s); err != nil {
- return err
- }
- break
- }
- if len(args) == 0 {
- return f.failf("flag needs an argument: %q in -%s", c, shorthands)
- }
- if err := f.setFlag(flag, args[0], s); err != nil {
- return err
- }
- args = args[1:]
- break // should be unnecessary
- }
- }
- }
- return nil
-}
-
-// Parse parses flag definitions from the argument list, which should not
-// include the command name. Must be called after all flags in the FlagSet
-// are defined and before flags are accessed by the program.
-// The return value will be ErrHelp if -help was set but not defined.
-func (f *FlagSet) Parse(arguments []string) error {
- f.parsed = true
- f.args = make([]string, 0, len(arguments))
- err := f.parseArgs(arguments)
- if err != nil {
- switch f.errorHandling {
- case ContinueOnError:
- return err
- case ExitOnError:
- os.Exit(2)
- case PanicOnError:
- panic(err)
- }
- }
- return nil
-}
-
-// Parsed reports whether f.Parse has been called.
-func (f *FlagSet) Parsed() bool {
- return f.parsed
-}
-
-// Parse parses the command-line flags from os.Args[1:]. Must be called
-// after all flags are defined and before flags are accessed by the program.
-func Parse() {
- // Ignore errors; CommandLine is set for ExitOnError.
- CommandLine.Parse(os.Args[1:])
-}
-
-// Whether to support interspersed option/non-option arguments.
-func SetInterspersed(interspersed bool) {
- CommandLine.SetInterspersed(interspersed)
-}
-
-// Parsed returns true if the command-line flags have been parsed.
-func Parsed() bool {
- return CommandLine.Parsed()
-}
-
-// The default set of command-line flags, parsed from os.Args.
-var CommandLine = NewFlagSet(os.Args[0], ExitOnError)
-
-// NewFlagSet returns a new, empty flag set with the specified name and
-// error handling property.
-func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet {
- f := &FlagSet{
- name: name,
- errorHandling: errorHandling,
- interspersed: true,
- }
- return f
-}
-
-// Whether to support interspersed option/non-option arguments.
-func (f *FlagSet) SetInterspersed(interspersed bool) {
- f.interspersed = interspersed
-}
-
-// Init sets the name and error handling property for a flag set.
-// By default, the zero FlagSet uses an empty name and the
-// ContinueOnError error handling policy.
-func (f *FlagSet) Init(name string, errorHandling ErrorHandling) {
- f.name = name
- f.errorHandling = errorHandling
-}