From 0c5b8196b07a1e819e83f8505979ddc88ab85af3 Mon Sep 17 00:00:00 2001 From: kargakis Date: Sun, 8 Mar 2015 13:58:19 +0100 Subject: [PATCH] Address some cli usage msg inconsistencies --- pkg/cmd/cli/cli.go | 14 +++++++------- pkg/cmd/cli/cmd/buildlogs.go | 17 ++++++++++------- pkg/cmd/cli/cmd/cancelbuild.go | 28 +++++++++++++++------------- pkg/cmd/cli/cmd/newapp.go | 12 ++++++------ pkg/cmd/cli/cmd/process.go | 24 +++++++++++++----------- pkg/cmd/cli/cmd/rollback.go | 12 ++++++------ pkg/cmd/cli/cmd/startbuild.go | 20 +++++++++++--------- 7 files changed, 68 insertions(+), 59 deletions(-) diff --git a/pkg/cmd/cli/cli.go b/pkg/cmd/cli/cli.go index 0cd6257f3b7c..174d4bc6f807 100644 --- a/pkg/cmd/cli/cli.go +++ b/pkg/cmd/cli/cli.go @@ -61,23 +61,23 @@ func NewCommandCLI(name, fullName string) *cobra.Command { cmds.SetUsageTemplate(templates.CliUsageTemplate()) cmds.SetHelpTemplate(templates.CliHelpTemplate()) - cmds.AddCommand(cmd.NewCmdNewApplication(f, out)) - cmds.AddCommand(cmd.NewCmdStartBuild(f, out)) - cmds.AddCommand(cmd.NewCmdCancelBuild(f, out)) - cmds.AddCommand(cmd.NewCmdBuildLogs(f, out)) - cmds.AddCommand(cmd.NewCmdRollback(name, "rollback", f, out)) + cmds.AddCommand(cmd.NewCmdNewApplication(fullName, f, out)) + cmds.AddCommand(cmd.NewCmdStartBuild(fullName, f, out)) + cmds.AddCommand(cmd.NewCmdCancelBuild(fullName, f, out)) + cmds.AddCommand(cmd.NewCmdBuildLogs(fullName, f, out)) + cmds.AddCommand(cmd.NewCmdRollback(fullName, f, out)) cmds.AddCommand(cmd.NewCmdGet(fullName, f, out)) cmds.AddCommand(f.NewCmdDescribe(out)) // Deprecate 'osc apply' with 'osc create' command. cmds.AddCommand(applyToCreate(cmd.NewCmdCreate(fullName, f, out))) - cmds.AddCommand(cmd.NewCmdProcess(f, out)) + cmds.AddCommand(cmd.NewCmdProcess(fullName, f, out)) cmds.AddCommand(cmd.NewCmdUpdate(fullName, f, out)) cmds.AddCommand(cmd.NewCmdDelete(fullName, f, out)) cmds.AddCommand(cmd.NewCmdLog(fullName, f, out)) cmds.AddCommand(f.NewCmdProxy(out)) cmds.AddCommand(kubecmd.NewCmdNamespace(out)) cmds.AddCommand(cmd.NewCmdOptions(f, out)) - cmds.AddCommand(version.NewVersionCommand(name)) + cmds.AddCommand(version.NewVersionCommand(fullName)) return cmds } diff --git a/pkg/cmd/cli/cmd/buildlogs.go b/pkg/cmd/cli/cmd/buildlogs.go index fca3b6caeb10..911ec2d3e6bd 100644 --- a/pkg/cmd/cli/cmd/buildlogs.go +++ b/pkg/cmd/cli/cmd/buildlogs.go @@ -1,6 +1,7 @@ package cmd import ( + "fmt" "io" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" @@ -9,19 +10,21 @@ import ( "github.com/openshift/origin/pkg/cmd/util/clientcmd" ) -func NewCmdBuildLogs(f *clientcmd.Factory, out io.Writer) *cobra.Command { - cmd := &cobra.Command{ - Use: "build-logs ", - Short: "Show container logs from the build container", - Long: `Retrieve logs from the containers where the build occured +const buildLogsLongDesc = `Retrieve logs from the containers where the build occured NOTE: This command may be moved in the future. Examples: # Stream logs from container to stdout - $ osc build-logs 566bed879d2d -`, + $ %[1]s build-logs 566bed879d2d +` + +func NewCmdBuildLogs(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command { + cmd := &cobra.Command{ + Use: "build-logs ", + Short: "Show container logs from the build container", + Long: fmt.Sprintf(buildLogsLongDesc, fullName), Run: func(cmd *cobra.Command, args []string) { if len(args) != 1 { usageError(cmd, " is a required argument") diff --git a/pkg/cmd/cli/cmd/cancelbuild.go b/pkg/cmd/cli/cmd/cancelbuild.go index cac512fafddc..3690b60238ed 100644 --- a/pkg/cmd/cli/cmd/cancelbuild.go +++ b/pkg/cmd/cli/cmd/cancelbuild.go @@ -14,28 +14,30 @@ import ( "github.com/openshift/origin/pkg/cmd/util/clientcmd" ) -// NewCmdCancelBuild manages a build cancelling event. -// To cancel a build its name has to be specified, and two options -// are available: displaying logs and restarting. -func NewCmdCancelBuild(f *clientcmd.Factory, out io.Writer) *cobra.Command { - - cmd := &cobra.Command{ - Use: "cancel-build ", - Short: "Cancel a pending or running build.", - Long: ` +const cancelBuildLongDesc = ` Cancels a pending or running build. Examples: # Cancel the build with the given name - $ osc cancel-build 1da32cvq + $ %[1]s cancel-build 1da32cvq # Cancel the named build and print the build logs - $ osc cancel-build 1da32cvq --dump-logs + $ %[1]s cancel-build 1da32cvq --dump-logs # Cancel the named build and create a new one with the same parameters - $ osc cancel-build 1da32cvq --restart -`, + $ %[1]s cancel-build 1da32cvq --restart +` + +// NewCmdCancelBuild manages a build cancelling event. +// To cancel a build its name has to be specified, and two options +// are available: displaying logs and restarting. +func NewCmdCancelBuild(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command { + + cmd := &cobra.Command{ + Use: "cancel-build ", + Short: "Cancel a pending or running build.", + Long: fmt.Sprintf(cancelBuildLongDesc, fullName), Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 || len(args[0]) == 0 { diff --git a/pkg/cmd/cli/cmd/newapp.go b/pkg/cmd/cli/cmd/newapp.go index 24c8dba4b369..f68a137c803a 100644 --- a/pkg/cmd/cli/cmd/newapp.go +++ b/pkg/cmd/cli/cmd/newapp.go @@ -23,7 +23,7 @@ type usage interface { UsageError(commandName string) string } -const longNewAppDescription = ` +const newAppLongDesc = ` Create a new application in OpenShift by specifying source code, templates, and/or images. This command will try to build up the components of an application using images or code @@ -36,13 +36,13 @@ configuration, and a service will be hookup up to the first public port of the a Examples: # Try to create an application based on the source code in the current directory - $ osc new-app . + $ %[1]s new-app . $ Use the public Docker Hub MySQL image to create an app - $ osc new-app mysql + $ %[1]s new-app mysql # Use a MySQL image in a private registry to create an app - $ osc new-app myregistry.com/mycompany/mysql + $ %[1]s new-app myregistry.com/mycompany/mysql If you specify source code, you may need to run a build with 'start-build' after the application is created. @@ -50,14 +50,14 @@ application is created. ALPHA: This command is under active development - feedback is appreciated. ` -func NewCmdNewApplication(f *clientcmd.Factory, out io.Writer) *cobra.Command { +func NewCmdNewApplication(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command { config := newcmd.NewAppConfig() helper := dockerutil.NewHelper() cmd := &cobra.Command{ Use: "new-app [--code=]", Short: "Create a new application", - Long: longNewAppDescription, + Long: fmt.Sprintf(newAppLongDesc, fullName), Run: func(c *cobra.Command, args []string) { namespace, err := f.DefaultNamespace(c) diff --git a/pkg/cmd/cli/cmd/process.go b/pkg/cmd/cli/cmd/process.go index 24c15aca4b4f..f345edf9553d 100644 --- a/pkg/cmd/cli/cmd/process.go +++ b/pkg/cmd/cli/cmd/process.go @@ -1,7 +1,7 @@ package cmd import ( - "errors" + "fmt" "io" "strings" @@ -36,23 +36,25 @@ func injectUserVars(cmd *cobra.Command, t *api.Template) { } } -// NewCmdProcess returns a 'process' command -func NewCmdProcess(f *clientcmd.Factory, out io.Writer) *cobra.Command { - cmd := &cobra.Command{ - Use: "process -f filename", - Short: "Process template into list of resources", - Long: `Process template into a list of resources specified in filename or stdin +const processLongDesc = `Process template into a list of resources specified in filename or stdin JSON and YAML formats are accepted. Examples: # Convert template.json into resource list - $ osc process -f template.json + $ %[1]s process -f template.json # Convert template.json into resource list - $ cat template.json | osc process -f - -`, + $ cat template.json | %[1]s process -f - +` + +// NewCmdProcess returns a 'process' command +func NewCmdProcess(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command { + cmd := &cobra.Command{ + Use: "process -f filename", + Short: "Process template into list of resources", + Long: fmt.Sprintf(processLongDesc, fullName), Run: func(cmd *cobra.Command, args []string) { filename := cmdutil.GetFlagString(cmd, "filename") if len(filename) == 0 { @@ -74,7 +76,7 @@ Examples: templateObj, ok := obj.(*api.Template) if !ok { - checkErr(errors.New("Unable to the convert input to the Template")) + checkErr(fmt.Errorf("cannot convert input to Template")) } client, _, err := f.Clients(cmd) diff --git a/pkg/cmd/cli/cmd/rollback.go b/pkg/cmd/cli/cmd/rollback.go index 99f8a966c1d7..868732af2d75 100644 --- a/pkg/cmd/cli/cmd/rollback.go +++ b/pkg/cmd/cli/cmd/rollback.go @@ -33,16 +33,16 @@ will be. Examples: # Perform a rollback - $ %[1]s %[2]s deployment-1 + $ %[1]s rollback deployment-1 # See what the rollback will look like, but don't perform the rollback - $ %[1]s %[2]s deployment-1 --dry-run + $ %[1]s rollback deployment-1 --dry-run # Perform the rollback manually by piping the JSON of the new config back to %[1]s - $ %[1]s %[2]s deployment-1 --output=json | %[1]s update deploymentConfigs deployment -f - + $ %[1]s rollback deployment-1 --output=json | %[1]s update deploymentConfigs deployment -f - ` -func NewCmdRollback(parentName string, name string, f *clientcmd.Factory, out io.Writer) *cobra.Command { +func NewCmdRollback(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command { rollback := &deployapi.DeploymentConfigRollback{ Spec: deployapi.DeploymentConfigRollbackSpec{ IncludeTemplate: true, @@ -50,9 +50,9 @@ func NewCmdRollback(parentName string, name string, f *clientcmd.Factory, out io } cmd := &cobra.Command{ - Use: fmt.Sprintf("%s ", name), + Use: "rollback ", Short: "Revert part of an application back to a previous deployment.", - Long: fmt.Sprintf(rollbackLongDesc, parentName, name), + Long: fmt.Sprintf(rollbackLongDesc, fullName), Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 || len(args[0]) == 0 { usageError(cmd, "A deployment name is required.") diff --git a/pkg/cmd/cli/cmd/startbuild.go b/pkg/cmd/cli/cmd/startbuild.go index ad658f6038a9..778b3a039ed8 100644 --- a/pkg/cmd/cli/cmd/startbuild.go +++ b/pkg/cmd/cli/cmd/startbuild.go @@ -15,11 +15,7 @@ import ( "github.com/openshift/origin/pkg/cmd/util/clientcmd" ) -func NewCmdStartBuild(f *clientcmd.Factory, out io.Writer) *cobra.Command { - cmd := &cobra.Command{ - Use: "start-build (|--from-build=)", - Short: "Starts a new build from existing build or buildConfig", - Long: ` +const startBuildLongDesc = ` Manually starts build from existing build or buildConfig NOTE: This command is experimental and is subject to change in the future. @@ -27,14 +23,20 @@ NOTE: This command is experimental and is subject to change in the future. Examples: # Starts build from build configuration matching the name "3bd2ug53b" - $ osc start-build 3bd2ug53b + $ %[1]s start-build 3bd2ug53b # Starts build from build matching the name "3bd2ug53b" - $ osc start-build --from-build=3bd2ug53b + $ %[1]s start-build --from-build=3bd2ug53b # Starts build from build configuration matching the name "3bd2ug53b" and watches the logs until the build completes or fails - $ osc start-build 3bd2ug53b --follow -`, + $ %[1]s start-build 3bd2ug53b --follow +` + +func NewCmdStartBuild(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command { + cmd := &cobra.Command{ + Use: "start-build (|--from-build=)", + Short: "Starts a new build from existing build or buildConfig", + Long: fmt.Sprintf(startBuildLongDesc, fullName), Run: func(cmd *cobra.Command, args []string) { buildName := cmdutil.GetFlagString(cmd, "from-build") follow := cmdutil.GetFlagBool(cmd, "follow")