1
0
mirror of https://github.com/docker/cli.git synced 2026-01-15 07:40:57 +03:00

integcli: consolidate cmd exit code processing

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
Upstream-commit: 97b50e0f292847a8e3f166aa9386f3e51b1c5e95
Component: engine
This commit is contained in:
unclejack
2014-08-13 17:23:11 +03:00
parent e9760e60ca
commit 5314f1d0ea

View File

@@ -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
}