diff --git a/cmd/micro/util.go b/cmd/micro/util.go index c81fadbf..3f2ecd1b 100644 --- a/cmd/micro/util.go +++ b/cmd/micro/util.go @@ -248,17 +248,20 @@ func SplitCommandArgs(input string) []string { escape = false curArg.WriteRune(r) } - if curArg.Len() > 0 || len(result) == 0 { - result = append(result, curArg.String()) - } + //if curArg.Len() > 0 || len(result) == 0 { + result = append(result, curArg.String()) + // } return result } // JoinCommandArgs joins multiple command arguments and quote the strings if needed. func JoinCommandArgs(args ...string) string { buf := new(bytes.Buffer) + first := true for _, arg := range args { - if buf.Len() > 0 { + if first { + first = false + } else { buf.WriteRune(' ') } if !strings.Contains(arg, " ") { diff --git a/cmd/micro/util_test.go b/cmd/micro/util_test.go index 79ea5a4d..f224b905 100644 --- a/cmd/micro/util_test.go +++ b/cmd/micro/util_test.go @@ -79,15 +79,18 @@ func TestJoinAndSplitCommandArgs(t *testing.T) { {[]string{`foo`}, `foo`}, {[]string{`foo\"bar`}, `foo\"bar`}, {[]string{``}, ``}, + {[]string{`a`, ``}, `a `}, + {[]string{``, ``, ``, ``}, ` `}, } for i, test := range tests { if result := JoinCommandArgs(test.Query...); test.Wanted != result { - t.Errorf("JoinCommandArgs failed at Test %d\nGot: %v", i, result) + t.Errorf("JoinCommandArgs failed at Test %d\nGot: %q", i, result) } if result := SplitCommandArgs(test.Wanted); !reflect.DeepEqual(test.Query, result) { - t.Errorf("SplitCommandArgs failed at Test %d\nGot: %v", i, result) + t.Errorf("SplitCommandArgs failed at Test %d\nGot: `%s`", i, result) } } + }