github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/helper/flags/autopilot_flags.go (about) 1 package flags 2 3 // These flag type implementations are provided to maintain autopilot command 4 // backwards compatibility. 5 6 import ( 7 "fmt" 8 "strconv" 9 "time" 10 ) 11 12 // BoolValue provides a flag value that's aware if it has been set. 13 type BoolValue struct { 14 v *bool 15 } 16 17 // Merge will overlay this value if it has been set. 18 func (b *BoolValue) Merge(onto *bool) { 19 if b.v != nil { 20 *onto = *(b.v) 21 } 22 } 23 24 // Set implements the flag.Value interface. 25 func (b *BoolValue) Set(v string) error { 26 if b.v == nil { 27 b.v = new(bool) 28 } 29 var err error 30 *(b.v), err = strconv.ParseBool(v) 31 return err 32 } 33 34 // String implements the flag.Value interface. 35 func (b *BoolValue) String() string { 36 var current bool 37 if b.v != nil { 38 current = *(b.v) 39 } 40 return fmt.Sprintf("%v", current) 41 } 42 43 // DurationValue provides a flag value that's aware if it has been set. 44 type DurationValue struct { 45 v *time.Duration 46 } 47 48 // Merge will overlay this value if it has been set. 49 func (d *DurationValue) Merge(onto *time.Duration) { 50 if d.v != nil { 51 *onto = *(d.v) 52 } 53 } 54 55 // Set implements the flag.Value interface. 56 func (d *DurationValue) Set(v string) error { 57 if d.v == nil { 58 d.v = new(time.Duration) 59 } 60 var err error 61 *(d.v), err = time.ParseDuration(v) 62 return err 63 } 64 65 // String implements the flag.Value interface. 66 func (d *DurationValue) String() string { 67 var current time.Duration 68 if d.v != nil { 69 current = *(d.v) 70 } 71 return current.String() 72 } 73 74 // UintValue provides a flag value that's aware if it has been set. 75 type UintValue struct { 76 v *uint 77 } 78 79 // Merge will overlay this value if it has been set. 80 func (u *UintValue) Merge(onto *uint) { 81 if u.v != nil { 82 *onto = *(u.v) 83 } 84 } 85 86 // Set implements the flag.Value interface. 87 func (u *UintValue) Set(v string) error { 88 if u.v == nil { 89 u.v = new(uint) 90 } 91 parsed, err := strconv.ParseUint(v, 0, 64) 92 *(u.v) = (uint)(parsed) 93 return err 94 } 95 96 // String implements the flag.Value interface. 97 func (u *UintValue) String() string { 98 var current uint 99 if u.v != nil { 100 current = *(u.v) 101 } 102 return fmt.Sprintf("%v", current) 103 }