(projectDir, cmdWithArgs string, env map[string]string)
| 15 | ) |
| 16 | |
| 17 | func RunScript(projectDir, cmdWithArgs string, env map[string]string) error { |
| 18 | if cmdWithArgs == "" { |
| 19 | return errors.New("attempted to run an empty command or script") |
| 20 | } |
| 21 | |
| 22 | envPairs := []string{} |
| 23 | for k, v := range env { |
| 24 | envPairs = append(envPairs, fmt.Sprintf("%s=%s", k, v)) |
| 25 | } |
| 26 | |
| 27 | // Try to find sh in the PATH, if not, default to a well known absolute path. |
| 28 | shPath := cmdutil.GetPathOrDefault("sh", "/bin/sh") |
| 29 | cmd := exec.Command(shPath, "-c", cmdWithArgs) |
| 30 | cmd.Env = envPairs |
| 31 | cmd.Dir = projectDir |
| 32 | cmd.Stdin = os.Stdin |
| 33 | cmd.Stdout = os.Stdout |
| 34 | cmd.Stderr = os.Stderr |
| 35 | |
| 36 | slog.Debug("executing script", "cmd", cmd.Args) |
| 37 | // Report error as exec error when executing scripts. |
| 38 | return usererr.NewExecError(cmd.Run()) |
| 39 | } |
no test coverage detected