From 4d92bd086f40c44b63cb46db6810d21fe7681974 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Tue, 28 Jun 2016 22:36:47 -0700 Subject: [PATCH] fix(cmd): lazy load client --- cmd/helm/helm.go | 12 ++++++------ cmd/helm/list.go | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 4552df3fc..886be4ef0 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -19,6 +19,7 @@ package main import ( "errors" "fmt" + "io" "os" "strings" @@ -63,7 +64,7 @@ Environment: $HELM_HOST Set an alternative Tiller host. The format is host:port (default ":44134"). ` -func newRootCmd() *cobra.Command { +func newRootCmd(out io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "helm", Short: "The Helm package manager for Kubernetes.", @@ -83,18 +84,17 @@ func newRootCmd() *cobra.Command { 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") + + cmd.AddCommand(newListCmd(nil, out)) + return cmd } // RootCommand is the top-level command for Helm. -var RootCommand = newRootCmd() +var RootCommand = newRootCmd(os.Stdout) func main() { - out := os.Stdout - client := helm.NewClient(helm.HelmHost(helm.Config.ServAddr)) - cmd := RootCommand - cmd.AddCommand(newListCmd(client, out)) if err := cmd.Execute(); err != nil { os.Exit(1) } diff --git a/cmd/helm/list.go b/cmd/helm/list.go index a767cbec9..42537a71f 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -65,10 +65,7 @@ type lister struct { } func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { - list := &lister{ - client: client, - out: out, - } + list := &lister{out: out} cmd := &cobra.Command{ Use: "list [flags] [FILTER]", Short: "list releases", @@ -79,6 +76,9 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { if len(args) > 0 { list.filter = strings.Join(args, " ") } + if list.client == nil { + list.client = helm.NewClient(helm.HelmHost(helm.Config.ServAddr)) + } return list.run() }, }