Skip to content

Commit

Permalink
Merge pull request #105 from xushiwei/log
Browse files Browse the repository at this point in the history
gsh: exec cmdline first
  • Loading branch information
xushiwei committed Feb 18, 2024
2 parents e1d042b + a765755 commit 55e88da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions gsh/classfile.go
Expand Up @@ -68,15 +68,10 @@ func (p *App) Exec__0(env map[string]string, name string, args ...string) error
return p.execWith(cmdEnv, name, args...)
}

// Exec executes a shell command.
func (p *App) Exec__1(name string, args ...string) error {
return p.execWith(nil, name, args...)
}

// Exec executes a shell command line with $env variables support.
// - exec "GOP_GOCMD=tinygo gop run ."
// - exec "ls -l $HOME"
func (p *App) Exec__2(cmdline string) error {
func (p *App) Exec__1(cmdline string) error {
var iCmd = -1
var items = strings.Fields(cmdline)
var env []string
Expand Down Expand Up @@ -116,6 +111,11 @@ func (p *App) Exec__2(cmdline string) error {
return p.execWith(env, items[iCmd], items[iCmd+1:]...)
}

// Exec executes a shell command.
func (p *App) Exec__2(name string, args ...string) error {
return p.execWith(nil, name, args...)
}

// LastErr returns error of last command execution.
func (p *App) LastErr() error {
return p.err
Expand Down
10 changes: 5 additions & 5 deletions gsh/gsh_test.go
Expand Up @@ -79,7 +79,7 @@ func (p *myApp) MainEntry() {
t := p.t
err := p.Gop_Exec("ls", "-l")
check(t, err)
err = p.Exec__1("ls", "-l")
err = p.Exec__2("ls", "-l")
check(t, err)
}

Expand Down Expand Up @@ -119,7 +119,7 @@ func TestExecSh(t *testing.T) {
var app App
app.initApp()
capout(&app, func() {
err := app.Exec__2("FOO=123 ./app $BAR")
err := app.Exec__1("FOO=123 ./app $BAR")
check(t, err)
})
if v := app.Output(); v != "[FOO=123 BAR=bar] [./app bar]\n" {
Expand All @@ -131,7 +131,7 @@ func TestExecSh2(t *testing.T) {
var app App
app.initApp()
capout(&app, func() {
err := app.Exec__2("FOO=$BAR ./app $FOO")
err := app.Exec__1("FOO=$BAR ./app $FOO")
check(t, err)
})
if v := app.Output(); v != "[FOO=bar BAR=bar] [./app bar]\n" {
Expand All @@ -142,15 +142,15 @@ func TestExecSh2(t *testing.T) {
func TestExecSh3(t *testing.T) {
var app App
app.initApp()
err := app.Exec__2("FOO=$BAR X=1")
err := app.Exec__1("FOO=$BAR X=1")
checkErr(t, err, "exec: no command")
}

func TestExecSh4(t *testing.T) {
var app App
app.initApp()
capout(&app, func() {
err := app.Exec__2("FOO=$BAR X=1 ./app")
err := app.Exec__1("FOO=$BAR X=1 ./app")
check(t, err)
})
if v := app.Output(); v != "[FOO=bar BAR=bar X=1] [./app]\n" {
Expand Down

0 comments on commit 55e88da

Please sign in to comment.