(defaults runFlagDefaults)
| 41 | } |
| 42 | |
| 43 | func runCmd(defaults runFlagDefaults) *cobra.Command { |
| 44 | flags := runCmdFlags{} |
| 45 | command := &cobra.Command{ |
| 46 | Use: "run [<script> | <cmd>]", |
| 47 | Short: "Run a script or command in a shell with access to your packages", |
| 48 | Long: "Start a new shell and runs your script or command in it, exiting when done.\n\n" + |
| 49 | "The script must be defined in `devbox.json`, or else it will be interpreted as an " + |
| 50 | "arbitrary command. You can pass arguments to your script or command. Everything " + |
| 51 | "after `--` will be passed verbatim into your command (see examples).\n\n", |
| 52 | Example: "\nRun a command directly:\n\n devbox add cowsay\n devbox run cowsay hello\n " + |
| 53 | "devbox run -- cowsay -d hello\n\nRun a script (defined as `\"moo\": \"cowsay moo\"`) " + |
| 54 | "in your devbox.json:\n\n devbox run moo", |
| 55 | PreRunE: ensureNixInstalled, |
| 56 | RunE: func(cmd *cobra.Command, args []string) error { |
| 57 | return runScriptCmd(cmd, args, flags) |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | flags.envFlag.register(command) |
| 62 | flags.config.register(command) |
| 63 | command.Flags().BoolVar( |
| 64 | &flags.pure, "pure", false, "if this flag is specified, devbox runs the script in an isolated environment inheriting almost no variables from the current environment. A few variables, in particular HOME, USER and DISPLAY, are retained.") |
| 65 | command.Flags().BoolVarP( |
| 66 | &flags.listScripts, "list", "l", false, "list all scripts defined in devbox.json") |
| 67 | command.Flags().BoolVar( |
| 68 | &flags.omitNixEnv, "omit-nix-env", defaults.omitNixEnv, |
| 69 | "shell environment will omit the env-vars from print-dev-env", |
| 70 | ) |
| 71 | _ = command.Flags().MarkHidden("omit-nix-env") |
| 72 | command.Flags().BoolVar(&flags.recomputeEnv, "recompute", true, "recompute environment if needed") |
| 73 | command.Flags().BoolVar( |
| 74 | &flags.allProjects, |
| 75 | "all-projects", |
| 76 | false, |
| 77 | "run command in all projects in the working directory, recursively. If command is not found in any project, it will be skipped.", |
| 78 | ) |
| 79 | |
| 80 | command.ValidArgs = listScripts(command, flags) |
| 81 | |
| 82 | return command |
| 83 | } |
| 84 | |
| 85 | func listScripts(cmd *cobra.Command, flags runCmdFlags) []string { |
| 86 | path := flags.config.path |
no test coverage detected