From 0ceeb19deda23cb188a8bb1ddc916f33ff97c197 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Fri, 1 Jul 2016 12:25:59 -0700 Subject: [PATCH] ref(cmd): refactor status cmd --- cmd/helm/helm.go | 1 + cmd/helm/status.go | 50 +++++++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index bbc271456..7a9ab74fc 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -89,6 +89,7 @@ func newRootCmd(out io.Writer) *cobra.Command { newCreateCmd(out), newGetCmd(nil, out), newListCmd(nil, out), + newStatusCmd(nil, out), ) return cmd } diff --git a/cmd/helm/status.go b/cmd/helm/status.go index e69774043..b60748dea 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -18,6 +18,7 @@ package main import ( "fmt" + "io" "github.com/spf13/cobra" @@ -29,33 +30,46 @@ var statusHelp = ` This command shows the status of a named release. ` -var statusCommand = &cobra.Command{ - Use: "status [flags] RELEASE_NAME", - Short: "displays the status of the named release", - Long: statusHelp, - RunE: status, - PersistentPreRunE: setupConnection, +type statusCmd struct { + release string + out io.Writer + client helm.Interface } -func init() { - RootCommand.AddCommand(statusCommand) -} - -func status(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return errReleaseRequired +func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command { + status := &statusCmd{ + out: out, + client: client, + } + cmd := &cobra.Command{ + Use: "status [flags] RELEASE_NAME", + Short: "displays the status of the named release", + Long: statusHelp, + PersistentPreRunE: setupConnection, + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) == 0 { + return errReleaseRequired + } + status.release = args[0] + if status.client == nil { + status.client = helm.NewClient(helm.Host(helm.Config.ServAddr)) + } + return status.run() + }, } + return cmd +} - res, err := helm.GetReleaseStatus(args[0]) +func (s *statusCmd) run() error { + res, err := s.client.ReleaseStatus(s.release) if err != nil { return prettyError(err) } - fmt.Printf("Last Deployed: %s\n", timeconv.String(res.Info.LastDeployed)) - fmt.Printf("Status: %s\n", res.Info.Status.Code) + fmt.Fprintf(s.out, "Last Deployed: %s\n", timeconv.String(res.Info.LastDeployed)) + fmt.Fprintf(s.out, "Status: %s\n", res.Info.Status.Code) if res.Info.Status.Details != nil { - fmt.Printf("Details: %s\n", res.Info.Status.Details) + fmt.Fprintf(s.out, "Details: %s\n", res.Info.Status.Details) } - return nil }