pkg/cmd/cli/cmd/wrappers.go
5aaa3548
 package cmd
 
 import (
1558f2d9
 	"bufio"
5aaa3548
 	"fmt"
 	"io"
bfa9bb91
 	"os"
1558f2d9
 	"strings"
5aaa3548
 
 	"github.com/spf13/cobra"
37b6c5f1
 	kclientcmd "k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
83c702b4
 	kcmd "k8s.io/kubernetes/pkg/kubectl/cmd"
bfa9bb91
 	"k8s.io/kubernetes/pkg/kubectl/cmd/config"
997787d8
 	kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
987aca9b
 	kvalidation "k8s.io/kubernetes/pkg/util/validation"
5aaa3548
 
222bff8e
 	"github.com/openshift/origin/pkg/cmd/cli/cmd/create"
bfa9bb91
 	cmdconfig "github.com/openshift/origin/pkg/cmd/cli/config"
f0b7b2a1
 	"github.com/openshift/origin/pkg/cmd/cli/describe"
6267dded
 	"github.com/openshift/origin/pkg/cmd/templates"
5aaa3548
 	"github.com/openshift/origin/pkg/cmd/util/clientcmd"
 )
 
25c24210
 func adjustCmdExamples(cmd *cobra.Command, parentName string, name string) {
 	for _, subCmd := range cmd.Commands() {
 		adjustCmdExamples(subCmd, parentName, cmd.Name())
 	}
 	cmd.Example = strings.Replace(cmd.Example, "kubectl", parentName, -1)
 	tabbing := "  "
 	examples := []string{}
 	scanner := bufio.NewScanner(strings.NewReader(cmd.Example))
633b1b93
 	for scanner.Scan() {
25c24210
 		examples = append(examples, tabbing+strings.TrimSpace(scanner.Text()))
633b1b93
 	}
25c24210
 	cmd.Example = strings.Join(examples, "\n")
633b1b93
 }
 
6267dded
 var (
 	getLong = templates.LongDesc(`
 		Display one or many resources
5aaa3548
 
6267dded
 		Possible resources include builds, buildConfigs, services, pods, etc. To see
 		a list of common resources, use '%[1]s get'. Some resources may omit advanced
 		details that you can see with '-o wide'.  If you want an even more detailed
 		view, use '%[1]s describe'.`)
5aaa3548
 
6267dded
 	getExample = templates.Examples(`
 		# List all pods in ps output format.
 		%[1]s get pods
5aaa3548
 
6267dded
 		# List a single replication controller with specified ID in ps output format.
 		%[1]s get rc redis
149dafc0
 
6267dded
 		# List all pods and show more details about them.
 		%[1]s get -o wide pods
5aaa3548
 
6267dded
 		# List a single pod in JSON output format.
 		%[1]s get -o json pod redis-pod
5aaa3548
 
6267dded
 		# Return only the status value of the specified pod.
 		%[1]s get -o template pod redis-pod --template={{.currentState.status}}`)
1558f2d9
 )
 
 // NewCmdGet is a wrapper for the Kubernetes cli get command
1f74d3fb
 func NewCmdGet(fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdGet(f.Factory, out, errOut)
149dafc0
 	cmd.Long = fmt.Sprintf(getLong, fullName)
c36413f1
 	cmd.Example = fmt.Sprintf(getExample, fullName)
b3e77d8d
 	cmd.SuggestFor = []string{"list"}
5aaa3548
 	return cmd
 }
 
6267dded
 var (
 	replaceLong = templates.LongDesc(`
 		Replace a resource by filename or stdin
5aaa3548
 
6267dded
 		JSON and YAML formats are accepted.`)
5aaa3548
 
6267dded
 	replaceExample = templates.Examples(`
 		# Replace a pod using the data in pod.json.
 	  %[1]s replace -f pod.json
5aaa3548
 
6267dded
 	  # Replace a pod based on the JSON passed into stdin.
 	  cat pod.json | %[1]s replace -f -
52f82cd4
 
6267dded
 	  # Force replace, delete and then re-create the resource
 	  %[1]s replace --force -f pod.json`)
1558f2d9
 )
 
52f82cd4
 // NewCmdReplace is a wrapper for the Kubernetes cli replace command
 func NewCmdReplace(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
d3282b30
 	cmd := kcmd.NewCmdReplace(f.Factory, out)
52f82cd4
 	cmd.Long = replaceLong
 	cmd.Example = fmt.Sprintf(replaceExample, fullName)
 	return cmd
 }
 
