Skip to content

Commit 5cb689f

Browse files
committed
Add infos count to oc status
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.
1 parent a5d2ee0 commit 5cb689f

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

pkg/oc/cli/describe/projectstatus.go

Lines changed: 20 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,26 @@ 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) > 0 {
359+
infos = fmt.Sprintf("%d info", len(infoMarkers))
360+
}
358361

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)
362+
markerStrings := []string{errors, warnings, infos}
363+
markerString := ""
364+
count := 0
365+
for _, m := range markerStrings {
366+
if len(m) > 0 {
367+
if count > 0 {
368+
markerString = fmt.Sprintf("%s, ", markerString)
369+
}
370+
markerString = fmt.Sprintf("%s%s", markerString, m)
371+
count++
372+
}
373+
}
365374

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)
375+
switch {
376+
case !d.Suggest && ((len(errorMarkers) > 0 && errorSuggestions > 0) || len(warningMarkers) > 0 || len(infoMarkers) > 0):
377+
fmt.Fprintf(out, "%s identified, use '%s status -v' to see details.\n", markerString, d.CommandBaseName)
368378

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

0 commit comments

Comments
 (0)