Skip to content

Commit

Permalink
use shellquote (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-eeo authored and stanislas-m committed Sep 23, 2018
1 parent cfb4532 commit 27624dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions bubbler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ func Test_Exec(t *testing.T) {
c("echo hello")
r.Equal("hello\n", bb.String())
}

func Test_ExecQuoted(t *testing.T) {
r := require.New(t)

b := NewBubbler(nil)
f := fizzer{b}
bb := &bytes.Buffer{}
c := f.Exec(bb)
// without proper splitting we would get "'a b c'"
c("echo 'a b c'")
r.Equal("a b c\n", bb.String())
}
9 changes: 6 additions & 3 deletions fizz.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"io/ioutil"
"os"
"os/exec"
"strings"

"github.com/kballard/go-shellquote"
"github.com/pkg/errors"
)

Expand All @@ -26,12 +26,15 @@ func (f fizzer) add(s string, err error) error {

func (f fizzer) Exec(out io.Writer) func(string) error {
return func(s string) error {
args := strings.Split(s, " ")
args, err := shellquote.Split(s)
if err != nil {
return errors.Wrapf(err, "error parsing command: %s", s)
}
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = out
cmd.Stderr = os.Stderr
err := cmd.Run()
err = cmd.Run()
if err != nil {
return errors.Wrapf(err, "error executing command: %s", s)
}
Expand Down

0 comments on commit 27624dc

Please sign in to comment.