Skip to content

Commit

Permalink
update cmd to make output quoted
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Jun 5, 2024
1 parent b2c3ae1 commit ceb96b7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cmd/xgo/runtime_gen/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.39"
const REVISION = "7fa581a5041d839180502f1d2377ea043803bde7+1"
const NUMBER = 262
const REVISION = "b2c3ae1e20700a8710d719b492b6db9e60fc4800+1"
const NUMBER = 263

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import "fmt"

const VERSION = "1.0.39"
const REVISION = "7fa581a5041d839180502f1d2377ea043803bde7+1"
const NUMBER = 262
const REVISION = "b2c3ae1e20700a8710d719b492b6db9e60fc4800+1"
const NUMBER = 263

func getRevision() string {
revSuffix := ""
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.39"
const REVISION = "7fa581a5041d839180502f1d2377ea043803bde7+1"
const NUMBER = 262
const REVISION = "b2c3ae1e20700a8710d719b492b6db9e60fc4800+1"
const NUMBER = 263

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down
42 changes: 31 additions & 11 deletions support/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ func Run(cmd string, args ...string) error {
}

type CmdBuilder struct {
env []string
dir string
debug bool
stdout io.Writer
stderr io.Writer
env []string
dir string
debug bool
ignoreError bool
stdout io.Writer
stderr io.Writer
}

func Env(env []string) *CmdBuilder {
Expand All @@ -40,6 +41,10 @@ func Debug() *CmdBuilder {
debug: true,
}
}
func IgnoreError(b ...bool) *CmdBuilder {
c := &CmdBuilder{}
return c.IgnoreError(b...)
}

func New() *CmdBuilder {
return &CmdBuilder{}
Expand Down Expand Up @@ -69,6 +74,15 @@ func (c *CmdBuilder) Debug() *CmdBuilder {
return c
}

func (c *CmdBuilder) IgnoreError(b ...bool) *CmdBuilder {
ignore := true
if len(b) > 0 {
ignore = b[0]
}
c.ignoreError = ignore
return c
}

func (c *CmdBuilder) Output(cmd string, args ...string) (string, error) {
return cmdExecEnv(cmd, args, c.env, c.dir, false, c)
}
Expand Down Expand Up @@ -96,12 +110,14 @@ func cmdExecEnv(cmd string, args []string, env []string, dir string, useStdout b
}
}
if dir != "" {
lines = append(lines, "# cd "+dir)
lines = append(lines, "# cd "+Quote(dir))
}
cmdStr := cmd
if len(args) > 0 {
cmdStr += " " + strings.Join(args, " ")
cmdQuotes := make([]string, 0, 1+len(args))
cmdQuotes = append(cmdQuotes, cmd)
for _, arg := range args {
cmdQuotes = append(cmdQuotes, Quote(arg))
}
cmdStr := strings.Join(cmdQuotes, " ")
lines = append(lines, cmdStr)
for _, line := range lines {
fmt.Fprintln(stderr, line)
Expand All @@ -123,8 +139,12 @@ func cmdExecEnv(cmd string, args []string, env []string, dir string, useStdout b
return "", execCmd.Run()
}
out, err := execCmd.Output()
outStr := strings.TrimSuffix(string(out), "\n")
if err != nil {
return "", err
if !c.ignoreError {
return outStr, err
}
err = nil
}
return strings.TrimSuffix(string(out), "\n"), nil
return outStr, nil
}

0 comments on commit ceb96b7

Please sign in to comment.