Implement Float64Flag. See #46

This commit is contained in:
Katrina Owen
2013-12-03 05:42:09 -08:00
parent 41fe2d8682
commit 2ec51afe91
4 changed files with 72 additions and 0 deletions

View File

@@ -27,6 +27,10 @@ func (c *Context) Int(name string) int {
return lookupInt(name, c.flagSet)
}
func (c *Context) Float64(name string) float64 {
return lookupFloat64(name, c.flagSet)
}
// Looks up the value of a local bool flag, returns false if no bool flag exists
func (c *Context) Bool(name string) bool {
return lookupBool(name, c.flagSet)
@@ -120,6 +124,19 @@ func lookupInt(name string, set *flag.FlagSet) int {
return 0
}
func lookupFloat64(name string, set *flag.FlagSet) float64 {
f := set.Lookup(name)
if f != nil {
val, err := strconv.ParseFloat(f.Value.String(), 64)
if err != nil {
return 0
}
return val
}
return 0
}
func lookupString(name string, set *flag.FlagSet) string {
f := set.Lookup(name)
if f != nil {