All arguments should be of the form --k=v so that bool flags will work

Previously a bool flag would be rendered as --flag false for `flag: false`
which is invalid and results in the opposite of what you'd expect.

Signed-off-by: Darren Shepherd <darren@rancher.com>
pull/2207/head
Darren Shepherd 4 years ago committed by Craig Jellick
parent 64ae6affc5
commit 289ba8df6a

@ -104,15 +104,11 @@ func readConfigFile(file string) (result []string, _ error) {
if slice, ok := v.([]interface{}); ok { if slice, ok := v.([]interface{}); ok {
for _, v := range slice { for _, v := range slice {
result = append(result, prefix+k, convert.ToString(v)) result = append(result, prefix+k+"="+convert.ToString(v))
result = append(result)
} }
} else { } else {
str := convert.ToString(v) str := convert.ToString(v)
result = append(result, prefix+k) result = append(result, prefix+k+"="+str)
if str != "" {
result = append(result, str)
}
} }
} }

@ -150,14 +150,15 @@ func TestConfigFile(t *testing.T) {
func TestParse(t *testing.T) { func TestParse(t *testing.T) {
testDataOutput := []string{ testDataOutput := []string{
"--foo-bar", "baz", "--foo-bar=baz",
"--a-slice", "1", "--a-slice=1",
"--a-slice", "2", "--a-slice=2",
"--a-slice", "", "--a-slice=",
"--a-slice", "three", "--a-slice=three",
"--isempty", "--isempty=",
"-c", "b", "-c=b",
"--islast", "true", "--isfalse=false",
"--islast=true",
} }
defParser := Parser{ defParser := Parser{

@ -6,4 +6,5 @@ a-slice:
- three - three
isempty: isempty:
c: b c: b
isfalse: false
islast: true islast: true
Loading…
Cancel
Save