MCPcopy Index your code
hub / github.com/jetify-com/devbox / RunScript

Function RunScript

internal/nix/run.go:17–39  ·  view source on GitHub ↗
(projectDir, cmdWithArgs string, env map[string]string)

Source from the content-addressed store, hash-verified

15)
16
17func 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}

Callers 1

RunScriptMethod · 0.92

Calls 4

GetPathOrDefaultFunction · 0.92
NewExecErrorFunction · 0.92
CommandMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected