diff --git a/util/command.go b/util/command.go index 7457c80..2bfa778 100644 --- a/util/command.go +++ b/util/command.go @@ -1,6 +1,7 @@ package util import ( + "fmt" "os" "os/exec" "strings" @@ -8,8 +9,13 @@ import ( // 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:]...) } diff --git a/util/command_test.go b/util/command_test.go index 9e75742..e98d246 100644 --- a/util/command_test.go +++ b/util/command_test.go @@ -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\"")) }