Skip to content

Commit

Permalink
extend stringToString pflag binding to stringToInt pflag
Browse files Browse the repository at this point in the history
(cherry picked from commit 0c4bf03)
  • Loading branch information
vorishirne authored and VOrishirne committed Nov 8, 2022
1 parent d9854e3 commit 4c789b2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ func (v *Viper) find(lcaseKey string, flagDefault bool) interface{} {
res, _ := readAsCSV(s)
return cast.ToIntSlice(res)
case "stringToString", "stringToInt":
return csvKeyValueConv(flag.ValueString())
return stringToInterfaceCong(flag.ValueString())
default:
return flag.ValueString()
}
Expand Down Expand Up @@ -1349,7 +1349,7 @@ func (v *Viper) find(lcaseKey string, flagDefault bool) interface{} {
res, _ := readAsCSV(s)
return cast.ToIntSlice(res)
case "stringToString", "stringToInt":
return csvKeyValueConv(flag.ValueString())
return stringToInterfaceCong(flag.ValueString())
default:
return flag.ValueString()
}
Expand All @@ -1371,7 +1371,7 @@ func readAsCSV(val string) ([]string, error) {

// mostly copied from pflag's implementation of this operation here https://github.com/spf13/pflag/blob/master/string_to_string.go#L79
// alterations are: errors are swallowed, map[string]interface{} is returned in order to enable cast.ToStringMap
func csvKeyValueConv(val string) interface{} {
func stringToInterfaceCong(val string) interface{} {
val = strings.Trim(val, "[]")
// An empty string would cause an empty map
if len(val) == 0 {
Expand Down

0 comments on commit 4c789b2

Please sign in to comment.