-
Notifications
You must be signed in to change notification settings - Fork 2k
/
autopilot_flags.go
103 lines (89 loc) · 2 KB
/
autopilot_flags.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package flags
// These flag type implementations are provided to maintain autopilot command
// backwards compatibility.
import (
"fmt"
"strconv"
"time"
)
// BoolValue provides a flag value that's aware if it has been set.
type BoolValue struct {
v *bool
}
// Merge will overlay this value if it has been set.
func (b *BoolValue) Merge(onto *bool) {
if b.v != nil {
*onto = *(b.v)
}
}
// Set implements the flag.Value interface.
func (b *BoolValue) Set(v string) error {
if b.v == nil {
b.v = new(bool)
}
var err error
*(b.v), err = strconv.ParseBool(v)
return err
}
// String implements the flag.Value interface.
func (b *BoolValue) String() string {
var current bool
if b.v != nil {
current = *(b.v)
}
return fmt.Sprintf("%v", current)
}
// DurationValue provides a flag value that's aware if it has been set.
type DurationValue struct {
v *time.Duration
}
// Merge will overlay this value if it has been set.
func (d *DurationValue) Merge(onto *time.Duration) {
if d.v != nil {
*onto = *(d.v)
}
}
// Set implements the flag.Value interface.
func (d *DurationValue) Set(v string) error {
if d.v == nil {
d.v = new(time.Duration)
}
var err error
*(d.v), err = time.ParseDuration(v)
return err
}
// String implements the flag.Value interface.
func (d *DurationValue) String() string {
var current time.Duration
if d.v != nil {
current = *(d.v)
}
return current.String()
}
// UintValue provides a flag value that's aware if it has been set.
type UintValue struct {
v *uint
}
// Merge will overlay this value if it has been set.
func (u *UintValue) Merge(onto *uint) {
if u.v != nil {
*onto = *(u.v)
}
}
// Set implements the flag.Value interface.
func (u *UintValue) Set(v string) error {
if u.v == nil {
u.v = new(uint)
}
parsed, err := strconv.ParseUint(v, 0, 64)
*(u.v) = (uint)(parsed)
return err
}
// String implements the flag.Value interface.
func (u *UintValue) String() string {
var current uint
if u.v != nil {
current = *(u.v)
}
return fmt.Sprintf("%v", current)
}