feat(helm): Detailed exit code for helm plugins (#4367)

Resolves #4170
pull/4379/head
KUOKA Yusuke 7 years ago committed by Matt Butcher
parent 4efa18a5ec
commit 3e5b4066d2

@ -158,7 +158,12 @@ func init() {
func main() { func main() {
cmd := newRootCmd(os.Args[1:]) cmd := newRootCmd(os.Args[1:])
if err := cmd.Execute(); err != nil { if err := cmd.Execute(); err != nil {
os.Exit(1) switch e := err.(type) {
case pluginError:
os.Exit(e.code)
default:
os.Exit(1)
}
} }
} }

@ -22,12 +22,18 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"syscall"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/helm/pkg/plugin" "k8s.io/helm/pkg/plugin"
) )
type pluginError struct {
error
code int
}
// loadPlugins loads plugins into the command list. // loadPlugins loads plugins into the command list.
// //
// This follows a different pattern than the other commands because it has // This follows a different pattern than the other commands because it has
@ -87,7 +93,11 @@ func loadPlugins(baseCmd *cobra.Command, out io.Writer) {
if err := prog.Run(); err != nil { if err := prog.Run(); err != nil {
if eerr, ok := err.(*exec.ExitError); ok { if eerr, ok := err.(*exec.ExitError); ok {
os.Stderr.Write(eerr.Stderr) os.Stderr.Write(eerr.Stderr)
return fmt.Errorf("plugin %q exited with error", md.Name) status := eerr.Sys().(syscall.WaitStatus)
return pluginError{
error: fmt.Errorf("plugin %q exited with error", md.Name),
code: status.ExitStatus(),
}
} }
return err return err
} }

Loading…
Cancel
Save