forked from hashicorp/consul-replicate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
42 lines (35 loc) · 1.14 KB
/
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
package main
import (
"strconv"
"time"
)
// funcVar is a type of flag that accepts a function that is the string given
// by the user.
type funcVar func(s string) error
func (f funcVar) Set(s string) error { return f(s) }
func (f funcVar) String() string { return "" }
func (f funcVar) IsBoolFlag() bool { return false }
// funcBoolVar is a type of flag that accepts a function, converts the user's
// value to a bool, and then calls the given function.
type funcBoolVar func(b bool) error
func (f funcBoolVar) Set(s string) error {
v, err := strconv.ParseBool(s)
if err != nil {
return err
}
return f(v)
}
func (f funcBoolVar) String() string { return "" }
func (f funcBoolVar) IsBoolFlag() bool { return true }
// funcDurationVar is a type of flag that accepts a function, converts the
// user's value to a duration, and then calls the given function.
type funcDurationVar func(d time.Duration) error
func (f funcDurationVar) Set(s string) error {
v, err := time.ParseDuration(s)
if err != nil {
return err
}
return f(v)
}
func (f funcDurationVar) String() string { return "" }
func (f funcDurationVar) IsBoolFlag() bool { return false }