diff --git a/cmd/helm/flags.go b/cmd/helm/flags.go index a3cf59bae..467abbd6e 100644 --- a/cmd/helm/flags.go +++ b/cmd/helm/flags.go @@ -52,14 +52,8 @@ func addChartPathOptionsFlags(f *pflag.FlagSet, c *action.ChartPathOptions) { // bindOutputFlag will add the output flag to the given command and bind the // value to the given format pointer func bindOutputFlag(cmd *cobra.Command, varRef *output.Format) { - var formats strings.Builder - for index, format := range output.Formats() { - if index != 0 { - formats.WriteString(", ") - } - formats.WriteString(format.String()) - } - cmd.Flags().VarP(newOutputValue(output.Table, varRef), outputFlag, "o", fmt.Sprintf("prints the output in the specified format. Allowed values: %s", formats.String())) + cmd.Flags().VarP(newOutputValue(output.Table, varRef), outputFlag, "o", + fmt.Sprintf("prints the output in the specified format. Allowed values: %s", strings.Join(output.Formats(), ", "))) // Setup shell completion for the flag cmd.MarkFlagCustom(outputFlag, "__helm_output_options") } diff --git a/cmd/helm/root.go b/cmd/helm/root.go index 0fed728e8..644a9d7db 100644 --- a/cmd/helm/root.go +++ b/cmd/helm/root.go @@ -206,19 +206,13 @@ By default, the default directories depend on the Operating System. The defaults ` func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string) *cobra.Command { - var formats strings.Builder - for _, format := range output.Formats() { - formats.WriteString(format.String()) - formats.WriteByte(' ') - } - cmd := &cobra.Command{ Use: "helm", Short: "The Helm package manager for Kubernetes.", Long: globalUsage, SilenceUsage: true, Args: require.NoArgs, - BashCompletionFunction: fmt.Sprintf(bashCompletionFunc, formats.String()), + BashCompletionFunction: fmt.Sprintf(bashCompletionFunc, strings.Join(output.Formats(), " ")), } flags := cmd.PersistentFlags() diff --git a/pkg/cli/output/output.go b/pkg/cli/output/output.go index 3e6a52a2c..e4eb046fc 100644 --- a/pkg/cli/output/output.go +++ b/pkg/cli/output/output.go @@ -35,15 +35,15 @@ const ( YAML Format = "yaml" ) -// Formats returns a list of supported formats -func Formats() []Format { - return []Format{Table, JSON, YAML} +// Formats returns a list of the string representation of the supported formats +func Formats() []string { + return []string{Table.String(), JSON.String(), YAML.String()} } // ErrInvalidFormatType is returned when an unsupported format type is used var ErrInvalidFormatType = fmt.Errorf("invalid format type") -// String returns the string reprsentation of the Format +// String returns the string representation of the Format func (o Format) String() string { return string(o) }