Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shellquote #24

Merged
merged 1 commit into from
Sep 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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