exit with correct exit code on plugin failure

parent dfdfb893
...@@ -19,6 +19,9 @@ package cmd ...@@ -19,6 +19,9 @@ package cmd
import ( import (
"fmt" "fmt"
"io" "io"
"os"
"os/exec"
"syscall"
"github.com/golang/glog" "github.com/golang/glog"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -109,6 +112,15 @@ func NewCmdForPlugin(f cmdutil.Factory, plugin *plugins.Plugin, runner plugins.P ...@@ -109,6 +112,15 @@ func NewCmdForPlugin(f cmdutil.Factory, plugin *plugins.Plugin, runner plugins.P
} }
if err := runner.Run(plugin, runningContext); err != nil { if err := runner.Run(plugin, runningContext); err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
// check for (and exit with) the correct exit code
// from a failed plugin command execution
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
fmt.Fprintf(errout, "error: %v\n", err)
os.Exit(status.ExitStatus())
}
}
cmdutil.CheckErr(err) cmdutil.CheckErr(err)
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment