7
// -- time.Duration Value
8
type durationValue time.Duration
10
func newDurationValue(val time.Duration, p *time.Duration) *durationValue {
12
return (*durationValue)(p)
15
func (d *durationValue) Set(s string) error {
16
v, err := time.ParseDuration(s)
21
func (d *durationValue) Type() string {
25
func (d *durationValue) String() string { return (*time.Duration)(d).String() }
27
func durationConv(sval string) (interface{}, error) {
28
return time.ParseDuration(sval)
31
// GetDuration return the duration value of a flag with the given name
32
func (f *FlagSet) GetDuration(name string) (time.Duration, error) {
33
val, err := f.getFlagType(name, "duration", durationConv)
37
return val.(time.Duration), nil
40
// DurationVar defines a time.Duration flag with specified name, default value, and usage string.
41
// The argument p points to a time.Duration variable in which to store the value of the flag.
42
func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
43
f.VarP(newDurationValue(value, p), name, "", usage)
46
// DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
47
func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) {
48
f.VarP(newDurationValue(value, p), name, shorthand, usage)
51
// DurationVar defines a time.Duration flag with specified name, default value, and usage string.
52
// The argument p points to a time.Duration variable in which to store the value of the flag.
53
func DurationVar(p *time.Duration, name string, value time.Duration, usage string) {
54
CommandLine.VarP(newDurationValue(value, p), name, "", usage)
57
// DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
58
func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) {
59
CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage)
62
// Duration defines a time.Duration flag with specified name, default value, and usage string.
63
// The return value is the address of a time.Duration variable that stores the value of the flag.
64
func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration {
65
p := new(time.Duration)
66
f.DurationVarP(p, name, "", value, usage)
70
// DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
71
func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration {
72
p := new(time.Duration)
73
f.DurationVarP(p, name, shorthand, value, usage)
77
// Duration defines a time.Duration flag with specified name, default value, and usage string.
78
// The return value is the address of a time.Duration variable that stores the value of the flag.
79
func Duration(name string, value time.Duration, usage string) *time.Duration {
80
return CommandLine.DurationP(name, "", value, usage)
83
// DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
84
func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration {
85
return CommandLine.DurationP(name, shorthand, value, usage)