Skip to content

Commit

Permalink
Add infos count to oc status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
damemi committed Feb 2, 2018
1 parent a5d2ee0 commit 5cb689f
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions pkg/oc/cli/describe/projectstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error

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

errors, warnings := "", ""
errors, warnings, infos := "", "", ""
if len(errorMarkers) == 1 {
errors = "1 error"
} else if len(errorMarkers) > 1 {
Expand All @@ -355,16 +355,26 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
} else if len(warningMarkers) > 1 {
warnings = fmt.Sprintf("%d warnings", len(warningMarkers))
}
if len(infoMarkers) > 0 {
infos = fmt.Sprintf("%d info", len(infoMarkers))
}

switch {
case !d.Suggest && len(errorMarkers) > 0 && len(warningMarkers) > 0:
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 '%[2]s status -v' to see details.\n", errors, d.CommandBaseName)
markerStrings := []string{errors, warnings, infos}
markerString := ""
count := 0
for _, m := range markerStrings {
if len(m) > 0 {
if count > 0 {
markerString = fmt.Sprintf("%s, ", markerString)
}
markerString = fmt.Sprintf("%s%s", markerString, m)
count++
}
}

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

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

0 comments on commit 5cb689f

Please sign in to comment.