Skip to content

Commit

Permalink
close #24
Browse files Browse the repository at this point in the history
  • Loading branch information
voidint committed May 10, 2017
1 parent 584958d commit 96d5628
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion tool/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strings"

"github.com/lmika/shellwords"
"github.com/voidint/gbb/config"
"github.com/voidint/gbb/variable"
)
Expand Down Expand Up @@ -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(' ')
}
Expand Down
4 changes: 2 additions & 2 deletions tool/gb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/lmika/shellwords"
"github.com/voidint/gbb/config"
)

Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion tool/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"runtime"
"strings"

"github.com/lmika/shellwords"
"github.com/voidint/gbb/config"
)

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion variable/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os/exec"
"strings"

"github.com/lmika/shellwords"
)

// CmdVar 命令变量
Expand Down Expand Up @@ -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])
Expand Down
4 changes: 3 additions & 1 deletion variable/git_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os/exec"
"strings"

"github.com/lmika/shellwords"
)

const (
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions variable/git_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/bouk/monkey"
"github.com/lmika/shellwords"
. "github.com/smartystreets/goconvey/convey"
)

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 96d5628

Please sign in to comment.