From 96d5628709f68f1e59a7f46e3a50dae2a533dd04 Mon Sep 17 00:00:00 2001 From: voidint Date: Wed, 10 May 2017 14:03:02 +0800 Subject: [PATCH] close https://github.com/voidint/gbb/issues/24 --- tool/builder.go | 3 ++- tool/gb.go | 4 ++-- tool/golang.go | 3 ++- variable/cmd.go | 4 +++- variable/git_commit.go | 4 +++- variable/git_commit_test.go | 5 +++-- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tool/builder.go b/tool/builder.go index 619f6e9..b86a2c2 100644 --- a/tool/builder.go +++ b/tool/builder.go @@ -7,6 +7,7 @@ import ( "os" "strings" + "github.com/lmika/shellwords" "github.com/voidint/gbb/config" "github.com/voidint/gbb/variable" ) @@ -52,7 +53,7 @@ func chdir(dir string, debug bool) (err error) { func ldflags(conf *config.Config) (flags string, err error) { var buf bytes.Buffer - if val := Args(strings.Fields(conf.Tool)).ExtractLdflags(); val != "" { + if val := Args(shellwords.Split(conf.Tool)).ExtractLdflags(); val != "" { buf.WriteString(val) buf.WriteByte(' ') } diff --git a/tool/gb.go b/tool/gb.go index f4ed7df..7459850 100644 --- a/tool/gb.go +++ b/tool/gb.go @@ -4,8 +4,8 @@ import ( "fmt" "os" "os/exec" - "strings" + "github.com/lmika/shellwords" "github.com/voidint/gbb/config" ) @@ -32,7 +32,7 @@ func (b *GBBuilder) buildDir(dir string) error { return err } - cmdArgs := strings.Fields(b.conf.Tool) // go install ==> []string{"go", "install"} + cmdArgs := shellwords.Split(b.conf.Tool) // go install ==> []string{"go", "install"} flags, err := ldflags(b.conf) if err != nil { diff --git a/tool/golang.go b/tool/golang.go index 670e0e8..b66d2e1 100644 --- a/tool/golang.go +++ b/tool/golang.go @@ -10,6 +10,7 @@ import ( "runtime" "strings" + "github.com/lmika/shellwords" "github.com/voidint/gbb/config" ) @@ -45,7 +46,7 @@ func (b *GoBuilder) buildDir(dir string) error { return err } - cmdArgs := strings.Fields(b.conf.Tool) // go install ==> []string{"go", "install"} + cmdArgs := shellwords.Split(b.conf.Tool) // go install ==> []string{"go", "install"} mainPkg, err := isMainPkg(dir) if err != nil { diff --git a/variable/cmd.go b/variable/cmd.go index b838d99..705ece4 100644 --- a/variable/cmd.go +++ b/variable/cmd.go @@ -4,6 +4,8 @@ import ( "fmt" "os/exec" "strings" + + "github.com/lmika/shellwords" ) // CmdVar 命令变量 @@ -32,7 +34,7 @@ func (v *CmdVar) Eval(expr string, debug bool) (val string, err error) { } func (v *CmdVar) exec(nameAndArgs string) (output []byte, err error) { - fields := strings.Fields(nameAndArgs) + fields := shellwords.Split(nameAndArgs) var cmd *exec.Cmd if len(fields) == 1 { cmd = exec.Command(fields[0]) diff --git a/variable/git_commit.go b/variable/git_commit.go index 9723097..f1e4f54 100644 --- a/variable/git_commit.go +++ b/variable/git_commit.go @@ -4,6 +4,8 @@ import ( "fmt" "os/exec" "strings" + + "github.com/lmika/shellwords" ) const ( @@ -51,7 +53,7 @@ func (v *GitCommitVar) Match(expr string) (matched bool) { func (v *GitCommitVar) headCommit(debug bool) (commit string, err error) { var cmd *exec.Cmd - cmdAndArgs := strings.Fields(v.cmd) + cmdAndArgs := shellwords.Split(v.cmd) if len(cmdAndArgs) == 1 { cmd = exec.Command(cmdAndArgs[0]) } else if len(cmdAndArgs) >= 2 { diff --git a/variable/git_commit_test.go b/variable/git_commit_test.go index 754f15a..956bd5b 100644 --- a/variable/git_commit_test.go +++ b/variable/git_commit_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/bouk/monkey" + "github.com/lmika/shellwords" . "github.com/smartystreets/goconvey/convey" ) @@ -70,10 +71,10 @@ func TestGitCommitVarEval(t *testing.T) { }) Convey("panic", func() { - monkey.Patch(strings.Fields, func(s string) []string { + monkey.Patch(shellwords.Split, func(s string) []string { return []string{} }) - defer monkey.Unpatch(strings.Fields) + defer monkey.Unpatch(shellwords.Split) So(func() { _, _ = DefaultGitCommitVar.Eval("", true) }, ShouldPanicWith, "unreachable")