From bcf8d9bbf9c486adee68d316cea130691d4bc517 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Fri, 29 Jul 2016 12:57:19 -0400 Subject: [PATCH] update hardcoded "oc" cmd suggestion in cmd output `oc` status output contains suggestions for "oc" commands with "oc" hardcoded, rather than being dynamic to the current root cmd being used --- pkg/cmd/cli/cmd/status.go | 10 ++++++++-- pkg/cmd/cli/describe/projectstatus.go | 13 ++++++++----- pkg/cmd/cli/describe/projectstatus_test.go | 2 +- test/cmd/basicresources.sh | 2 ++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/cli/cmd/status.go b/pkg/cmd/cli/cmd/status.go index b740d0853808..7b04cc33f47f 100644 --- a/pkg/cmd/cli/cmd/status.go +++ b/pkg/cmd/cli/cmd/status.go @@ -67,7 +67,7 @@ func NewCmdStatus(name, baseCLIName, fullName string, f *clientcmd.Factory, out Long: fmt.Sprintf(statusLong, baseCLIName), Example: fmt.Sprintf(statusExample, fullName), Run: func(cmd *cobra.Command, args []string) { - err := opts.Complete(f, cmd, args, out) + err := opts.Complete(f, cmd, baseCLIName, args, out) kcmdutil.CheckErr(err) if err := opts.Validate(); err != nil { @@ -87,7 +87,7 @@ func NewCmdStatus(name, baseCLIName, fullName string, f *clientcmd.Factory, out } // Complete completes the options for the Openshift cli status command. -func (o *StatusOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string, out io.Writer) error { +func (o *StatusOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, baseCLIName string, args []string, out io.Writer) error { if len(args) > 0 { return kcmdutil.UsageError(cmd, "no arguments should be provided") } @@ -116,12 +116,18 @@ func (o *StatusOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args o.namespace = namespace } + if baseCLIName == "" { + baseCLIName = "oc" + } + o.describer = &describe.ProjectStatusDescriber{ K: kclient, C: client, Server: config.Host, Suggest: o.verbose, + CommandBaseName: baseCLIName, + // TODO: Remove these and reference them inside the markers using constants. LogsCommandName: o.logsCommandName, SecurityPolicyCommandFormat: o.securityPolicyCommandFormat, diff --git a/pkg/cmd/cli/describe/projectstatus.go b/pkg/cmd/cli/describe/projectstatus.go index 68be867e5605..fb7b786f4b62 100644 --- a/pkg/cmd/cli/describe/projectstatus.go +++ b/pkg/cmd/cli/describe/projectstatus.go @@ -52,6 +52,9 @@ type ProjectStatusDescriber struct { Server string Suggest bool + // root command used when calling this command + CommandBaseName string + LogsCommandName string SecurityPolicyCommandFormat string SetProbeCommandName string @@ -311,20 +314,20 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error switch { case !d.Suggest && len(errorMarkers) > 0 && len(warningMarkers) > 0: - fmt.Fprintf(out, "%s and %s identified, use 'oc status -v' to see details.\n", errors, warnings) + fmt.Fprintf(out, "%s and %s identified, use '%[3]s status -v' to see details.\n", errors, warnings, d.CommandBaseName) case !d.Suggest && len(errorMarkers) > 0 && errorSuggestions > 0: - fmt.Fprintf(out, "%s identified, use 'oc status -v' to see details.\n", errors) + fmt.Fprintf(out, "%s identified, use '%[2]s status -v' to see details.\n", errors, d.CommandBaseName) case !d.Suggest && len(warningMarkers) > 0: - fmt.Fprintf(out, "%s identified, use 'oc status -v' to see details.\n", warnings) + fmt.Fprintf(out, "%s identified, use '%[2]s status -v' to see details.\n", warnings, d.CommandBaseName) case (len(services) == 0) && (len(standaloneDCs) == 0) && (len(standaloneImages) == 0): fmt.Fprintln(out, "You have no services, deployment configs, or build configs.") - fmt.Fprintln(out, "Run 'oc new-app' to create an application.") + fmt.Fprintf(out, "Run '%[1]s new-app' to create an application.\n", d.CommandBaseName) default: - fmt.Fprintln(out, "View details with 'oc describe /' or list everything with 'oc get all'.") + fmt.Fprintf(out, "View details with '%[1]s describe /' or list everything with '%[1]s get all'.\n", d.CommandBaseName) } return nil diff --git a/pkg/cmd/cli/describe/projectstatus_test.go b/pkg/cmd/cli/describe/projectstatus_test.go index 8f90212c4f6b..74e08a5f274a 100644 --- a/pkg/cmd/cli/describe/projectstatus_test.go +++ b/pkg/cmd/cli/describe/projectstatus_test.go @@ -347,7 +347,7 @@ func TestProjectStatus(t *testing.T) { o.Add(obj) } oc, kc := testclient.NewFixtureClients(o) - d := ProjectStatusDescriber{C: oc, K: kc, Server: "https://example.com:8443", Suggest: true, LogsCommandName: "oc logs -p", SecurityPolicyCommandFormat: "policycommand %s %s"} + d := ProjectStatusDescriber{C: oc, K: kc, Server: "https://example.com:8443", Suggest: true, CommandBaseName: "oc", LogsCommandName: "oc logs -p", SecurityPolicyCommandFormat: "policycommand %s %s"} out, err := d.Describe("example", "") if !test.ErrFn(err) { t.Errorf("%s: unexpected error: %v", k, err) diff --git a/test/cmd/basicresources.sh b/test/cmd/basicresources.sh index 5cc41ce64e77..6c3ab08cf550 100755 --- a/test/cmd/basicresources.sh +++ b/test/cmd/basicresources.sh @@ -76,6 +76,8 @@ os::test::junit::declare_suite_end os::test::junit::declare_suite_start "cmd/basicresources/status" os::cmd::expect_success_and_text 'openshift cli status -h' 'openshift cli describe buildConfig' os::cmd::expect_success_and_text 'oc status -h' 'oc describe buildConfig' +os::cmd::expect_success_and_text 'oc status' 'oc new-app' +os::cmd::expect_success_and_text 'openshift cli status' 'openshift cli new-app' echo "status help output: ok" os::test::junit::declare_suite_end