Browse code

only os.Exits on error

Victor Vieux authored on 2013/09/10 06:26:35
Showing 3 changed files
... ...
@@ -1479,7 +1479,9 @@ func (cli *DockerCli) CmdRun(args ...string) error {
1479 1479
 		if err != nil {
1480 1480
 			return err
1481 1481
 		}
1482
-		os.Exit(status)
1482
+		if status != 0 {
1483
+			return &utils.StatusError{status}
1484
+		}
1483 1485
 	}
1484 1486
 
1485 1487
 	return nil
... ...
@@ -75,6 +75,9 @@ func main() {
75 75
 		}
76 76
 		protoAddrParts := strings.SplitN(flHosts[0], "://", 2)
77 77
 		if err := docker.ParseCommands(protoAddrParts[0], protoAddrParts[1], flag.Args()...); err != nil {
78
+			if sterr, ok := err.(*utils.StatusError); ok {
79
+				os.Exit(sterr.Status)
80
+			}
78 81
 			log.Fatal(err)
79 82
 			os.Exit(-1)
80 83
 		}
... ...
@@ -1012,3 +1012,12 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
1012 1012
 	}
1013 1013
 	return result, nil
1014 1014
 }
1015
+
1016
+// An StatusError reports an unsuccessful exit by a command.
1017
+type StatusError struct {
1018
+	Status int
1019
+}
1020
+
1021
+func (e *StatusError) Error() string {
1022
+	return fmt.Sprintf("Status: %d", e.Status)
1023
+}