Skip to content

Commit

Permalink
Merge pull request #42 from dyweb/todo/exec
Browse files Browse the repository at this point in the history
Go run shell commands properly
  • Loading branch information
at15 authored Jul 8, 2016
2 parents ebc6c20 + c00974a commit ae4da24
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .ayi.example.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
debug: true
test:
# FIXME: why sh is needed.... why can't just run the script
- sh ./scripts/test.sh
- sh -c "go test -v -cover $(glide novendor)"
user: example-user
project:
name: example
Expand Down
3 changes: 0 additions & 3 deletions scripts/test.sh

This file was deleted.

7 changes: 1 addition & 6 deletions util/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ import (

// Command return a Command struct from a full commad
func Command(cmd string) (*exec.Cmd, error) {
// NOTE: do not use strings.Fields or Split !
segments, err := shellquote.Split(cmd)
if err != nil {
return nil, errors.Wrap(err, "Cannot parse command")
}
name := segments[0]
// FIXME: this is not working ...
// 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:]...), nil
}

Expand Down
5 changes: 1 addition & 4 deletions util/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ func TestCommand(t *testing.T) {
assert := assert.New(t)
cmd, _ := Command("ls")
assert.Equal(1, len(cmd.Args))
// FIXME: $(glide novendor) will not be interpreted
// TODO: try sh -c "go test -v -cover $(glide novendor)"
cmd, _ = Command("go test -v -cover $(glide novendor)")
assert.Equal("test", cmd.Args[1])
// NOTE: you must use sh -c since subshell is included
cmd, _ = Command("sh -c \"go test -v -cover $(glide novendor)\"")
assert.Equal("go test -v -cover $(glide novendor)", cmd.Args[2])
}
Expand Down

0 comments on commit ae4da24

Please sign in to comment.