1package pflag
2
3import (
4	"fmt"
5	"strconv"
6)
7
8// -- float32 Value
9type float32Value float32
10
11func newFloat32Value(val float32, p *float32) *float32Value {
12	*p = val
13	return (*float32Value)(p)
14}
15
16func (f *float32Value) Set(s string) error {
17	v, err := strconv.ParseFloat(s, 32)
18	*f = float32Value(v)
19	return err
20}
21
22func (f *float32Value) Type() string {
23	return "float32"
24}
25
26func (f *float32Value) String() string { return fmt.Sprintf("%v", *f) }
27
28// Float32Var defines a float32 flag with specified name, default value, and usage string.
29// The argument p points to a float32 variable in which to store the value of the flag.
30func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) {
31	f.VarP(newFloat32Value(value, p), name, "", usage)
32}
33
34// Like Float32Var, but accepts a shorthand letter that can be used after a single dash.
35func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
36	f.VarP(newFloat32Value(value, p), name, shorthand, usage)
37}
38
39// Float32Var defines a float32 flag with specified name, default value, and usage string.
40// The argument p points to a float32 variable in which to store the value of the flag.
41func Float32Var(p *float32, name string, value float32, usage string) {
42	CommandLine.VarP(newFloat32Value(value, p), name, "", usage)
43}
44
45// Like Float32Var, but accepts a shorthand letter that can be used after a single dash.
46func Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
47	CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage)
48}
49
50// Float32 defines a float32 flag with specified name, default value, and usage string.
51// The return value is the address of a float32 variable that stores the value of the flag.
52func (f *FlagSet) Float32(name string, value float32, usage string) *float32 {
53	p := new(float32)
54	f.Float32VarP(p, name, "", value, usage)
55	return p
56}
57
58// Like Float32, but accepts a shorthand letter that can be used after a single dash.
59func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 {
60	p := new(float32)
61	f.Float32VarP(p, name, shorthand, value, usage)
62	return p
63}
64
65// Float32 defines a float32 flag with specified name, default value, and usage string.
66// The return value is the address of a float32 variable that stores the value of the flag.
67func Float32(name string, value float32, usage string) *float32 {
68	return CommandLine.Float32P(name, "", value, usage)
69}
70
71// Like Float32, but accepts a shorthand letter that can be used after a single dash.
72func Float32P(name, shorthand string, value float32, usage string) *float32 {
73	return CommandLine.Float32P(name, shorthand, value, usage)
74}
75