diff --git a/cmd/helm/init.go b/cmd/helm/init.go index c7bfba482..2a2a3c331 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 81dd22743..0e65d72d8 100644 --- a/cmd/helm/installer/options.go +++ b/cmd/helm/installer/options.go @@ -77,7 +77,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 @@ -112,3 +112,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) +}