Skip to content

Commit d670e2d

Browse files
committed
new-app/new-build/process: read envvars/params from file
1 parent 64ff6be commit d670e2d

28 files changed

+308
-116
lines changed

contrib/completions/bash/oc

+16
Original file line numberDiff line numberDiff line change
@@ -10434,6 +10434,10 @@ _oc_new-app()
1043410434
flags+=("--env=")
1043510435
two_word_flags+=("-e")
1043610436
local_nonpersistent_flags+=("--env=")
10437+
flags+=("--env-file=")
10438+
flags_with_completion+=("--env-file")
10439+
flags_completion+=("_filedir")
10440+
local_nonpersistent_flags+=("--env-file=")
1043710441
flags+=("--file=")
1043810442
flags_with_completion+=("--file")
1043910443
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
@@ -10468,6 +10472,10 @@ _oc_new-app()
1046810472
flags+=("--param=")
1046910473
two_word_flags+=("-p")
1047010474
local_nonpersistent_flags+=("--param=")
10475+
flags+=("--param-file=")
10476+
flags_with_completion+=("--param-file")
10477+
flags_completion+=("_filedir")
10478+
local_nonpersistent_flags+=("--param-file=")
1047110479
flags+=("--search")
1047210480
flags+=("-S")
1047310481
local_nonpersistent_flags+=("--search")
@@ -10540,6 +10548,10 @@ _oc_new-build()
1054010548
flags+=("--env=")
1054110549
two_word_flags+=("-e")
1054210550
local_nonpersistent_flags+=("--env=")
10551+
flags+=("--env-file=")
10552+
flags_with_completion+=("--env-file")
10553+
flags_completion+=("_filedir")
10554+
local_nonpersistent_flags+=("--env-file=")
1054310555
flags+=("--image-stream=")
1054410556
two_word_flags+=("-i")
1054510557
local_nonpersistent_flags+=("--image-stream=")
@@ -11512,6 +11524,10 @@ _oc_process()
1151211524
flags+=("--param=")
1151311525
two_word_flags+=("-p")
1151411526
local_nonpersistent_flags+=("--param=")
11527+
flags+=("--param-file=")
11528+
flags_with_completion+=("--param-file")
11529+
flags_completion+=("_filedir")
11530+
local_nonpersistent_flags+=("--param-file=")
1151511531
flags+=("--parameters")
1151611532
local_nonpersistent_flags+=("--parameters")
1151711533
flags+=("--raw")

contrib/completions/bash/openshift

+16
Original file line numberDiff line numberDiff line change
@@ -15080,6 +15080,10 @@ _openshift_cli_new-app()
1508015080
flags+=("--env=")
1508115081
two_word_flags+=("-e")
1508215082
local_nonpersistent_flags+=("--env=")
15083+
flags+=("--env-file=")
15084+
flags_with_completion+=("--env-file")
15085+
flags_completion+=("_filedir")
15086+
local_nonpersistent_flags+=("--env-file=")
1508315087
flags+=("--file=")
1508415088
flags_with_completion+=("--file")
1508515089
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
@@ -15114,6 +15118,10 @@ _openshift_cli_new-app()
1511415118
flags+=("--param=")
1511515119
two_word_flags+=("-p")
1511615120
local_nonpersistent_flags+=("--param=")
15121+
flags+=("--param-file=")
15122+
flags_with_completion+=("--param-file")
15123+
flags_completion+=("_filedir")
15124+
local_nonpersistent_flags+=("--param-file=")
1511715125
flags+=("--search")
1511815126
flags+=("-S")
1511915127
local_nonpersistent_flags+=("--search")
@@ -15187,6 +15195,10 @@ _openshift_cli_new-build()
1518715195
flags+=("--env=")
1518815196
two_word_flags+=("-e")
1518915197
local_nonpersistent_flags+=("--env=")
15198+
flags+=("--env-file=")
15199+
flags_with_completion+=("--env-file")
15200+
flags_completion+=("_filedir")
15201+
local_nonpersistent_flags+=("--env-file=")
1519015202
flags+=("--image-stream=")
1519115203
two_word_flags+=("-i")
1519215204
local_nonpersistent_flags+=("--image-stream=")
@@ -16174,6 +16186,10 @@ _openshift_cli_process()
1617416186
flags+=("--param=")
1617516187
two_word_flags+=("-p")
1617616188
local_nonpersistent_flags+=("--param=")
16189+
flags+=("--param-file=")
16190+
flags_with_completion+=("--param-file")
16191+
flags_completion+=("_filedir")
16192+
local_nonpersistent_flags+=("--param-file=")
1617716193
flags+=("--parameters")
1617816194
local_nonpersistent_flags+=("--parameters")
1617916195
flags+=("--raw")

