Skip to content

Commit 5f0e901

Browse files
committed
cli: remove support for comma-separated template values
1 parent 26734b2 commit 5f0e901

File tree

12 files changed

+54
-18
lines changed

12 files changed

+54
-18
lines changed

docs/man/man1/oc-new-app.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ If you provide source code, a new build will be automatically triggered. You can
108108

109109
.PP
110110
\fB\-p\fP, \fB\-\-param\fP=[]
111-
Specify a list of key value pairs (e.g., \-p FOO=BAR,BAR=FOO) to set/override parameter values in the template.
111+
Specify a key\-value pair (e.g., \-p FOO=BAR) to set/override parameter value in the template.
112112

113113
.PP
114114
\fB\-S\fP, \fB\-\-search\fP=false

docs/man/man1/oc-process.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The output of the process command is always a list of one or more resources. You
5454

5555
.PP
5656
\fB\-v\fP, \fB\-\-value\fP=[]
57-
Specify a list of key\-value pairs (eg. \-v FOO=BAR,BAR=FOO) to set/override parameter values
57+
Specify a key\-value pair (eg. \-v FOO=BAR) to set/override parameter value in the template.
5858

5959

6060
.SH OPTIONS INHERITED FROM PARENT COMMANDS

docs/man/man1/openshift-cli-new-app.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ If you provide source code, a new build will be automatically triggered. You can
108108

109109
.PP
110110
\fB\-p\fP, \fB\-\-param\fP=[]
111-
Specify a list of key value pairs (e.g., \-p FOO=BAR,BAR=FOO) to set/override parameter values in the template.
111+
Specify a key\-value pair (e.g., \-p FOO=BAR) to set/override parameter value in the template.
112112

113113
.PP
114114
\fB\-S\fP, \fB\-\-search\fP=false

docs/man/man1/openshift-cli-process.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The output of the process command is always a list of one or more resources. You
5454

5555
.PP
5656
\fB\-v\fP, \fB\-\-value\fP=[]
57-
Specify a list of key\-value pairs (eg. \-v FOO=BAR,BAR=FOO) to set/override parameter values
57+
Specify a key\-value pair (eg. \-v FOO=BAR) to set/override parameter value in the template.
5858

5959

6060
.SH OPTIONS INHERITED FROM PARENT COMMANDS

pkg/cmd/cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
156156
cmd.NewCmdReplace(fullName, f, out),
157157
cmd.NewCmdApply(fullName, f, out),
158158
cmd.NewCmdPatch(fullName, f, out),
159-
cmd.NewCmdProcess(fullName, f, out),
159+
cmd.NewCmdProcess(fullName, f, out, errout),
160160
cmd.NewCmdExport(fullName, f, in, out),
161161
cmd.NewCmdExtract(fullName, f, in, out, errout),
162162
observe.NewCmdObserve(fullName, f, out, errout),

pkg/cmd/cli/cmd/helper.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package cmd
22

3-
import "strings"
3+
import (
4+
"strings"
5+
6+
"github.com/golang/glog"
7+
"github.com/spf13/cobra"
8+
)
49

510
// parseNamespaceResourceName parses the value and returns namespace, resource and the
611
// value (resource name) itself. The valid syntax is:
@@ -20,3 +25,11 @@ func parseNamespaceResourceName(v, defaultNamespace string) (ns, resource, name
2025
}
2126
return "", "", "", false
2227
}
28+
29+
func getFlagStringArray(cmd *cobra.Command, flag string) []string {
30+
s, err := cmd.Flags().GetStringArray(flag)
31+
if err != nil {
32+
glog.Fatalf("error accessing flag %s for command %s: %v", flag, cmd.Name(), err)
33+
}
34+
return s
35+
}

pkg/cmd/cli/cmd/newapp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, erro
166166
cmd.Flags().StringSliceVar(&config.Templates, "template", config.Templates, "Name of a stored template to use in the app.")
167167
cmd.Flags().StringSliceVarP(&config.TemplateFiles, "file", "f", config.TemplateFiles, "Path to a template file to use for the app.")
168168
cmd.MarkFlagFilename("file", "yaml", "yml", "json")
169-
cmd.Flags().StringSliceVarP(&config.TemplateParameters, "param", "p", config.TemplateParameters, "Specify a list of key value pairs (e.g., -p FOO=BAR,BAR=FOO) to set/override parameter values in the template.")
169+
cmd.Flags().StringArrayVarP(&config.TemplateParameters, "param", "p", config.TemplateParameters, "Specify a key-value pair (e.g., -p FOO=BAR) to set/override parameter value in the template.")
170170
cmd.Flags().StringSliceVar(&config.Groups, "group", config.Groups, "Indicate components that should be grouped together as <comp1>+<comp2>.")
171171
cmd.Flags().StringSliceVarP(&config.Environment, "env", "e", config.Environment, "Specify key-value pairs of environment variables to set into each container. This doesn't apply to objects created from a template, use parameters instead.")
172172
cmd.Flags().StringVar(&config.Name, "name", "", "Set name to use for generated application artifacts")

pkg/cmd/cli/cmd/process.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ var (
5757
)
5858

5959
// NewCmdProcess implements the OpenShift cli process command
60-
func NewCmdProcess(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
60+
func NewCmdProcess(fullName string, f *clientcmd.Factory, out, errout io.Writer) *cobra.Command {
6161
cmd := &cobra.Command{
6262
Use: "process (TEMPLATE | -f FILENAME) [-v=KEY=VALUE]",
6363
Short: "Process a template into list of resources",
6464
Long: processLong,
6565
Example: fmt.Sprintf(processExample, fullName),
6666
Run: func(cmd *cobra.Command, args []string) {
67-
err := RunProcess(f, out, cmd, args)
67+
err := RunProcess(f, out, errout, cmd, args)
6868
kcmdutil.CheckErr(err)
6969
},
7070
}
7171
cmd.Flags().StringP("filename", "f", "", "Filename or URL to file to read a template")
7272
cmd.MarkFlagFilename("filename", "yaml", "yml", "json")
73-
cmd.Flags().StringSliceP("value", "v", nil, "Specify a list of key-value pairs (eg. -v FOO=BAR,BAR=FOO) to set/override parameter values")
73+
cmd.Flags().StringArrayP("value", "v", nil, "Specify a key-value pair (eg. -v FOO=BAR) to set/override parameter value in the template.")
7474
cmd.Flags().BoolP("parameters", "", false, "Do not process but only print available parameters")
7575
cmd.Flags().StringP("labels", "l", "", "Label to set in all resources for this template")
7676

@@ -83,7 +83,7 @@ func NewCmdProcess(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.
8383
}
8484

8585
// RunProcess contains all the necessary functionality for the OpenShift cli process command
86-
func RunProcess(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
86+
func RunProcess(f *clientcmd.Factory, out, errout io.Writer, cmd *cobra.Command, args []string) error {
8787
templateName, valueArgs := "", []string{}
8888
for _, s := range args {
8989
isValue := strings.Contains(s, "=")
@@ -102,7 +102,13 @@ func RunProcess(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []
102102

103103
var flagValues []string
104104
if cmd.Flag("value").Changed {
105-
flagValues = kcmdutil.GetFlagStringSlice(cmd, "value")
105+
flagValues = getFlagStringArray(cmd, "value")
106+
}
107+
108+
for _, value := range flagValues {
109+
if strings.ContainsRune(value, ',') {
110+
fmt.Fprintf(errout, "warning: --value no longer accepts comma-separated list of values. %q will be treated as a single key-value pair.\n", value)
111+
}
106112
}
107113

108114
for _, value := range flagValues {
@@ -238,7 +244,7 @@ func RunProcess(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []
238244
// Override the values for the current template parameters
239245
// when user specify the --value
240246
if cmd.Flag("value").Changed {
241-
values := kcmdutil.GetFlagStringSlice(cmd, "value")
247+
values := getFlagStringArray(cmd, "value")
242248
if errs := injectUserVars(values, obj); errs != nil {
243249
return kerrors.NewAggregate(errs)
244250
}

pkg/generate/app/cmd/newapp.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,12 @@ func (c *AppConfig) RunQuery() (*QueryResult, error) {
563563
func (c *AppConfig) validate() (cmdutil.Environment, cmdutil.Environment, error) {
564564
var errs []error
565565

566+
for _, value := range c.TemplateParameters {
567+
if strings.ContainsRune(value, ',') {
568+
fmt.Fprintf(c.ErrOut, "warning: --param no longer accepts comma-separated list of values. %q will be treated as a single key-value pair.\n", value)
569+
}
570+
}
571+
566572
env, duplicateEnv, envErrs := cmdutil.ParseEnvironmentArguments(c.Environment)
567573
for _, s := range duplicateEnv {
568574
fmt.Fprintf(c.ErrOut, "warning: The environment variable %q was overwritten", s)

test/cmd/newapp.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'AD
6363
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample -o yaml' 'ADMIN_PASSWORD'
6464
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample --param MYSQL_PASSWORD=hello -o yaml' 'hello'
6565

66+
# check that values are not split on commas
67+
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample --param MYSQL_PASSWORD=hello,MYSQL_USER=fail -o yaml' 'value: hello,MYSQL_USER=fail'
68+
# check that warning is printed when --param PARAM1=VAL1,PARAM2=VAL2 is used
69+
os::cmd::expect_success_and_text 'oc new-app ruby-helloworld-sample --param MYSQL_PASSWORD=hello,MYSQL_USER=fail -o yaml' 'no longer accepts comma-separated list'
70+
6671
# verify we can create from a template when some objects in the template declare an app label
6772
# the app label will not be applied to any objects in the template.
6873
os::cmd::expect_success_and_not_text 'oc new-app -f test/testdata/template-with-app-label.json -o yaml' 'app: ruby-helloworld-sample'

test/cmd/process.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,12 @@ os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=req
5555
# failure on labels fails the entire call
5656
os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=required_param=someval --labels======" 'error parsing labels'
5757

58+
# values are not split on commas, required parameter is not recognized
59+
os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=optional_param=a,required_param=b" 'parameter required_param is required and must be specified'
60+
# warning is printed when --value has comma in it
61+
os::cmd::expect_success_and_text "oc process -f '${required_params}' --value=required_param=a,b,c,d" 'no longer accepts comma-separated list'
62+
# warning is not printed for template values passed as positional arguments
63+
os::cmd::expect_success_and_not_text "oc process -f '${required_params}' required_param=a,b,c,d" 'no longer accepts comma-separated list'
64+
5865
echo "process: ok"
5966
os::test::junit::declare_suite_end

test/cmd/templates.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ echo "template+config: ok"
3737
os::test::junit::declare_suite_end
3838

3939
os::test::junit::declare_suite_start "cmd/templates/parameters"
40-
# Joined parameter values are honored
41-
os::cmd::expect_success_and_text 'oc process -f test/templates/testdata/guestbook.json -v ADMIN_USERNAME=myuser,ADMIN_PASSWORD=mypassword' '"myuser"'
42-
os::cmd::expect_success_and_text 'oc process -f test/templates/testdata/guestbook.json -v ADMIN_USERNAME=myuser,ADMIN_PASSWORD=mypassword' '"mypassword"'
4340
# Individually specified parameter values are honored
4441
os::cmd::expect_success_and_text 'oc process -f test/templates/testdata/guestbook.json -v ADMIN_USERNAME=myuser -v ADMIN_PASSWORD=mypassword' '"myuser"'
4542
os::cmd::expect_success_and_text 'oc process -f test/templates/testdata/guestbook.json -v ADMIN_USERNAME=myuser -v ADMIN_PASSWORD=mypassword' '"mypassword"'
@@ -48,8 +45,10 @@ os::cmd::expect_success_and_text 'oc process ADMIN_USERNAME=myuser ADMIN_PASSWOR
4845
os::cmd::expect_success_and_text 'oc process -f test/templates/testdata/guestbook.json ADMIN_USERNAME=myuser ADMIN_PASSWORD=mypassword' '"mypassword"'
4946
# Argument values with commas are honored
5047
os::cmd::expect_success 'oc create -f examples/sample-app/application-template-stibuild.json'
51-
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample MYSQL_USER=myself MYSQL_PASSWORD=my,1%pass' '"myself"'
52-
os::cmd::expect_success_and_text 'oc process MYSQL_USER=myself MYSQL_PASSWORD=my,1%pass ruby-helloworld-sample' '"my,1%pass"'
48+
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample MYSQL_USER=myself MYSQL_PASSWORD=my,1%pass' '"myself"'
49+
os::cmd::expect_success_and_text 'oc process MYSQL_USER=myself MYSQL_PASSWORD=my,1%pass ruby-helloworld-sample' '"my,1%pass"'
50+
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -v MYSQL_USER=myself -v MYSQL_PASSWORD=my,1%pass' '"myself"'
51+
os::cmd::expect_success_and_text 'oc process -v MYSQL_USER=myself -v MYSQL_PASSWORD=my,1%pass ruby-helloworld-sample' '"my,1%pass"'
5352
os::cmd::expect_success 'oc delete template ruby-helloworld-sample'
5453
echo "template+parameters: ok"
5554
os::test::junit::declare_suite_end

0 commit comments

Comments
 (0)