forked from urfave/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag_float64.go
46 lines (35 loc) · 973 Bytes
/
flag_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
package cli
import (
"fmt"
"strconv"
)
type Float64Flag = FlagBase[float64, NoConfig, float64Value]
// -- float64 Value
type float64Value float64
// Below functions are to satisfy the ValueCreator interface
func (f float64Value) Create(val float64, p *float64, c NoConfig) Value {
*p = val
return (*float64Value)(p)
}
func (f float64Value) ToString(b float64) string {
return fmt.Sprintf("%v", b)
}
// Below functions are to satisfy the flag.Value interface
func (f *float64Value) Set(s string) error {
v, err := strconv.ParseFloat(s, 64)
if err != nil {
return err
}
*f = float64Value(v)
return err
}
func (f *float64Value) Get() any { return float64(*f) }
func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) }
// Int looks up the value of a local IntFlag, returns
// 0 if not found
func (cCtx *Context) Float64(name string) float64 {
if v, ok := cCtx.Value(name).(float64); ok {
return v
}
return 0
}