-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from asdf-vm/tb/shim-exec-2
feat(golang-rewrite): create `asdf exec` command
- Loading branch information
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Package exec handles replacing the asdf go process with | ||
package exec | ||
|
||
import ( | ||
"syscall" | ||
) | ||
|
||
// Exec invokes syscall.Exec to exec an executable. Requires an absolute path to | ||
// executable. | ||
func Exec(executablePath string, args []string, env []string) error { | ||
return syscall.Exec(executablePath, append([]string{executablePath}, args...), env) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package exec | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/rogpeppe/go-internal/testscript" | ||
) | ||
|
||
func execit() int { | ||
// Exec only works with absolute path | ||
cmdPath, _ := exec.LookPath(os.Args[1]) | ||
err := Exec(cmdPath, os.Args[2:], os.Environ()) | ||
|
||
if err != nil { | ||
fmt.Printf("Err: %#+v\n", err.Error()) | ||
} | ||
|
||
return 0 | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
os.Exit(testscript.RunMain(m, map[string]func() int{ | ||
"execit": execit, | ||
})) | ||
} | ||
|
||
func TestExec(t *testing.T) { | ||
testscript.Run(t, testscript.Params{ | ||
Dir: "testdata/script", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
env ENV=foo | ||
execit echo this is a $ENV | ||
stdout 'this is a foo\n' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
execit echo this is a test | ||
stdout 'this is a test\n' |