fix command run path bug (#52)

* rebase upstream

* rebase

* trim no need line

* trim no need line

* trim no need line

* optimized go path logic

Co-authored-by: kingxt <dream4kingxt@163.com>
This commit is contained in:
kingxt
2020-09-08 12:19:34 +08:00
committed by GitHub
parent ff7c14c6b6
commit 4408767981
5 changed files with 24 additions and 16 deletions

View File

@@ -8,7 +8,7 @@ import (
"runtime"
)
func Run(arg string) (string, error) {
func Run(arg string, dir string) (string, error) {
goos := runtime.GOOS
var cmd *exec.Cmd
switch goos {
@@ -19,7 +19,9 @@ func Run(arg string) (string, error) {
default:
return "", fmt.Errorf("unexpected os: %v", goos)
}
if len(dir) > 0 {
cmd.Dir = dir
}
dtsout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
cmd.Stdout = dtsout

View File

@@ -169,7 +169,7 @@ func (g *defaultRpcGenerator) genCall() error {
// if mockgen is already installed, it will generate code of gomock for shared files
_, err = exec.LookPath("mockgen")
if mockGenInstalled {
execx.Run(fmt.Sprintf("go generate %s", filename))
execx.Run(fmt.Sprintf("go generate %s", filename), "")
}
return nil

View File

@@ -74,7 +74,7 @@ func (g *defaultRpcGenerator) genPb() error {
func (g *defaultRpcGenerator) protocGenGo(target string) error {
src := filepath.Dir(g.Ctx.ProtoFileSrc)
sh := fmt.Sprintf(`protoc -I=%s --go_out=plugins=grpc:%s %s`, src, target, g.Ctx.ProtoFileSrc)
stdout, err := execx.Run(sh)
stdout, err := execx.Run(sh, "")
if err != nil {
return err
}