contrib/completions/zsh/oc

+16
Original file line numberDiff line numberDiff line change
@@ -10595,6 +10595,10 @@ _oc_new-app()
1059510595
flags+=("--env=")
1059610596
two_word_flags+=("-e")
1059710597
local_nonpersistent_flags+=("--env=")
10598+
flags+=("--env-file=")
10599+
flags_with_completion+=("--env-file")
10600+
flags_completion+=("_filedir")
10601+
local_nonpersistent_flags+=("--env-file=")
1059810602
flags+=("--file=")
1059910603
flags_with_completion+=("--file")
1060010604
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
@@ -10629,6 +10633,10 @@ _oc_new-app()
1062910633
flags+=("--param=")
1063010634
two_word_flags+=("-p")
1063110635
local_nonpersistent_flags+=("--param=")
10636+
flags+=("--param-file=")
10637+
flags_with_completion+=("--param-file")
10638+
flags_completion+=("_filedir")
10639+
local_nonpersistent_flags+=("--param-file=")
1063210640
flags+=("--search")
1063310641
flags+=("-S")
1063410642
local_nonpersistent_flags+=("--search")
@@ -10701,6 +10709,10 @@ _oc_new-build()
1070110709
flags+=("--env=")
1070210710
two_word_flags+=("-e")
1070310711
local_nonpersistent_flags+=("--env=")
10712+
flags+=("--env-file=")
10713+
flags_with_completion+=("--env-file")
10714+
flags_completion+=("_filedir")
10715+
local_nonpersistent_flags+=("--env-file=")
1070410716
flags+=("--image-stream=")
1070510717
two_word_flags+=("-i")
1070610718
local_nonpersistent_flags+=("--image-stream=")
@@ -11673,6 +11685,10 @@ _oc_process()
1167311685
flags+=("--param=")
1167411686
two_word_flags+=("-p")
1167511687
local_nonpersistent_flags+=("--param=")
11688+
flags+=("--param-file=")
11689+
flags_with_completion+=("--param-file")
11690+
flags_completion+=("_filedir")
11691+
local_nonpersistent_flags+=("--param-file=")
1167611692
flags+=("--parameters")
1167711693
local_nonpersistent_flags+=("--parameters")
1167811694
flags+=("--raw")

contrib/completions/zsh/openshift

