Skip to content

Commit

Permalink
Parse booleans and null as string values with --set-string flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Elmar Ritsch committed May 29, 2018
1 parent 1c25929 commit 272d9bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/strvals/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ func inMap(k rune, m map[rune]bool) bool {

func typedVal(v []rune, st bool) interface{} {
val := string(v)

if st {
return val
}

if strings.EqualFold(val, "true") {
return true
}
Expand All @@ -337,8 +342,8 @@ func typedVal(v []rune, st bool) interface{} {
return nil
}

// If this value does not start with zero, and not returnString, try parsing it to an int
if !st && len(val) != 0 && val[0] != '0' {
// If this value does not start with zero, try parsing it to an int
if len(val) != 0 && val[0] != '0' {
if iv, err := strconv.ParseInt(val, 10, 64); err == nil {
return iv
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/strvals/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ func TestParseSet(t *testing.T) {
expect: map[string]interface{}{"long_int_string": "1234567890"},
err: false,
},
{
str: "boolean=true",
expect: map[string]interface{}{"boolean": "true"},
err: false,
},
}
tests := []struct {
str string
Expand Down Expand Up @@ -117,6 +122,10 @@ func TestParseSet(t *testing.T) {
str: "long_int=1234567890",
expect: map[string]interface{}{"long_int": 1234567890},
},
{
str: "boolean=true",
expect: map[string]interface{}{"boolean": true},
},
{
str: "name1,name2=",
err: true,
Expand Down

0 comments on commit 272d9bc

Please sign in to comment.