Skip to content

Commit e749a56

Browse files
authored
boxcli: don't print help w/ shell non-zero exit code (#38)
Don't print an error message or the usage help when `devbox shell` exits with a non-zero code. We still want to propagate the shell's exit code in order to support scripts. Before: $ devbox shell Installing nix packages. This may take a while... Starting a devbox shell... $ exit 1 Usage: devbox shell [<dir>] [flags] Flags: -h, --help help for shell After: $ devbox shell Installing nix packages. This may take a while... Starting a devbox shell... $ exit 1 $ echo $? 1
1 parent 14c47ea commit e749a56

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

boxcli/shell.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package boxcli
66
import (
77
"fmt"
88
"os"
9+
"os/exec"
910

1011
"github.com/pkg/errors"
1112
"github.com/spf13/cobra"
@@ -37,5 +38,11 @@ func runShellCmd(cmd *cobra.Command, args []string) error {
3738

3839
fmt.Println("Installing nix packages. This may take a while...")
3940

40-
return box.Shell()
41+
err = box.Shell()
42+
var exitErr *exec.ExitError
43+
if errors.As(err, &exitErr) {
44+
cmd.SilenceErrors = true
45+
cmd.SilenceUsage = true
46+
}
47+
return err
4148
}

0 commit comments

Comments
 (0)