+16
Original file line numberDiff line numberDiff line change
@@ -15241,6 +15241,10 @@ _openshift_cli_new-app()
1524115241
flags+=("--env=")
1524215242
two_word_flags+=("-e")
1524315243
local_nonpersistent_flags+=("--env=")
15244+
flags+=("--env-file=")
15245+
flags_with_completion+=("--env-file")
15246+
flags_completion+=("_filedir")
15247+
local_nonpersistent_flags+=("--env-file=")
1524415248
flags+=("--file=")
1524515249
flags_with_completion+=("--file")
1524615250
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
@@ -15275,6 +15279,10 @@ _openshift_cli_new-app()
1527515279
flags+=("--param=")
1527615280
two_word_flags+=("-p")
1527715281
local_nonpersistent_flags+=("--param=")
15282+
flags+=("--param-file=")
15283+
flags_with_completion+=("--param-file")
15284+
flags_completion+=("_filedir")
15285+
local_nonpersistent_flags+=("--param-file=")
1527815286
flags+=("--search")
1527915287
flags+=("-S")
1528015288
local_nonpersistent_flags+=("--search")
@@ -15348,6 +15356,10 @@ _openshift_cli_new-build()
1534815356
flags+=("--env=")
1534915357
two_word_flags+=("-e")
1535015358
local_nonpersistent_flags+=("--env=")
15359+
flags+=("--env-file=")
15360+
flags_with_completion+=("--env-file")
15361+
flags_completion+=("_filedir")
15362+
local_nonpersistent_flags+=("--env-file=")
1535115363
flags+=("--image-stream=")
1535215364
two_word_flags+=("-i")
1535315365
local_nonpersistent_flags+=("--image-stream=")
@@ -16335,6 +16347,10 @@ _openshift_cli_process()
1633516347
flags+=("--param=")
1633616348
two_word_flags+=("-p")
1633716349
local_nonpersistent_flags+=("--param=")
16350+
flags+=("--param-file=")
16351+
flags_with_completion+=("--param-file")
16352+
flags_completion+=("_filedir")
16353+
local_nonpersistent_flags+=("--param-file=")
1633816354
flags+=("--parameters")
1633916355
local_nonpersistent_flags+=("--parameters")
1634016356
flags+=("--raw")

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

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ If you provide source code, a new build will be automatically triggered. You can
5858
\fB\-e\fP, \fB\-\-env\fP=[]
5959
Specify a key\-value pair for an environment variable to set into each container.
6060

61+
.PP
62+
\fB\-\-env\-file\fP=""
63+
File containing key\-value pairs of environment variables to set into each container.
64+
6165
.PP
6266
\fB\-f\fP, \fB\-\-file\fP=[]
6367
Path to a template file to use for the app.
@@ -110,6 +114,10 @@ If you provide source code, a new build will be automatically triggered. You can
110114
\fB\-p\fP, \fB\-\-param\fP=[]
111115
Specify a key\-value pair (e.g., \-p FOO=BAR) to set/override a parameter value in the template.
112116

117+
.PP
118+
\fB\-\-param\-file\fP=""
119+
File containing environment parameter values to set/override in the template.
120+
113121
.PP
114122
\fB\-S\fP, \fB\-\-search\fP=false
115123
Search all templates, image streams, and Docker images that match the arguments provided.

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

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ Once the build configuration is created a new build will be automatically trigge
6666
\fB\-e\fP, \fB\-\-env\fP=[]
6767
Specify a key\-value pair for an environment variable to set into resulting image.
6868

69+
.PP
70+
\fB\-\-env\-file\fP=""
71+
File containing key\-value pairs of environment variables to set into each container.
72+
6973
.PP
7074
\fB\-\-image\fP=[]
7175
Name of an image stream to to use as a builder. (deprecated)

docs/man/man1/oc-process.1

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ The output of the process command is always a list of one or more resources. You
4343
\fB\-p\fP, \fB\-\-param\fP=[]
4444
Specify a key\-value pair (eg. \-p FOO=BAR) to set/override a parameter value in the template.
4545

46+
.PP
47+
\fB\-\-param\-file\fP=""
48+
File containing template parameter values to set/override in the template.
49+
4650
.PP
4751
\fB\-\-parameters\fP=false
4852
Do not process but only print available parameters

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

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ If you provide source code, a new build will be automatically triggered. You can
5858
\fB\-e\fP, \fB\-\-env\fP=[]
5959
Specify a key\-value pair for an environment variable to set into each container.
6060

61+
.PP
62+
\fB\-\-env\-file\fP=""
63+
File containing key\-value pairs of environment variables to set into each container.
64+
6165
.PP
6266
\fB\-f\fP, \fB\-\-file\fP=[]
6367
Path to a template file to use for the app.
@@ -110,6 +114,10 @@ If you provide source code, a new build will be automatically triggered. You can
110114
\fB\-p\fP, \fB\-\-param\fP=[]
111115
Specify a key\-value pair (e.g., \-p FOO=BAR) to set/override a parameter value in the template.
112116