6267dded
 var (
 	patchLong = templates.LongDesc(`
 		Update field(s) of a resource using strategic merge patch
52f82cd4
 
6267dded
 		JSON and YAML formats are accepted.`)
52f82cd4
 
6267dded
 	patchExample = templates.Examples(`
 		# Partially update a node using strategic merge patch
   	%[1]s patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'`)
52f82cd4
 )
 
 // NewCmdPatch is a wrapper for the Kubernetes cli patch command
 func NewCmdPatch(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdPatch(f.Factory, out)
 	cmd.Long = patchLong
 	cmd.Example = fmt.Sprintf(patchExample, fullName)
5aaa3548
 	return cmd
 }
 
6267dded
 var (
 	deleteLong = templates.LongDesc(`
 		Delete a resource
5aaa3548
 
6267dded
 		JSON and YAML formats are accepted.
5aaa3548
 
6267dded
 		If both a filename and command line arguments are passed, the command line
 		arguments are used and the filename is ignored.
5aaa3548
 
6267dded
 		Note that the delete command does NOT do resource version checks, so if someone
 		submits an update to a resource right when you submit a delete, their update
 		will be lost along with the rest of the resource.`)
5aaa3548
 
6267dded
 	deleteExample = templates.Examples(`
 		# Delete a pod using the type and ID specified in pod.json.
 	  %[1]s delete -f pod.json
5aaa3548
 
6267dded
 	  # Delete a pod based on the type and ID in the JSON passed into stdin.
 	  cat pod.json | %[1]s delete -f -
5aaa3548
 
6267dded
 	  # Delete pods and services with label name=myLabel.
 	  %[1]s delete pods,services -l name=myLabel
5aaa3548
 
6267dded
 	  # Delete a pod with name node-1-vsjnm.
 	  %[1]s delete pod node-1-vsjnm
5aaa3548
 
6267dded
 	  # Delete all resources associated with a running app, includes
 	  # buildconfig,deploymentconfig,service,imagestream,route and pod,
 	  # where 'appName' is listed in 'Labels' of 'oc describe [resource] [resource name]' output.
 	  %[1]s delete all -l app=appName
7abc4b80
 
6267dded
 	  # Delete all pods
 	  %[1]s delete pods --all`)
1558f2d9
 )
 
 // NewCmdDelete is a wrapper for the Kubernetes cli delete command
 func NewCmdDelete(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
434705f6
 	cmd := kcmd.NewCmdDelete(f.Factory, out)
c36413f1
 	cmd.Long = deleteLong
95ec120f
 	cmd.Short = "Delete one or more resources"
c36413f1
 	cmd.Example = fmt.Sprintf(deleteExample, fullName)
95ec120f
 	cmd.SuggestFor = []string{"remove", "stop"}
5aaa3548
 	return cmd
 }
 
6267dded
 var (
 	createLong = templates.LongDesc(`
 		Create a resource by filename or stdin
5aaa3548
 
6267dded
 		JSON and YAML formats are accepted.`)
5aaa3548
 
6267dded
 	createExample = templates.Examples(`
 		# Create a pod using the data in pod.json.
 	  %[1]s create -f pod.json
1558f2d9
 
6267dded
 	  # Create a pod based on the JSON passed into stdin.
 	  cat pod.json | %[1]s create -f -`)
1558f2d9
 )
5aaa3548
 
13eb76ee
 // NewCmdCreate is a wrapper for the Kubernetes cli create command
