Skip to content

Commit f0f943a

Browse files
authored
Fix incorrect docs on shell -- cmd (#837)
## Summary Our docs and inline help for `devbox shell` are not updated to show that `devbox shell -- cmd` is deprecated, potentially leading to a lot of user errors. This PR update the docs and inline help. We should also try to detect when `--` is passed to `devbox shell`, and direct users to `devbox run` instead ## How was it tested? localhost,
1 parent ff35719 commit f0f943a

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

docs/app/docs/cli_reference/devbox_run.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# devbox run
22

3-
Starts a new interactive shell and runs your target script in it. The shell will exit once your target script is completed or when it is terminated via CTRL-C. Scripts can be defined in your `devbox.json`
3+
Starts a new interactive shell and runs your target script in it. The shell will exit once your target script is completed or when it is terminated via CTRL-C. Scripts can be defined in your `devbox.json`.
4+
5+
You can also run arbitrary commands in your devbox shell by passing them as arguments to `devbox run`. For example:
6+
7+
```bash
8+
devbox run echo "Hello World"
9+
```
10+
Will print `Hello World` to the console from within your devbox shell.
411

512
For more details, read our [scripts guide](../guides/scripts.md)
613

714
```bash
8-
devbox run <script> [flags]
15+
devbox run <script | command> [flags]
916
```
1017

1118
## Options

docs/app/docs/cli_reference/devbox_shell.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ Start a new shell or run a command with access to your packages
44

55
## Synopsis
66

7-
Start a new shell or run a command with access to your packages.
8-
If invoked without `cmd`, this will start an interactive shell based on the devbox.json in your current directory, or the directory provided with `dir`.
9-
If invoked with a `cmd`, this will start a shell based on the devbox.json provided in `dir`, run the command, and then exit.
7+
Start a new shell or run a command with access to your packages. The interactive shell will use the devbox.json in your current directory, or the directory provided with `dir`.
108

119
```bash
12-
devbox shell [<dir>] -- [<cmd>] [flags]
10+
devbox shell [<dir>] [flags]
1311
```
1412

1513
## Options

docs/app/docs/guides/scripts.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,25 @@ Again
4444

4545
Your devbox shell will exit once the last line of your script has finished running, or when you interrupt the script with CTRL-C (or a SIGINT signal).
4646

47+
## Running a One-off Command
48+
49+
You can use `devbox run` to run any command in your Devbox shell, even if you have not defined it as a script. For example, you can run the command below to print "Hello World" in your Devbox shell:
50+
51+
```bash
52+
devbox run echo "Hello World"
53+
```
54+
55+
For commands that use flags, you can use the `--` separator to tell Devbox that the rest of the command is a single command to run. For example, the following command will show you all the processes listening on port 80:
56+
57+
```bash
58+
devbox run -- lsof -i :80
59+
```
60+
4761

4862
## Tips on using Scripts
4963

5064
1. Since `init_hook` runs everytime you start your shell, you should use primarily use it for setting environment variables and aliases. For longer running tasks like database setup, you can create and run a Devbox script
51-
2. You can use Devbox scripts to start and manage long running background processes and daemons. For example -- If you are working on a LAMP stack project, you can use scripts to start MySQL and Apache in separate shells and monitor their logs. Once you are done developing, you can use CTRL-C to exit the processes and shells
65+
2. You can use Devbox scripts to start and manage long running background processes and daemons.
66+
1. For example -- If you are working on a LAMP stack project, you can use scripts to start MySQL and Apache in separate shells and monitor their logs. Once you are done developing, you can use CTRL-C to exit the processes and shells
5267
3. If a script feels too long to put it directly in `devbox.json`, you can save it as a shell script in your project, and then invoke it in your `devbox scripts`.
5368
4. For more ideas, see the LAMP stack example in our [Devbox examples repo](https://github.com/jetpack-io/devbox/tree/main/examples/stacks/lapp-stack).

internal/boxcli/shell.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ func ShellCmd() *cobra.Command {
2222
command := &cobra.Command{
2323
Use: "shell",
2424
Short: "Start a new shell with access to your packages",
25-
Long: "Start a new shell or run a command with access to your packages.\n\n" +
26-
"If invoked without `cmd`, devbox will start an interactive shell.\n" +
27-
"If invoked with a `cmd`, devbox will run the command in a shell and then exit.\n" +
28-
"In both cases, the shell will be started using the devbox.json found in the --config flag directory. " +
25+
Long: "Start a new shell with access to your packages.\n\n" +
26+
"If the --config flag is set, the shell will be started using the devbox.json found in the --config flag directory. " +
2927
"If --config isn't set, then devbox recursively searches the current directory and its parents.",
3028
Args: cobra.NoArgs,
3129
PreRunE: ensureNixInstalled,

0 commit comments

Comments
 (0)