Skip to content

Commit

Permalink
kops: Don't try to split --set flags on commas
Browse files Browse the repository at this point in the history
Passing quotes in very difficult with the --set flag, because the
pflag library tries to parse it using strict CSV semantics.  We switch
to using the StringArrayVar, which does not attempt splitting.

This is a breaking change; compound flags must now be written as two flags, but I think that is clearer.

Example: `--set=a,b` must now be `--set=a --set=b`
  • Loading branch information
justinsb committed Nov 23, 2023
1 parent 7c17b16 commit 3239b22
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/kops/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command {
return []string{"json", "yaml"}, cobra.ShellCompDirectiveNoFileComp
})

cmd.Flags().StringSliceVar(&options.Sets, "override", options.Sets, "Directly set values in the spec")
cmd.Flags().StringArrayVar(&options.Sets, "override", options.Sets, "Directly set values in the spec")
cmd.Flags().MarkDeprecated("override", "use --set instead")
cmd.Flags().StringSliceVar(&options.Sets, "set", options.Sets, "Directly set values in the spec")
cmd.Flags().StringArrayVar(&options.Sets, "set", options.Sets, "Directly set values in the spec")
cmd.RegisterFlagCompletionFunc("set", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveNoFileComp
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/kops/edit_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewCmdEditCluster(f *util.Factory, out io.Writer) *cobra.Command {
},
}

cmd.Flags().StringSliceVar(&options.Sets, "set", options.Sets, "Directly set values in the spec")
cmd.Flags().StringArrayVar(&options.Sets, "set", options.Sets, "Directly set values in the spec")
cmd.RegisterFlagCompletionFunc("set", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveNoFileComp
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/kops/edit_instancegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func NewCmdEditInstanceGroup(f *util.Factory, out io.Writer) *cobra.Command {
},
}

cmd.Flags().StringSliceVar(&options.Sets, "set", options.Sets, "Directly set values in the spec")
cmd.Flags().StringArrayVar(&options.Sets, "set", options.Sets, "Directly set values in the spec")
cmd.RegisterFlagCompletionFunc("set", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveNoFileComp
})
Expand Down

0 comments on commit 3239b22

Please sign in to comment.