From 3f24a29cca6666dd63d9b36befffef5bc77ee238 Mon Sep 17 00:00:00 2001 From: John Gardiner Myers Date: Thu, 25 Jun 2020 22:32:07 -0700 Subject: [PATCH] Change toolbox template flag for consistency --- cmd/kops/BUILD.bazel | 1 + cmd/kops/toolbox_dump.go | 2 -- cmd/kops/toolbox_template.go | 10 +++++++++- docs/cli/kops_toolbox_template.md | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/kops/BUILD.bazel b/cmd/kops/BUILD.bazel index 14f25120b0..263fb7c730 100644 --- a/cmd/kops/BUILD.bazel +++ b/cmd/kops/BUILD.bazel @@ -102,6 +102,7 @@ go_library( "//vendor/github.com/blang/semver/v4:go_default_library", "//vendor/github.com/spf13/cobra:go_default_library", "//vendor/github.com/spf13/cobra/doc:go_default_library", + "//vendor/github.com/spf13/pflag:go_default_library", "//vendor/github.com/spf13/viper:go_default_library", "//vendor/golang.org/x/crypto/ssh:go_default_library", "//vendor/helm.sh/helm/v3/pkg/cli/values:go_default_library", diff --git a/cmd/kops/toolbox_dump.go b/cmd/kops/toolbox_dump.go index 42ceba079d..6c85053cfa 100644 --- a/cmd/kops/toolbox_dump.go +++ b/cmd/kops/toolbox_dump.go @@ -96,8 +96,6 @@ func NewCmdToolboxDump(f *util.Factory, out io.Writer) *cobra.Command { }, } - // TODO: Push up to top-level command? - // Yes please! (@kris-nova) cmd.Flags().StringVarP(&options.Output, "output", "o", options.Output, "output format. One of: yaml, json") cmd.Flags().StringVar(&options.Dir, "dir", options.Dir, "target directory; if specified will collect logs and other information.") diff --git a/cmd/kops/toolbox_template.go b/cmd/kops/toolbox_template.go index 582c47fa52..1329437a96 100644 --- a/cmd/kops/toolbox_template.go +++ b/cmd/kops/toolbox_template.go @@ -26,6 +26,7 @@ import ( "strings" "github.com/spf13/cobra" + "github.com/spf13/pflag" "helm.sh/helm/v3/pkg/strvals" "k8s.io/kubectl/pkg/util/i18n" "k8s.io/kubectl/pkg/util/templates" @@ -101,10 +102,17 @@ func NewCmdToolboxTemplate(f *util.Factory, out io.Writer) *cobra.Command { cmd.Flags().StringSliceVar(&options.templatePath, "template", options.templatePath, "Path to template file or directory of templates to render") cmd.Flags().StringSliceVar(&options.snippetsPath, "snippets", options.snippetsPath, "Path to directory containing snippets used for templating") cmd.Flags().StringVar(&options.channel, "channel", options.channel, "Channel to use for the channel* functions") - cmd.Flags().StringVar(&options.outputPath, "output", options.outputPath, "Path to output file, otherwise defaults to stdout") + cmd.Flags().StringVar(&options.outputPath, "out", options.outputPath, "Path to output file, otherwise defaults to stdout") cmd.Flags().StringVar(&options.configValue, "config-value", "", "Show the value of a specific configuration value") cmd.Flags().BoolVar(&options.failOnMissing, "fail-on-missing", true, "Fail on referencing unset variables in templates") cmd.Flags().BoolVar(&options.formatYAML, "format-yaml", false, "Attempt to format the generated yaml content before output") + cmd.Flags().SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName { + // Old flag name for outputPath + if name == "output" { + name = "out" + } + return pflag.NormalizedName(name) + }) return cmd } diff --git a/docs/cli/kops_toolbox_template.md b/docs/cli/kops_toolbox_template.md index d523c3a898..9a7b02adde 100644 --- a/docs/cli/kops_toolbox_template.md +++ b/docs/cli/kops_toolbox_template.md @@ -34,7 +34,7 @@ kops toolbox template [flags] --fail-on-missing Fail on referencing unset variables in templates (default true) --format-yaml Attempt to format the generated yaml content before output -h, --help help for template - --output string Path to output file, otherwise defaults to stdout + --out string Path to output file, otherwise defaults to stdout --set stringArray Set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) --set-string stringArray Set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) --snippets strings Path to directory containing snippets used for templating