Skip to content

Commit

Permalink
new-app/new-build/process: read envvars/params from file
Browse files Browse the repository at this point in the history
test/cmd/process.sh has been merged into test/cmd/templates.sh since
they test the same functionality.
  • Loading branch information
mmilata committed Dec 9, 2016
1 parent 7128035 commit 9ccbf31
Show file tree
Hide file tree
Showing 28 changed files with 454 additions and 212 deletions.
16 changes: 16 additions & 0 deletions contrib/completions/bash/oc
Original file line number Diff line number Diff line change
Expand Up @@ -10434,6 +10434,10 @@ _oc_new-app()
flags+=("--env=")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--env=")
flags+=("--env-file=")
flags_with_completion+=("--env-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--env-file=")
flags+=("--file=")
flags_with_completion+=("--file")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
Expand Down Expand Up @@ -10468,6 +10472,10 @@ _oc_new-app()
flags+=("--param=")
two_word_flags+=("-p")
local_nonpersistent_flags+=("--param=")
flags+=("--param-file=")
flags_with_completion+=("--param-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--param-file=")
flags+=("--search")
flags+=("-S")
local_nonpersistent_flags+=("--search")
Expand Down Expand Up @@ -10540,6 +10548,10 @@ _oc_new-build()
flags+=("--env=")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--env=")
flags+=("--env-file=")
flags_with_completion+=("--env-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--env-file=")
flags+=("--image-stream=")
two_word_flags+=("-i")
local_nonpersistent_flags+=("--image-stream=")
Expand Down Expand Up @@ -11512,6 +11524,10 @@ _oc_process()
flags+=("--param=")
two_word_flags+=("-p")
local_nonpersistent_flags+=("--param=")
flags+=("--param-file=")
flags_with_completion+=("--param-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--param-file=")
flags+=("--parameters")
local_nonpersistent_flags+=("--parameters")
flags+=("--raw")
Expand Down
16 changes: 16 additions & 0 deletions contrib/completions/bash/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -15080,6 +15080,10 @@ _openshift_cli_new-app()
flags+=("--env=")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--env=")
flags+=("--env-file=")
flags_with_completion+=("--env-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--env-file=")
flags+=("--file=")
flags_with_completion+=("--file")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
Expand Down Expand Up @@ -15114,6 +15118,10 @@ _openshift_cli_new-app()
flags+=("--param=")
two_word_flags+=("-p")
local_nonpersistent_flags+=("--param=")
flags+=("--param-file=")
flags_with_completion+=("--param-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--param-file=")
flags+=("--search")
flags+=("-S")
local_nonpersistent_flags+=("--search")
Expand Down Expand Up @@ -15187,6 +15195,10 @@ _openshift_cli_new-build()
flags+=("--env=")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--env=")
flags+=("--env-file=")
flags_with_completion+=("--env-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--env-file=")
flags+=("--image-stream=")
two_word_flags+=("-i")
local_nonpersistent_flags+=("--image-stream=")
Expand Down Expand Up @@ -16174,6 +16186,10 @@ _openshift_cli_process()
flags+=("--param=")
two_word_flags+=("-p")
local_nonpersistent_flags+=("--param=")
flags+=("--param-file=")
flags_with_completion+=("--param-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--param-file=")
flags+=("--parameters")
local_nonpersistent_flags+=("--parameters")
flags+=("--raw")
Expand Down
16 changes: 16 additions & 0 deletions contrib/completions/zsh/oc
Original file line number Diff line number Diff line change
Expand Up @@ -10595,6 +10595,10 @@ _oc_new-app()
flags+=("--env=")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--env=")
flags+=("--env-file=")
flags_with_completion+=("--env-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--env-file=")
flags+=("--file=")
flags_with_completion+=("--file")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
Expand Down Expand Up @@ -10629,6 +10633,10 @@ _oc_new-app()
flags+=("--param=")
two_word_flags+=("-p")
local_nonpersistent_flags+=("--param=")
flags+=("--param-file=")
flags_with_completion+=("--param-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--param-file=")
flags+=("--search")
flags+=("-S")
local_nonpersistent_flags+=("--search")
Expand Down Expand Up @@ -10701,6 +10709,10 @@ _oc_new-build()
flags+=("--env=")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--env=")
flags+=("--env-file=")
flags_with_completion+=("--env-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--env-file=")
flags+=("--image-stream=")
two_word_flags+=("-i")
local_nonpersistent_flags+=("--image-stream=")
Expand Down Expand Up @@ -11673,6 +11685,10 @@ _oc_process()
flags+=("--param=")
two_word_flags+=("-p")
local_nonpersistent_flags+=("--param=")
flags+=("--param-file=")
flags_with_completion+=("--param-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--param-file=")
flags+=("--parameters")
local_nonpersistent_flags+=("--parameters")
flags+=("--raw")
Expand Down
16 changes: 16 additions & 0 deletions contrib/completions/zsh/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -15241,6 +15241,10 @@ _openshift_cli_new-app()
flags+=("--env=")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--env=")
flags+=("--env-file=")
flags_with_completion+=("--env-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--env-file=")
flags+=("--file=")
flags_with_completion+=("--file")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
Expand Down Expand Up @@ -15275,6 +15279,10 @@ _openshift_cli_new-app()
flags+=("--param=")
two_word_flags+=("-p")
local_nonpersistent_flags+=("--param=")
flags+=("--param-file=")
flags_with_completion+=("--param-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--param-file=")
flags+=("--search")
flags+=("-S")
local_nonpersistent_flags+=("--search")
Expand Down Expand Up @@ -15348,6 +15356,10 @@ _openshift_cli_new-build()
flags+=("--env=")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--env=")
flags+=("--env-file=")
flags_with_completion+=("--env-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--env-file=")
flags+=("--image-stream=")
two_word_flags+=("-i")
local_nonpersistent_flags+=("--image-stream=")
Expand Down Expand Up @@ -16335,6 +16347,10 @@ _openshift_cli_process()
flags+=("--param=")
two_word_flags+=("-p")
local_nonpersistent_flags+=("--param=")
flags+=("--param-file=")
flags_with_completion+=("--param-file")
flags_completion+=("_filedir")
local_nonpersistent_flags+=("--param-file=")
flags+=("--parameters")
local_nonpersistent_flags+=("--parameters")
flags+=("--raw")
Expand Down
8 changes: 8 additions & 0 deletions docs/man/man1/oc-new-app.1
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ If you provide source code, a new build will be automatically triggered. You can
\fB\-e\fP, \fB\-\-env\fP=[]
Specify a key\-value pair for an environment variable to set into each container.

.PP
\fB\-\-env\-file\fP=[]
File containing key\-value pairs of environment variables to set into each container.

.PP
\fB\-f\fP, \fB\-\-file\fP=[]
Path to a template file to use for the app.
Expand Down Expand Up @@ -110,6 +114,10 @@ If you provide source code, a new build will be automatically triggered. You can
\fB\-p\fP, \fB\-\-param\fP=[]
Specify a key\-value pair (e.g., \-p FOO=BAR) to set/override a parameter value in the template.

.PP
\fB\-\-param\-file\fP=[]
File containing parameter values to set/override in the template.

.PP
\fB\-S\fP, \fB\-\-search\fP=false
Search all templates, image streams, and Docker images that match the arguments provided.
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/oc-new-build.1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ Once the build configuration is created a new build will be automatically trigge
\fB\-e\fP, \fB\-\-env\fP=[]
Specify a key\-value pair for an environment variable to set into resulting image.

.PP
\fB\-\-env\-file\fP=[]
File containing key\-value pairs of environment variables to set into each container.

.PP
\fB\-\-image\fP=[]
Name of an image stream to to use as a builder. (deprecated)
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/oc-process.1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ The output of the process command is always a list of one or more resources. You
\fB\-p\fP, \fB\-\-param\fP=[]
Specify a key\-value pair (eg. \-p FOO=BAR) to set/override a parameter value in the template.

.PP
\fB\-\-param\-file\fP=[]
File containing template parameter values to set/override in the template.

.PP
\fB\-\-parameters\fP=false
Do not process but only print available parameters
Expand Down
8 changes: 8 additions & 0 deletions docs/man/man1/openshift-cli-new-app.1
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ If you provide source code, a new build will be automatically triggered. You can
\fB\-e\fP, \fB\-\-env\fP=[]
Specify a key\-value pair for an environment variable to set into each container.

.PP
\fB\-\-env\-file\fP=[]
File containing key\-value pairs of environment variables to set into each container.

.PP
\fB\-f\fP, \fB\-\-file\fP=[]
Path to a template file to use for the app.
Expand Down Expand Up @@ -110,6 +114,10 @@ If you provide source code, a new build will be automatically triggered. You can
\fB\-p\fP, \fB\-\-param\fP=[]
Specify a key\-value pair (e.g., \-p FOO=BAR) to set/override a parameter value in the template.

.PP
\fB\-\-param\-file\fP=[]
File containing parameter values to set/override in the template.

.PP
\fB\-S\fP, \fB\-\-search\fP=false
Search all templates, image streams, and Docker images that match the arguments provided.
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/openshift-cli-new-build.1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ Once the build configuration is created a new build will be automatically trigge
\fB\-e\fP, \fB\-\-env\fP=[]
Specify a key\-value pair for an environment variable to set into resulting image.

.PP
\fB\-\-env\-file\fP=[]
File containing key\-value pairs of environment variables to set into each container.

.PP
\fB\-\-image\fP=[]
Name of an image stream to to use as a builder. (deprecated)
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/openshift-cli-process.1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ The output of the process command is always a list of one or more resources. You
\fB\-p\fP, \fB\-\-param\fP=[]
Specify a key\-value pair (eg. \-p FOO=BAR) to set/override a parameter value in the template.

.PP
\fB\-\-param\-file\fP=[]
File containing template parameter values to set/override in the template.

.PP
\fB\-\-parameters\fP=false
Do not process but only print available parameters
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
cmd.NewCmdTypes(fullName, f, out),
loginCmd,
cmd.NewCmdRequestProject(cmd.RequestProjectRecommendedCommandName, fullName, f, out, errout),
cmd.NewCmdNewApplication(cmd.NewAppRecommendedCommandName, fullName, f, out, errout),
cmd.NewCmdNewApplication(cmd.NewAppRecommendedCommandName, fullName, f, in, out, errout),
cmd.NewCmdStatus(cmd.StatusRecommendedName, fullName, fullName+" "+cmd.StatusRecommendedName, f, out),
cmd.NewCmdProject(fullName+" project", f, out),
cmd.NewCmdProjects(fullName, f, out),
Expand Down Expand Up @@ -156,7 +156,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
cmd.NewCmdReplace(fullName, f, out),
cmd.NewCmdApply(fullName, f, out),
cmd.NewCmdPatch(fullName, f, out),
cmd.NewCmdProcess(fullName, f, out, errout),
cmd.NewCmdProcess(fullName, f, in, out, errout),
cmd.NewCmdExport(fullName, f, in, out),
cmd.NewCmdExtract(fullName, f, in, out, errout),
observe.NewCmdObserve(fullName, f, out, errout),
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/cli/cmd/dockerbuild/dockerbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/openshift/origin/pkg/cmd/templates"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
"github.com/openshift/origin/pkg/generate/app"
)

var (
Expand Down Expand Up @@ -55,7 +56,7 @@ type DockerbuildOptions struct {
DockerfilePath string
AllowPull bool
Keyring credentialprovider.DockerKeyring
Arguments cmdutil.Environment
Arguments app.Environment
}

func NewCmdDockerbuild(fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
Expand Down Expand Up @@ -97,7 +98,7 @@ func (o *DockerbuildOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command,
if len(paths) != 2 {
return kcmdutil.UsageError(cmd, "the directory to build and tag must be specified")
}
o.Arguments, _, _ = cmdutil.ParseEnvironmentArguments(envArgs)
o.Arguments, _, _ = app.ParseEnvironment(envArgs...)
o.Directory = paths[0]
o.Tag = paths[1]
if len(o.DockerfilePath) == 0 {
Expand Down
17 changes: 10 additions & 7 deletions pkg/cmd/cli/cmd/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ import (
// NewAppRecommendedCommandName is the recommended command name.
const NewAppRecommendedCommandName = "new-app"

type usage interface {
UsageError(baseName string) string
}

var (
newAppLong = templates.LongDesc(`
Create a new application by specifying source code, templates, and/or images
Expand Down Expand Up @@ -129,14 +125,15 @@ type NewAppOptions struct {
CommandPath string
CommandName string

In io.Reader
Out, ErrOut io.Writer
Output string
PrintObject func(obj runtime.Object) error
LogsForObject LogsForObjectFunc
}

// NewCmdNewApplication implements the OpenShift cli new-app command.
func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, errout io.Writer) *cobra.Command {
func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, in io.Reader, out, errout io.Writer) *cobra.Command {
config := newcmd.NewAppConfig()
config.Deploy = true
o := &NewAppOptions{Config: config}
Expand All @@ -148,7 +145,7 @@ func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, erro
Example: fmt.Sprintf(newAppExample, baseName, name),
SuggestFor: []string{"app", "application"},
Run: func(c *cobra.Command, args []string) {
kcmdutil.CheckErr(o.Complete(baseName, name, f, c, args, out, errout))
kcmdutil.CheckErr(o.Complete(baseName, name, f, c, args, in, out, errout))
err := o.RunNewApp()
if err == cmdutil.ErrExit {
os.Exit(1)
Expand All @@ -168,8 +165,12 @@ func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, erro
cmd.Flags().StringSliceVarP(&config.TemplateFiles, "file", "f", config.TemplateFiles, "Path to a template file to use for the app.")
cmd.MarkFlagFilename("file", "yaml", "yml", "json")
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.")
cmd.Flags().StringArrayVar(&config.TemplateParameterFiles, "param-file", config.TemplateParameterFiles, "File containing parameter values to set/override in the template.")
cmd.MarkFlagFilename("param-file")
cmd.Flags().StringSliceVar(&config.Groups, "group", config.Groups, "Indicate components that should be grouped together as <comp1>+<comp2>.")
cmd.Flags().StringArrayVarP(&config.Environment, "env", "e", config.Environment, "Specify a key-value pair for an environment variable to set into each container.")
cmd.Flags().StringArrayVar(&config.EnvironmentFiles, "env-file", config.EnvironmentFiles, "File containing key-value pairs of environment variables to set into each container.")
cmd.MarkFlagFilename("env-file")
cmd.Flags().StringVar(&config.Name, "name", "", "Set name to use for generated application artifacts")
cmd.Flags().Var(&config.Strategy, "strategy", "Specify the build strategy to use if you don't want to detect (docker|pipeline|source).")
cmd.Flags().StringP("labels", "l", "", "Label to set in all resources for this application.")
Expand All @@ -188,12 +189,14 @@ func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, erro
}

// Complete sets any default behavior for the command
func (o *NewAppOptions) Complete(baseName, name string, f *clientcmd.Factory, c *cobra.Command, args []string, out, errout io.Writer) error {
func (o *NewAppOptions) Complete(baseName, name string, f *clientcmd.Factory, c *cobra.Command, args []string, in io.Reader, out, errout io.Writer) error {
o.In = in
o.Out = out
o.ErrOut = errout
o.Output = kcmdutil.GetFlagString(c, "output")
// Only output="" should print descriptions of intermediate steps. Everything
// else should print only some specific output (json, yaml, go-template, ...)
o.Config.In = o.In
if len(o.Output) == 0 {
o.Config.Out = o.Out
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/cmd/newapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestNewAppDefaultFlags(t *testing.T) {
},
}

cmd := NewCmdNewApplication("oc", NewAppRecommendedCommandName, nil, nil, nil)
cmd := NewCmdNewApplication("oc", NewAppRecommendedCommandName, nil, nil, nil, nil)

for _, v := range tests {
f := cmd.Flag(v.flagName)
Expand Down
Loading

0 comments on commit 9ccbf31

Please sign in to comment.