Skip to content

Commit

Permalink
Merge pull request #12230 from mmilata/oc-process-o-template
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Dec 14, 2016
2 parents 6b08947 + b97df34 commit 41702ed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/man/man1/oc-process.1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The output of the process command is always a list of one or more resources. You

.PP
\fB\-o\fP, \fB\-\-output\fP="json"
Output format. One of: describe|json|yaml|name|template|templatefile.
Output format. One of: describe|json|yaml|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=...

.PP
\fB\-\-output\-version\fP=""
Expand All @@ -53,7 +53,7 @@ The output of the process command is always a list of one or more resources. You

.PP
\fB\-t\fP, \fB\-\-template\fP=""
Template string or path to template file to use when \-o=template or \-o=templatefile. The template format is golang templates [
Template string or path to template file to use when \-o=go\-template, \-o=go\-templatefile. The template format is golang templates [
\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]


Expand Down
4 changes: 2 additions & 2 deletions docs/man/man1/openshift-cli-process.1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The output of the process command is always a list of one or more resources. You

.PP
\fB\-o\fP, \fB\-\-output\fP="json"
Output format. One of: describe|json|yaml|name|template|templatefile.
Output format. One of: describe|json|yaml|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=...

.PP
\fB\-\-output\-version\fP=""
Expand All @@ -53,7 +53,7 @@ The output of the process command is always a list of one or more resources. You

.PP
\fB\-t\fP, \fB\-\-template\fP=""
Template string or path to template file to use when \-o=template or \-o=templatefile. The template format is golang templates [
Template string or path to template file to use when \-o=go\-template, \-o=go\-templatefile. The template format is golang templates [
\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]


Expand Down
14 changes: 11 additions & 3 deletions pkg/cmd/cli/cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ func NewCmdProcess(fullName string, f *clientcmd.Factory, out, errout io.Writer)
cmd.Flags().BoolP("parameters", "", false, "Do not process but only print available parameters")
cmd.Flags().StringP("labels", "l", "", "Label to set in all resources for this template")

cmd.Flags().StringP("output", "o", "json", "Output format. One of: describe|json|yaml|name|template|templatefile.")
cmd.Flags().StringP("output", "o", "json", "Output format. One of: describe|json|yaml|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...")
cmd.Flags().Bool("raw", false, "If true output the processed template instead of the template's objects. Implied by -o describe")
cmd.Flags().String("output-version", "", "Output the formatted object with the given version (default api-version).")
cmd.Flags().StringP("template", "t", "", "Template string or path to template file to use when -o=template or -o=templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]")
cmd.Flags().StringP("template", "t", "", "Template string or path to template file to use when -o=go-template, -o=go-templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]")

// kcmdutil.PrinterForCommand needs these flags, however they are useless
// here because oc process returns list of heterogeneous objects that is
// not suitable for formatting as a table.
cmd.Flags().Bool("no-headers", false, "When using the default output, don't print headers.")
cmd.Flags().MarkHidden("no-headers")
cmd.Flags().String("sort-by", "", "If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string.")
cmd.Flags().MarkHidden("sort-by")

return cmd
}
Expand Down Expand Up @@ -273,7 +281,7 @@ func RunProcess(f *clientcmd.Factory, out, errout io.Writer, cmd *cobra.Command,
}
objects = append(objects, resultObj.Objects...)

p, _, err := kubectl.GetPrinter(outputFormat, "", false)
p, _, err := kcmdutil.PrinterForCommand(cmd)
if err != nil {
return err
}
Expand Down
13 changes: 12 additions & 1 deletion test/cmd/templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ os::cmd::expect_success 'oc get templates'
os::cmd::expect_success 'oc get templates ruby-helloworld-sample'
os::cmd::expect_success 'oc get template ruby-helloworld-sample -o json | oc process -f -'
os::cmd::expect_success 'oc process ruby-helloworld-sample'
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -o template --template "{{.kind}}"' "List"
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -o go-template --template "{{.kind}}"' "List"
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -o go-template={{.kind}}' "List"
os::cmd::expect_success 'oc process ruby-helloworld-sample -o go-template-file=/dev/null'
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -o jsonpath --template "{.kind}"' "List"
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -o jsonpath={.kind}' "List"
os::cmd::expect_success 'oc process ruby-helloworld-sample -o jsonpath-file=/dev/null'
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -o describe' "ruby-22-centos7"
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -o json' "ruby-22-centos7"
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -o yaml' "ruby-22-centos7"
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -o name' "ruby-22-centos7"
os::cmd::expect_success_and_text 'oc describe templates ruby-helloworld-sample' "BuildConfig.*ruby-sample-build"
os::cmd::expect_success 'oc delete templates ruby-helloworld-sample'
os::cmd::expect_success 'oc get templates'
Expand Down Expand Up @@ -94,4 +105,4 @@ os::cmd::expect_success 'oc process openshift/template/ruby-helloworld-sample'
echo "processing templates in different namespace: ok"
os::test::junit::declare_suite_end

os::test::junit::declare_suite_end
os::test::junit::declare_suite_end

0 comments on commit 41702ed

Please sign in to comment.