mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
fix issue #27454: replace flag type StringSlice with StringArray in configMap
This commit is contained in:
parent
6140ab26d0
commit
f4a95ff3d9
@ -70,7 +70,7 @@ func NewCmdCreateConfigMap(f *cmdutil.Factory, cmdOut io.Writer) *cobra.Command
|
|||||||
cmdutil.AddPrinterFlags(cmd)
|
cmdutil.AddPrinterFlags(cmd)
|
||||||
cmdutil.AddGeneratorFlags(cmd, cmdutil.ConfigMapV1GeneratorName)
|
cmdutil.AddGeneratorFlags(cmd, cmdutil.ConfigMapV1GeneratorName)
|
||||||
cmd.Flags().StringSlice("from-file", []string{}, "Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid configmap key.")
|
cmd.Flags().StringSlice("from-file", []string{}, "Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid configmap key.")
|
||||||
cmd.Flags().StringSlice("from-literal", []string{}, "Specify a key and literal value to insert in configmap (i.e. mykey=somevalue)")
|
cmd.Flags().StringArray("from-literal", []string{}, "Specify a key and literal value to insert in configmap (i.e. mykey=somevalue)")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ func CreateConfigMap(f *cmdutil.Factory, cmdOut io.Writer, cmd *cobra.Command, a
|
|||||||
generator = &kubectl.ConfigMapGeneratorV1{
|
generator = &kubectl.ConfigMapGeneratorV1{
|
||||||
Name: name,
|
Name: name,
|
||||||
FileSources: cmdutil.GetFlagStringSlice(cmd, "from-file"),
|
FileSources: cmdutil.GetFlagStringSlice(cmd, "from-file"),
|
||||||
LiteralSources: cmdutil.GetFlagStringSlice(cmd, "from-literal"),
|
LiteralSources: cmdutil.GetFlagStringArray(cmd, "from-literal"),
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
|
return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not supported.", generatorName))
|
||||||
|
@ -296,7 +296,7 @@ func GetFlagString(cmd *cobra.Command, flag string) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFlagStringList can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...)
|
// GetFlagStringSlice can be used to accept multiple argument with flag repetition (e.g. -f arg1,arg2 -f arg3 ...)
|
||||||
func GetFlagStringSlice(cmd *cobra.Command, flag string) []string {
|
func GetFlagStringSlice(cmd *cobra.Command, flag string) []string {
|
||||||
s, err := cmd.Flags().GetStringSlice(flag)
|
s, err := cmd.Flags().GetStringSlice(flag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -305,6 +305,15 @@ func GetFlagStringSlice(cmd *cobra.Command, flag string) []string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFlagStringArray can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...)
|
||||||
|
func GetFlagStringArray(cmd *cobra.Command, flag string) []string {
|
||||||
|
s, err := cmd.Flags().GetStringArray(flag)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
// GetWideFlag is used to determine if "-o wide" is used
|
// GetWideFlag is used to determine if "-o wide" is used
|
||||||
func GetWideFlag(cmd *cobra.Command) bool {
|
func GetWideFlag(cmd *cobra.Command) bool {
|
||||||
f := cmd.Flags().Lookup("output")
|
f := cmd.Flags().Lookup("output")
|
||||||
|
Loading…
Reference in New Issue
Block a user