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

Method Run

internal/devbox/shell.go:220–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

218}
219
220func (s *DevboxShell) Run() error {
221 var cmd *exec.Cmd
222 shellrc, err := s.writeDevboxShellrc()
223 if err != nil {
224 // We don't have a good fallback here, since all the variables we need for anything to work
225 // are in the shellrc file. For now let's fail. Later on, we should remove the vars from the
226 // shellrc file. That said, one of the variables we have to evaluate ($shellHook), so we need
227 // the shellrc file anyway (unless we remove the hook somehow).
228 slog.Error("failed to write devbox shellrc", "err", err)
229 return errors.WithStack(err)
230 }
231
232 // Setup other files that affect the shell settings and environments.
233 s.setupShellStartupFiles(filepath.Dir(shellrc))
234 extraEnv, extraArgs := s.shellRCOverrides(shellrc)
235 env := s.env
236 for k, v := range extraEnv {
237 env[k] = v
238 }
239 env["SHELL"] = s.binPath
240
241 cmd = exec.Command(s.binPath)
242 cmd.Env = envir.MapToPairs(env)
243 cmd.Args = append(cmd.Args, extraArgs...)
244 cmd.Stdin = os.Stdin
245 cmd.Stdout = os.Stdout
246 cmd.Stderr = os.Stderr
247
248 slog.Debug("Executing shell %s with args: %v", s.binPath, cmd.Args)
249 err = cmd.Run()
250
251 // If the error is an ExitError, this means the shell started up fine but there was
252 // an error from executing a shell command or script.
253 //
254 // This could be from one of the generated shellrc commands, but more likely is from
255 // a user's command or script. So, we want to return nil for this.
256 if exitErr := (&exec.ExitError{}); errors.As(err, &exitErr) {
257 return nil
258 }
259
260 // This means that there was an error from devbox's code or nix's code. Not a user
261 // error and so we do return it.
262 return errors.WithStack(err)
263}
264
265func (s *DevboxShell) shellRCOverrides(shellrc string) (extraEnv map[string]string, extraArgs []string) {
266 // Shells have different ways of overriding the shellrc, so we need to

Callers

nothing calls this directly

Calls 7

writeDevboxShellrcMethod · 0.95
shellRCOverridesMethod · 0.95
RunMethod · 0.95
MapToPairsFunction · 0.92
CommandMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected