Skip to content

Commit ad4bd3f

Browse files
Merge pull request #18422 from damemi/iss18016-1
Automatic merge from submit-queue. Issue 18016: Add infos count to `oc status` Fix for #18016 Now `oc status` without `-v` will show a count for number of errors, warnings, and info identified. Also refactored this output to reduce redundant switch statements with including infos.
2 parents 6ff50ac + c6edabd commit ad4bd3f

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

pkg/oc/cli/describe/projectstatus.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,11 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
340340

341341
// We print errors by default and warnings if -v is used. If we get none,
342342
// this would be an extra new line.
343-
if len(errorMarkers) != 0 || (d.Suggest && len(warningMarkers) != 0) {
343+
if len(errorMarkers) != 0 || len(infoMarkers) != 0 || (d.Suggest && len(warningMarkers) != 0) {
344344
fmt.Fprintln(out)
345345
}
346346

347-
errors, warnings := "", ""
347+
errors, warnings, infos := "", "", ""
348348
if len(errorMarkers) == 1 {
349349
errors = "1 error"
350350
} else if len(errorMarkers) > 1 {
@@ -355,16 +355,28 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
355355
} else if len(warningMarkers) > 1 {
356356
warnings = fmt.Sprintf("%d warnings", len(warningMarkers))
357357
}
358+
if len(infoMarkers) == 1 {
359+
infos = "1 info"
360+
} else if len(infoMarkers) > 0 {
361+
infos = fmt.Sprintf("%d infos", len(infoMarkers))
362+
}
358363

359-
switch {
360-
case !d.Suggest && len(errorMarkers) > 0 && len(warningMarkers) > 0:
361-
fmt.Fprintf(out, "%s and %s identified, use '%[3]s status -v' to see details.\n", errors, warnings, d.CommandBaseName)
362-
363-
case !d.Suggest && len(errorMarkers) > 0 && errorSuggestions > 0:
364-
fmt.Fprintf(out, "%s identified, use '%[2]s status -v' to see details.\n", errors, d.CommandBaseName)
364+
markerStrings := []string{errors, warnings, infos}
365+
markerString := ""
366+
count := 0
367+
for _, m := range markerStrings {
368+
if len(m) > 0 {
369+
if count > 0 {
370+
markerString = fmt.Sprintf("%s, ", markerString)
371+
}
372+
markerString = fmt.Sprintf("%s%s", markerString, m)
373+
count++
374+
}
375+
}
365376

366-
case !d.Suggest && len(warningMarkers) > 0:
367-
fmt.Fprintf(out, "%s identified, use '%[2]s status -v' to see details.\n", warnings, d.CommandBaseName)
377+
switch {
378+
case !d.Suggest && ((len(errorMarkers) > 0 && errorSuggestions > 0) || len(warningMarkers) > 0 || len(infoMarkers) > 0):
379+
fmt.Fprintf(out, "%s identified, use '%s status -v' to see details.\n", markerString, d.CommandBaseName)
368380

369381
case (len(services) == 0) && (len(standaloneDCs) == 0) && (len(standaloneImages) == 0):
370382
fmt.Fprintln(out, "You have no services, deployment configs, or build configs.")

0 commit comments

Comments
 (0)