Skip to content

Commit

Permalink
boxcli: don't print help w/ shell non-zero exit code (#38)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gcurtis committed Aug 30, 2022
1 parent 14c47ea commit e749a56
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion boxcli/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package boxcli
import (
"fmt"
"os"
"os/exec"

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

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

return box.Shell()
err = box.Shell()
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
cmd.SilenceErrors = true
cmd.SilenceUsage = true
}
return err
}

0 comments on commit e749a56

Please sign in to comment.