From 1cebee8d974a7d4055211bd34b8b3a5b590e0e10 Mon Sep 17 00:00:00 2001 From: spf13 Date: Fri, 11 Jul 2014 10:28:03 -0400 Subject: [PATCH] Better binding to Pflag --- viper.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/viper.go b/viper.go index 2037881..709349c 100644 --- a/viper.go +++ b/viper.go @@ -123,7 +123,15 @@ func BindPFlag(key string, flag *pflag.Flag) (err error) { return fmt.Errorf("flag for %q is nil", key) } pflags[key] = flag - SetDefault(key, flag.Value.String()) + + 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()) + } return nil }