bfa9bb91
 func NewCmdCreate(parentName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
434705f6
 	cmd := kcmd.NewCmdCreate(f.Factory, out)
c36413f1
 	cmd.Long = createLong
bfa9bb91
 	cmd.Example = fmt.Sprintf(createExample, parentName)
a555a357
 
6267dded
 	// normalize long descs and examples
 	// TODO remove when normalization is moved upstream
 	templates.NormalizeAll(cmd)
 
a555a357
 	// create subcommands
25c24210
 	cmd.AddCommand(create.NewCmdCreateRoute(parentName, f, out))
222bff8e
 	cmd.AddCommand(create.NewCmdCreatePolicyBinding(create.PolicyBindingRecommendedName, parentName+" create "+create.PolicyBindingRecommendedName, f, out))
0bde6e55
 	cmd.AddCommand(create.NewCmdCreateDeploymentConfig(create.DeploymentConfigRecommendedName, parentName+" create "+create.DeploymentConfigRecommendedName, f, out))
ee5e6a81
 	cmd.AddCommand(create.NewCmdCreateClusterQuota(create.ClusterQuotaRecommendedName, parentName+" create "+create.ClusterQuotaRecommendedName, f, out))
bfa9bb91
 
2ab359c3
 	cmd.AddCommand(create.NewCmdCreateUser(create.UserRecommendedName, parentName+" create "+create.UserRecommendedName, f, out))
 	cmd.AddCommand(create.NewCmdCreateIdentity(create.IdentityRecommendedName, parentName+" create "+create.IdentityRecommendedName, f, out))
 	cmd.AddCommand(create.NewCmdCreateUserIdentityMapping(create.UserIdentityMappingRecommendedName, parentName+" create "+create.UserIdentityMappingRecommendedName, f, out))
2f76071a
 	cmd.AddCommand(create.NewCmdCreateImageStream(create.ImageStreamRecommendedName, parentName+" create "+create.ImageStreamRecommendedName, f, out))
2ab359c3
 
bfa9bb91
 	adjustCmdExamples(cmd, parentName, "create")
 
1558f2d9
 	return cmd
 }
5aaa3548
 
6267dded
 var (
 	completionLong = templates.LongDesc(`
 		This command prints shell code which must be evaluated to provide interactive
 		completion of %s commands.`)
5aaa3548
 
6267dded
 	completionExample = templates.Examples(`
 		# Generate the %s completion code for bash
 	  %s completion bash > bash_completion.sh
 	  source bash_completion.sh
5aaa3548
 
6267dded
 	  # The above example depends on the bash-completion framework.
 	  # It must be sourced before sourcing the openshift cli completion,
 		# i.e. on the Mac:
e3b3c957
 
6267dded
 	  brew install bash-completion
 	  source $(brew --prefix)/etc/bash_completion
 	  %s completion bash > bash_completion.sh
 	  source bash_completion.sh
e3b3c957
 
6267dded
 	  # In zsh*, the following will load openshift cli zsh completion:
 	  source <(%s completion zsh)
13d085f3
 
6267dded
 	  * zsh completions are only supported in versions of zsh >= 5.2`)
6ec3ba99
 )
4432b5c0
 
6ec3ba99
 func NewCmdCompletion(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
 	cmdHelpName := fullName
 
e3b3c957
 	if strings.HasSuffix(fullName, "completion") {
6ec3ba99
 		cmdHelpName = "openshift"
 	}
4432b5c0
 
6ec3ba99
 	cmd := kcmd.NewCmdCompletion(f.Factory, out)
e3b3c957
 	cmd.Long = fmt.Sprintf(completionLong, cmdHelpName)
 	cmd.Example = fmt.Sprintf(completionExample, cmdHelpName, cmdHelpName, cmdHelpName, cmdHelpName)
 	return cmd
 }
4432b5c0
 
6267dded
 var (
 	execLong = templates.LongDesc(`Execute a command in a container`)
4432b5c0
 
6267dded
 	execExample = templates.Examples(`
 	# Get output from running 'date' in ruby-container from pod 'mypod'
e3b3c957
   %[1]s exec mypod -c ruby-container date
4432b5c0
 
e3b3c957
   # Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod 'mypod' and sends stdout/stderr from 'bash' back to the client
6267dded
   %[1]s exec mypod -c ruby-container -i -t -- bash -il`)
e3b3c957
 )
4432b5c0
 
13eb76ee
 // NewCmdExec is a wrapper for the Kubernetes cli exec command
