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

Function runShellCmd

internal/boxcli/shell.go:65–116  ·  view source on GitHub ↗
(cmd *cobra.Command, flags shellCmdFlags)

Source from the content-addressed store, hash-verified

63}
64
65func runShellCmd(cmd *cobra.Command, flags shellCmdFlags) error {
66 ctx := cmd.Context()
67 env, err := flags.Env(flags.config.path)
68 if err != nil {
69 return err
70 }
71
72 // Check the directory exists.
73 box, err := devbox.Open(&devopt.Opts{
74 Dir: flags.config.path,
75 Env: env,
76 Environment: flags.config.environment,
77 Stderr: cmd.ErrOrStderr(),
78 })
79 if err != nil {
80 return errors.WithStack(err)
81 }
82
83 if flags.printEnv {
84 // false for includeHooks is because init hooks is not compatible with .envrc files generated
85 // by versions older than 0.4.6
86 script, err := box.EnvExports(cmd.Context(), devopt.EnvExportsOpts{})
87 if err != nil {
88 return err
89 }
90 // explicitly print to stdout instead of stderr so that direnv can read the output
91 fmt.Fprint(cmd.OutOrStdout(), script)
92 return nil // return here to prevent opening a devbox shell
93 }
94
95 if envir.IsDevboxShellEnabled() {
96 return shellInceptionErrorMsg("devbox shell")
97 }
98
99 return box.Shell(ctx, devopt.EnvOptions{
100 Hooks: devopt.LifecycleHooks{
101 OnStaleState: func() {
102 if !flags.recomputeEnv {
103 ux.FHidableWarning(
104 ctx,
105 cmd.ErrOrStderr(),
106 devbox.StateOutOfDateMessage,
107 "with --recompute=true",
108 )
109 }
110 },
111 },
112 OmitNixEnv: flags.omitNixEnv,
113 Pure: flags.pure,
114 SkipRecompute: !flags.recomputeEnv,
115 })
116}
117
118func shellInceptionErrorMsg(cmdPath string) error {
119 return usererr.New("You are already in an active %[1]s.\nRun `exit` before calling `%[1]s` again."+

Callers 1

shellCmdFunction · 0.85

Calls 7

OpenFunction · 0.92
IsDevboxShellEnabledFunction · 0.92
FHidableWarningFunction · 0.92
shellInceptionErrorMsgFunction · 0.85
EnvExportsMethod · 0.80
ShellMethod · 0.80
EnvMethod · 0.65

Tested by

no test coverage detected