Skip to content

Commit

Permalink
Dynamic commands: support --flag as true value (#1551)
Browse files Browse the repository at this point in the history
  • Loading branch information
crufter committed Oct 30, 2020
1 parent 09a3110 commit c248621
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/dynamic.go
Expand Up @@ -281,6 +281,9 @@ func flagsToRequest(flags map[string][]string, req *goregistry.Value) (map[strin
coerceValue := func(valueType string, value []string) (interface{}, error) {
switch valueType {
case "bool":
if len(strings.TrimSpace(value[0])) == 0 {
return true, nil
}
return strconv.ParseBool(value[0])
case "int32":
return strconv.Atoi(value[0])
Expand Down
14 changes: 14 additions & 0 deletions cmd/dynamic_test.go
Expand Up @@ -202,6 +202,20 @@ func TestDynamicFlagParsing(t *testing.T) {
},
},
},
{
args: []string{"--b"},
values: &goregistry.Value{
Values: []*goregistry.Value{
{
Name: "b",
Type: "bool",
},
},
},
expected: map[string]interface{}{
"b": true,
},
},
}
for _, c := range cases {
_, flags, err := splitCmdArgs(c.args)
Expand Down

0 comments on commit c248621

Please sign in to comment.