1
0
Fork 0
mirror of https://github.com/Luzifer/update-gotools.git synced 2024-12-22 12:51:20 +00:00

Execute commands with env passthrough

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-03-19 19:58:58 +01:00
parent a84766069d
commit a0edebea21
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -5,10 +5,11 @@ import (
"os" "os"
"os/exec" "os/exec"
"path" "path"
"strings"
"github.com/Luzifer/go_helpers/str"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/Luzifer/go_helpers/env"
"github.com/Luzifer/go_helpers/str"
) )
func executeCommands(logEntry *log.Entry, commands [][]string) error { func executeCommands(logEntry *log.Entry, commands [][]string) error {
@ -27,14 +28,12 @@ func executeCommands(logEntry *log.Entry, commands [][]string) error {
} }
func executeCommand(command []string, stdout, stderr io.Writer, cwd string) error { func executeCommand(command []string, stdout, stderr io.Writer, cwd string) error {
env := []string{ e := env.ListToMap(os.Environ())
strings.Join([]string{"GOPATH", cfgFile.GoPath}, "="), e["GOPATH"] = cfgFile.GoPath
strings.Join([]string{"PATH", os.Getenv("PATH")}, "="),
}
cmd := exec.Command(command[0], command[1:]...) cmd := exec.Command(command[0], command[1:]...)
cmd.Dir = cwd cmd.Dir = cwd
cmd.Env = env cmd.Env = env.MapToList(e)
cmd.Stdout = stdout cmd.Stdout = stdout
cmd.Stderr = stderr cmd.Stderr = stderr
return cmd.Run() return cmd.Run()