From 46a1cd69a99a9adc7bc366f1eb2c03b62f464d39 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Mon, 9 Sep 2013 21:26:35 +0000 Subject: [PATCH] only os.Exits on error --- commands.go | 4 +++- docker/docker.go | 3 +++ utils/utils.go | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/commands.go b/commands.go index b5eed0888f..df6feac93b 100644 --- a/commands.go +++ b/commands.go @@ -1479,7 +1479,9 @@ func (cli *DockerCli) CmdRun(args ...string) error { if err != nil { return err } - os.Exit(status) + if status != 0 { + return &utils.StatusError{status} + } } return nil diff --git a/docker/docker.go b/docker/docker.go index 9bbd40b696..a0021f3a87 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -75,6 +75,9 @@ func main() { } protoAddrParts := strings.SplitN(flHosts[0], "://", 2) if err := docker.ParseCommands(protoAddrParts[0], protoAddrParts[1], flag.Args()...); err != nil { + if sterr, ok := err.(*utils.StatusError); ok { + os.Exit(sterr.Status) + } log.Fatal(err) os.Exit(-1) } diff --git a/utils/utils.go b/utils/utils.go index aa34abdddc..d417690c0c 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1012,3 +1012,12 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) { } return result, nil } + +// An StatusError reports an unsuccessful exit by a command. +type StatusError struct { + Status int +} + +func (e *StatusError) Error() string { + return fmt.Sprintf("Status: %d", e.Status) +}