-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuint64.go
61 lines (49 loc) · 1.19 KB
/
uint64.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 flags
import "github.com/cstockton/go-conv"
// Uint64Value flag type.
type Uint64Value struct {
Value
V *uint64
}
// Set converts and sets a value
func (val *Uint64Value) Set(v interface{}) error {
converted, err := conv.Uint64(v)
if err != nil {
return err
}
*val.V = converted
return nil
}
// Uint64 creates new Uint64 flag.
// Accepts a list of additional resolvers that are evaluated in sequence and
// the first one to yield a valid value is chosen.
// If no resolver yileds a valid value the default flag value is used.
// If flag is provided as a cli arg it will take precedence over all resolvers and the default value.
func (fs *FlagSet) Uint64(name, usage string, val uint64, r ...ResolverFunc) *uint64 {
fs.initFlagSet()
v := Uint64Value{
Value: Value{
name: name,
resolvers: r,
},
V: fs.fs.Uint64(name, val, usage),
}
fs.Values = append(fs.Values, v)
return v.V
}
func (fs *FlagSet) parseUint64Vals() {
for i, val := range fs.Values {
uint64Val, ok := val.(Uint64Value)
if !ok {
continue
}
if fs.hasArg(uint64Val.name) {
continue
}
for _, r := range uint64Val.resolvers {
if r(fs, uint64Val.name, uint64(0), i) {
break
}
}
}
}