87d9e2ab
 func NewCmdExec(fullName string, f *clientcmd.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *cobra.Command {
22fca2a2
 	cmd := kcmd.NewCmdExec(f.Factory, cmdIn, cmdOut, cmdErr)
dfd8b768
 	cmd.Use = "exec [options] POD [-c CONTAINER] -- COMMAND [args...]"
c36413f1
 	cmd.Long = execLong
 	cmd.Example = fmt.Sprintf(execExample, fullName)
6a2a9996
 	cmd.Flag("pod").Usage = cmd.Flag("pod").Usage + " (deprecated)"
87d9e2ab
 	return cmd
 }
 
6267dded
 var (
 	portForwardLong = templates.LongDesc(`Forward 1 or more local ports to a pod`)
87d9e2ab
 
6267dded
 	portForwardExample = templates.Examples(`
 		# Listens on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
 	  %[1]s port-forward mypod 5000 6000
87d9e2ab
 
6267dded
 	  # Listens on port 8888 locally, forwarding to 5000 in the pod
 	  %[1]s port-forward mypod 8888:5000
87d9e2ab
 
6267dded
 	  # Listens on a random port locally, forwarding to 5000 in the pod
 	  %[1]s port-forward mypod :5000
87d9e2ab
 
6267dded
 	  # Listens on a random port locally, forwarding to 5000 in the pod
 	  %[1]s port-forward mypod 0:5000`)
1558f2d9
 )
 
 // NewCmdPortForward is a wrapper for the Kubernetes cli port-forward command
508f280e
 func NewCmdPortForward(fullName string, f *clientcmd.Factory, out, errout io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdPortForward(f.Factory, out, errout)
c36413f1
 	cmd.Long = portForwardLong
 	cmd.Example = fmt.Sprintf(portForwardExample, fullName)
ba185e7b
 	cmd.Flag("pod").Usage = cmd.Flag("pod").Usage + " (deprecated)"
87d9e2ab
 	return cmd
 }
263c38f6
 
6267dded
 var (
 	describeLong = templates.LongDesc(`
 		Show details of a specific resource
263c38f6
 
6267dded
 		This command joins many API calls together to form a detailed description of a
 		given resource.`)
263c38f6
 
6267dded
 	describeExample = templates.Examples(`
 		# Provide details about the ruby-22-centos7 image repository
 	  %[1]s describe imageRepository ruby-22-centos7
263c38f6
 
6267dded
 	  # Provide details about the ruby-sample-build build configuration
 	  %[1]s describe bc ruby-sample-build`)
1558f2d9
 )
 
 // NewCmdDescribe is a wrapper for the Kubernetes cli describe command
1f74d3fb
 func NewCmdDescribe(fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdDescribe(f.Factory, out, errOut)
c36413f1
 	cmd.Long = describeLong
 	cmd.Example = fmt.Sprintf(describeExample, fullName)
f0b7b2a1
 	cmd.ValidArgs = describe.DescribableResources()
263c38f6
 	return cmd
 }
38da818d
 
6267dded
 var (
 	proxyLong = templates.LongDesc(`Run a proxy to the API server`)
38da818d
 
6267dded
 	proxyExample = templates.Examples(`
 		# Run a proxy to the api server on port 8011, serving static content from ./local/www/
 	  %[1]s proxy --port=8011 --www=./local/www/
38da818d
 
6267dded
 	  # Run a proxy to the api server on an arbitrary local port.
 	  # The chosen port for the server will be output to stdout.
 	  %[1]s proxy --port=0
16c524d9
 
6267dded
 	  # Run a proxy to the api server, changing the api prefix to my-api
 	  # This makes e.g. the pods api available at localhost:8011/my-api/api/v1/pods/
 	  %[1]s proxy --api-prefix=/my-api`)
1558f2d9
 )
 
 // NewCmdProxy is a wrapper for the Kubernetes cli proxy command
 func NewCmdProxy(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
434705f6
 	cmd := kcmd.NewCmdProxy(f.Factory, out)
c36413f1
 	cmd.Long = proxyLong
 	cmd.Example = fmt.Sprintf(proxyExample, fullName)
38da818d
 	return cmd
 }
1558f2d9
 
6267dded
 var (
 	scaleLong = templates.LongDesc(`
 		Set a new size for a deployment or replication controller
d49bc6ea
 
6267dded
 		Scale also allows users to specify one or more preconditions for the scale action.
 		If --current-replicas or --resource-version is specified, it is validated before the
 		scale is attempted, and it is guaranteed that the precondition holds true when the
 		scale is sent to the server.
1408123a
 
6267dded
 		Note that scaling a deployment configuration with no deployments will update the
 		desired replicas in the configuration template.`)
1408123a
 
6267dded
 	scaleExample = templates.Examples(`
 		# Scale replication controller named 'foo' to 3.
 	  %[1]s scale --replicas=3 replicationcontrollers foo
d49bc6ea
 
6267dded
 	  # If the replication controller named foo's current size is 2, scale foo to 3.
 	  %[1]s scale --current-replicas=2 --replicas=3 replicationcontrollers foo
1408123a
 
6267dded
 	  # Scale the latest deployment of 'bar'. In case of no deployment, bar's template
 	  # will be scaled instead.
 	  %[1]s scale --replicas=10 dc bar`)
d49bc6ea
 )
 
4d2d5534
 // NewCmdScale is a wrapper for the Kubernetes cli scale command
 func NewCmdScale(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdScale(f.Factory, out)
64391fc2
 	cmd.Short = "Change the number of pods in a deployment"
4d2d5534
 	cmd.Long = scaleLong
 	cmd.Example = fmt.Sprintf(scaleExample, fullName)
442adafd
 	cmd.ValidArgs = append(cmd.ValidArgs, "deploymentconfig")
d49bc6ea
 	return cmd
 }
633b1b93
 
6267dded
 var (
 	autoScaleLong = templates.LongDesc(`
 		Autoscale a deployment config or replication controller.
c4a51c18
 
6267dded
 		Looks up a deployment config or replication controller by name and creates an autoscaler that uses
 		this deployment config or replication controller as a reference. An autoscaler can automatically
 		increase or decrease number of pods deployed within the system as needed.`)
c4a51c18
 
6267dded
 	autoScaleExample = templates.Examples(`
 		# Auto scale a deployment config "foo", with the number of pods between 2 to
 		# 10, target CPU utilization at a default value that server applies:
 	  %[1]s autoscale dc/foo --min=2 --max=10
c4a51c18
 
6267dded
 	  # Auto scale a replication controller "foo", with the number of pods between
 		# 1 to 5, target CPU utilization at 80%%
 	  %[1]s autoscale rc/foo --max=5 --cpu-percent=80`)
c4a51c18
 )
 
 // NewCmdAutoscale is a wrapper for the Kubernetes cli autoscale command
 func NewCmdAutoscale(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdAutoscale(f.Factory, out)
442adafd
 	cmd.Short = "Autoscale a deployment config, deployment, replication controller, or replica set"
c4a51c18
 	cmd.Long = autoScaleLong
 	cmd.Example = fmt.Sprintf(autoScaleExample, fullName)
442adafd
 	cmd.ValidArgs = append(cmd.ValidArgs, "deploymentconfig")
c4a51c18
 	return cmd
 }
 
6267dded
 var (
 	runLong = templates.LongDesc(`
 		Create and run a particular image, possibly replicated
633b1b93
 
6267dded
 		Creates a deployment config to manage the created container(s). You can choose to run in the
 		foreground for an interactive container execution.  You may pass 'run/v1' to
 		--generator to create a replication controller instead of a deployment config.`)
745b8da5
 
6267dded
 	runExample = templates.Examples(`
 		# Starts a single instance of nginx.
 	  %[1]s run nginx --image=nginx
745b8da5
 
6267dded
 	  # Starts a replicated instance of nginx.
 	  %[1]s run nginx --image=nginx --replicas=5
745b8da5
 
6267dded
 	  # Dry run. Print the corresponding API objects without creating them.
 	  %[1]s run nginx --image=nginx --dry-run
745b8da5
 
6267dded
 	  # Start a single instance of nginx, but overload the spec of the replication
 	  # controller with a partial set of values parsed from JSON.
 	  %[1]s run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { ... } }'
745b8da5
 
3dd75654
   # Start a single instance of nginx and keep it in the foreground, don't restart it if it exits.
d3851ba5
   %[1]s run -i --tty nginx --image=nginx --restart=Never
745b8da5
 
d3851ba5
   # Start the nginx container using the default command, but use custom
   # arguments (arg1 .. argN) for that command.
   %[1]s run nginx --image=nginx -- <arg1> <arg2> ... <argN>
745b8da5
 
d3851ba5
   # Start the nginx container using a different command and custom arguments
6267dded
   %[1]s run nginx --image=nginx --command -- <cmd> <arg1> ... <argN>`)
745b8da5
 )
 
 // NewCmdRun is a wrapper for the Kubernetes cli run command
 func NewCmdRun(fullName string, f *clientcmd.Factory, in io.Reader, out, errout io.Writer) *cobra.Command {
15335d51
 	opts := &kcmd.RunOptions{DefaultRestartAlwaysGenerator: "deploymentconfig/v1", DefaultGenerator: kcmdutil.RunPodV1GeneratorName}
997787d8
 	cmd := kcmd.NewCmdRunWithOptions(f.Factory, opts, in, out, errout)
745b8da5
 	cmd.Long = runLong
 	cmd.Example = fmt.Sprintf(runExample, fullName)
b3e77d8d
 	cmd.SuggestFor = []string{"image"}
9e518a80
 	cmd.Flags().Set("generator", "")
15335d51
 	cmd.Flag("generator").Usage = "The name of the API generator to use.  Default is 'deploymentconfig/v1' if --restart=Always, otherwise the default is 'run-pod/v1'."
9e518a80
 	cmd.Flag("generator").DefValue = ""
4d8fc679
 	cmd.Flag("generator").Changed = false
745b8da5
 	return cmd
 }
 
6267dded
 var (
 	attachLong = templates.LongDesc(`
 		Attach to a running container
745b8da5
 
6267dded
 		Attach the current shell to a remote container, returning output or setting up a full
 		terminal session. Can be used to debug containers and invoke interactive commands.`)
745b8da5
 
6267dded
 	attachExample = templates.Examples(`
 		# Get output from running pod 123456-7890, using the first container by default
 	  %[1]s attach 123456-7890
745b8da5
 
6267dded
 	  # Get output from ruby-container from pod 123456-7890
 	  %[1]s attach 123456-7890 -c ruby-container
745b8da5
 
6267dded
 	  # Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod 123456-780
 	  # and sends stdout/stderr from 'bash' back to the client
 	  %[1]s attach 123456-7890 -c ruby-container -i -t`)
745b8da5
 )
 
 // NewCmdAttach is a wrapper for the Kubernetes cli attach command
 func NewCmdAttach(fullName string, f *clientcmd.Factory, in io.Reader, out, errout io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdAttach(f.Factory, in, out, errout)
 	cmd.Long = attachLong
 	cmd.Example = fmt.Sprintf(attachExample, fullName)
 	return cmd
 }
 
6267dded
 var (
 	annotateLong = templates.LongDesc(`
 		Update the annotations on one or more resources
745b8da5
 
6267dded
 		An annotation is a key/value pair that can hold larger (compared to a label),
 		and possibly not human-readable, data. It is intended to store non-identifying
 		auxiliary data, especially data manipulated by tools and system extensions. If
 		--overwrite is true, then existing annotations can be overwritten, otherwise
 		attempting to overwrite an annotation will result in an error. If
 		--resource-version is specified, then updates will use this resource version,
 		otherwise the existing resource-version will be used.
745b8da5
 
6267dded
 		Run '%[1]s types' for a list of valid resources.`)
745b8da5
 
6267dded
 	annotateExample = templates.Examples(`
 		# Update pod 'foo' with the annotation 'description' and the value 'my frontend'.
 	  # If the same annotation is set multiple times, only the last value will be applied
 	  %[1]s annotate pods foo description='my frontend'
745b8da5
 
6267dded
 	  # Update pod 'foo' with the annotation 'description' and the value
 	  # 'my frontend running nginx', overwriting any existing value.
 	  %[1]s annotate --overwrite pods foo description='my frontend running nginx'
745b8da5
 
6267dded
 	  # Update all pods in the namespace
 	  %[1]s annotate pods --all description='my frontend running nginx'
745b8da5
 
6267dded
 	  # Update pod 'foo' only if the resource is unchanged from version 1.
 	  %[1]s annotate pods foo description='my frontend running nginx' --resource-version=1
745b8da5
 
6267dded
 	  # Update pod 'foo' by removing an annotation named 'description' if it exists.
 	  # Does not require the --overwrite flag.
 	  %[1]s annotate pods foo description-`)
745b8da5
 )
 
 // NewCmdAnnotate is a wrapper for the Kubernetes cli annotate command
 func NewCmdAnnotate(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdAnnotate(f.Factory, out)
 	cmd.Long = fmt.Sprintf(annotateLong, fullName)
 	cmd.Example = fmt.Sprintf(annotateExample, fullName)
 	return cmd
 }
 
6267dded
 var (
 	labelLong = templates.LongDesc(`
 		Update the labels on one or more resources
745b8da5
 
6267dded
 		A valid label value is consisted of letters and/or numbers with a max length of %[1]d
 		characters. If --overwrite is true, then existing labels can be overwritten, otherwise
 		attempting to overwrite a label will result in an error. If --resource-version is
 		specified, then updates will use this resource version, otherwise the existing
 		resource-version will be used.`)
633b1b93
 
6267dded
 	labelExample = templates.Examples(`
 		# Update pod 'foo' with the label 'unhealthy' and the value 'true'.
 	  %[1]s label pods foo unhealthy=true
633b1b93
 
6267dded
 	  # Update pod 'foo' with the label 'status' and the value 'unhealthy', overwriting any existing value.
 	  %[1]s label --overwrite pods foo status=unhealthy
633b1b93
 
6267dded
 	  # Update all pods in the namespace
 	  %[1]s label pods --all status=unhealthy
633b1b93
 
6267dded
 	  # Update pod 'foo' only if the resource is unchanged from version 1.
 	  %[1]s label pods foo status=unhealthy --resource-version=1
633b1b93
 
6267dded
 	  # Update pod 'foo' by removing a label named 'bar' if it exists.
 	  # Does not require the --overwrite flag.
 	  %[1]s label pods foo bar-`)
633b1b93
 )
 
 // NewCmdLabel is a wrapper for the Kubernetes cli label command
 func NewCmdLabel(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdLabel(f.Factory, out)
987aca9b
 	cmd.Long = fmt.Sprintf(labelLong, kvalidation.LabelValueMaxLength)
633b1b93
 	cmd.Example = fmt.Sprintf(labelExample, fullName)
 	return cmd
 }
987aca9b
 
6267dded
 var (
 	applyLong = templates.LongDesc(`
 		Apply a configuration to a resource by filename or stdin.
987aca9b
 
6267dded
 		JSON and YAML formats are accepted.`)
987aca9b
 
6267dded
 	applyExample = templates.Examples(`
 		# Apply the configuration in pod.json to a pod.
 		%[1]s apply -f ./pod.json
987aca9b
 
6267dded
 		# Apply the JSON passed into stdin to a pod.
 		cat pod.json | %[1]s apply -f -`)
987aca9b
 )
 
25c24210
 // NewCmdApply is a wrapper for the Kubernetes cli apply command
987aca9b
 func NewCmdApply(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdApply(f.Factory, out)
 	cmd.Long = applyLong
 	cmd.Example = fmt.Sprintf(applyExample, fullName)
 	return cmd
 }
 
6267dded
 var (
 	explainLong = templates.LongDesc(`
 		Documentation of resources.
987aca9b
 
6267dded
 		Possible resource types include: pods (po), services (svc),
 		replicationcontrollers (rc), nodes (no), events (ev), componentstatuses (cs),
 		limitranges (limits), persistentvolumes (pv), persistentvolumeclaims (pvc),
 		resourcequotas (quota), namespaces (ns) or endpoints (ep).`)
987aca9b
 
6267dded
 	explainExample = templates.Examples(`
 		# Get the documentation of the resource and its fields
 		%[1]s explain pods
987aca9b
 
6267dded
 		# Get the documentation of a specific field of a resource
 		%[1]s explain pods.spec.containers`)
987aca9b
 )
 
25c24210
 // NewCmdExplain is a wrapper for the Kubernetes cli explain command
1f74d3fb
 func NewCmdExplain(fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdExplain(f.Factory, out, errOut)
987aca9b
 	cmd.Long = explainLong
 	cmd.Example = fmt.Sprintf(explainExample, fullName)
 	return cmd
 }
 
6267dded
 var (
 	convertLong = templates.LongDesc(`
 		Convert config files between different API versions. Both YAML
 		and JSON formats are accepted.
 
 		The command takes filename, directory, or URL as input, and convert it into format
 		of version specified by --output-version flag. If target version is not specified or
 		not supported, convert to latest version.
987aca9b
 
6267dded
 		The default output will be printed to stdout in YAML format. One can use -o option
 		to change to output destination.`)
987aca9b
 
6267dded
 	convertExample = templates.Examples(`
 		# Convert 'pod.yaml' to latest version and print to stdout.
 	  %[1]s convert -f pod.yaml
987aca9b
 
6267dded
 	  # Convert the live state of the resource specified by 'pod.yaml' to the latest version
 	  # and print to stdout in json format.
 	  %[1]s convert -f pod.yaml --local -o json
987aca9b
 
6267dded
 	  # Convert all files under current directory to latest version and create them all.
 	  %[1]s convert -f . | %[1]s create -f -`)
987aca9b
 )
 
25c24210
 // NewCmdConvert is a wrapper for the Kubernetes cli convert command
987aca9b
 func NewCmdConvert(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdConvert(f.Factory, out)
 	cmd.Long = convertLong
 	cmd.Example = fmt.Sprintf(convertExample, fullName)
 	return cmd
 }
ca882b60
 
6267dded
 var (
 	editLong = templates.LongDesc(`
 		Edit a resource from the default editor
ca882b60
 
6267dded
 		The edit command allows you to directly edit any API resource you can retrieve via the
 		command line tools. It will open the editor defined by your OC_EDITOR, or EDITOR environment
 		variables, or fall back to 'vi' for Linux or 'notepad' for Windows. You can edit multiple
 		objects, although changes are applied one at a time. The command accepts filenames as well
 		as command line arguments, although the files you point to must be previously saved versions
 		of resources.
ca882b60
 
6267dded
 		The files to edit will be output in the default API version, or a version specified
 		by --output-version. The default format is YAML - if you would like to edit in JSON
 		pass -o json. The flag --windows-line-endings can be used to force Windows line endings,
 		otherwise the default for your operating system will be used.
ca882b60
 
6267dded
 		In the event an error occurs while updating, a temporary file will be created on disk
 		that contains your unapplied changes. The most common error when updating a resource
 		is another editor changing the resource on the server. When this occurs, you will have
 		to apply your changes to the newer version of the resource, or update your temporary
 		saved copy to include the latest resource version.`)
ca882b60
 
6267dded
 	editExample = templates.Examples(`
 		# Edit the service named 'docker-registry':
 	  %[1]s edit svc/docker-registry
ca882b60
 
6267dded
 	  # Edit the DeploymentConfig named 'my-deployment':
 	  %[1]s edit dc/my-deployment
ca882b60
 
6267dded
 	  # Use an alternative editor
 	  OC_EDITOR="nano" %[1]s edit dc/my-deployment
ca882b60
 
6267dded
 	  # Edit the service 'docker-registry' in JSON using the v1 API format:
 	  %[1]s edit svc/docker-registry --output-version=v1 -o json`)
ca882b60
 )
 
25c24210
 // NewCmdEdit is a wrapper for the Kubernetes cli edit command
71e8da8f
 func NewCmdEdit(fullName string, f *clientcmd.Factory, out, errout io.Writer) *cobra.Command {
 	cmd := kcmd.NewCmdEdit(f.Factory, out, errout)
ca882b60
 	cmd.Long = editLong
 	cmd.Example = fmt.Sprintf(editExample, fullName)
 	return cmd
 }
bfa9bb91
 
6267dded
 var (
 	configLong = templates.LongDesc(`
 		Manage the client config files
bfa9bb91
 
6267dded
 		The client stores configuration in the current user's home directory (under the .kube directory as
 		config). When you login the first time, a new config file is created, and subsequent project changes with the
 		'project' command will set the current context. These subcommands allow you to manage the config directly.
bfa9bb91
 
6267dded
 		Reference: https://github.com/kubernetes/kubernetes/blob/master/docs/user-guide/kubeconfig-file.md`)
bfa9bb91
 
6267dded
 	configExample = templates.Examples(`
 		# Change the config context to use
 	  %[1]s %[2]s use-context my-context
bfa9bb91
 
6267dded
 	  # Set the value of a config preference
 	  %[1]s %[2]s set preferences.some true`)
bfa9bb91
 )
 
25c24210
 // NewCmdConfig is a wrapper for the Kubernetes cli config command
bfa9bb91
 func NewCmdConfig(parentName, name string) *cobra.Command {
37b6c5f1
 	pathOptions := &kclientcmd.PathOptions{
bfa9bb91
 		GlobalFile:       cmdconfig.RecommendedHomeFile,
 		EnvVar:           cmdconfig.OpenShiftConfigPathEnvVar,
 		ExplicitFileFlag: cmdconfig.OpenShiftConfigFlagName,
 
 		GlobalFileSubpath: cmdconfig.OpenShiftConfigHomeDirFileName,
 
 		LoadingRules: cmdconfig.NewOpenShiftClientConfigLoadingRules(),
 	}
 	pathOptions.LoadingRules.DoNotResolvePaths = true
 
 	cmd := config.NewCmdConfig(pathOptions, os.Stdout)
 	cmd.Short = "Change configuration files for the client"
 	cmd.Long = configLong
 	cmd.Example = fmt.Sprintf(configExample, parentName, name)
6267dded
 	// normalize long descs and examples
 	// TODO remove when normalization is moved upstream
 	templates.NormalizeAll(cmd)
bfa9bb91
 	adjustCmdExamples(cmd, parentName, name)
 	return cmd
 }