Better binding to Pflag

This commit is contained in:
spf13 2014-07-11 10:28:03 -04:00
parent 7c42740ea6
commit 1cebee8d97
1 changed files with 9 additions and 1 deletions

View File

@ -123,7 +123,15 @@ func BindPFlag(key string, flag *pflag.Flag) (err error) {
return fmt.Errorf("flag for %q is nil", key) return fmt.Errorf("flag for %q is nil", key)
} }
pflags[key] = flag pflags[key] = flag
switch flag.Value.Type() {
case "int", "int8", "int16", "int32", "int64":
SetDefault(key, cast.ToInt(flag.Value.String()))
case "bool":
SetDefault(key, cast.ToBool(flag.Value.String()))
default:
SetDefault(key, flag.Value.String()) SetDefault(key, flag.Value.String())
}
return nil return nil
} }