Browse code

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

juanvallejo authored on 2016/07/30 01:57:19
Showing 4 changed files
... ...
@@ -67,7 +67,7 @@ func NewCmdStatus(name, baseCLIName, fullName string, f *clientcmd.Factory, out
67 67
 		Long:    fmt.Sprintf(statusLong, baseCLIName),
68 68
 		Example: fmt.Sprintf(statusExample, fullName),
69 69
 		Run: func(cmd *cobra.Command, args []string) {
70
-			err := opts.Complete(f, cmd, args, out)
70
+			err := opts.Complete(f, cmd, baseCLIName, args, out)
71 71
 			kcmdutil.CheckErr(err)
72 72
 
73 73
 			if err := opts.Validate(); err != nil {
... ...
@@ -87,7 +87,7 @@ func NewCmdStatus(name, baseCLIName, fullName string, f *clientcmd.Factory, out
87 87
 }
88 88
 
89 89
 // Complete completes the options for the Openshift cli status command.
90
-func (o *StatusOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string, out io.Writer) error {
90
+func (o *StatusOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, baseCLIName string, args []string, out io.Writer) error {
91 91
 	if len(args) > 0 {
92 92
 		return kcmdutil.UsageError(cmd, "no arguments should be provided")
93 93
 	}
... ...
@@ -116,12 +116,18 @@ func (o *StatusOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args
116 116
 		o.namespace = namespace
117 117
 	}
118 118
 
119
+	if baseCLIName == "" {
120
+		baseCLIName = "oc"
121
+	}
122
+
119 123
 	o.describer = &describe.ProjectStatusDescriber{
120 124
 		K:       kclient,
121 125
 		C:       client,
122 126
 		Server:  config.Host,
123 127
 		Suggest: o.verbose,
124 128
 
129
+		CommandBaseName: baseCLIName,
130
+
125 131
 		// TODO: Remove these and reference them inside the markers using constants.
126 132
 		LogsCommandName:             o.logsCommandName,
127 133
 		SecurityPolicyCommandFormat: o.securityPolicyCommandFormat,
... ...
@@ -52,6 +52,9 @@ type ProjectStatusDescriber struct {
52 52
 	Server  string
53 53
 	Suggest bool
54 54
 
55
+	// root command used when calling this command
56
+	CommandBaseName string
57
+
55 58
 	LogsCommandName             string
56 59
 	SecurityPolicyCommandFormat string
57 60
 	SetProbeCommandName         string
... ...
@@ -311,20 +314,20 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
311 311
 
312 312
 		switch {
313 313
 		case !d.Suggest && len(errorMarkers) > 0 && len(warningMarkers) > 0:
314
-			fmt.Fprintf(out, "%s and %s identified, use 'oc status -v' to see details.\n", errors, warnings)
314
+			fmt.Fprintf(out, "%s and %s identified, use '%[3]s status -v' to see details.\n", errors, warnings, d.CommandBaseName)
315 315
 
316 316
 		case !d.Suggest && len(errorMarkers) > 0 && errorSuggestions > 0:
317
-			fmt.Fprintf(out, "%s identified, use 'oc status -v' to see details.\n", errors)
317
+			fmt.Fprintf(out, "%s identified, use '%[2]s status -v' to see details.\n", errors, d.CommandBaseName)
318 318
 
319 319
 		case !d.Suggest && len(warningMarkers) > 0:
320
-			fmt.Fprintf(out, "%s identified, use 'oc status -v' to see details.\n", warnings)
320
+			fmt.Fprintf(out, "%s identified, use '%[2]s status -v' to see details.\n", warnings, d.CommandBaseName)
321 321
 
322 322
 		case (len(services) == 0) && (len(standaloneDCs) == 0) && (len(standaloneImages) == 0):
323 323
 			fmt.Fprintln(out, "You have no services, deployment configs, or build configs.")
324
-			fmt.Fprintln(out, "Run 'oc new-app' to create an application.")
324
+			fmt.Fprintf(out, "Run '%[1]s new-app' to create an application.\n", d.CommandBaseName)
325 325
 
326 326
 		default:
327
-			fmt.Fprintln(out, "View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.")
327
+			fmt.Fprintf(out, "View details with '%[1]s describe <resource>/<name>' or list everything with '%[1]s get all'.\n", d.CommandBaseName)
328 328
 		}
329 329
 
330 330
 		return nil
... ...
@@ -347,7 +347,7 @@ func TestProjectStatus(t *testing.T) {
347 347
 			o.Add(obj)
348 348
 		}
349 349
 		oc, kc := testclient.NewFixtureClients(o)
350
-		d := ProjectStatusDescriber{C: oc, K: kc, Server: "https://example.com:8443", Suggest: true, LogsCommandName: "oc logs -p", SecurityPolicyCommandFormat: "policycommand %s %s"}
350
+		d := ProjectStatusDescriber{C: oc, K: kc, Server: "https://example.com:8443", Suggest: true, CommandBaseName: "oc", LogsCommandName: "oc logs -p", SecurityPolicyCommandFormat: "policycommand %s %s"}
351 351
 		out, err := d.Describe("example", "")
352 352
 		if !test.ErrFn(err) {
353 353
 			t.Errorf("%s: unexpected error: %v", k, err)
... ...
@@ -76,6 +76,8 @@ os::test::junit::declare_suite_end
76 76
 os::test::junit::declare_suite_start "cmd/basicresources/status"
77 77
 os::cmd::expect_success_and_text 'openshift cli status -h' 'openshift cli describe buildConfig'
78 78
 os::cmd::expect_success_and_text 'oc status -h' 'oc describe buildConfig'
79
+os::cmd::expect_success_and_text 'oc status' 'oc new-app'
80
+os::cmd::expect_success_and_text 'openshift cli status' 'openshift cli new-app'
79 81
 echo "status help output: ok"
80 82
 os::test::junit::declare_suite_end
81 83