1package pflag
2
3import (
4	"fmt"
5	"strconv"
6)
7
8// -- float64 Value
9type float64Value float64
10
11func newFloat64Value(val float64, p *float64) *float64Value {
12	*p = val
13	return (*float64Value)(p)
14}
15
16func (f *float64Value) Set(s string) error {
17	v, err := strconv.ParseFloat(s, 64)
18	*f = float64Value(v)
19	return err
20}
21
22func (f *float64Value) Type() string {
23	return "float64"
24}
25
26func (f *float64Value) String() string { return fmt.Sprintf("%v", *f) }
27
28func float64Conv(sval string) (interface{}, error) {
29	return strconv.ParseFloat(sval, 64)
30}
31
32// GetFloat64 return the float64 value of a flag with the given name
33func (f *FlagSet) GetFloat64(name string) (float64, error) {
34	val, err := f.getFlagType(name, "float64", float64Conv)
35	if err != nil {
36		return 0, err
37	}
38	return val.(float64), nil
39}
40
41// Float64Var defines a float64 flag with specified name, default value, and usage string.
42// The argument p points to a float64 variable in which to store the value of the flag.
43func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) {
44	f.VarP(newFloat64Value(value, p), name, "", usage)
45}
46
47// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
48func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
49	f.VarP(newFloat64Value(value, p), name, shorthand, usage)
50}
51
52// Float64Var defines a float64 flag with specified name, default value, and usage string.
53// The argument p points to a float64 variable in which to store the value of the flag.
54func Float64Var(p *float64, name string, value float64, usage string) {
55	CommandLine.VarP(newFloat64Value(value, p), name, "", usage)
56}
57
58// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
59func Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
60	CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage)
61}
62
63// Float64 defines a float64 flag with specified name, default value, and usage string.
64// The return value is the address of a float64 variable that stores the value of the flag.
65func (f *FlagSet) Float64(name string, value float64, usage string) *float64 {
66	p := new(float64)
67	f.Float64VarP(p, name, "", value, usage)
68	return p
69}
70
71// Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
72func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 {
73	p := new(float64)
74	f.Float64VarP(p, name, shorthand, value, usage)
75	return p
76}
77
78// Float64 defines a float64 flag with specified name, default value, and usage string.
79// The return value is the address of a float64 variable that stores the value of the flag.
80func Float64(name string, value float64, usage string) *float64 {
81	return CommandLine.Float64P(name, "", value, usage)
82}
83
84// Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
85func Float64P(name, shorthand string, value float64, usage string) *float64 {
86	return CommandLine.Float64P(name, shorthand, value, usage)
87}
88