Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ echo "templates: ok"
[ "$(openshift cli get --help 2>&1 | grep 'Display one or many resources')" ]
[ "$(openshift kubectl get --help 2>&1 | grep 'Display one or many resources')" ]
[ "$(openshift start --help 2>&1 | grep 'Start an OpenShift server')" ]
[ "$(osc get --help 2>&1 | grep 'osc')" ]

# help for given command through help command must be consistent
[ "$(osc help get 2>&1 | grep 'Display one or many resources')" ]
[ "$(openshift cli help get 2>&1 | grep 'Display one or many resources')" ]
[ "$(openshift kubectl help get 2>&1 | grep 'Display one or many resources')" ]
[ "$(openshift help start 2>&1 | grep 'Start an OpenShift server')" ]
[ "$(openshift cli help update 2>&1 | grep 'openshift')" ]

# runnable commands with required flags must error consistently
[ "$(osc get 2>&1 | grep 'you must provide one or more resources')" ]
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ func NewCommandCLI(name, fullName string) *cobra.Command {
cmds.AddCommand(cmd.NewCmdBuildLogs(f, out))
cmds.AddCommand(cmd.NewCmdRollback(name, "rollback", f, out))

cmds.AddCommand(f.NewCmdGet(out))
cmds.AddCommand(cmd.NewCmdGet(fullName, f, out))
cmds.AddCommand(f.NewCmdDescribe(out))
// Deprecate 'osc apply' with 'osc create' command.
cmds.AddCommand(applyToCreate(f.NewCmdCreate(out)))
cmds.AddCommand(applyToCreate(cmd.NewCmdCreate(fullName, f, out)))
cmds.AddCommand(cmd.NewCmdProcess(f, out))
cmds.AddCommand(f.NewCmdUpdate(out))
cmds.AddCommand(f.NewCmdDelete(out))
cmds.AddCommand(cmd.NewCmdUpdate(fullName, f, out))
cmds.AddCommand(cmd.NewCmdDelete(fullName, f, out))

cmds.AddCommand(f.NewCmdLog(out))
cmds.AddCommand(cmd.NewCmdLog(fullName, f, out))
cmds.AddCommand(f.NewCmdProxy(out))

cmds.AddCommand(kubecmd.NewCmdNamespace(out))
Expand Down
123 changes: 123 additions & 0 deletions pkg/cmd/cli/cmd/wrappers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package cmd

import (
"fmt"
"io"

"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/cmd/util/clientcmd"
)

func NewCmdGet(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
cmd := f.NewCmdGet(out)
longDesc := `Display one or many resources.

Possible resources include builds, buildConfigs, services, pods, etc.

Examples:

# List all pods in ps output format.
$ %[1]s get pods

# List a single replication controller with specified ID in ps output format.
$ %[1]s get replicationController 1234-56-7890-234234-456456

# List a single pod in JSON output format.
$ %[1]s get -o json pod 1234-56-7890-234234-456456

# Return only the status value of the specified pod.
$ %[1]s get -o template pod 1234-56-7890-234234-456456 --template={{.currentState.status}}
`
cmd.Long = fmt.Sprintf(longDesc, fullName)
return cmd
}

func NewCmdUpdate(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
cmd := f.NewCmdUpdate(out)
longDesc := `Update a resource by filename or stdin.

JSON and YAML formats are accepted.

Examples:

# Update a pod using the data in pod.json.
$ %[1]s update -f pod.json

# Update a pod based on the JSON passed into stdin.
$ cat pod.json | %[1]s update -f -

# Update a pod by downloading it, applying the patch, then updating. Requires apiVersion be specified.
$ %[1]s update pods my-pod --patch='{ "apiVersion": "v1beta1", "desiredState": { "manifest": [{ "cpu": 100 }]}}'
`
cmd.Long = fmt.Sprintf(longDesc, fullName)
return cmd
}

func NewCmdDelete(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
cmd := f.NewCmdDelete(out)
longDesc := `Delete a resource by filename, stdin, resource and ID, or by resources and label selector.

JSON and YAML formats are accepted.

If both a filename and command line arguments are passed, the command line
arguments are used and the filename is ignored.

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.

Examples:

# Delete a pod using the type and ID specified in pod.json.
$ %[1]s delete -f pod.json

# Delete a pod based on the type and ID in the JSON passed into stdin.
$ cat pod.json | %[1]s delete -f -

# Delete pods and services with label name=myLabel.
$ %[1]s delete pods,services -l name=myLabel

# Delete a pod with ID 1234-56-7890-234234-456456.
$ %[1]s delete pod 1234-56-7890-234234-456456

# Delete all pods
$ %[1]s delete pods --all
`
cmd.Long = fmt.Sprintf(longDesc, fullName)
return cmd
}

func NewCmdLog(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
cmd := f.NewCmdLog(out)
longDesc := `Print the logs for a container in a pod. If the pod has only one container, the container name is optional.

Examples:

# Returns snapshot of ruby-container logs from pod 123456-7890.
$ %[1]s log 123456-7890 ruby-container

# Starts streaming of ruby-container logs from pod 123456-7890.
$ %[1]s log -f 123456-7890 ruby-container
`
cmd.Long = fmt.Sprintf(longDesc, fullName)
return cmd
}

func NewCmdCreate(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
cmd := f.NewCmdCreate(out)
longDesc := `Create a resource by filename or stdin.

JSON and YAML formats are accepted.

Examples:

# Create a pod using the data in pod.json.
$ %[1]s create -f pod.json

# Create a pod based on the JSON passed into stdin.
$ cat pod.json | %[1]s create -f -
`
cmd.Long = fmt.Sprintf(longDesc, fullName)
return cmd
}