From d32c20fd5ce8a835999cc736a9460e88cb8891ca Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 28 Jun 2016 12:49:10 -0700 Subject: [PATCH] ref(cmd): move flags out of init() --- cmd/helm/helm.go | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 3a42044e0..779403d8a 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -63,30 +63,35 @@ Environment: $HELM_HOST Set an alternative Tiller host. The format is host:port (default ":44134"). ` -// RootCommand is the top-level command for Helm. -var RootCommand = &cobra.Command{ - Use: "helm", - Short: "The Helm package manager for Kubernetes.", - Long: globalUsage, - PersistentPostRun: teardown, - SilenceUsage: true, -} - -func init() { +func newRootCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "helm", + Short: "The Helm package manager for Kubernetes.", + Long: globalUsage, + SilenceUsage: true, + PersistentPostRun: func(cmd *cobra.Command, args []string) { + teardown() + }, + } home := os.Getenv(homeEnvVar) if home == "" { home = "$HOME/.helm" } thost := os.Getenv(hostEnvVar) - p := RootCommand.PersistentFlags() + p := cmd.PersistentFlags() p.StringVar(&helmHome, "home", home, "location of your Helm config. Overrides $HELM_HOME.") p.StringVar(&tillerHost, "host", thost, "address of tiller. Overrides $HELM_HOST.") p.StringVarP(&tillerNamespace, "namespace", "", "", "kubernetes namespace") p.BoolVarP(&flagDebug, "debug", "", false, "enable verbose output") + return cmd } +// RootCommand is the top-level command for Helm. +var RootCommand = newRootCmd() + func main() { - if err := RootCommand.Execute(); err != nil { + cmd := RootCommand + if err := cmd.Execute(); err != nil { os.Exit(1) } } @@ -112,7 +117,7 @@ func setupConnection(c *cobra.Command, args []string) error { return nil } -func teardown(c *cobra.Command, args []string) { +func teardown() { if tunnel != nil { tunnel.Close() }