117+
.PP
118+
\fB\-\-param\-file\fP=""
119+
File containing environment parameter values to set/override in the template.
120+
113121
.PP
114122
\fB\-S\fP, \fB\-\-search\fP=false
115123
Search all templates, image streams, and Docker images that match the arguments provided.

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

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ Once the build configuration is created a new build will be automatically trigge
6666
\fB\-e\fP, \fB\-\-env\fP=[]
6767
Specify a key\-value pair for an environment variable to set into resulting image.
6868

69+
.PP
70+
\fB\-\-env\-file\fP=""
71+
File containing key\-value pairs of environment variables to set into each container.
72+
6973
.PP
7074
\fB\-\-image\fP=[]
7175
Name of an image stream to to use as a builder. (deprecated)

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

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ The output of the process command is always a list of one or more resources. You
4343
\fB\-p\fP, \fB\-\-param\fP=[]
4444
Specify a key\-value pair (eg. \-p FOO=BAR) to set/override a parameter value in the template.
4545

46+
.PP
47+
\fB\-\-param\-file\fP=""
48+
File containing template parameter values to set/override in the template.
49+
4650
.PP
4751
\fB\-\-parameters\fP=false
4852
Do not process but only print available parameters

pkg/cmd/cli/cli.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
9595
cmd.NewCmdTypes(fullName, f, out),
9696
loginCmd,
9797
cmd.NewCmdRequestProject(cmd.RequestProjectRecommendedCommandName, fullName, f, out, errout),
98-
cmd.NewCmdNewApplication(cmd.NewAppRecommendedCommandName, fullName, f, out, errout),
98+
cmd.NewCmdNewApplication(cmd.NewAppRecommendedCommandName, fullName, f, in, out, errout),
9999
cmd.NewCmdStatus(cmd.StatusRecommendedName, fullName, fullName+" "+cmd.StatusRecommendedName, f, out),
100100
cmd.NewCmdProject(fullName+" project", f, out),
101101
cmd.NewCmdProjects(fullName, f, out),
@@ -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, errout),
159+
cmd.NewCmdProcess(fullName, f, in, 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/dockerbuild/dockerbuild.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/openshift/origin/pkg/cmd/templates"
2121
cmdutil "github.com/openshift/origin/pkg/cmd/util"
2222
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
23+
"github.com/openshift/origin/pkg/generate/app"
2324
)
2425

