ref(cmd): remove Writer from Cmd options stucts

pull/4027/head
Adam Reese 6 years ago
parent 4015a653f8
commit c30637b8a1
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -57,12 +57,11 @@ will be overwritten, but other files will be left alone.
type createCmd struct { type createCmd struct {
home helmpath.Home home helmpath.Home
name string name string
out io.Writer
starter string starter string
} }
func newCreateCmd(out io.Writer) *cobra.Command { func newCreateCmd(out io.Writer) *cobra.Command {
cc := &createCmd{out: out} cc := &createCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "create NAME", 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") return errors.New("the name of the new chart is required")
} }
cc.name = args[0] cc.name = args[0]
return cc.run() return cc.run(out)
}, },
} }
@ -82,8 +81,8 @@ func newCreateCmd(out io.Writer) *cobra.Command {
return cmd return cmd
} }
func (c *createCmd) run() error { func (c *createCmd) run(out io.Writer) error {
fmt.Fprintf(c.out, "Creating %s\n", c.name) fmt.Fprintf(out, "Creating %s\n", c.name)
chartname := filepath.Base(c.name) chartname := filepath.Base(c.name)
cfile := &chart.Metadata{ cfile := &chart.Metadata{

@ -41,15 +41,11 @@ type deleteCmd struct {
purge bool purge bool
timeout int64 timeout int64
out io.Writer
client helm.Interface client helm.Interface
} }
func newDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command { func newDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command {
del := &deleteCmd{ del := &deleteCmd{client: c}
out: out,
client: c,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "delete [flags] RELEASE_NAME [...]", 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++ { for i := 0; i < len(args); i++ {
del.name = args[i] del.name = args[i]
if err := del.run(); err != nil { if err := del.run(out); err != nil {
return err return err
} }
@ -84,7 +80,7 @@ func newDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command {
return cmd return cmd
} }
func (d *deleteCmd) run() error { func (d *deleteCmd) run(out io.Writer) error {
opts := []helm.DeleteOption{ opts := []helm.DeleteOption{
helm.DeleteDryRun(d.dryRun), helm.DeleteDryRun(d.dryRun),
helm.DeleteDisableHooks(d.disableHooks), helm.DeleteDisableHooks(d.disableHooks),
@ -93,7 +89,7 @@ func (d *deleteCmd) run() error {
} }
res, err := d.client.DeleteRelease(d.name, opts...) res, err := d.client.DeleteRelease(d.name, opts...)
if res != nil && res.Info != "" { if res != nil && res.Info != "" {
fmt.Fprintln(d.out, res.Info) fmt.Fprintln(out, res.Info)
} }
return err return err

@ -103,12 +103,11 @@ func newDependencyCmd(out io.Writer) *cobra.Command {
} }
type dependencyListCmd struct { type dependencyListCmd struct {
out io.Writer
chartpath string chartpath string
} }
func newDependencyListCmd(out io.Writer) *cobra.Command { func newDependencyListCmd(out io.Writer) *cobra.Command {
dlc := &dependencyListCmd{out: out} dlc := &dependencyListCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "list [flags] CHART", Use: "list [flags] CHART",
@ -128,7 +127,7 @@ func newDependencyListCmd(out io.Writer) *cobra.Command {
return cmd return cmd
} }
func (l *dependencyListCmd) run() error { func (l *dependencyListCmd) run(out io.Writer) error {
c, err := chartutil.Load(l.chartpath) c, err := chartutil.Load(l.chartpath)
if err != nil { if err != nil {
return err return err
@ -137,15 +136,15 @@ func (l *dependencyListCmd) run() error {
r, err := chartutil.LoadRequirements(c) r, err := chartutil.LoadRequirements(c)
if err != nil { if err != nil {
if err == chartutil.ErrRequirementsNotFound { 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 nil
} }
return err return err
} }
l.printRequirements(r, l.out) l.printRequirements(out, r)
fmt.Fprintln(l.out) fmt.Fprintln(out)
l.printMissing(r) l.printMissing(out, r)
return nil return nil
} }
@ -224,7 +223,7 @@ func (l *dependencyListCmd) dependencyStatus(dep *chartutil.Dependency) string {
} }
// printRequirements prints all of the requirements in the yaml file. // 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 := uitable.New()
table.MaxColWidth = 80 table.MaxColWidth = 80
table.AddRow("NAME", "VERSION", "REPOSITORY", "STATUS") 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. // 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/*") folder := filepath.Join(l.chartpath, "charts/*")
files, err := filepath.Glob(folder) files, err := filepath.Glob(folder)
if err != nil { if err != nil {
fmt.Fprintln(l.out, err) fmt.Fprintln(out, err)
return return
} }
for _, f := range files { for _, f := range files {
fi, err := os.Stat(f) fi, err := os.Stat(f)
if err != nil { 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. // Skip anything that is not a directory and not a tgz file.
if !fi.IsDir() && filepath.Ext(f) != ".tgz" { if !fi.IsDir() && filepath.Ext(f) != ".tgz" {
@ -254,7 +253,7 @@ func (l *dependencyListCmd) printMissing(reqs *chartutil.Requirements) {
} }
c, err := chartutil.Load(f) c, err := chartutil.Load(f)
if err != nil { 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 continue
} }
found := false found := false
@ -265,7 +264,7 @@ func (l *dependencyListCmd) printMissing(reqs *chartutil.Requirements) {
} }
} }
if !found { 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)
} }
} }

@ -37,7 +37,6 @@ of 'helm dependency update'.
` `
type dependencyBuildCmd struct { type dependencyBuildCmd struct {
out io.Writer
chartpath string chartpath string
verify bool verify bool
keyring string keyring string
@ -45,7 +44,7 @@ type dependencyBuildCmd struct {
} }
func newDependencyBuildCmd(out io.Writer) *cobra.Command { func newDependencyBuildCmd(out io.Writer) *cobra.Command {
dbc := &dependencyBuildCmd{out: out} dbc := &dependencyBuildCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "build [flags] CHART", Use: "build [flags] CHART",
@ -58,7 +57,7 @@ func newDependencyBuildCmd(out io.Writer) *cobra.Command {
if len(args) > 0 { if len(args) > 0 {
dbc.chartpath = 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 return cmd
} }
func (d *dependencyBuildCmd) run() error { func (d *dependencyBuildCmd) run(out io.Writer) error {
man := &downloader.Manager{ man := &downloader.Manager{
Out: d.out, Out: out,
ChartPath: d.chartpath, ChartPath: d.chartpath,
HelmHome: d.helmhome, HelmHome: d.helmhome,
Keyring: d.keyring, Keyring: d.keyring,

@ -43,7 +43,6 @@ in the requirements.yaml file, but (b) at the wrong version.
// dependencyUpdateCmd describes a 'helm dependency update' // dependencyUpdateCmd describes a 'helm dependency update'
type dependencyUpdateCmd struct { type dependencyUpdateCmd struct {
out io.Writer
chartpath string chartpath string
helmhome helmpath.Home helmhome helmpath.Home
verify bool verify bool
@ -53,7 +52,7 @@ type dependencyUpdateCmd struct {
// newDependencyUpdateCmd creates a new dependency update command. // newDependencyUpdateCmd creates a new dependency update command.
func newDependencyUpdateCmd(out io.Writer) *cobra.Command { func newDependencyUpdateCmd(out io.Writer) *cobra.Command {
duc := &dependencyUpdateCmd{out: out} duc := &dependencyUpdateCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "update [flags] CHART", Use: "update [flags] CHART",
@ -74,7 +73,7 @@ func newDependencyUpdateCmd(out io.Writer) *cobra.Command {
duc.helmhome = settings.Home 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. // run runs the full dependency update process.
func (d *dependencyUpdateCmd) run() error { func (d *dependencyUpdateCmd) run(out io.Writer) error {
man := &downloader.Manager{ man := &downloader.Manager{
Out: d.out, Out: out,
ChartPath: d.chartpath, ChartPath: d.chartpath,
HelmHome: d.helmhome, HelmHome: d.helmhome,
Keyring: d.keyring, Keyring: d.keyring,

@ -190,11 +190,11 @@ func TestDependencyUpdateCmd_DontDeleteOldChartsOnError(t *testing.T) {
} }
out := bytes.NewBuffer(nil) out := bytes.NewBuffer(nil)
duc := &dependencyUpdateCmd{out: out} duc := &dependencyUpdateCmd{}
duc.helmhome = helmpath.Home(hh) duc.helmhome = helmpath.Home(hh)
duc.chartpath = hh.Path(chartname) duc.chartpath = hh.Path(chartname)
if err := duc.run(); err != nil { if err := duc.run(out); err != nil {
output := out.String() output := out.String()
t.Logf("Output: %s", output) t.Logf("Output: %s", output)
t.Fatal(err) t.Fatal(err)
@ -203,7 +203,7 @@ func TestDependencyUpdateCmd_DontDeleteOldChartsOnError(t *testing.T) {
// Chart repo is down // Chart repo is down
srv.Stop() srv.Stop()
if err := duc.run(); err == nil { if err := duc.run(out); err == nil {
output := out.String() output := out.String()
t.Logf("Output: %s", output) t.Logf("Output: %s", output)
t.Fatal("Expected error, got nil") t.Fatal("Expected error, got nil")

@ -24,6 +24,7 @@ import (
"path/filepath" "path/filepath"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/downloader" "k8s.io/helm/pkg/downloader"
"k8s.io/helm/pkg/getter" "k8s.io/helm/pkg/getter"
@ -64,12 +65,10 @@ type fetchCmd struct {
caFile string caFile string
devel bool devel bool
out io.Writer
} }
func newFetchCmd(out io.Writer) *cobra.Command { func newFetchCmd(out io.Writer) *cobra.Command {
fch := &fetchCmd{out: out} fch := &fetchCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "fetch [flags] [chart URL | repo/chartname] [...]", 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++ { for i := 0; i < len(args); i++ {
fch.chartRef = args[i] fch.chartRef = args[i]
if err := fch.run(); err != nil { if err := fch.run(out); err != nil {
return err return err
} }
} }
@ -114,10 +113,10 @@ func newFetchCmd(out io.Writer) *cobra.Command {
return cmd return cmd
} }
func (f *fetchCmd) run() error { func (f *fetchCmd) run(out io.Writer) error {
c := downloader.ChartDownloader{ c := downloader.ChartDownloader{
HelmHome: settings.Home, HelmHome: settings.Home,
Out: f.out, Out: out,
Keyring: f.keyring, Keyring: f.keyring,
Verify: downloader.VerifyNever, Verify: downloader.VerifyNever,
Getters: getter.All(settings), Getters: getter.All(settings),
@ -157,7 +156,7 @@ func (f *fetchCmd) run() error {
} }
if f.verify { 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. // After verification, untar the chart into the requested directory.

@ -44,15 +44,11 @@ type getCmd struct {
release string release string
version int version int
out io.Writer
client helm.Interface client helm.Interface
} }
func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command { func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
get := &getCmd{ get := &getCmd{client: client}
out: out,
client: client,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "get [flags] RELEASE_NAME", Use: "get [flags] RELEASE_NAME",
@ -64,7 +60,7 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
} }
get.release = args[0] get.release = args[0]
get.client = ensureHelmClient(get.client, false) 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' // 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) res, err := g.client.ReleaseContent(g.release, g.version)
if err != nil { if err != nil {
return err return err
} }
return printRelease(g.out, res) return printRelease(out, res)
} }

@ -33,16 +33,13 @@ Hooks are formatted in YAML and separated by the YAML '---\n' separator.
type getHooksCmd struct { type getHooksCmd struct {
release string release string
out io.Writer
client helm.Interface client helm.Interface
version int version int
} }
func newGetHooksCmd(client helm.Interface, out io.Writer) *cobra.Command { func newGetHooksCmd(client helm.Interface, out io.Writer) *cobra.Command {
ghc := &getHooksCmd{ ghc := &getHooksCmd{client: client}
out: out,
client: client,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "hooks [flags] RELEASE_NAME", Use: "hooks [flags] RELEASE_NAME",
Short: "download all hooks for a named release", 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.release = args[0]
ghc.client = ensureHelmClient(ghc.client, false) 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") cmd.Flags().IntVar(&ghc.version, "revision", 0, "get the named release with revision")
return cmd return cmd
} }
func (g *getHooksCmd) run() error { func (g *getHooksCmd) run(out io.Writer) error {
res, err := g.client.ReleaseContent(g.release, g.version) res, err := g.client.ReleaseContent(g.release, g.version)
if err != nil { if err != nil {
fmt.Fprintln(g.out, g.release) fmt.Fprintln(out, g.release)
return err return err
} }
for _, hook := range res.Hooks { 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 return nil
} }

@ -35,16 +35,13 @@ charts, those resources will also be included in the manifest.
type getManifestCmd struct { type getManifestCmd struct {
release string release string
out io.Writer
client helm.Interface client helm.Interface
version int version int
} }
func newGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command { func newGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command {
get := &getManifestCmd{ get := &getManifestCmd{client: client}
out: out,
client: client,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "manifest [flags] RELEASE_NAME", Use: "manifest [flags] RELEASE_NAME",
Short: "download the manifest for a named release", 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.release = args[0]
get.client = ensureHelmClient(get.client, false) 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' // 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) res, err := g.client.ReleaseContent(g.release, g.version)
if err != nil { if err != nil {
return err return err
} }
fmt.Fprintln(g.out, res.Manifest) fmt.Fprintln(out, res.Manifest)
return nil return nil
} }

@ -33,16 +33,13 @@ This command downloads a values file for a given release.
type getValuesCmd struct { type getValuesCmd struct {
release string release string
allValues bool allValues bool
out io.Writer
client helm.Interface client helm.Interface
version int version int
} }
func newGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command { func newGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command {
get := &getValuesCmd{ get := &getValuesCmd{client: client}
out: out,
client: client,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "values [flags] RELEASE_NAME", Use: "values [flags] RELEASE_NAME",
Short: "download the values file for a named release", 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.release = args[0]
get.client = ensureHelmClient(get.client, false) 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' // 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) res, err := g.client.ReleaseContent(g.release, g.version)
if err != nil { if err != nil {
return err return err
@ -79,10 +76,10 @@ func (g *getValuesCmd) run() error {
if err != nil { if err != nil {
return err return err
} }
fmt.Fprintln(g.out, cfgStr) fmt.Fprintln(out, cfgStr)
return nil return nil
} }
fmt.Fprintln(g.out, string(res.Config)) fmt.Fprintln(out, string(res.Config))
return nil return nil
} }

@ -59,14 +59,13 @@ The historical release set is printed as a formatted table, e.g:
type historyCmd struct { type historyCmd struct {
max int max int
rls string rls string
out io.Writer
helmc helm.Interface helmc helm.Interface
colWidth uint colWidth uint
outputFormat string outputFormat string
} }
func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command { func newHistoryCmd(c helm.Interface, out io.Writer) *cobra.Command {
his := &historyCmd{out: w, helmc: c} his := &historyCmd{helmc: c}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "history [flags] RELEASE_NAME", 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.helmc = ensureHelmClient(his.helmc, false)
his.rls = args[0] 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 return cmd
} }
func (cmd *historyCmd) run() error { func (cmd *historyCmd) run(out io.Writer) error {
rels, err := cmd.helmc.ReleaseHistory(cmd.rls, cmd.max) rels, err := cmd.helmc.ReleaseHistory(cmd.rls, cmd.max)
if err != nil { if err != nil {
return err return err
@ -120,7 +119,7 @@ func (cmd *historyCmd) run() error {
return formattingError return formattingError
} }
fmt.Fprintln(cmd.out, string(history)) fmt.Fprintln(out, string(history))
return nil return nil
} }

@ -39,12 +39,11 @@ var stableRepositoryURL = "https://kubernetes-charts.storage.googleapis.com"
type initCmd struct { type initCmd struct {
skipRefresh bool skipRefresh bool
out io.Writer
home helmpath.Home home helmpath.Home
} }
func newInitCmd(out io.Writer) *cobra.Command { func newInitCmd(out io.Writer) *cobra.Command {
i := &initCmd{out: out} i := &initCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "init", Use: "init",
@ -55,7 +54,7 @@ func newInitCmd(out io.Writer) *cobra.Command {
return errors.New("This command does not accept arguments") return errors.New("This command does not accept arguments")
} }
i.home = settings.Home 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. // run initializes local config and installs Tiller to Kubernetes cluster.
func (i *initCmd) run() error { func (i *initCmd) run(out io.Writer) error {
if err := ensureDirectories(i.home, i.out); err != nil { if err := ensureDirectories(i.home, out); err != nil {
return err 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 return err
} }
if err := ensureRepoFileFormat(i.home.RepositoryFile(), i.out); err != nil { if err := ensureRepoFileFormat(i.home.RepositoryFile(), out); err != nil {
return err return err
} }
fmt.Fprintf(i.out, "$HELM_HOME has been configured at %s.\n", settings.Home) fmt.Fprintf(out, "$HELM_HOME has been configured at %s.\n", settings.Home)
fmt.Fprintln(i.out, "Happy Helming!") fmt.Fprintln(out, "Happy Helming!")
return nil return nil
} }

@ -55,7 +55,6 @@ type inspectCmd struct {
output string output string
verify bool verify bool
keyring string keyring string
out io.Writer
version string version string
repoURL string repoURL string
username string username string
@ -76,10 +75,7 @@ const (
var readmeFileNames = []string{"readme.md", "readme.txt", "readme"} var readmeFileNames = []string{"readme.md", "readme.txt", "readme"}
func newInspectCmd(out io.Writer) *cobra.Command { func newInspectCmd(out io.Writer) *cobra.Command {
insp := &inspectCmd{ insp := &inspectCmd{output: all}
out: out,
output: all,
}
inspectCommand := &cobra.Command{ inspectCommand := &cobra.Command{
Use: "inspect [CHART]", Use: "inspect [CHART]",
@ -95,7 +91,7 @@ func newInspectCmd(out io.Writer) *cobra.Command {
return err return err
} }
insp.chartpath = cp insp.chartpath = cp
return insp.run() return insp.run(out)
}, },
} }
@ -114,7 +110,7 @@ func newInspectCmd(out io.Writer) *cobra.Command {
return err return err
} }
insp.chartpath = cp insp.chartpath = cp
return insp.run() return insp.run(out)
}, },
} }
@ -133,7 +129,7 @@ func newInspectCmd(out io.Writer) *cobra.Command {
return err return err
} }
insp.chartpath = cp insp.chartpath = cp
return insp.run() return insp.run(out)
}, },
} }
@ -152,7 +148,7 @@ func newInspectCmd(out io.Writer) *cobra.Command {
return err return err
} }
insp.chartpath = cp insp.chartpath = cp
return insp.run() return insp.run(out)
}, },
} }
@ -219,7 +215,7 @@ func newInspectCmd(out io.Writer) *cobra.Command {
return inspectCommand return inspectCommand
} }
func (i *inspectCmd) run() error { func (i *inspectCmd) run(out io.Writer) error {
chrt, err := chartutil.Load(i.chartpath) chrt, err := chartutil.Load(i.chartpath)
if err != nil { if err != nil {
return err return err
@ -230,25 +226,25 @@ func (i *inspectCmd) run() error {
} }
if i.output == chartOnly || i.output == all { 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 == valuesOnly || i.output == all) && chrt.Values != nil {
if i.output == all { 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 == readmeOnly || i.output == all {
if i.output == all { if i.output == all {
fmt.Fprintln(i.out, "---") fmt.Fprintln(out, "---")
} }
readme := findReadme(chrt.Files) readme := findReadme(chrt.Files)
if readme == nil { if readme == nil {
return nil return nil
} }
fmt.Fprintln(i.out, string(readme.Data)) fmt.Fprintln(out, string(readme.Data))
} }
return nil return nil
} }

@ -29,9 +29,8 @@ func TestInspect(t *testing.T) {
insp := &inspectCmd{ insp := &inspectCmd{
chartpath: "testdata/testcharts/alpine", chartpath: "testdata/testcharts/alpine",
output: all, output: all,
out: b,
} }
insp.run() insp.run(b)
// Load the data from the textfixture directly. // Load the data from the textfixture directly.
cdata, err := ioutil.ReadFile("testdata/testcharts/alpine/Chart.yaml") cdata, err := ioutil.ReadFile("testdata/testcharts/alpine/Chart.yaml")
@ -71,9 +70,8 @@ func TestInspect(t *testing.T) {
insp = &inspectCmd{ insp = &inspectCmd{
chartpath: "testdata/testcharts/novals", chartpath: "testdata/testcharts/novals",
output: "values", output: "values",
out: b,
} }
insp.run() insp.run(b)
if b.Len() != 0 { if b.Len() != 0 {
t.Errorf("expected empty values buffer, got %q", b.String()) t.Errorf("expected empty values buffer, got %q", b.String())
} }

@ -128,7 +128,6 @@ type installCmd struct {
caFile string // --ca-file caFile string // --ca-file
chartPath string // arg chartPath string // arg
out io.Writer
client helm.Interface client helm.Interface
} }
@ -150,10 +149,7 @@ func (v *valueFiles) Set(value string) error {
} }
func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command { func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command {
inst := &installCmd{ inst := &installCmd{client: c}
out: out,
client: c,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "install [CHART]", Use: "install [CHART]",
@ -177,7 +173,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command {
} }
inst.chartPath = cp inst.chartPath = cp
inst.client = ensureHelmClient(inst.client, false) 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 return cmd
} }
func (i *installCmd) run() error { func (i *installCmd) run(out io.Writer) error {
debug("CHART PATH: %s\n", i.chartPath) debug("CHART PATH: %s\n", i.chartPath)
rawVals, err := vals(i.valueFiles, i.values, i.stringValues) 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 err := checkDependencies(chartRequested, req); err != nil {
if i.depUp { if i.depUp {
man := &downloader.Manager{ man := &downloader.Manager{
Out: i.out, Out: out,
ChartPath: i.chartPath, ChartPath: i.chartPath,
HelmHome: settings.Home, HelmHome: settings.Home,
Keyring: defaultKeyring(), Keyring: defaultKeyring(),
@ -274,7 +270,7 @@ func (i *installCmd) run() error {
if rel == nil { if rel == nil {
return nil return nil
} }
i.printRelease(rel) i.printRelease(out, rel)
// If this is a dry run, we can't display status. // If this is a dry run, we can't display status.
if i.dryRun { if i.dryRun {
@ -286,7 +282,7 @@ func (i *installCmd) run() error {
if err != nil { if err != nil {
return err return err
} }
PrintStatus(i.out, status) PrintStatus(out, status)
return nil 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. // 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 { if rel == nil {
return return
} }
// TODO: Switch to text/template like everything else. // 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 { if settings.Debug {
printRelease(i.out, rel) printRelease(out, rel)
} }
} }

@ -49,14 +49,11 @@ type lintCmd struct {
sValues []string sValues []string
strict bool strict bool
paths []string paths []string
out io.Writer
} }
func newLintCmd(out io.Writer) *cobra.Command { func newLintCmd(out io.Writer) *cobra.Command {
l := &lintCmd{ l := &lintCmd{paths: []string{"."}}
paths: []string{"."},
out: out,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "lint [flags] PATH", Use: "lint [flags] PATH",
Short: "examines a chart for possible issues", Short: "examines a chart for possible issues",
@ -65,7 +62,7 @@ func newLintCmd(out io.Writer) *cobra.Command {
if len(args) > 0 { if len(args) > 0 {
l.paths = args 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)") 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 var lowestTolerance int
if l.strict { if l.strict {
lowestTolerance = support.WarningSev lowestTolerance = support.WarningSev
@ -126,7 +123,7 @@ func (l *lintCmd) run() error {
return fmt.Errorf("%s, %d chart(s) failed", msg, failures) 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 return nil
} }

@ -63,7 +63,6 @@ type listCmd struct {
offset string offset string
byDate bool byDate bool
sortDesc bool sortDesc bool
out io.Writer
all bool all bool
deleted bool deleted bool
deleting bool deleting bool
@ -77,10 +76,7 @@ type listCmd struct {
} }
func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { func newListCmd(client helm.Interface, out io.Writer) *cobra.Command {
list := &listCmd{ list := &listCmd{client: client}
out: out,
client: client,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "list [flags] [FILTER]", Use: "list [flags] [FILTER]",
@ -92,7 +88,7 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command {
list.filter = strings.Join(args, " ") list.filter = strings.Join(args, " ")
} }
list.client = ensureHelmClient(list.client, list.allNamespaces) 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 return cmd
} }
func (l *listCmd) run() error { func (l *listCmd) run(out io.Writer) error {
sortBy := hapi.SortByName sortBy := hapi.SortByName
if l.byDate { if l.byDate {
sortBy = hapi.SortByLastReleased sortBy = hapi.SortByLastReleased
@ -148,11 +144,11 @@ func (l *listCmd) run() error {
if l.short { if l.short {
for _, r := range rels { for _, r := range rels {
fmt.Fprintln(l.out, r.Name) fmt.Fprintln(out, r.Name)
} }
return nil return nil
} }
fmt.Fprintln(l.out, formatList(rels, l.colWidth)) fmt.Fprintln(out, formatList(rels, l.colWidth))
return nil return nil
} }

@ -62,12 +62,11 @@ type packageCmd struct {
destination string destination string
dependencyUpdate bool dependencyUpdate bool
out io.Writer
home helmpath.Home home helmpath.Home
} }
func newPackageCmd(out io.Writer) *cobra.Command { func newPackageCmd(out io.Writer) *cobra.Command {
pkg := &packageCmd{out: out} pkg := &packageCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "package [flags] [CHART_PATH] [...]", Use: "package [flags] [CHART_PATH] [...]",
@ -88,7 +87,7 @@ func newPackageCmd(out io.Writer) *cobra.Command {
} }
for i := 0; i < len(args); i++ { for i := 0; i < len(args); i++ {
pkg.path = args[i] pkg.path = args[i]
if err := pkg.run(); err != nil { if err := pkg.run(out); err != nil {
return err return err
} }
} }
@ -111,7 +110,7 @@ func newPackageCmd(out io.Writer) *cobra.Command {
return cmd return cmd
} }
func (p *packageCmd) run() error { func (p *packageCmd) run(out io.Writer) error {
path, err := filepath.Abs(p.path) path, err := filepath.Abs(p.path)
if err != nil { if err != nil {
return err return err
@ -119,7 +118,7 @@ func (p *packageCmd) run() error {
if p.dependencyUpdate { if p.dependencyUpdate {
downloadManager := &downloader.Manager{ downloadManager := &downloader.Manager{
Out: p.out, Out: out,
ChartPath: path, ChartPath: path,
HelmHome: settings.Home, HelmHome: settings.Home,
Keyring: p.keyring, Keyring: p.keyring,
@ -192,7 +191,7 @@ func (p *packageCmd) run() error {
name, err := chartutil.Save(ch, dest) name, err := chartutil.Save(ch, dest)
if err == nil { 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 { } else {
return fmt.Errorf("Failed to save: %s", err) return fmt.Errorf("Failed to save: %s", err)
} }

@ -27,23 +27,22 @@ import (
type pluginListCmd struct { type pluginListCmd struct {
home helmpath.Home home helmpath.Home
out io.Writer
} }
func newPluginListCmd(out io.Writer) *cobra.Command { func newPluginListCmd(out io.Writer) *cobra.Command {
pcmd := &pluginListCmd{out: out} pcmd := &pluginListCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "list", Use: "list",
Short: "list installed Helm plugins", Short: "list installed Helm plugins",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
pcmd.home = settings.Home pcmd.home = settings.Home
return pcmd.run() return pcmd.run(out)
}, },
} }
return cmd return cmd
} }
func (pcmd *pluginListCmd) run() error { func (pcmd *pluginListCmd) run(out io.Writer) error {
debug("pluginDirs: %s", settings.PluginDirs()) debug("pluginDirs: %s", settings.PluginDirs())
plugins, err := findPlugins(settings.PluginDirs()) plugins, err := findPlugins(settings.PluginDirs())
if err != nil { if err != nil {
@ -55,6 +54,6 @@ func (pcmd *pluginListCmd) run() error {
for _, p := range plugins { for _, p := range plugins {
table.AddRow(p.Metadata.Name, p.Metadata.Version, p.Metadata.Description) table.AddRow(p.Metadata.Name, p.Metadata.Version, p.Metadata.Description)
} }
fmt.Fprintln(pcmd.out, table) fmt.Fprintln(out, table)
return nil return nil
} }

@ -31,11 +31,10 @@ import (
type pluginRemoveCmd struct { type pluginRemoveCmd struct {
names []string names []string
home helmpath.Home home helmpath.Home
out io.Writer
} }
func newPluginRemoveCmd(out io.Writer) *cobra.Command { func newPluginRemoveCmd(out io.Writer) *cobra.Command {
pcmd := &pluginRemoveCmd{out: out} pcmd := &pluginRemoveCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "remove <plugin>...", Use: "remove <plugin>...",
Short: "remove one or more Helm plugins", Short: "remove one or more Helm plugins",
@ -43,7 +42,7 @@ func newPluginRemoveCmd(out io.Writer) *cobra.Command {
return pcmd.complete(args) return pcmd.complete(args)
}, },
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return pcmd.run() return pcmd.run(out)
}, },
} }
return cmd return cmd
@ -58,7 +57,7 @@ func (pcmd *pluginRemoveCmd) complete(args []string) error {
return nil return nil
} }
func (pcmd *pluginRemoveCmd) run() error { func (pcmd *pluginRemoveCmd) run(out io.Writer) error {
debug("loading installed plugins from %s", settings.PluginDirs()) debug("loading installed plugins from %s", settings.PluginDirs())
plugins, err := findPlugins(settings.PluginDirs()) plugins, err := findPlugins(settings.PluginDirs())
if err != nil { if err != nil {
@ -70,7 +69,7 @@ func (pcmd *pluginRemoveCmd) run() error {
if err := removePlugin(found); err != nil { if err := removePlugin(found); err != nil {
errorPlugins = append(errorPlugins, fmt.Sprintf("Failed to remove plugin %s, got error (%v)", name, err)) errorPlugins = append(errorPlugins, fmt.Sprintf("Failed to remove plugin %s, got error (%v)", name, err))
} else { } else {
fmt.Fprintf(pcmd.out, "Removed plugin: %s\n", name) fmt.Fprintf(out, "Removed plugin: %s\n", name)
} }
} else { } else {
errorPlugins = append(errorPlugins, fmt.Sprintf("Plugin: %s not found", name)) errorPlugins = append(errorPlugins, fmt.Sprintf("Plugin: %s not found", name))

@ -32,11 +32,10 @@ import (
type pluginUpdateCmd struct { type pluginUpdateCmd struct {
names []string names []string
home helmpath.Home home helmpath.Home
out io.Writer
} }
func newPluginUpdateCmd(out io.Writer) *cobra.Command { func newPluginUpdateCmd(out io.Writer) *cobra.Command {
pcmd := &pluginUpdateCmd{out: out} pcmd := &pluginUpdateCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "update <plugin>...", Use: "update <plugin>...",
Short: "update one or more Helm plugins", Short: "update one or more Helm plugins",
@ -44,7 +43,7 @@ func newPluginUpdateCmd(out io.Writer) *cobra.Command {
return pcmd.complete(args) return pcmd.complete(args)
}, },
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return pcmd.run() return pcmd.run(out)
}, },
} }
return cmd return cmd
@ -59,7 +58,7 @@ func (pcmd *pluginUpdateCmd) complete(args []string) error {
return nil return nil
} }
func (pcmd *pluginUpdateCmd) run() error { func (pcmd *pluginUpdateCmd) run(out io.Writer) error {
installer.Debug = settings.Debug installer.Debug = settings.Debug
debug("loading installed plugins from %s", settings.PluginDirs()) debug("loading installed plugins from %s", settings.PluginDirs())
plugins, err := findPlugins(settings.PluginDirs()) plugins, err := findPlugins(settings.PluginDirs())
@ -73,7 +72,7 @@ func (pcmd *pluginUpdateCmd) run() error {
if err := updatePlugin(found, pcmd.home); err != nil { if err := updatePlugin(found, pcmd.home); err != nil {
errorPlugins = append(errorPlugins, fmt.Sprintf("Failed to update plugin %s, got error (%v)", name, err)) errorPlugins = append(errorPlugins, fmt.Sprintf("Failed to update plugin %s, got error (%v)", name, err))
} else { } else {
fmt.Fprintf(pcmd.out, "Updated plugin: %s\n", name) fmt.Fprintf(out, "Updated plugin: %s\n", name)
} }
} else { } else {
errorPlugins = append(errorPlugins, fmt.Sprintf("Plugin: %s not found", name)) errorPlugins = append(errorPlugins, fmt.Sprintf("Plugin: %s not found", name))

@ -35,17 +35,13 @@ The tests to be run are defined in the chart that was installed.
type releaseTestCmd struct { type releaseTestCmd struct {
name string name string
out io.Writer
client helm.Interface client helm.Interface
timeout int64 timeout int64
cleanup bool cleanup bool
} }
func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command { func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command {
rlsTest := &releaseTestCmd{ rlsTest := &releaseTestCmd{client: c}
out: out,
client: c,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "test [RELEASE]", Use: "test [RELEASE]",
@ -58,7 +54,7 @@ func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command {
rlsTest.name = args[0] rlsTest.name = args[0]
rlsTest.client = ensureHelmClient(rlsTest.client, false) 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 return cmd
} }
func (t *releaseTestCmd) run() (err error) { func (t *releaseTestCmd) run(out io.Writer) (err error) {
c, errc := t.client.RunReleaseTest( c, errc := t.client.RunReleaseTest(
t.name, t.name,
helm.ReleaseTestTimeout(t.timeout), helm.ReleaseTestTimeout(t.timeout),
@ -92,12 +88,9 @@ func (t *releaseTestCmd) run() (err error) {
if res.Status == release.TestRunFailure { if res.Status == release.TestRunFailure {
testErr.failed++ testErr.failed++
} }
fmt.Fprintf(out, res.Msg+"\n")
fmt.Fprintf(t.out, res.Msg+"\n")
} }
} }
} }
type testErr struct { type testErr struct {

@ -38,12 +38,10 @@ type repoAddCmd struct {
certFile string certFile string
keyFile string keyFile string
caFile string caFile string
out io.Writer
} }
func newRepoAddCmd(out io.Writer) *cobra.Command { func newRepoAddCmd(out io.Writer) *cobra.Command {
add := &repoAddCmd{out: out} add := &repoAddCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "add [flags] [NAME] [URL]", Use: "add [flags] [NAME] [URL]",
@ -57,7 +55,7 @@ func newRepoAddCmd(out io.Writer) *cobra.Command {
add.url = args[1] add.url = args[1]
add.home = settings.Home add.home = settings.Home
return add.run() return add.run(out)
}, },
} }
@ -72,11 +70,11 @@ func newRepoAddCmd(out io.Writer) *cobra.Command {
return cmd 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 { 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 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 return nil
} }

@ -41,12 +41,11 @@ into the existing index, with local charts taking priority over existing charts.
type repoIndexCmd struct { type repoIndexCmd struct {
dir string dir string
url string url string
out io.Writer
merge string merge string
} }
func newRepoIndexCmd(out io.Writer) *cobra.Command { func newRepoIndexCmd(out io.Writer) *cobra.Command {
index := &repoIndexCmd{out: out} index := &repoIndexCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "index [flags] [DIR]", Use: "index [flags] [DIR]",
@ -59,7 +58,7 @@ func newRepoIndexCmd(out io.Writer) *cobra.Command {
index.dir = args[0] index.dir = args[0]
return index.run() return index.run(out)
}, },
} }
@ -70,7 +69,7 @@ func newRepoIndexCmd(out io.Writer) *cobra.Command {
return cmd return cmd
} }
func (i *repoIndexCmd) run() error { func (i *repoIndexCmd) run(out io.Writer) error {
path, err := filepath.Abs(i.dir) path, err := filepath.Abs(i.dir)
if err != nil { if err != nil {
return err return err

@ -29,26 +29,25 @@ import (
) )
type repoListCmd struct { type repoListCmd struct {
out io.Writer
home helmpath.Home home helmpath.Home
} }
func newRepoListCmd(out io.Writer) *cobra.Command { func newRepoListCmd(out io.Writer) *cobra.Command {
list := &repoListCmd{out: out} list := &repoListCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "list [flags]", Use: "list [flags]",
Short: "list chart repositories", Short: "list chart repositories",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
list.home = settings.Home list.home = settings.Home
return list.run() return list.run(out)
}, },
} }
return cmd return cmd
} }
func (a *repoListCmd) run() error { func (a *repoListCmd) run(out io.Writer) error {
f, err := repo.LoadRepositoriesFile(a.home.RepositoryFile()) f, err := repo.LoadRepositoriesFile(a.home.RepositoryFile())
if err != nil { if err != nil {
return err return err
@ -61,6 +60,6 @@ func (a *repoListCmd) run() error {
for _, re := range f.Repositories { for _, re := range f.Repositories {
table.AddRow(re.Name, re.URL) table.AddRow(re.Name, re.URL)
} }
fmt.Fprintln(a.out, table) fmt.Fprintln(out, table)
return nil return nil
} }

@ -28,13 +28,12 @@ import (
) )
type repoRemoveCmd struct { type repoRemoveCmd struct {
out io.Writer
name string name string
home helmpath.Home home helmpath.Home
} }
func newRepoRemoveCmd(out io.Writer) *cobra.Command { func newRepoRemoveCmd(out io.Writer) *cobra.Command {
remove := &repoRemoveCmd{out: out} remove := &repoRemoveCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "remove [flags] [NAME]", Use: "remove [flags] [NAME]",
@ -47,15 +46,15 @@ func newRepoRemoveCmd(out io.Writer) *cobra.Command {
remove.name = args[0] remove.name = args[0]
remove.home = settings.Home remove.home = settings.Home
return remove.run() return remove.run(out)
}, },
} }
return cmd return cmd
} }
func (r *repoRemoveCmd) run() error { func (r *repoRemoveCmd) run(out io.Writer) error {
return removeRepoLine(r.out, r.name, r.home) return removeRepoLine(out, r.name, r.home)
} }
func removeRepoLine(out io.Writer, name string, home helmpath.Home) error { func removeRepoLine(out io.Writer, name string, home helmpath.Home) error {

@ -42,14 +42,11 @@ var errNoRepositories = errors.New("no repositories found. You must add one befo
type repoUpdateCmd struct { type repoUpdateCmd struct {
update func([]*repo.ChartRepository, io.Writer, helmpath.Home) update func([]*repo.ChartRepository, io.Writer, helmpath.Home)
home helmpath.Home home helmpath.Home
out io.Writer
} }
func newRepoUpdateCmd(out io.Writer) *cobra.Command { func newRepoUpdateCmd(out io.Writer) *cobra.Command {
u := &repoUpdateCmd{ u := &repoUpdateCmd{update: updateCharts}
out: out,
update: updateCharts,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "update", Use: "update",
Aliases: []string{"up"}, Aliases: []string{"up"},
@ -57,13 +54,13 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command {
Long: updateDesc, Long: updateDesc,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
u.home = settings.Home u.home = settings.Home
return u.run() return u.run(out)
}, },
} }
return cmd return cmd
} }
func (u *repoUpdateCmd) run() error { func (u *repoUpdateCmd) run(out io.Writer) error {
f, err := repo.LoadRepositoriesFile(u.home.RepositoryFile()) f, err := repo.LoadRepositoriesFile(u.home.RepositoryFile())
if err != nil { if err != nil {
return err return err
@ -81,7 +78,7 @@ func (u *repoUpdateCmd) run() error {
repos = append(repos, r) repos = append(repos, r)
} }
u.update(repos, u.out, u.home) u.update(repos, out, u.home)
return nil return nil
} }

@ -54,9 +54,8 @@ func TestUpdateCmd(t *testing.T) {
uc := &repoUpdateCmd{ uc := &repoUpdateCmd{
update: updater, update: updater,
home: helmpath.Home(thome), home: helmpath.Home(thome),
out: out,
} }
if err := uc.run(); err != nil { if err := uc.run(out); err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -41,17 +41,13 @@ type rollbackCmd struct {
recreate bool recreate bool
force bool force bool
disableHooks bool disableHooks bool
out io.Writer
client helm.Interface client helm.Interface
timeout int64 timeout int64
wait bool wait bool
} }
func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command { func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command {
rollback := &rollbackCmd{ rollback := &rollbackCmd{client: c}
out: out,
client: c,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "rollback [flags] [RELEASE] [REVISION]", Use: "rollback [flags] [RELEASE] [REVISION]",
@ -71,7 +67,7 @@ func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command {
rollback.revision = int(v64) rollback.revision = int(v64)
rollback.client = ensureHelmClient(rollback.client, false) 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 return cmd
} }
func (r *rollbackCmd) run() error { func (r *rollbackCmd) run(out io.Writer) error {
_, err := r.client.RollbackRelease( _, err := r.client.RollbackRelease(
r.name, r.name,
helm.RollbackDryRun(r.dryRun), helm.RollbackDryRun(r.dryRun),
@ -100,7 +96,7 @@ func (r *rollbackCmd) run() error {
return err 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 return nil
} }

@ -41,7 +41,6 @@ Repositories are managed with 'helm repo' commands.
const searchMaxScore = 25 const searchMaxScore = 25
type searchCmd struct { type searchCmd struct {
out io.Writer
helmhome helmpath.Home helmhome helmpath.Home
versions bool versions bool
@ -50,7 +49,7 @@ type searchCmd struct {
} }
func newSearchCmd(out io.Writer) *cobra.Command { func newSearchCmd(out io.Writer) *cobra.Command {
sc := &searchCmd{out: out} sc := &searchCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "search [keyword]", Use: "search [keyword]",
@ -58,7 +57,7 @@ func newSearchCmd(out io.Writer) *cobra.Command {
Long: searchDesc, Long: searchDesc,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
sc.helmhome = settings.Home 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 return cmd
} }
func (s *searchCmd) run(args []string) error { func (s *searchCmd) run(out io.Writer, args []string) error {
index, err := s.buildIndex() index, err := s.buildIndex(out)
if err != nil { if err != nil {
return err return err
} }
@ -93,7 +92,7 @@ func (s *searchCmd) run(args []string) error {
return err return err
} }
fmt.Fprintln(s.out, s.formatSearchResults(data)) fmt.Fprintln(out, s.formatSearchResults(data))
return nil return nil
} }
@ -139,7 +138,7 @@ func (s *searchCmd) formatSearchResults(res []*search.Result) string {
return table.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 // Load the repositories.yaml
rf, err := repo.LoadRepositoriesFile(s.helmhome.RepositoryFile()) rf, err := repo.LoadRepositoriesFile(s.helmhome.RepositoryFile())
if err != nil { if err != nil {
@ -152,7 +151,8 @@ func (s *searchCmd) buildIndex() (*search.Index, error) {
f := s.helmhome.CacheIndex(n) f := s.helmhome.CacheIndex(n)
ind, err := repo.LoadIndexFile(f) ind, err := repo.LoadIndexFile(f)
if err != nil { 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 continue
} }

@ -46,17 +46,13 @@ The status consists of:
type statusCmd struct { type statusCmd struct {
release string release string
out io.Writer
client helm.Interface client helm.Interface
version int version int
outfmt string outfmt string
} }
func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command { func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command {
status := &statusCmd{ status := &statusCmd{client: client}
out: out,
client: client,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "status [flags] RELEASE_NAME", Use: "status [flags] RELEASE_NAME",
@ -68,7 +64,7 @@ func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command {
} }
status.release = args[0] status.release = args[0]
status.client = ensureHelmClient(status.client, false) 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 return cmd
} }
func (s *statusCmd) run() error { func (s *statusCmd) run(out io.Writer) error {
res, err := s.client.ReleaseStatus(s.release, s.version) res, err := s.client.ReleaseStatus(s.release, s.version)
if err != nil { if err != nil {
return err return err
@ -86,21 +82,21 @@ func (s *statusCmd) run() error {
switch s.outfmt { switch s.outfmt {
case "": case "":
PrintStatus(s.out, res) PrintStatus(out, res)
return nil return nil
case "json": case "json":
data, err := json.Marshal(res) data, err := json.Marshal(res)
if err != nil { if err != nil {
return fmt.Errorf("Failed to Marshal JSON output: %s", err) return fmt.Errorf("Failed to Marshal JSON output: %s", err)
} }
s.out.Write(data) out.Write(data)
return nil return nil
case "yaml": case "yaml":
data, err := yaml.Marshal(res) data, err := yaml.Marshal(res)
if err != nil { if err != nil {
return fmt.Errorf("Failed to Marshal YAML output: %s", err) return fmt.Errorf("Failed to Marshal YAML output: %s", err)
} }
s.out.Write(data) out.Write(data)
return nil return nil
} }

@ -63,7 +63,6 @@ To render just one template in a chart, use '-x':
type templateCmd struct { type templateCmd struct {
valueFiles valueFiles valueFiles valueFiles
chartPath string chartPath string
out io.Writer
values []string values []string
stringValues []string stringValues []string
nameTemplate string nameTemplate string
@ -75,16 +74,26 @@ type templateCmd struct {
} }
func newTemplateCmd(out io.Writer) *cobra.Command { func newTemplateCmd(out io.Writer) *cobra.Command {
t := &templateCmd{}
t := &templateCmd{
out: out,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "template [flags] CHART", Use: "template [flags] CHART",
Short: fmt.Sprintf("locally render templates"), Short: fmt.Sprintf("locally render templates"),
Long: templateDesc, 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() f := cmd.Flags()
@ -101,18 +110,7 @@ func newTemplateCmd(out io.Writer) *cobra.Command {
return cmd return cmd
} }
func (t *templateCmd) run(cmd *cobra.Command, args []string) error { func (t *templateCmd) run(out io.Writer) 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
}
// verify specified templates exist relative to chart // verify specified templates exist relative to chart
rf := []string{} rf := []string{}
var af string var af string
@ -208,14 +206,14 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
return err return err
} }
out, err := renderer.Render(c, vals) rendered, err := renderer.Render(c, vals)
listManifests := []tiller.Manifest{} listManifests := []tiller.Manifest{}
if err != nil { if err != nil {
return err return err
} }
// extract kind and name // extract kind and name
re := regexp.MustCompile("kind:(.*)\n") re := regexp.MustCompile("kind:(.*)\n")
for k, v := range out { for k, v := range rendered {
match := re.FindStringSubmatch(v) match := re.FindStringSubmatch(v)
h := "Unknown" h := "Unknown"
if len(match) == 2 { if len(match) == 2 {
@ -245,7 +243,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
Version: 1, Version: 1,
Info: &release.Info{LastDeployed: time.Now()}, Info: &release.Info{LastDeployed: time.Now()},
} }
printRelease(os.Stdout, rel) printRelease(out, rel)
} }
for _, m := range tiller.SortByKind(listManifests) { for _, m := range tiller.SortByKind(listManifests) {

@ -56,7 +56,6 @@ set for a key called 'foo', the 'newbar' value would take precedence:
type upgradeCmd struct { type upgradeCmd struct {
release string release string
chart string chart string
out io.Writer
client helm.Interface client helm.Interface
dryRun bool dryRun bool
recreate bool recreate bool
@ -84,11 +83,7 @@ type upgradeCmd struct {
} }
func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command { func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command {
upgrade := &upgradeCmd{client: client}
upgrade := &upgradeCmd{
out: out,
client: client,
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "upgrade [RELEASE] [CHART]", Use: "upgrade [RELEASE] [CHART]",
@ -108,7 +103,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command {
upgrade.chart = args[1] upgrade.chart = args[1]
upgrade.client = ensureHelmClient(upgrade.client, false) 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 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) 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 { if err != nil {
return err return err
@ -154,11 +149,10 @@ func (u *upgradeCmd) run() error {
_, err := u.client.ReleaseHistory(u.release, 1) _, err := u.client.ReleaseHistory(u.release, 1)
if err != nil && strings.Contains(err.Error(), driver.ErrReleaseNotFound(u.release).Error()) { 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{ ic := &installCmd{
chartPath: chartPath, chartPath: chartPath,
client: u.client, client: u.client,
out: u.out,
name: u.release, name: u.release,
valueFiles: u.valueFiles, valueFiles: u.valueFiles,
dryRun: u.dryRun, dryRun: u.dryRun,
@ -170,7 +164,7 @@ func (u *upgradeCmd) run() error {
timeout: u.timeout, timeout: u.timeout,
wait: u.wait, wait: u.wait,
} }
return ic.run() return ic.run(out)
} }
} }
@ -209,17 +203,17 @@ func (u *upgradeCmd) run() error {
} }
if settings.Debug { 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 // Print the status like status command does
status, err := u.client.ReleaseStatus(u.release, 0) status, err := u.client.ReleaseStatus(u.release, 0)
if err != nil { if err != nil {
return err return err
} }
PrintStatus(u.out, status) PrintStatus(out, status)
return nil return nil
} }

@ -38,12 +38,10 @@ the 'helm package --sign' command.
type verifyCmd struct { type verifyCmd struct {
keyring string keyring string
chartfile string chartfile string
out io.Writer
} }
func newVerifyCmd(out io.Writer) *cobra.Command { func newVerifyCmd(out io.Writer) *cobra.Command {
vc := &verifyCmd{out: out} vc := &verifyCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "verify [flags] PATH", 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") return errors.New("a path to a package file is required")
} }
vc.chartfile = args[0] vc.chartfile = args[0]
return vc.run() return vc.run(out)
}, },
} }
@ -64,7 +62,7 @@ func newVerifyCmd(out io.Writer) *cobra.Command {
return cmd return cmd
} }
func (v *verifyCmd) run() error { func (v *verifyCmd) run(out io.Writer) error {
_, err := downloader.VerifyChart(v.chartfile, v.keyring) _, err := downloader.VerifyChart(v.chartfile, v.keyring)
return err return err
} }

@ -41,20 +41,19 @@ version.BuildInfo{Version:"v2.0.0", GitCommit:"ff52399e51bb880526e9cd0ed8386f643
` `
type versionCmd struct { type versionCmd struct {
out io.Writer
short bool short bool
template string template string
} }
func newVersionCmd(out io.Writer) *cobra.Command { func newVersionCmd(out io.Writer) *cobra.Command {
version := &versionCmd{out: out} version := &versionCmd{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "version", Use: "version",
Short: "print the client version information", Short: "print the client version information",
Long: versionDesc, Long: versionDesc,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return version.run() return version.run(out)
}, },
} }
f := cmd.Flags() f := cmd.Flags()
@ -64,15 +63,15 @@ func newVersionCmd(out io.Writer) *cobra.Command {
return cmd return cmd
} }
func (v *versionCmd) run() error { func (v *versionCmd) run(out io.Writer) error {
if v.template != "" { if v.template != "" {
tt, err := template.New("_").Parse(v.template) tt, err := template.New("_").Parse(v.template)
if err != nil { if err != nil {
return err 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 return nil
} }

Loading…
Cancel
Save