Skip to content

Commit

Permalink
cmd: Propage return codes when forwarding to Toolbx on the host
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryMichal committed May 13, 2022
1 parent ebfc2d2 commit 59d71d7
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 40 deletions.
8 changes: 3 additions & 5 deletions src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,9 @@ func create(cmd *cobra.Command, args []string) error {
return errors.New("this is not a toolbox container")
}

if _, err := utils.ForwardToHost(); err != nil {
return err
}

return nil
cmd.SilenceErrors = true
exitCode, err := utils.ForwardToHost()
return &exitError{exitCode, err}
}

if cmd.Flag("distro").Changed && cmd.Flag("image").Changed {
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ func enter(cmd *cobra.Command, args []string) error {
return errors.New("this is not a toolbox container")
}

if _, err := utils.ForwardToHost(); err != nil {
return err
}

return nil
cmd.SilenceErrors = true
exitCode, err := utils.ForwardToHost()
return &exitError{exitCode, err}
}

var container string
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ func help(cmd *cobra.Command, args []string) error {
return errors.New("this is not a toolbox container")
}

if _, err := utils.ForwardToHost(); err != nil {
return err
}

return nil
cmd.SilenceErrors = true
exitCode, err := utils.ForwardToHost()
return &exitError{exitCode, err}
}

if err := helpShowManual(args); err != nil {
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ func list(cmd *cobra.Command, args []string) error {
return errors.New("this is not a toolbox container")
}

if _, err := utils.ForwardToHost(); err != nil {
return err
}

return nil
cmd.SilenceErrors = true
exitCode, err := utils.ForwardToHost()
return &exitError{exitCode, err}
}

lsContainers := true
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ func rm(cmd *cobra.Command, args []string) error {
return errors.New("this is not a toolbox container")
}

if _, err := utils.ForwardToHost(); err != nil {
return err
}

return nil
cmd.SilenceErrors = true
exitCode, err := utils.ForwardToHost()
return &exitError{exitCode, err}
}

if rmFlags.deleteAll {
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/rmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ func rmi(cmd *cobra.Command, args []string) error {
return errors.New("this is not a toolbox container")
}

if _, err := utils.ForwardToHost(); err != nil {
return err
}

return nil
cmd.SilenceErrors = true
exitCode, err := utils.ForwardToHost()
return &exitError{exitCode, err}
}

if rmiFlags.deleteAll {
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/rootMigrationPath.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ func rootRunImpl(cmd *cobra.Command, args []string) error {
return errors.New("this is not a toolbox container")
}

if _, err := utils.ForwardToHost(); err != nil {
return err
}

return nil
cmd.SilenceErrors = true
exitCode, err := utils.ForwardToHost()
return &exitError{exitCode, err}
}

image, release, err := utils.ResolveImageName("", "", "")
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ func run(cmd *cobra.Command, args []string) error {
return errors.New("this is not a toolbox container")
}

if _, err := utils.ForwardToHost(); err != nil {
return err
}

return nil
cmd.SilenceErrors = true
exitCode, err := utils.ForwardToHost()
return &exitError{exitCode, err}
}

var defaultContainer bool = true
Expand Down
9 changes: 9 additions & 0 deletions test/system/104-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,12 @@ teardown() {
assert_line --index 2 "Error: failed to invoke command /etc in container $(get_latest_container_name)"
assert [ ${#lines[@]} -eq 3 ]
}

@test "run: Run command exiting with non-zero code in a toolbx from within a toolbx" {
create_default_container

run $TOOLBOX run toolbox run /bin/sh -c "exit 42"
assert_failure
assert [ $status -eq 42 ]
assert_output ""
}

0 comments on commit 59d71d7

Please sign in to comment.