diff options
| author | Eric Paris <[email protected]> | 2015-06-22 14:19:06 -0500 |
|---|---|---|
| committer | Eric Paris <[email protected]> | 2015-06-22 14:19:06 -0500 |
| commit | 0367f40254871b491ab74dbe3cc237f06fb34f27 (patch) | |
| tree | 540c2f9b6983fcc366426429ff977a5a46c3fd45 /float64.go | |
| parent | 381cb823881391d5673cf2fc41e38feba8a8e49a (diff) | |
| parent | 1e0a23de9163cb0706137856f1d060f88e3f277c (diff) | |
Merge pull request #25 from eparis/GetFlagType
Add new FlagSet.Get{Int,String,...} accessor functions
Diffstat (limited to 'float64.go')
| -rw-r--r-- | float64.go | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -25,6 +25,19 @@ func (f *float64Value) Type() string { func (f *float64Value) String() string { return fmt.Sprintf("%v", *f) } +func float64Conv(sval string) (interface{}, error) { + return strconv.ParseFloat(sval, 64) +} + +// GetFloat64 return the float64 value of a flag with the given name +func (f *FlagSet) GetFloat64(name string) (float64, error) { + val, err := f.getFlagType(name, "float64", float64Conv) + if err != nil { + return 0, err + } + return val.(float64), nil +} + // Float64Var defines a float64 flag with specified name, default value, and usage string. // The argument p points to a float64 variable in which to store the value of the flag. func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) { |
