mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-17 22:37:10 +09:00
keep trailing space at commandline
This commit is contained in:
@@ -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, " ") {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user