(defaults shellFlagDefaults)
| 32 | } |
| 33 | |
| 34 | func shellCmd(defaults shellFlagDefaults) *cobra.Command { |
| 35 | flags := shellCmdFlags{} |
| 36 | command := &cobra.Command{ |
| 37 | Use: "shell", |
| 38 | Short: "Start a new shell with access to your packages", |
| 39 | Long: "Start a new shell with access to your packages.\n\n" + |
| 40 | "If the --config flag is set, the shell will be started using the devbox.json found in the --config flag directory. " + |
| 41 | "If --config isn't set, then devbox recursively searches the current directory and its parents.", |
| 42 | Args: cobra.NoArgs, |
| 43 | PreRunE: ensureNixInstalled, |
| 44 | RunE: func(cmd *cobra.Command, args []string) error { |
| 45 | return runShellCmd(cmd, flags) |
| 46 | }, |
| 47 | } |
| 48 | |
| 49 | command.Flags().BoolVar( |
| 50 | &flags.printEnv, "print-env", false, "print script to setup shell environment") |
| 51 | command.Flags().BoolVar( |
| 52 | &flags.pure, "pure", false, "if this flag is specified, devbox creates an isolated shell inheriting almost no variables from the current environment. A few variables, in particular HOME, USER and DISPLAY, are retained.") |
| 53 | command.Flags().BoolVar( |
| 54 | &flags.omitNixEnv, "omit-nix-env", defaults.omitNixEnv, |
| 55 | "shell environment will omit the env-vars from print-dev-env", |
| 56 | ) |
| 57 | _ = command.Flags().MarkHidden("omit-nix-env") |
| 58 | command.Flags().BoolVar(&flags.recomputeEnv, "recompute", true, "recompute environment if needed") |
| 59 | |
| 60 | flags.config.register(command) |
| 61 | flags.envFlag.register(command) |
| 62 | return command |
| 63 | } |
| 64 | |
| 65 | func runShellCmd(cmd *cobra.Command, flags shellCmdFlags) error { |
| 66 | ctx := cmd.Context() |
no test coverage detected