From 97b50e0f292847a8e3f166aa9386f3e51b1c5e95 Mon Sep 17 00:00:00 2001 From: unclejack Date: Wed, 13 Aug 2014 17:23:11 +0300 Subject: [PATCH] integcli: consolidate cmd exit code processing Docker-DCO-1.1-Signed-off-by: Cristian Staretu (github: unclejack) --- integration-cli/utils.go | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/integration-cli/utils.go b/integration-cli/utils.go index c686a0b085..c828e94fef 100644 --- a/integration-cli/utils.go +++ b/integration-cli/utils.go @@ -28,9 +28,7 @@ func getExitCode(err error) (int, error) { return exitCode, fmt.Errorf("failed to get exit code") } -func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) { - exitCode = 0 - out, err := cmd.CombinedOutput() +func processExitCode(err error) (exitCode int) { if err != nil { var exiterr error if exitCode, exiterr = getExitCode(err); exiterr != nil { @@ -39,6 +37,13 @@ func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error exitCode = 127 } } + return +} + +func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) { + exitCode = 0 + out, err := cmd.CombinedOutput() + exitCode = processExitCode(err) output = string(out) return } @@ -51,15 +56,8 @@ func runCommandWithStdoutStderr(cmd *exec.Cmd) (stdout string, stderr string, ex cmd.Stderr = &stderrBuffer cmd.Stdout = &stdoutBuffer err = cmd.Run() + exitCode = processExitCode(err) - if err != nil { - var exiterr error - if exitCode, exiterr = getExitCode(err); exiterr != nil { - // TODO: Fix this so we check the error's text. - // we've failed to retrieve exit code, so we set it to 127 - exitCode = 127 - } - } stdout = stdoutBuffer.String() stderr = stderrBuffer.String() return @@ -68,28 +66,14 @@ func runCommandWithStdoutStderr(cmd *exec.Cmd) (stdout string, stderr string, ex func runCommand(cmd *exec.Cmd) (exitCode int, err error) { exitCode = 0 err = cmd.Run() - if err != nil { - var exiterr error - if exitCode, exiterr = getExitCode(err); exiterr != nil { - // TODO: Fix this so we check the error's text. - // we've failed to retrieve exit code, so we set it to 127 - exitCode = 127 - } - } + exitCode = processExitCode(err) return } func startCommand(cmd *exec.Cmd) (exitCode int, err error) { exitCode = 0 err = cmd.Start() - if err != nil { - var exiterr error - if exitCode, exiterr = getExitCode(err); exiterr != nil { - // TODO: Fix this so we check the error's text. - // we've failed to retrieve exit code, so we set it to 127 - exitCode = 127 - } - } + exitCode = processExitCode(err) return }