stringarray pulls directly from pflag

This commit is contained in:
Patrick Dufour 2018-09-15 12:32:22 -04:00
parent 3171ef9a22
commit 98d51522b2
2 changed files with 16 additions and 0 deletions

View file

@ -14,6 +14,7 @@ type FlagValue interface {
HasChanged() bool
Name() string
ValueString() string
ValueStringArray() []string
ValueType() string
}
@ -51,6 +52,11 @@ func (p pflagValue) ValueString() string {
return p.flag.Value.String()
}
// ValueStringArray returns the value of the flag as []string.
func (p pflagValue) ValueStringArray() []string {
return p.flag.Value.StringArray()
}
// ValueType returns the type of the flag as a string.
func (p pflagValue) ValueType() string {
return p.flag.Value.Type()

View file

@ -731,6 +731,12 @@ func (v *Viper) GetDuration(key string) time.Duration {
return cast.ToDuration(v.Get(key))
}
// GetStringArray returns the value associated with the key as a slice of strings.
func GetStringArray(key string) []string { return v.GetStringArray(key) }
func (v *Viper) GetStringArray(key string) []string {
return cast.ToStringSlice(v.Get(key))
}
// GetStringSlice returns the value associated with the key as a slice of strings.
func GetStringSlice(key string) []string { return v.GetStringSlice(key) }
func (v *Viper) GetStringSlice(key string) []string {
@ -955,6 +961,8 @@ func (v *Viper) find(lcaseKey string) interface{} {
s = strings.TrimSuffix(s, "]")
res, _ := readAsCSV(s)
return res
case "stringArray":
return flag.ValueStringArray()
default:
return flag.ValueString()
}
@ -1024,6 +1032,8 @@ func (v *Viper) find(lcaseKey string) interface{} {
s = strings.TrimSuffix(s, "]")
res, _ := readAsCSV(s)
return res
case "stringArray":
return flag.ValueStringArray()
default:
return flag.ValueString()
}