Path: blob/main/vendor/github.com/spf13/pflag/float32.go
2875 views
package pflag12import "strconv"34// -- float32 Value5type float32Value float3267func newFloat32Value(val float32, p *float32) *float32Value {8*p = val9return (*float32Value)(p)10}1112func (f *float32Value) Set(s string) error {13v, err := strconv.ParseFloat(s, 32)14*f = float32Value(v)15return err16}1718func (f *float32Value) Type() string {19return "float32"20}2122func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) }2324func float32Conv(sval string) (interface{}, error) {25v, err := strconv.ParseFloat(sval, 32)26if err != nil {27return 0, err28}29return float32(v), nil30}3132// GetFloat32 return the float32 value of a flag with the given name33func (f *FlagSet) GetFloat32(name string) (float32, error) {34val, err := f.getFlagType(name, "float32", float32Conv)35if err != nil {36return 0, err37}38return val.(float32), nil39}4041// Float32Var defines a float32 flag with specified name, default value, and usage string.42// The argument p points to a float32 variable in which to store the value of the flag.43func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) {44f.VarP(newFloat32Value(value, p), name, "", usage)45}4647// Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.48func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) {49f.VarP(newFloat32Value(value, p), name, shorthand, usage)50}5152// Float32Var defines a float32 flag with specified name, default value, and usage string.53// The argument p points to a float32 variable in which to store the value of the flag.54func Float32Var(p *float32, name string, value float32, usage string) {55CommandLine.VarP(newFloat32Value(value, p), name, "", usage)56}5758// Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.59func Float32VarP(p *float32, name, shorthand string, value float32, usage string) {60CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage)61}6263// Float32 defines a float32 flag with specified name, default value, and usage string.64// The return value is the address of a float32 variable that stores the value of the flag.65func (f *FlagSet) Float32(name string, value float32, usage string) *float32 {66p := new(float32)67f.Float32VarP(p, name, "", value, usage)68return p69}7071// Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.72func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 {73p := new(float32)74f.Float32VarP(p, name, shorthand, value, usage)75return p76}7778// Float32 defines a float32 flag with specified name, default value, and usage string.79// The return value is the address of a float32 variable that stores the value of the flag.80func Float32(name string, value float32, usage string) *float32 {81return CommandLine.Float32P(name, "", value, usage)82}8384// Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.85func Float32P(name, shorthand string, value float32, usage string) *float32 {86return CommandLine.Float32P(name, shorthand, value, usage)87}888990