github.com/puellanivis/breton@v0.2.16/lib/gnuflag/float.go (about) 1 package gnuflag 2 3 import ( 4 "strconv" 5 ) 6 7 // -- float64 Value 8 type float64Value float64 9 10 func (f *float64Value) Set(s string) error { 11 v, err := strconv.ParseFloat(s, 64) 12 *f = float64Value(v) 13 return err 14 } 15 16 func (f float64Value) Get() interface{} { return float64(f) } 17 18 func (f float64Value) String() string { return strconv.FormatFloat(float64(f), 'g', -1, 64) } 19 20 // Float defines a float64 flag with specified name, and usage string. 21 // The return value is the address of a float64 variable that stores the value of the flag. 22 func (f *FlagSet) Float(name string, usage string, options ...Option) *float64 { 23 p := new(float64) 24 if err := f.Var((*float64Value)(p), name, usage, options...); err != nil { 25 panic(err) 26 } 27 return p 28 } 29 30 // Float defines a float64 flag with specified name, and usage string. 31 // The return value is the address of a float64 variable that stores the value of the flag. 32 func Float(name string, usage string, options ...Option) *float64 { 33 return CommandLine.Float(name, usage, options...) 34 }