-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue.go
61 lines (47 loc) · 954 Bytes
/
value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package flaq
import (
"strconv"
"time"
)
// Value is the interface to the dynamic value stored in a flag.
type Value interface {
Set(string) error
}
type stringValue string
func (s *stringValue) Set(val string) error {
*s = stringValue(val)
return nil
}
type boolValue bool
func (b *boolValue) Set(val string) error {
if val == "" {
*b = true
return nil
}
v, err := strconv.ParseBool(val)
*b = boolValue(v)
return err
}
type countValue int
func (c *countValue) Set(_ string) error {
*c++
return nil
}
type intValue int
func (i *intValue) Set(val string) error {
v, err := strconv.Atoi(val)
*i = intValue(v)
return err
}
type durationValue time.Duration
func (d *durationValue) Set(val string) error {
v, err := time.ParseDuration(val)
*d = durationValue(v)
return err
}
type float64Value float64
func (f *float64Value) Set(val string) error {
v, err := strconv.ParseFloat(val, 64)
*f = float64Value(v)
return err
}