Skip to content

Commit

Permalink
[cmd][test] try to use sh -c but failed
Browse files Browse the repository at this point in the history
- sh -c is not working properly, even for simple command
- $(glide novendor) does not even work when direct typed into gitbash,
  it seems the new line has stopped the command from executing

Issue #7
  • Loading branch information
at15 committed Jul 8, 2016
1 parent 603e365 commit 4e813c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion util/command.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package util

import (
"fmt"
"os"
"os/exec"
"strings"
)

// Command return a Command struct from a full commad
func Command(cmd string) *exec.Cmd {
segments := strings.Split(cmd, " ")
segments := strings.Fields(cmd)
name := segments[0]
if (name == "sh") && (segments[1] == "-c") {
// TODO: this does not support use like go test $(glide novendor)
fmt.Println(strings.Join(segments[2:], " "))
return exec.Command("sh", "-c", strings.Join(segments[2:], " "))
}
return exec.Command(name, segments[1:]...)
}

Expand Down
3 changes: 3 additions & 0 deletions util/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ func TestCommand(t *testing.T) {
assert := assert.New(t)
cmd := Command("ls")
assert.Equal(1, len(cmd.Args))
// FIXME: using $(glide novendor) will no work
// TODO: try sh -c "go test -v -cover $(glide novendor)"
cmd = Command("go test -v -cover $(glide novendor)")
assert.Equal("test", cmd.Args[1])
assert.Nil(RunCommand("sh -c \"echo Hi\""))
}

0 comments on commit 4e813c5

Please sign in to comment.