(cmd *cobra.Command, flags shellCmdFlags)
| 63 | } |
| 64 | |
| 65 | func 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 | |
| 118 | func shellInceptionErrorMsg(cmdPath string) error { |
| 119 | return usererr.New("You are already in an active %[1]s.\nRun `exit` before calling `%[1]s` again."+ |
no test coverage detected