summaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/pflag/duration.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/github.com/spf13/pflag/duration.go (renamed from vendor/github.com/victorhaggqvist/pflag/duration.go)32
1 files changed, 22 insertions, 10 deletions
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)
}