From 2889f97b5cdd4b02019881c130ba63682ec1410d Mon Sep 17 00:00:00 2001 From: Justin Scott Date: Wed, 5 Jul 2017 13:24:09 -0700 Subject: [PATCH] Rebase from master --- cmd/helm/init.go | 5 ++--- cmd/helm/installer/options.go | 27 ++++++++++++++++++++++++++- docs/helm/helm_init.md | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/cmd/helm/init.go b/cmd/helm/init.go index d765d07f3..d6270402e 100644 --- a/cmd/helm/init.go +++ b/cmd/helm/init.go @@ -21,7 +21,6 @@ import ( "fmt" "io" "os" - "strings" "github.com/spf13/cobra" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -123,7 +122,7 @@ func newInitCmd(out io.Writer) *cobra.Command { f.StringVar(&i.serviceAccount, "service-account", "", "name of service account") f.StringVar(&i.opts.NodeSelectors, "node-selectors", "", "labels to specify the node on which Tiller is installed (app=tiller,helm=rocks)") - f.StringVarP(&i.opts.Output, "output", "o", "", "skip installation and output Tiller's manifest in specified format (json or yaml)") + f.VarP(&i.opts.Output, "output", "o", "skip installation and output Tiller's manifest in specified format (json or yaml)") f.StringArrayVar(&i.opts.Values, "set", []string{}, "set values for the Tiller Deployment manifest (can specify multiple or separate values with commas: key1=val1,key2=val2)") return cmd @@ -195,7 +194,7 @@ func (i *initCmd) run() error { if body, err = installer.DeploymentManifest(&i.opts); err != nil { return err } - switch strings.ToLower(i.opts.Output) { + switch i.opts.Output.String() { case "json": jsonb, err := yaml.ToJSON([]byte(body)) if err != nil { diff --git a/cmd/helm/installer/options.go b/cmd/helm/installer/options.go index 32cdae391..29c39f4f3 100644 --- a/cmd/helm/installer/options.go +++ b/cmd/helm/installer/options.go @@ -78,7 +78,7 @@ type Options struct { NodeSelectors string // Output dumps the Tiller manifest in the specified format (e.g. JSON) but skips Helm/Tiller installation - Output string + Output outputFormat // Set merges additional values into the Tiller Deployment manifest Values []string @@ -113,3 +113,28 @@ func (opts *Options) valuesMap(m map[string]interface{}) (map[string]interface{} } return m, nil } + +type outputFormat string + +func (f *outputFormat) String() string { + return string(*f) +} + +func (f *outputFormat) Type() string { + return "outputFormat" +} + +const ( + fmtJSON outputFormat = "json" + fmtYAML = "yaml" +) + +func (f *outputFormat) Set(s string) error { + for _, of := range []outputFormat{fmtJSON, fmtYAML} { + if s == string(of) { + *f = of + return nil + } + } + return fmt.Errorf("unknown output format %q", s) +} diff --git a/docs/helm/helm_init.md b/docs/helm/helm_init.md index d80bb440f..de4ee75fe 100644 --- a/docs/helm/helm_init.md +++ b/docs/helm/helm_init.md @@ -39,7 +39,7 @@ helm init --local-repo-url string URL for local repository (default "http://127.0.0.1:8879/charts") --net-host install Tiller with net=host --node-selectors string labels to specify the node on which Tiller is installed (app=tiller,helm=rocks) - -o, --output string skip installation and output Tiller's manifest in specified format (json or yaml) + -o, --output outputFormat skip installation and output Tiller's manifest in specified format (json or yaml) --service-account string name of service account --set stringArray set values for the Tiller Deployment manifest (can specify multiple or separate values with commas: key1=val1,key2=val2) --skip-refresh do not refresh (download) the local repository cache