diff --git a/cmd/cue/cmd/script_test.go b/cmd/cue/cmd/script_test.go index 233cc9b19f1..32fcd1740fe 100644 --- a/cmd/cue/cmd/script_test.go +++ b/cmd/cue/cmd/script_test.go @@ -27,6 +27,7 @@ import ( "strings" "testing" + "github.com/google/shlex" "github.com/rogpeppe/go-internal/goproxytest" "github.com/rogpeppe/go-internal/gotooltest" "github.com/rogpeppe/go-internal/testscript" @@ -154,13 +155,10 @@ func TestX(t *testing.T) { continue } - // TODO: Ugly hack to get args. Do more principled parsing. - var args []string - for _, a := range strings.Split(cmd, " ")[1:] { - args = append(args, strings.Trim(a, "'")) - } + args, err := shlex.Split(cmd) + check(err) - c, err := New(args) + c, err := New(args[1:]) check(err) b := &bytes.Buffer{} c.SetOutput(b) diff --git a/go.mod b/go.mod index 3dc147bed67..a77dbf5bb19 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ require ( github.com/cockroachdb/apd/v2 v2.0.1 github.com/emicklei/proto v1.6.15 github.com/google/go-cmp v0.4.0 + github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/google/uuid v1.2.0 github.com/kr/pretty v0.1.0 github.com/kylelemons/godebug v1.1.0 diff --git a/go.sum b/go.sum index cfe3f2bd92e..c3de26aa440 100644 --- a/go.sum +++ b/go.sum @@ -45,6 +45,8 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=