-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfloat64.go
61 lines (49 loc) · 1.21 KB
/
float64.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"
// Float64Value flag type.
type Float64Value struct {
Value
V *float64
}
// Set converts and sets a value
func (val *Float64Value) Set(v interface{}) error {
converted, err := conv.Float64(v)
if err != nil {
return err
}
*val.V = converted
return nil
}
// Float64 creates new Float64 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) Float64(name, usage string, val float64, r ...ResolverFunc) *float64 {
fs.initFlagSet()
v := Float64Value{
Value: Value{
name: name,
resolvers: r,
},
V: fs.fs.Float64(name, val, usage),
}
fs.Values = append(fs.Values, v)
return v.V
}
func (fs *FlagSet) parseFloat64Vals() {
for i, val := range fs.Values {
float64Val, ok := val.(Float64Value)
if !ok {
continue
}
if fs.hasArg(float64Val.name) {
continue
}
for _, r := range float64Val.resolvers {
if r(fs, float64Val.name, 1.0, i) {
break
}
}
}
}