2526
var (
@@ -55,7 +56,7 @@ type DockerbuildOptions struct {
5556
DockerfilePath string
5657
AllowPull bool
5758
Keyring credentialprovider.DockerKeyring
58-
Arguments cmdutil.Environment
59+
Arguments app.Environment
5960
}
6061

6162
func NewCmdDockerbuild(fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
@@ -97,7 +98,7 @@ func (o *DockerbuildOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command,
9798
if len(paths) != 2 {
9899
return kcmdutil.UsageError(cmd, "the directory to build and tag must be specified")
99100
}
100-
o.Arguments, _, _ = cmdutil.ParseEnvironmentArguments(envArgs)
101+
o.Arguments, _, _ = app.ParseEnvironment(envArgs...)
101102
o.Directory = paths[0]
102103
o.Tag = paths[1]
103104
if len(o.DockerfilePath) == 0 {

pkg/cmd/cli/cmd/newapp.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ import (
4545
// NewAppRecommendedCommandName is the recommended command name.
4646
const NewAppRecommendedCommandName = "new-app"
4747

48-
type usage interface {
49-
UsageError(baseName string) string
50-
}
51-
5248
var (
5349
newAppLong = templates.LongDesc(`
5450
Create a new application by specifying source code, templates, and/or images
@@ -129,14 +125,15 @@ type NewAppOptions struct {
129125
CommandPath string
130126
CommandName string
131127

128+
In io.Reader
132129
Out, ErrOut io.Writer
133130
Output string
134131
PrintObject func(obj runtime.Object) error
135132
LogsForObject LogsForObjectFunc
136133
}
137134

138135
// NewCmdNewApplication implements the OpenShift cli new-app command.
139-
func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, errout io.Writer) *cobra.Command {
136+
func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, in io.Reader, out, errout io.Writer) *cobra.Command {
140137
config := newcmd.NewAppConfig()
141138
config.Deploy = true
142139
o := &NewAppOptions{Config: config}
@@ -148,7 +145,7 @@ func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, erro
148145
Example: fmt.Sprintf(newAppExample, baseName, name),
149146
SuggestFor: []string{"app", "application"},
150147
Run: func(c *cobra.Command, args []string) {
151-
kcmdutil.CheckErr(o.Complete(baseName, name, f, c, args, out, errout))
148+
kcmdutil.CheckErr(o.Complete(baseName, name, f, c, args, in, out, errout))
152149
err := o.RunNewApp()
153150
if err == cmdutil.ErrExit {
154151
os.Exit(1)
@@ -168,8 +165,12 @@ func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, erro
168165
cmd.Flags().StringSliceVarP(&config.TemplateFiles, "file", "f", config.TemplateFiles, "Path to a template file to use for the app.")
169166
cmd.MarkFlagFilename("file", "yaml", "yml", "json")
170167
cmd.Flags().StringArrayVarP(&config.TemplateParameters, "param", "p", config.TemplateParameters, "Specify a key-value pair (e.g., -p FOO=BAR) to set/override a parameter value in the template.")
168+
cmd.Flags().StringVar(&config.TemplateParametersFile, "param-file", "", "File containing parameter values to set/override in the template.")
169+
cmd.MarkFlagFilename("param-file")
171170
cmd.Flags().StringSliceVar(&config.Groups, "group", config.Groups, "Indicate components that should be grouped together as <comp1>+<comp2>.")
172171
cmd.Flags().StringArrayVarP(&config.Environment, "env", "e", config.Environment, "Specify a key-value pair for an environment variable to set into each container.")
172+
cmd.Flags().StringVar(&config.EnvironmentFile, "env-file", "", "File containing key-value pairs of environment variables to set into each container.")
173+
cmd.MarkFlagFilename("env-file")
173174
cmd.Flags().StringVar(&config.Name, "name", "", "Set name to use for generated application artifacts")
174175
cmd.Flags().Var(&config.Strategy, "strategy", "Specify the build strategy to use if you don't want to detect (docker|pipeline|source).")
175176
cmd.Flags().StringP("labels", "l", "", "Label to set in all resources for this application.")
@@ -188,12 +189,14 @@ func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, erro
188189
}
189190

190191
// Complete sets any default behavior for the command
191-
func (o *NewAppOptions) Complete(baseName, name string, f *clientcmd.Factory, c *cobra.Command, args []string, out, errout io.Writer) error {
192+
func (o *NewAppOptions) Complete(baseName, name string, f *clientcmd.Factory, c *cobra.Command, args []string, in io.Reader, out, errout io.Writer) error {
193+
o.In = in
192194
o.Out = out
193195
o.ErrOut = errout
194196
o.Output = kcmdutil.GetFlagString(c, "output")
195197
// Only output="" should print descriptions of intermediate steps. Everything
196198
// else should print only some specific output (json, yaml, go-template, ...)
199+
o.Config.In = o.In
197200
if len(o.Output) == 0 {
198201
o.Config.Out = o.Out
199202
} else {

pkg/cmd/cli/cmd/newapp_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestNewAppDefaultFlags(t *testing.T) {
112112
},
113113
}
114114

115-
cmd := NewCmdNewApplication("oc", NewAppRecommendedCommandName, nil, nil, nil)
115+
cmd := NewCmdNewApplication("oc", NewAppRecommendedCommandName, nil, nil, nil, nil)
116116

117117
for _, v := range tests {
118118
f := cmd.Flag(v.flagName)

0 commit comments

Comments
 (0)