From c30637b8a1e04b66cdc4d02375ca67acd1d32ccb Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 2 May 2018 23:35:36 -0700 Subject: [PATCH] ref(cmd): remove Writer from Cmd options stucts --- cmd/helm/create.go | 9 +++---- cmd/helm/delete.go | 12 +++------ cmd/helm/dependency.go | 25 +++++++++---------- cmd/helm/dependency_build.go | 9 +++---- cmd/helm/dependency_update.go | 9 +++---- cmd/helm/dependency_update_test.go | 6 ++--- cmd/helm/fetch.go | 13 +++++----- cmd/helm/get.go | 12 +++------ cmd/helm/get_hooks.go | 15 +++++------ cmd/helm/get_manifest.go | 13 ++++------ cmd/helm/get_values.go | 15 +++++------ cmd/helm/history.go | 11 ++++---- cmd/helm/init.go | 17 ++++++------- cmd/helm/inspect.go | 26 ++++++++----------- cmd/helm/inspect_test.go | 6 ++--- cmd/helm/install.go | 22 +++++++--------- cmd/helm/lint.go | 13 ++++------ cmd/helm/list.go | 14 ++++------- cmd/helm/package.go | 11 ++++---- cmd/helm/plugin_list.go | 9 +++---- cmd/helm/plugin_remove.go | 9 +++---- cmd/helm/plugin_update.go | 9 +++---- cmd/helm/release_testing.go | 15 +++-------- cmd/helm/repo_add.go | 10 +++----- cmd/helm/repo_index.go | 7 +++--- cmd/helm/repo_list.go | 9 +++---- cmd/helm/repo_remove.go | 9 +++---- cmd/helm/repo_update.go | 13 ++++------ cmd/helm/repo_update_test.go | 3 +-- cmd/helm/rollback.go | 12 +++------ cmd/helm/search.go | 16 ++++++------ cmd/helm/status.go | 16 +++++------- cmd/helm/template.go | 40 ++++++++++++++---------------- cmd/helm/upgrade.go | 22 ++++++---------- cmd/helm/verify.go | 8 +++--- cmd/helm/version.go | 11 ++++---- 36 files changed, 198 insertions(+), 278 deletions(-) diff --git a/cmd/helm/create.go b/cmd/helm/create.go index d56f118bc..4cade8537 100644 --- a/cmd/helm/create.go +++ b/cmd/helm/create.go @@ -57,12 +57,11 @@ will be overwritten, but other files will be left alone. type createCmd struct { home helmpath.Home name string - out io.Writer starter string } func newCreateCmd(out io.Writer) *cobra.Command { - cc := &createCmd{out: out} + cc := &createCmd{} cmd := &cobra.Command{ Use: "create NAME", @@ -74,7 +73,7 @@ func newCreateCmd(out io.Writer) *cobra.Command { return errors.New("the name of the new chart is required") } cc.name = args[0] - return cc.run() + return cc.run(out) }, } @@ -82,8 +81,8 @@ func newCreateCmd(out io.Writer) *cobra.Command { return cmd } -func (c *createCmd) run() error { - fmt.Fprintf(c.out, "Creating %s\n", c.name) +func (c *createCmd) run(out io.Writer) error { + fmt.Fprintf(out, "Creating %s\n", c.name) chartname := filepath.Base(c.name) cfile := &chart.Metadata{ diff --git a/cmd/helm/delete.go b/cmd/helm/delete.go index 20d29b203..18f8efb81 100644 --- a/cmd/helm/delete.go +++ b/cmd/helm/delete.go @@ -41,15 +41,11 @@ type deleteCmd struct { purge bool timeout int64 - out io.Writer client helm.Interface } func newDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command { - del := &deleteCmd{ - out: out, - client: c, - } + del := &deleteCmd{client: c} cmd := &cobra.Command{ Use: "delete [flags] RELEASE_NAME [...]", @@ -65,7 +61,7 @@ func newDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command { for i := 0; i < len(args); i++ { del.name = args[i] - if err := del.run(); err != nil { + if err := del.run(out); err != nil { return err } @@ -84,7 +80,7 @@ func newDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command { return cmd } -func (d *deleteCmd) run() error { +func (d *deleteCmd) run(out io.Writer) error { opts := []helm.DeleteOption{ helm.DeleteDryRun(d.dryRun), helm.DeleteDisableHooks(d.disableHooks), @@ -93,7 +89,7 @@ func (d *deleteCmd) run() error { } res, err := d.client.DeleteRelease(d.name, opts...) if res != nil && res.Info != "" { - fmt.Fprintln(d.out, res.Info) + fmt.Fprintln(out, res.Info) } return err diff --git a/cmd/helm/dependency.go b/cmd/helm/dependency.go index b3ce2d064..e5163654a 100644 --- a/cmd/helm/dependency.go +++ b/cmd/helm/dependency.go @@ -103,12 +103,11 @@ func newDependencyCmd(out io.Writer) *cobra.Command { } type dependencyListCmd struct { - out io.Writer chartpath string } func newDependencyListCmd(out io.Writer) *cobra.Command { - dlc := &dependencyListCmd{out: out} + dlc := &dependencyListCmd{} cmd := &cobra.Command{ Use: "list [flags] CHART", @@ -128,7 +127,7 @@ func newDependencyListCmd(out io.Writer) *cobra.Command { return cmd } -func (l *dependencyListCmd) run() error { +func (l *dependencyListCmd) run(out io.Writer) error { c, err := chartutil.Load(l.chartpath) if err != nil { return err @@ -137,15 +136,15 @@ func (l *dependencyListCmd) run() error { r, err := chartutil.LoadRequirements(c) if err != nil { if err == chartutil.ErrRequirementsNotFound { - fmt.Fprintf(l.out, "WARNING: no requirements at %s/charts\n", l.chartpath) + fmt.Fprintf(out, "WARNING: no requirements at %s/charts\n", l.chartpath) return nil } return err } - l.printRequirements(r, l.out) - fmt.Fprintln(l.out) - l.printMissing(r) + l.printRequirements(out, r) + fmt.Fprintln(out) + l.printMissing(out, r) return nil } @@ -224,7 +223,7 @@ func (l *dependencyListCmd) dependencyStatus(dep *chartutil.Dependency) string { } // printRequirements prints all of the requirements in the yaml file. -func (l *dependencyListCmd) printRequirements(reqs *chartutil.Requirements, out io.Writer) { +func (l *dependencyListCmd) printRequirements(out io.Writer, reqs *chartutil.Requirements) { table := uitable.New() table.MaxColWidth = 80 table.AddRow("NAME", "VERSION", "REPOSITORY", "STATUS") @@ -235,18 +234,18 @@ func (l *dependencyListCmd) printRequirements(reqs *chartutil.Requirements, out } // printMissing prints warnings about charts that are present on disk, but are not in the requirements. -func (l *dependencyListCmd) printMissing(reqs *chartutil.Requirements) { +func (l *dependencyListCmd) printMissing(out io.Writer, reqs *chartutil.Requirements) { folder := filepath.Join(l.chartpath, "charts/*") files, err := filepath.Glob(folder) if err != nil { - fmt.Fprintln(l.out, err) + fmt.Fprintln(out, err) return } for _, f := range files { fi, err := os.Stat(f) if err != nil { - fmt.Fprintf(l.out, "Warning: %s\n", err) + fmt.Fprintf(out, "Warning: %s\n", err) } // Skip anything that is not a directory and not a tgz file. if !fi.IsDir() && filepath.Ext(f) != ".tgz" { @@ -254,7 +253,7 @@ func (l *dependencyListCmd) printMissing(reqs *chartutil.Requirements) { } c, err := chartutil.Load(f) if err != nil { - fmt.Fprintf(l.out, "WARNING: %q is not a chart.\n", f) + fmt.Fprintf(out, "WARNING: %q is not a chart.\n", f) continue } found := false @@ -265,7 +264,7 @@ func (l *dependencyListCmd) printMissing(reqs *chartutil.Requirements) { } } if !found { - fmt.Fprintf(l.out, "WARNING: %q is not in requirements.yaml.\n", f) + fmt.Fprintf(out, "WARNING: %q is not in requirements.yaml.\n", f) } } diff --git a/cmd/helm/dependency_build.go b/cmd/helm/dependency_build.go index ec5fd14b7..a702cca64 100644 --- a/cmd/helm/dependency_build.go +++ b/cmd/helm/dependency_build.go @@ -37,7 +37,6 @@ of 'helm dependency update'. ` type dependencyBuildCmd struct { - out io.Writer chartpath string verify bool keyring string @@ -45,7 +44,7 @@ type dependencyBuildCmd struct { } func newDependencyBuildCmd(out io.Writer) *cobra.Command { - dbc := &dependencyBuildCmd{out: out} + dbc := &dependencyBuildCmd{} cmd := &cobra.Command{ Use: "build [flags] CHART", @@ -58,7 +57,7 @@ func newDependencyBuildCmd(out io.Writer) *cobra.Command { if len(args) > 0 { dbc.chartpath = args[0] } - return dbc.run() + return dbc.run(out) }, } @@ -69,9 +68,9 @@ func newDependencyBuildCmd(out io.Writer) *cobra.Command { return cmd } -func (d *dependencyBuildCmd) run() error { +func (d *dependencyBuildCmd) run(out io.Writer) error { man := &downloader.Manager{ - Out: d.out, + Out: out, ChartPath: d.chartpath, HelmHome: d.helmhome, Keyring: d.keyring, diff --git a/cmd/helm/dependency_update.go b/cmd/helm/dependency_update.go index 20708fb5f..7bdd687d4 100644 --- a/cmd/helm/dependency_update.go +++ b/cmd/helm/dependency_update.go @@ -43,7 +43,6 @@ in the requirements.yaml file, but (b) at the wrong version. // dependencyUpdateCmd describes a 'helm dependency update' type dependencyUpdateCmd struct { - out io.Writer chartpath string helmhome helmpath.Home verify bool @@ -53,7 +52,7 @@ type dependencyUpdateCmd struct { // newDependencyUpdateCmd creates a new dependency update command. func newDependencyUpdateCmd(out io.Writer) *cobra.Command { - duc := &dependencyUpdateCmd{out: out} + duc := &dependencyUpdateCmd{} cmd := &cobra.Command{ Use: "update [flags] CHART", @@ -74,7 +73,7 @@ func newDependencyUpdateCmd(out io.Writer) *cobra.Command { duc.helmhome = settings.Home - return duc.run() + return duc.run(out) }, } @@ -87,9 +86,9 @@ func newDependencyUpdateCmd(out io.Writer) *cobra.Command { } // run runs the full dependency update process. -func (d *dependencyUpdateCmd) run() error { +func (d *dependencyUpdateCmd) run(out io.Writer) error { man := &downloader.Manager{ - Out: d.out, + Out: out, ChartPath: d.chartpath, HelmHome: d.helmhome, Keyring: d.keyring, diff --git a/cmd/helm/dependency_update_test.go b/cmd/helm/dependency_update_test.go index 71292b4e7..a7f079d69 100644 --- a/cmd/helm/dependency_update_test.go +++ b/cmd/helm/dependency_update_test.go @@ -190,11 +190,11 @@ func TestDependencyUpdateCmd_DontDeleteOldChartsOnError(t *testing.T) { } out := bytes.NewBuffer(nil) - duc := &dependencyUpdateCmd{out: out} + duc := &dependencyUpdateCmd{} duc.helmhome = helmpath.Home(hh) duc.chartpath = hh.Path(chartname) - if err := duc.run(); err != nil { + if err := duc.run(out); err != nil { output := out.String() t.Logf("Output: %s", output) t.Fatal(err) @@ -203,7 +203,7 @@ func TestDependencyUpdateCmd_DontDeleteOldChartsOnError(t *testing.T) { // Chart repo is down srv.Stop() - if err := duc.run(); err == nil { + if err := duc.run(out); err == nil { output := out.String() t.Logf("Output: %s", output) t.Fatal("Expected error, got nil") diff --git a/cmd/helm/fetch.go b/cmd/helm/fetch.go index 069f57eff..9ee82cd11 100644 --- a/cmd/helm/fetch.go +++ b/cmd/helm/fetch.go @@ -24,6 +24,7 @@ import ( "path/filepath" "github.com/spf13/cobra" + "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/downloader" "k8s.io/helm/pkg/getter" @@ -64,12 +65,10 @@ type fetchCmd struct { caFile string devel bool - - out io.Writer } func newFetchCmd(out io.Writer) *cobra.Command { - fch := &fetchCmd{out: out} + fch := &fetchCmd{} cmd := &cobra.Command{ Use: "fetch [flags] [chart URL | repo/chartname] [...]", @@ -87,7 +86,7 @@ func newFetchCmd(out io.Writer) *cobra.Command { for i := 0; i < len(args); i++ { fch.chartRef = args[i] - if err := fch.run(); err != nil { + if err := fch.run(out); err != nil { return err } } @@ -114,10 +113,10 @@ func newFetchCmd(out io.Writer) *cobra.Command { return cmd } -func (f *fetchCmd) run() error { +func (f *fetchCmd) run(out io.Writer) error { c := downloader.ChartDownloader{ HelmHome: settings.Home, - Out: f.out, + Out: out, Keyring: f.keyring, Verify: downloader.VerifyNever, Getters: getter.All(settings), @@ -157,7 +156,7 @@ func (f *fetchCmd) run() error { } if f.verify { - fmt.Fprintf(f.out, "Verification: %v\n", v) + fmt.Fprintf(out, "Verification: %v\n", v) } // After verification, untar the chart into the requested directory. diff --git a/cmd/helm/get.go b/cmd/helm/get.go index 960a3c1bd..1dd37f43a 100644 --- a/cmd/helm/get.go +++ b/cmd/helm/get.go @@ -44,15 +44,11 @@ type getCmd struct { release string version int - out io.Writer client helm.Interface } func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command { - get := &getCmd{ - out: out, - client: client, - } + get := &getCmd{client: client} cmd := &cobra.Command{ Use: "get [flags] RELEASE_NAME", @@ -64,7 +60,7 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command { } get.release = args[0] get.client = ensureHelmClient(get.client, false) - return get.run() + return get.run(out) }, } @@ -78,10 +74,10 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command { } // getCmd is the command that implements 'helm get' -func (g *getCmd) run() error { +func (g *getCmd) run(out io.Writer) error { res, err := g.client.ReleaseContent(g.release, g.version) if err != nil { return err } - return printRelease(g.out, res) + return printRelease(out, res) } diff --git a/cmd/helm/get_hooks.go b/cmd/helm/get_hooks.go index 5024c991f..8b67c32dd 100644 --- a/cmd/helm/get_hooks.go +++ b/cmd/helm/get_hooks.go @@ -33,16 +33,13 @@ Hooks are formatted in YAML and separated by the YAML '---\n' separator. type getHooksCmd struct { release string - out io.Writer client helm.Interface version int } func newGetHooksCmd(client helm.Interface, out io.Writer) *cobra.Command { - ghc := &getHooksCmd{ - out: out, - client: client, - } + ghc := &getHooksCmd{client: client} + cmd := &cobra.Command{ Use: "hooks [flags] RELEASE_NAME", Short: "download all hooks for a named release", @@ -53,22 +50,22 @@ func newGetHooksCmd(client helm.Interface, out io.Writer) *cobra.Command { } ghc.release = args[0] ghc.client = ensureHelmClient(ghc.client, false) - return ghc.run() + return ghc.run(out) }, } cmd.Flags().IntVar(&ghc.version, "revision", 0, "get the named release with revision") return cmd } -func (g *getHooksCmd) run() error { +func (g *getHooksCmd) run(out io.Writer) error { res, err := g.client.ReleaseContent(g.release, g.version) if err != nil { - fmt.Fprintln(g.out, g.release) + fmt.Fprintln(out, g.release) return err } for _, hook := range res.Hooks { - fmt.Fprintf(g.out, "---\n# %s\n%s", hook.Name, hook.Manifest) + fmt.Fprintf(out, "---\n# %s\n%s", hook.Name, hook.Manifest) } return nil } diff --git a/cmd/helm/get_manifest.go b/cmd/helm/get_manifest.go index 66bc0e2e8..8199cc801 100644 --- a/cmd/helm/get_manifest.go +++ b/cmd/helm/get_manifest.go @@ -35,16 +35,13 @@ charts, those resources will also be included in the manifest. type getManifestCmd struct { release string - out io.Writer client helm.Interface version int } func newGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command { - get := &getManifestCmd{ - out: out, - client: client, - } + get := &getManifestCmd{client: client} + cmd := &cobra.Command{ Use: "manifest [flags] RELEASE_NAME", Short: "download the manifest for a named release", @@ -55,7 +52,7 @@ func newGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command { } get.release = args[0] get.client = ensureHelmClient(get.client, false) - return get.run() + return get.run(out) }, } @@ -64,11 +61,11 @@ func newGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command { } // getManifest implements 'helm get manifest' -func (g *getManifestCmd) run() error { +func (g *getManifestCmd) run(out io.Writer) error { res, err := g.client.ReleaseContent(g.release, g.version) if err != nil { return err } - fmt.Fprintln(g.out, res.Manifest) + fmt.Fprintln(out, res.Manifest) return nil } diff --git a/cmd/helm/get_values.go b/cmd/helm/get_values.go index 7571e5dae..dd9377139 100644 --- a/cmd/helm/get_values.go +++ b/cmd/helm/get_values.go @@ -33,16 +33,13 @@ This command downloads a values file for a given release. type getValuesCmd struct { release string allValues bool - out io.Writer client helm.Interface version int } func newGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command { - get := &getValuesCmd{ - out: out, - client: client, - } + get := &getValuesCmd{client: client} + cmd := &cobra.Command{ Use: "values [flags] RELEASE_NAME", Short: "download the values file for a named release", @@ -53,7 +50,7 @@ func newGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command { } get.release = args[0] get.client = ensureHelmClient(get.client, false) - return get.run() + return get.run(out) }, } @@ -63,7 +60,7 @@ func newGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command { } // getValues implements 'helm get values' -func (g *getValuesCmd) run() error { +func (g *getValuesCmd) run(out io.Writer) error { res, err := g.client.ReleaseContent(g.release, g.version) if err != nil { return err @@ -79,10 +76,10 @@ func (g *getValuesCmd) run() error { if err != nil { return err } - fmt.Fprintln(g.out, cfgStr) + fmt.Fprintln(out, cfgStr) return nil } - fmt.Fprintln(g.out, string(res.Config)) + fmt.Fprintln(out, string(res.Config)) return nil } diff --git a/cmd/helm/history.go b/cmd/helm/history.go index 84cff22c8..54f3a2eb9 100644 --- a/cmd/helm/history.go +++ b/cmd/helm/history.go @@ -59,14 +59,13 @@ The historical release set is printed as a formatted table, e.g: type historyCmd struct { max int rls string - out io.Writer helmc helm.Interface colWidth uint outputFormat string } -func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command { - his := &historyCmd{out: w, helmc: c} +func newHistoryCmd(c helm.Interface, out io.Writer) *cobra.Command { + his := &historyCmd{helmc: c} cmd := &cobra.Command{ Use: "history [flags] RELEASE_NAME", @@ -79,7 +78,7 @@ func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command { } his.helmc = ensureHelmClient(his.helmc, false) his.rls = args[0] - return his.run() + return his.run(out) }, } @@ -91,7 +90,7 @@ func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command { return cmd } -func (cmd *historyCmd) run() error { +func (cmd *historyCmd) run(out io.Writer) error { rels, err := cmd.helmc.ReleaseHistory(cmd.rls, cmd.max) if err != nil { return err @@ -120,7 +119,7 @@ func (cmd *historyCmd) run() error { return formattingError } - fmt.Fprintln(cmd.out, string(history)) + fmt.Fprintln(out, string(history)) return nil } diff --git a/cmd/helm/init.go b/cmd/helm/init.go index c4faed4a4..b9eceea47 100644 --- a/cmd/helm/init.go +++ b/cmd/helm/init.go @@ -39,12 +39,11 @@ var stableRepositoryURL = "https://kubernetes-charts.storage.googleapis.com" type initCmd struct { skipRefresh bool - out io.Writer home helmpath.Home } func newInitCmd(out io.Writer) *cobra.Command { - i := &initCmd{out: out} + i := &initCmd{} cmd := &cobra.Command{ Use: "init", @@ -55,7 +54,7 @@ func newInitCmd(out io.Writer) *cobra.Command { return errors.New("This command does not accept arguments") } i.home = settings.Home - return i.run() + return i.run(out) }, } @@ -67,18 +66,18 @@ func newInitCmd(out io.Writer) *cobra.Command { } // run initializes local config and installs Tiller to Kubernetes cluster. -func (i *initCmd) run() error { - if err := ensureDirectories(i.home, i.out); err != nil { +func (i *initCmd) run(out io.Writer) error { + if err := ensureDirectories(i.home, out); err != nil { return err } - if err := ensureDefaultRepos(i.home, i.out, i.skipRefresh); err != nil { + if err := ensureDefaultRepos(i.home, out, i.skipRefresh); err != nil { return err } - if err := ensureRepoFileFormat(i.home.RepositoryFile(), i.out); err != nil { + if err := ensureRepoFileFormat(i.home.RepositoryFile(), out); err != nil { return err } - fmt.Fprintf(i.out, "$HELM_HOME has been configured at %s.\n", settings.Home) - fmt.Fprintln(i.out, "Happy Helming!") + fmt.Fprintf(out, "$HELM_HOME has been configured at %s.\n", settings.Home) + fmt.Fprintln(out, "Happy Helming!") return nil } diff --git a/cmd/helm/inspect.go b/cmd/helm/inspect.go index 830e2948e..8e4caf0ec 100644 --- a/cmd/helm/inspect.go +++ b/cmd/helm/inspect.go @@ -55,7 +55,6 @@ type inspectCmd struct { output string verify bool keyring string - out io.Writer version string repoURL string username string @@ -76,10 +75,7 @@ const ( var readmeFileNames = []string{"readme.md", "readme.txt", "readme"} func newInspectCmd(out io.Writer) *cobra.Command { - insp := &inspectCmd{ - out: out, - output: all, - } + insp := &inspectCmd{output: all} inspectCommand := &cobra.Command{ Use: "inspect [CHART]", @@ -95,7 +91,7 @@ func newInspectCmd(out io.Writer) *cobra.Command { return err } insp.chartpath = cp - return insp.run() + return insp.run(out) }, } @@ -114,7 +110,7 @@ func newInspectCmd(out io.Writer) *cobra.Command { return err } insp.chartpath = cp - return insp.run() + return insp.run(out) }, } @@ -133,7 +129,7 @@ func newInspectCmd(out io.Writer) *cobra.Command { return err } insp.chartpath = cp - return insp.run() + return insp.run(out) }, } @@ -152,7 +148,7 @@ func newInspectCmd(out io.Writer) *cobra.Command { return err } insp.chartpath = cp - return insp.run() + return insp.run(out) }, } @@ -219,7 +215,7 @@ func newInspectCmd(out io.Writer) *cobra.Command { return inspectCommand } -func (i *inspectCmd) run() error { +func (i *inspectCmd) run(out io.Writer) error { chrt, err := chartutil.Load(i.chartpath) if err != nil { return err @@ -230,25 +226,25 @@ func (i *inspectCmd) run() error { } if i.output == chartOnly || i.output == all { - fmt.Fprintln(i.out, string(cf)) + fmt.Fprintln(out, string(cf)) } if (i.output == valuesOnly || i.output == all) && chrt.Values != nil { if i.output == all { - fmt.Fprintln(i.out, "---") + fmt.Fprintln(out, "---") } - fmt.Fprintln(i.out, string(chrt.Values)) + fmt.Fprintln(out, string(chrt.Values)) } if i.output == readmeOnly || i.output == all { if i.output == all { - fmt.Fprintln(i.out, "---") + fmt.Fprintln(out, "---") } readme := findReadme(chrt.Files) if readme == nil { return nil } - fmt.Fprintln(i.out, string(readme.Data)) + fmt.Fprintln(out, string(readme.Data)) } return nil } diff --git a/cmd/helm/inspect_test.go b/cmd/helm/inspect_test.go index 44d71fbbd..a8ca7d64f 100644 --- a/cmd/helm/inspect_test.go +++ b/cmd/helm/inspect_test.go @@ -29,9 +29,8 @@ func TestInspect(t *testing.T) { insp := &inspectCmd{ chartpath: "testdata/testcharts/alpine", output: all, - out: b, } - insp.run() + insp.run(b) // Load the data from the textfixture directly. cdata, err := ioutil.ReadFile("testdata/testcharts/alpine/Chart.yaml") @@ -71,9 +70,8 @@ func TestInspect(t *testing.T) { insp = &inspectCmd{ chartpath: "testdata/testcharts/novals", output: "values", - out: b, } - insp.run() + insp.run(b) if b.Len() != 0 { t.Errorf("expected empty values buffer, got %q", b.String()) } diff --git a/cmd/helm/install.go b/cmd/helm/install.go index fb33ca65c..5c68d84f6 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -128,7 +128,6 @@ type installCmd struct { caFile string // --ca-file chartPath string // arg - out io.Writer client helm.Interface } @@ -150,10 +149,7 @@ func (v *valueFiles) Set(value string) error { } func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command { - inst := &installCmd{ - out: out, - client: c, - } + inst := &installCmd{client: c} cmd := &cobra.Command{ Use: "install [CHART]", @@ -177,7 +173,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command { } inst.chartPath = cp inst.client = ensureHelmClient(inst.client, false) - return inst.run() + return inst.run(out) }, } @@ -207,7 +203,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command { return cmd } -func (i *installCmd) run() error { +func (i *installCmd) run(out io.Writer) error { debug("CHART PATH: %s\n", i.chartPath) rawVals, err := vals(i.valueFiles, i.values, i.stringValues) @@ -238,7 +234,7 @@ func (i *installCmd) run() error { if err := checkDependencies(chartRequested, req); err != nil { if i.depUp { man := &downloader.Manager{ - Out: i.out, + Out: out, ChartPath: i.chartPath, HelmHome: settings.Home, Keyring: defaultKeyring(), @@ -274,7 +270,7 @@ func (i *installCmd) run() error { if rel == nil { return nil } - i.printRelease(rel) + i.printRelease(out, rel) // If this is a dry run, we can't display status. if i.dryRun { @@ -286,7 +282,7 @@ func (i *installCmd) run() error { if err != nil { return err } - PrintStatus(i.out, status) + PrintStatus(out, status) return nil } @@ -363,14 +359,14 @@ func vals(valueFiles valueFiles, values []string, stringValues []string) ([]byte } // printRelease prints info about a release if the Debug is true. -func (i *installCmd) printRelease(rel *release.Release) { +func (i *installCmd) printRelease(out io.Writer, rel *release.Release) { if rel == nil { return } // TODO: Switch to text/template like everything else. - fmt.Fprintf(i.out, "NAME: %s\n", rel.Name) + fmt.Fprintf(out, "NAME: %s\n", rel.Name) if settings.Debug { - printRelease(i.out, rel) + printRelease(out, rel) } } diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index 54c7f0db3..263de13ca 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -49,14 +49,11 @@ type lintCmd struct { sValues []string strict bool paths []string - out io.Writer } func newLintCmd(out io.Writer) *cobra.Command { - l := &lintCmd{ - paths: []string{"."}, - out: out, - } + l := &lintCmd{paths: []string{"."}} + cmd := &cobra.Command{ Use: "lint [flags] PATH", Short: "examines a chart for possible issues", @@ -65,7 +62,7 @@ func newLintCmd(out io.Writer) *cobra.Command { if len(args) > 0 { l.paths = args } - return l.run() + return l.run(out) }, } @@ -79,7 +76,7 @@ func newLintCmd(out io.Writer) *cobra.Command { var errLintNoChart = errors.New("No chart found for linting (missing Chart.yaml)") -func (l *lintCmd) run() error { +func (l *lintCmd) run(out io.Writer) error { var lowestTolerance int if l.strict { lowestTolerance = support.WarningSev @@ -126,7 +123,7 @@ func (l *lintCmd) run() error { return fmt.Errorf("%s, %d chart(s) failed", msg, failures) } - fmt.Fprintf(l.out, "%s, no failures\n", msg) + fmt.Fprintf(out, "%s, no failures\n", msg) return nil } diff --git a/cmd/helm/list.go b/cmd/helm/list.go index b2df59a7a..0ca7cb5cf 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -63,7 +63,6 @@ type listCmd struct { offset string byDate bool sortDesc bool - out io.Writer all bool deleted bool deleting bool @@ -77,10 +76,7 @@ type listCmd struct { } func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { - list := &listCmd{ - out: out, - client: client, - } + list := &listCmd{client: client} cmd := &cobra.Command{ Use: "list [flags] [FILTER]", @@ -92,7 +88,7 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { list.filter = strings.Join(args, " ") } list.client = ensureHelmClient(list.client, list.allNamespaces) - return list.run() + return list.run(out) }, } @@ -114,7 +110,7 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { return cmd } -func (l *listCmd) run() error { +func (l *listCmd) run(out io.Writer) error { sortBy := hapi.SortByName if l.byDate { sortBy = hapi.SortByLastReleased @@ -148,11 +144,11 @@ func (l *listCmd) run() error { if l.short { for _, r := range rels { - fmt.Fprintln(l.out, r.Name) + fmt.Fprintln(out, r.Name) } return nil } - fmt.Fprintln(l.out, formatList(rels, l.colWidth)) + fmt.Fprintln(out, formatList(rels, l.colWidth)) return nil } diff --git a/cmd/helm/package.go b/cmd/helm/package.go index 75c60e9be..68b94b608 100644 --- a/cmd/helm/package.go +++ b/cmd/helm/package.go @@ -62,12 +62,11 @@ type packageCmd struct { destination string dependencyUpdate bool - out io.Writer home helmpath.Home } func newPackageCmd(out io.Writer) *cobra.Command { - pkg := &packageCmd{out: out} + pkg := &packageCmd{} cmd := &cobra.Command{ Use: "package [flags] [CHART_PATH] [...]", @@ -88,7 +87,7 @@ func newPackageCmd(out io.Writer) *cobra.Command { } for i := 0; i < len(args); i++ { pkg.path = args[i] - if err := pkg.run(); err != nil { + if err := pkg.run(out); err != nil { return err } } @@ -111,7 +110,7 @@ func newPackageCmd(out io.Writer) *cobra.Command { return cmd } -func (p *packageCmd) run() error { +func (p *packageCmd) run(out io.Writer) error { path, err := filepath.Abs(p.path) if err != nil { return err @@ -119,7 +118,7 @@ func (p *packageCmd) run() error { if p.dependencyUpdate { downloadManager := &downloader.Manager{ - Out: p.out, + Out: out, ChartPath: path, HelmHome: settings.Home, Keyring: p.keyring, @@ -192,7 +191,7 @@ func (p *packageCmd) run() error { name, err := chartutil.Save(ch, dest) if err == nil { - fmt.Fprintf(p.out, "Successfully packaged chart and saved it to: %s\n", name) + fmt.Fprintf(out, "Successfully packaged chart and saved it to: %s\n", name) } else { return fmt.Errorf("Failed to save: %s", err) } diff --git a/cmd/helm/plugin_list.go b/cmd/helm/plugin_list.go index e7618f38a..4c2c9288a 100644 --- a/cmd/helm/plugin_list.go +++ b/cmd/helm/plugin_list.go @@ -27,23 +27,22 @@ import ( type pluginListCmd struct { home helmpath.Home - out io.Writer } func newPluginListCmd(out io.Writer) *cobra.Command { - pcmd := &pluginListCmd{out: out} + pcmd := &pluginListCmd{} cmd := &cobra.Command{ Use: "list", Short: "list installed Helm plugins", RunE: func(cmd *cobra.Command, args []string) error { pcmd.home = settings.Home - return pcmd.run() + return pcmd.run(out) }, } return cmd } -func (pcmd *pluginListCmd) run() error { +func (pcmd *pluginListCmd) run(out io.Writer) error { debug("pluginDirs: %s", settings.PluginDirs()) plugins, err := findPlugins(settings.PluginDirs()) if err != nil { @@ -55,6 +54,6 @@ func (pcmd *pluginListCmd) run() error { for _, p := range plugins { table.AddRow(p.Metadata.Name, p.Metadata.Version, p.Metadata.Description) } - fmt.Fprintln(pcmd.out, table) + fmt.Fprintln(out, table) return nil } diff --git a/cmd/helm/plugin_remove.go b/cmd/helm/plugin_remove.go index ec1154734..1b54ed4b0 100644 --- a/cmd/helm/plugin_remove.go +++ b/cmd/helm/plugin_remove.go @@ -31,11 +31,10 @@ import ( type pluginRemoveCmd struct { names []string home helmpath.Home - out io.Writer } func newPluginRemoveCmd(out io.Writer) *cobra.Command { - pcmd := &pluginRemoveCmd{out: out} + pcmd := &pluginRemoveCmd{} cmd := &cobra.Command{ Use: "remove ...", Short: "remove one or more Helm plugins", @@ -43,7 +42,7 @@ func newPluginRemoveCmd(out io.Writer) *cobra.Command { return pcmd.complete(args) }, RunE: func(cmd *cobra.Command, args []string) error { - return pcmd.run() + return pcmd.run(out) }, } return cmd @@ -58,7 +57,7 @@ func (pcmd *pluginRemoveCmd) complete(args []string) error { return nil } -func (pcmd *pluginRemoveCmd) run() error { +func (pcmd *pluginRemoveCmd) run(out io.Writer) error { debug("loading installed plugins from %s", settings.PluginDirs()) plugins, err := findPlugins(settings.PluginDirs()) if err != nil { @@ -70,7 +69,7 @@ func (pcmd *pluginRemoveCmd) run() error { if err := removePlugin(found); err != nil { errorPlugins = append(errorPlugins, fmt.Sprintf("Failed to remove plugin %s, got error (%v)", name, err)) } else { - fmt.Fprintf(pcmd.out, "Removed plugin: %s\n", name) + fmt.Fprintf(out, "Removed plugin: %s\n", name) } } else { errorPlugins = append(errorPlugins, fmt.Sprintf("Plugin: %s not found", name)) diff --git a/cmd/helm/plugin_update.go b/cmd/helm/plugin_update.go index d3778764d..fbdfe2d14 100644 --- a/cmd/helm/plugin_update.go +++ b/cmd/helm/plugin_update.go @@ -32,11 +32,10 @@ import ( type pluginUpdateCmd struct { names []string home helmpath.Home - out io.Writer } func newPluginUpdateCmd(out io.Writer) *cobra.Command { - pcmd := &pluginUpdateCmd{out: out} + pcmd := &pluginUpdateCmd{} cmd := &cobra.Command{ Use: "update ...", Short: "update one or more Helm plugins", @@ -44,7 +43,7 @@ func newPluginUpdateCmd(out io.Writer) *cobra.Command { return pcmd.complete(args) }, RunE: func(cmd *cobra.Command, args []string) error { - return pcmd.run() + return pcmd.run(out) }, } return cmd @@ -59,7 +58,7 @@ func (pcmd *pluginUpdateCmd) complete(args []string) error { return nil } -func (pcmd *pluginUpdateCmd) run() error { +func (pcmd *pluginUpdateCmd) run(out io.Writer) error { installer.Debug = settings.Debug debug("loading installed plugins from %s", settings.PluginDirs()) plugins, err := findPlugins(settings.PluginDirs()) @@ -73,7 +72,7 @@ func (pcmd *pluginUpdateCmd) run() error { if err := updatePlugin(found, pcmd.home); err != nil { errorPlugins = append(errorPlugins, fmt.Sprintf("Failed to update plugin %s, got error (%v)", name, err)) } else { - fmt.Fprintf(pcmd.out, "Updated plugin: %s\n", name) + fmt.Fprintf(out, "Updated plugin: %s\n", name) } } else { errorPlugins = append(errorPlugins, fmt.Sprintf("Plugin: %s not found", name)) diff --git a/cmd/helm/release_testing.go b/cmd/helm/release_testing.go index b3a3927ee..ba3943a59 100644 --- a/cmd/helm/release_testing.go +++ b/cmd/helm/release_testing.go @@ -35,17 +35,13 @@ The tests to be run are defined in the chart that was installed. type releaseTestCmd struct { name string - out io.Writer client helm.Interface timeout int64 cleanup bool } func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command { - rlsTest := &releaseTestCmd{ - out: out, - client: c, - } + rlsTest := &releaseTestCmd{client: c} cmd := &cobra.Command{ Use: "test [RELEASE]", @@ -58,7 +54,7 @@ func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command { rlsTest.name = args[0] rlsTest.client = ensureHelmClient(rlsTest.client, false) - return rlsTest.run() + return rlsTest.run(out) }, } @@ -69,7 +65,7 @@ func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command { return cmd } -func (t *releaseTestCmd) run() (err error) { +func (t *releaseTestCmd) run(out io.Writer) (err error) { c, errc := t.client.RunReleaseTest( t.name, helm.ReleaseTestTimeout(t.timeout), @@ -92,12 +88,9 @@ func (t *releaseTestCmd) run() (err error) { if res.Status == release.TestRunFailure { testErr.failed++ } - - fmt.Fprintf(t.out, res.Msg+"\n") - + fmt.Fprintf(out, res.Msg+"\n") } } - } type testErr struct { diff --git a/cmd/helm/repo_add.go b/cmd/helm/repo_add.go index 77a64cc89..763e8463b 100644 --- a/cmd/helm/repo_add.go +++ b/cmd/helm/repo_add.go @@ -38,12 +38,10 @@ type repoAddCmd struct { certFile string keyFile string caFile string - - out io.Writer } func newRepoAddCmd(out io.Writer) *cobra.Command { - add := &repoAddCmd{out: out} + add := &repoAddCmd{} cmd := &cobra.Command{ Use: "add [flags] [NAME] [URL]", @@ -57,7 +55,7 @@ func newRepoAddCmd(out io.Writer) *cobra.Command { add.url = args[1] add.home = settings.Home - return add.run() + return add.run(out) }, } @@ -72,11 +70,11 @@ func newRepoAddCmd(out io.Writer) *cobra.Command { return cmd } -func (a *repoAddCmd) run() error { +func (a *repoAddCmd) run(out io.Writer) error { if err := addRepository(a.name, a.url, a.username, a.password, a.home, a.certFile, a.keyFile, a.caFile, a.noupdate); err != nil { return err } - fmt.Fprintf(a.out, "%q has been added to your repositories\n", a.name) + fmt.Fprintf(out, "%q has been added to your repositories\n", a.name) return nil } diff --git a/cmd/helm/repo_index.go b/cmd/helm/repo_index.go index 540057eb8..a4d07152b 100644 --- a/cmd/helm/repo_index.go +++ b/cmd/helm/repo_index.go @@ -41,12 +41,11 @@ into the existing index, with local charts taking priority over existing charts. type repoIndexCmd struct { dir string url string - out io.Writer merge string } func newRepoIndexCmd(out io.Writer) *cobra.Command { - index := &repoIndexCmd{out: out} + index := &repoIndexCmd{} cmd := &cobra.Command{ Use: "index [flags] [DIR]", @@ -59,7 +58,7 @@ func newRepoIndexCmd(out io.Writer) *cobra.Command { index.dir = args[0] - return index.run() + return index.run(out) }, } @@ -70,7 +69,7 @@ func newRepoIndexCmd(out io.Writer) *cobra.Command { return cmd } -func (i *repoIndexCmd) run() error { +func (i *repoIndexCmd) run(out io.Writer) error { path, err := filepath.Abs(i.dir) if err != nil { return err diff --git a/cmd/helm/repo_list.go b/cmd/helm/repo_list.go index 0f795b2b0..8c0bf3b5f 100644 --- a/cmd/helm/repo_list.go +++ b/cmd/helm/repo_list.go @@ -29,26 +29,25 @@ import ( ) type repoListCmd struct { - out io.Writer home helmpath.Home } func newRepoListCmd(out io.Writer) *cobra.Command { - list := &repoListCmd{out: out} + list := &repoListCmd{} cmd := &cobra.Command{ Use: "list [flags]", Short: "list chart repositories", RunE: func(cmd *cobra.Command, args []string) error { list.home = settings.Home - return list.run() + return list.run(out) }, } return cmd } -func (a *repoListCmd) run() error { +func (a *repoListCmd) run(out io.Writer) error { f, err := repo.LoadRepositoriesFile(a.home.RepositoryFile()) if err != nil { return err @@ -61,6 +60,6 @@ func (a *repoListCmd) run() error { for _, re := range f.Repositories { table.AddRow(re.Name, re.URL) } - fmt.Fprintln(a.out, table) + fmt.Fprintln(out, table) return nil } diff --git a/cmd/helm/repo_remove.go b/cmd/helm/repo_remove.go index 201ee9ca8..958694c5d 100644 --- a/cmd/helm/repo_remove.go +++ b/cmd/helm/repo_remove.go @@ -28,13 +28,12 @@ import ( ) type repoRemoveCmd struct { - out io.Writer name string home helmpath.Home } func newRepoRemoveCmd(out io.Writer) *cobra.Command { - remove := &repoRemoveCmd{out: out} + remove := &repoRemoveCmd{} cmd := &cobra.Command{ Use: "remove [flags] [NAME]", @@ -47,15 +46,15 @@ func newRepoRemoveCmd(out io.Writer) *cobra.Command { remove.name = args[0] remove.home = settings.Home - return remove.run() + return remove.run(out) }, } return cmd } -func (r *repoRemoveCmd) run() error { - return removeRepoLine(r.out, r.name, r.home) +func (r *repoRemoveCmd) run(out io.Writer) error { + return removeRepoLine(out, r.name, r.home) } func removeRepoLine(out io.Writer, name string, home helmpath.Home) error { diff --git a/cmd/helm/repo_update.go b/cmd/helm/repo_update.go index 3532211ce..8f181bf26 100644 --- a/cmd/helm/repo_update.go +++ b/cmd/helm/repo_update.go @@ -42,14 +42,11 @@ var errNoRepositories = errors.New("no repositories found. You must add one befo type repoUpdateCmd struct { update func([]*repo.ChartRepository, io.Writer, helmpath.Home) home helmpath.Home - out io.Writer } func newRepoUpdateCmd(out io.Writer) *cobra.Command { - u := &repoUpdateCmd{ - out: out, - update: updateCharts, - } + u := &repoUpdateCmd{update: updateCharts} + cmd := &cobra.Command{ Use: "update", Aliases: []string{"up"}, @@ -57,13 +54,13 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command { Long: updateDesc, RunE: func(cmd *cobra.Command, args []string) error { u.home = settings.Home - return u.run() + return u.run(out) }, } return cmd } -func (u *repoUpdateCmd) run() error { +func (u *repoUpdateCmd) run(out io.Writer) error { f, err := repo.LoadRepositoriesFile(u.home.RepositoryFile()) if err != nil { return err @@ -81,7 +78,7 @@ func (u *repoUpdateCmd) run() error { repos = append(repos, r) } - u.update(repos, u.out, u.home) + u.update(repos, out, u.home) return nil } diff --git a/cmd/helm/repo_update_test.go b/cmd/helm/repo_update_test.go index 5dac59130..f455f97d7 100644 --- a/cmd/helm/repo_update_test.go +++ b/cmd/helm/repo_update_test.go @@ -54,9 +54,8 @@ func TestUpdateCmd(t *testing.T) { uc := &repoUpdateCmd{ update: updater, home: helmpath.Home(thome), - out: out, } - if err := uc.run(); err != nil { + if err := uc.run(out); err != nil { t.Fatal(err) } diff --git a/cmd/helm/rollback.go b/cmd/helm/rollback.go index 145011f36..8a8a4caa6 100644 --- a/cmd/helm/rollback.go +++ b/cmd/helm/rollback.go @@ -41,17 +41,13 @@ type rollbackCmd struct { recreate bool force bool disableHooks bool - out io.Writer client helm.Interface timeout int64 wait bool } func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command { - rollback := &rollbackCmd{ - out: out, - client: c, - } + rollback := &rollbackCmd{client: c} cmd := &cobra.Command{ Use: "rollback [flags] [RELEASE] [REVISION]", @@ -71,7 +67,7 @@ func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command { rollback.revision = int(v64) rollback.client = ensureHelmClient(rollback.client, false) - return rollback.run() + return rollback.run(out) }, } @@ -86,7 +82,7 @@ func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command { return cmd } -func (r *rollbackCmd) run() error { +func (r *rollbackCmd) run(out io.Writer) error { _, err := r.client.RollbackRelease( r.name, helm.RollbackDryRun(r.dryRun), @@ -100,7 +96,7 @@ func (r *rollbackCmd) run() error { return err } - fmt.Fprintf(r.out, "Rollback was a success! Happy Helming!\n") + fmt.Fprintf(out, "Rollback was a success! Happy Helming!\n") return nil } diff --git a/cmd/helm/search.go b/cmd/helm/search.go index 845bfd0be..3d33f268b 100644 --- a/cmd/helm/search.go +++ b/cmd/helm/search.go @@ -41,7 +41,6 @@ Repositories are managed with 'helm repo' commands. const searchMaxScore = 25 type searchCmd struct { - out io.Writer helmhome helmpath.Home versions bool @@ -50,7 +49,7 @@ type searchCmd struct { } func newSearchCmd(out io.Writer) *cobra.Command { - sc := &searchCmd{out: out} + sc := &searchCmd{} cmd := &cobra.Command{ Use: "search [keyword]", @@ -58,7 +57,7 @@ func newSearchCmd(out io.Writer) *cobra.Command { Long: searchDesc, RunE: func(cmd *cobra.Command, args []string) error { sc.helmhome = settings.Home - return sc.run(args) + return sc.run(out, args) }, } @@ -70,8 +69,8 @@ func newSearchCmd(out io.Writer) *cobra.Command { return cmd } -func (s *searchCmd) run(args []string) error { - index, err := s.buildIndex() +func (s *searchCmd) run(out io.Writer, args []string) error { + index, err := s.buildIndex(out) if err != nil { return err } @@ -93,7 +92,7 @@ func (s *searchCmd) run(args []string) error { return err } - fmt.Fprintln(s.out, s.formatSearchResults(data)) + fmt.Fprintln(out, s.formatSearchResults(data)) return nil } @@ -139,7 +138,7 @@ func (s *searchCmd) formatSearchResults(res []*search.Result) string { return table.String() } -func (s *searchCmd) buildIndex() (*search.Index, error) { +func (s *searchCmd) buildIndex(out io.Writer) (*search.Index, error) { // Load the repositories.yaml rf, err := repo.LoadRepositoriesFile(s.helmhome.RepositoryFile()) if err != nil { @@ -152,7 +151,8 @@ func (s *searchCmd) buildIndex() (*search.Index, error) { f := s.helmhome.CacheIndex(n) ind, err := repo.LoadIndexFile(f) if err != nil { - fmt.Fprintf(s.out, "WARNING: Repo %q is corrupt or missing. Try 'helm repo update'.", n) + // TODO should print to stderr + fmt.Fprintf(out, "WARNING: Repo %q is corrupt or missing. Try 'helm repo update'.", n) continue } diff --git a/cmd/helm/status.go b/cmd/helm/status.go index 891d88554..cb33c5f41 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -46,17 +46,13 @@ The status consists of: type statusCmd struct { release string - out io.Writer client helm.Interface version int outfmt string } func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command { - status := &statusCmd{ - out: out, - client: client, - } + status := &statusCmd{client: client} cmd := &cobra.Command{ Use: "status [flags] RELEASE_NAME", @@ -68,7 +64,7 @@ func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command { } status.release = args[0] status.client = ensureHelmClient(status.client, false) - return status.run() + return status.run(out) }, } @@ -78,7 +74,7 @@ func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command { return cmd } -func (s *statusCmd) run() error { +func (s *statusCmd) run(out io.Writer) error { res, err := s.client.ReleaseStatus(s.release, s.version) if err != nil { return err @@ -86,21 +82,21 @@ func (s *statusCmd) run() error { switch s.outfmt { case "": - PrintStatus(s.out, res) + PrintStatus(out, res) return nil case "json": data, err := json.Marshal(res) if err != nil { return fmt.Errorf("Failed to Marshal JSON output: %s", err) } - s.out.Write(data) + out.Write(data) return nil case "yaml": data, err := yaml.Marshal(res) if err != nil { return fmt.Errorf("Failed to Marshal YAML output: %s", err) } - s.out.Write(data) + out.Write(data) return nil } diff --git a/cmd/helm/template.go b/cmd/helm/template.go index 1377d27cd..fea475eb6 100644 --- a/cmd/helm/template.go +++ b/cmd/helm/template.go @@ -63,7 +63,6 @@ To render just one template in a chart, use '-x': type templateCmd struct { valueFiles valueFiles chartPath string - out io.Writer values []string stringValues []string nameTemplate string @@ -75,16 +74,26 @@ type templateCmd struct { } func newTemplateCmd(out io.Writer) *cobra.Command { - - t := &templateCmd{ - out: out, - } + t := &templateCmd{} cmd := &cobra.Command{ Use: "template [flags] CHART", Short: fmt.Sprintf("locally render templates"), Long: templateDesc, - RunE: t.run, + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + return errors.New("chart is required") + } + // verify chart path exists + if _, err := os.Stat(args[0]); err == nil { + if t.chartPath, err = filepath.Abs(args[0]); err != nil { + return err + } + } else { + return err + } + return t.run(out) + }, } f := cmd.Flags() @@ -101,18 +110,7 @@ func newTemplateCmd(out io.Writer) *cobra.Command { return cmd } -func (t *templateCmd) run(cmd *cobra.Command, args []string) error { - if len(args) < 1 { - return errors.New("chart is required") - } - // verify chart path exists - if _, err := os.Stat(args[0]); err == nil { - if t.chartPath, err = filepath.Abs(args[0]); err != nil { - return err - } - } else { - return err - } +func (t *templateCmd) run(out io.Writer) error { // verify specified templates exist relative to chart rf := []string{} var af string @@ -208,14 +206,14 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error { return err } - out, err := renderer.Render(c, vals) + rendered, err := renderer.Render(c, vals) listManifests := []tiller.Manifest{} if err != nil { return err } // extract kind and name re := regexp.MustCompile("kind:(.*)\n") - for k, v := range out { + for k, v := range rendered { match := re.FindStringSubmatch(v) h := "Unknown" if len(match) == 2 { @@ -245,7 +243,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error { Version: 1, Info: &release.Info{LastDeployed: time.Now()}, } - printRelease(os.Stdout, rel) + printRelease(out, rel) } for _, m := range tiller.SortByKind(listManifests) { diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 6f2611886..0fc39570b 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -56,7 +56,6 @@ set for a key called 'foo', the 'newbar' value would take precedence: type upgradeCmd struct { release string chart string - out io.Writer client helm.Interface dryRun bool recreate bool @@ -84,11 +83,7 @@ type upgradeCmd struct { } func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command { - - upgrade := &upgradeCmd{ - out: out, - client: client, - } + upgrade := &upgradeCmd{client: client} cmd := &cobra.Command{ Use: "upgrade [RELEASE] [CHART]", @@ -108,7 +103,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command { upgrade.chart = args[1] upgrade.client = ensureHelmClient(upgrade.client, false) - return upgrade.run() + return upgrade.run(out) }, } @@ -142,7 +137,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command { return cmd } -func (u *upgradeCmd) run() error { +func (u *upgradeCmd) run(out io.Writer) error { chartPath, err := locateChartPath(u.repoURL, u.username, u.password, u.chart, u.version, u.verify, u.keyring, u.certFile, u.keyFile, u.caFile) if err != nil { return err @@ -154,11 +149,10 @@ func (u *upgradeCmd) run() error { _, err := u.client.ReleaseHistory(u.release, 1) if err != nil && strings.Contains(err.Error(), driver.ErrReleaseNotFound(u.release).Error()) { - fmt.Fprintf(u.out, "Release %q does not exist. Installing it now.\n", u.release) + fmt.Fprintf(out, "Release %q does not exist. Installing it now.\n", u.release) ic := &installCmd{ chartPath: chartPath, client: u.client, - out: u.out, name: u.release, valueFiles: u.valueFiles, dryRun: u.dryRun, @@ -170,7 +164,7 @@ func (u *upgradeCmd) run() error { timeout: u.timeout, wait: u.wait, } - return ic.run() + return ic.run(out) } } @@ -209,17 +203,17 @@ func (u *upgradeCmd) run() error { } if settings.Debug { - printRelease(u.out, resp) + printRelease(out, resp) } - fmt.Fprintf(u.out, "Release %q has been upgraded. Happy Helming!\n", u.release) + fmt.Fprintf(out, "Release %q has been upgraded. Happy Helming!\n", u.release) // Print the status like status command does status, err := u.client.ReleaseStatus(u.release, 0) if err != nil { return err } - PrintStatus(u.out, status) + PrintStatus(out, status) return nil } diff --git a/cmd/helm/verify.go b/cmd/helm/verify.go index e82eb4e33..e561418ca 100644 --- a/cmd/helm/verify.go +++ b/cmd/helm/verify.go @@ -38,12 +38,10 @@ the 'helm package --sign' command. type verifyCmd struct { keyring string chartfile string - - out io.Writer } func newVerifyCmd(out io.Writer) *cobra.Command { - vc := &verifyCmd{out: out} + vc := &verifyCmd{} cmd := &cobra.Command{ Use: "verify [flags] PATH", @@ -54,7 +52,7 @@ func newVerifyCmd(out io.Writer) *cobra.Command { return errors.New("a path to a package file is required") } vc.chartfile = args[0] - return vc.run() + return vc.run(out) }, } @@ -64,7 +62,7 @@ func newVerifyCmd(out io.Writer) *cobra.Command { return cmd } -func (v *verifyCmd) run() error { +func (v *verifyCmd) run(out io.Writer) error { _, err := downloader.VerifyChart(v.chartfile, v.keyring) return err } diff --git a/cmd/helm/version.go b/cmd/helm/version.go index 100259896..82502f6e2 100644 --- a/cmd/helm/version.go +++ b/cmd/helm/version.go @@ -41,20 +41,19 @@ version.BuildInfo{Version:"v2.0.0", GitCommit:"ff52399e51bb880526e9cd0ed8386f643 ` type versionCmd struct { - out io.Writer short bool template string } func newVersionCmd(out io.Writer) *cobra.Command { - version := &versionCmd{out: out} + version := &versionCmd{} cmd := &cobra.Command{ Use: "version", Short: "print the client version information", Long: versionDesc, RunE: func(cmd *cobra.Command, args []string) error { - return version.run() + return version.run(out) }, } f := cmd.Flags() @@ -64,15 +63,15 @@ func newVersionCmd(out io.Writer) *cobra.Command { return cmd } -func (v *versionCmd) run() error { +func (v *versionCmd) run(out io.Writer) error { if v.template != "" { tt, err := template.New("_").Parse(v.template) if err != nil { return err } - return tt.Execute(v.out, version.GetBuildInfo()) + return tt.Execute(out, version.GetBuildInfo()) } - fmt.Fprintln(v.out, formatVersion(v.short)) + fmt.Fprintln(out, formatVersion(v.short)) return nil }