ref(cmd): move flags out of init()

pull/921/head
Adam Reese 9 years ago
parent eee6e143d8
commit d32c20fd5c

@ -63,30 +63,35 @@ 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").
` `
// RootCommand is the top-level command for Helm. func newRootCmd() *cobra.Command {
var RootCommand = &cobra.Command{ cmd := &cobra.Command{
Use: "helm", Use: "helm",
Short: "The Helm package manager for Kubernetes.", Short: "The Helm package manager for Kubernetes.",
Long: globalUsage, Long: globalUsage,
PersistentPostRun: teardown,
SilenceUsage: true, SilenceUsage: true,
PersistentPostRun: func(cmd *cobra.Command, args []string) {
teardown()
},
} }
func init() {
home := os.Getenv(homeEnvVar) home := os.Getenv(homeEnvVar)
if home == "" { if home == "" {
home = "$HOME/.helm" home = "$HOME/.helm"
} }
thost := os.Getenv(hostEnvVar) 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(&helmHome, "home", home, "location of your Helm config. Overrides $HELM_HOME.")
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")
return cmd
} }
// RootCommand is the top-level command for Helm.
var RootCommand = newRootCmd()
func main() { func main() {
if err := RootCommand.Execute(); err != nil { cmd := RootCommand
if err := cmd.Execute(); err != nil {
os.Exit(1) os.Exit(1)
} }
} }
@ -112,7 +117,7 @@ func setupConnection(c *cobra.Command, args []string) error {
return nil return nil
} }
func teardown(c *cobra.Command, args []string) { func teardown() {
if tunnel != nil { if tunnel != nil {
tunnel.Close() tunnel.Close()
} }

Loading…
Cancel
Save