Commit 4d92bd08 authored by Adam Reese's avatar Adam Reese

fix(cmd): lazy load client

parent 5013da3d
...@@ -19,6 +19,7 @@ package main ...@@ -19,6 +19,7 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"os" "os"
"strings" "strings"
...@@ -63,7 +64,7 @@ Environment: ...@@ -63,7 +64,7 @@ Environment:
$HELM_HOST Set an alternative Tiller host. The format is host:port (default ":44134"). $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{ cmd := &cobra.Command{
Use: "helm", Use: "helm",
Short: "The Helm package manager for Kubernetes.", Short: "The Helm package manager for Kubernetes.",
...@@ -83,18 +84,17 @@ func newRootCmd() *cobra.Command { ...@@ -83,18 +84,17 @@ func newRootCmd() *cobra.Command {
p.StringVar(&tillerHost, "host", thost, "address of tiller. Overrides $HELM_HOST.") p.StringVar(&tillerHost, "host", thost, "address of tiller. Overrides $HELM_HOST.")
p.StringVarP(&tillerNamespace, "namespace", "", "", "kubernetes namespace") p.StringVarP(&tillerNamespace, "namespace", "", "", "kubernetes namespace")
p.BoolVarP(&flagDebug, "debug", "", false, "enable verbose output") p.BoolVarP(&flagDebug, "debug", "", false, "enable verbose output")
cmd.AddCommand(newListCmd(nil, out))
return cmd return cmd
} }
// RootCommand is the top-level command for Helm. // RootCommand is the top-level command for Helm.
var RootCommand = newRootCmd() var RootCommand = newRootCmd(os.Stdout)
func main() { func main() {
out := os.Stdout
client := helm.NewClient(helm.HelmHost(helm.Config.ServAddr))
cmd := RootCommand cmd := RootCommand
cmd.AddCommand(newListCmd(client, out))
if err := cmd.Execute(); err != nil { if err := cmd.Execute(); err != nil {
os.Exit(1) os.Exit(1)
} }
......
...@@ -65,10 +65,7 @@ type lister struct { ...@@ -65,10 +65,7 @@ type lister struct {
} }
func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { func newListCmd(client helm.Interface, out io.Writer) *cobra.Command {
list := &lister{ list := &lister{out: out}
client: client,
out: out,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "list [flags] [FILTER]", Use: "list [flags] [FILTER]",
Short: "list releases", Short: "list releases",
...@@ -79,6 +76,9 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { ...@@ -79,6 +76,9 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command {
if len(args) > 0 { if len(args) > 0 {
list.filter = strings.Join(args, " ") list.filter = strings.Join(args, " ")
} }
if list.client == nil {
list.client = helm.NewClient(helm.HelmHost(helm.Config.ServAddr))
}
return list.run() return list.run()
}, },
} }
......
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