Path: blob/main/vendor/github.com/spf13/pflag/float64.go
2875 views
package pflag12import "strconv"34// -- float64 Value5type float64Value float6467func newFloat64Value(val float64, p *float64) *float64Value {8*p = val9return (*float64Value)(p)10}1112func (f *float64Value) Set(s string) error {13v, err := strconv.ParseFloat(s, 64)14*f = float64Value(v)15return err16}1718func (f *float64Value) Type() string {19return "float64"20}2122func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) }2324func float64Conv(sval string) (interface{}, error) {25return strconv.ParseFloat(sval, 64)26}2728// GetFloat64 return the float64 value of a flag with the given name29func (f *FlagSet) GetFloat64(name string) (float64, error) {30val, err := f.getFlagType(name, "float64", float64Conv)31if err != nil {32return 0, err33}34return val.(float64), nil35}3637// Float64Var defines a float64 flag with specified name, default value, and usage string.38// The argument p points to a float64 variable in which to store the value of the flag.39func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) {40f.VarP(newFloat64Value(value, p), name, "", usage)41}4243// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.44func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) {45f.VarP(newFloat64Value(value, p), name, shorthand, usage)46}4748// Float64Var defines a float64 flag with specified name, default value, and usage string.49// The argument p points to a float64 variable in which to store the value of the flag.50func Float64Var(p *float64, name string, value float64, usage string) {51CommandLine.VarP(newFloat64Value(value, p), name, "", usage)52}5354// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.55func Float64VarP(p *float64, name, shorthand string, value float64, usage string) {56CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage)57}5859// Float64 defines a float64 flag with specified name, default value, and usage string.60// The return value is the address of a float64 variable that stores the value of the flag.61func (f *FlagSet) Float64(name string, value float64, usage string) *float64 {62p := new(float64)63f.Float64VarP(p, name, "", value, usage)64return p65}6667// Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.68func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 {69p := new(float64)70f.Float64VarP(p, name, shorthand, value, usage)71return p72}7374// Float64 defines a float64 flag with specified name, default value, and usage string.75// The return value is the address of a float64 variable that stores the value of the flag.76func Float64(name string, value float64, usage string) *float64 {77return CommandLine.Float64P(name, "", value, usage)78}7980// Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.81func Float64P(name, shorthand string, value float64, usage string) *float64 {82return CommandLine.Float64P(name, shorthand, value, usage)83}848586