Skip to content

Commit

Permalink
create printMarkerSuggestions func
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Nov 18, 2016
1 parent 55bae56 commit 2ce9162
Showing 1 changed file with 30 additions and 46 deletions.
76 changes: 30 additions & 46 deletions pkg/cmd/cli/describe/projectstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,7 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
errorSuggestions := 0
if len(errorMarkers) > 0 {
fmt.Fprintln(out, "Errors:")
for _, marker := range errorMarkers {
fmt.Fprintln(out, indent+"* "+marker.Message)
if len(marker.Suggestion) > 0 {
errorSuggestions++
if d.Suggest {
switch s := marker.Suggestion.String(); {
case strings.Contains(s, "\n"):
fmt.Fprintln(out)
for _, line := range strings.Split(s, "\n") {
fmt.Fprintln(out, indent+" "+line)
}
case len(s) > 0:
fmt.Fprintln(out, indent+" try: "+s)
}
}
}
}
errorSuggestions += printMarkerSuggestions(errorMarkers, d.Suggest, out, indent)
}

warningMarkers := allMarkers.BySeverity(osgraph.WarningSeverity)
Expand All @@ -310,45 +294,19 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
}
fmt.Fprintln(out, "Warnings:")
}
for _, marker := range warningMarkers {
if d.Suggest {
fmt.Fprintln(out, indent+"* "+marker.Message)
switch s := marker.Suggestion.String(); {
case strings.Contains(s, "\n"):
fmt.Fprintln(out)
for _, line := range strings.Split(s, "\n") {
fmt.Fprintln(out, indent+" "+line)
}
case len(s) > 0:
fmt.Fprintln(out, indent+" try: "+s)
}
}
}
printMarkerSuggestions(warningMarkers, d.Suggest, out, indent)
}

infoMarkers := allMarkers.BySeverity(osgraph.InfoSeverity)
if len(infoMarkers) > 0 {
if d.Suggest {
// add linebreak between Warnings list and Info List
if len(warningMarkers) > 0 || len(warningMarkers) > 0 {
if len(warningMarkers) > 0 || len(errorMarkers) > 0 {
fmt.Fprintln(out)
}
fmt.Fprintln(out, "Info:")
}
for _, marker := range infoMarkers {
if d.Suggest {
fmt.Fprintln(out, indent+"* "+marker.Message)
switch s := marker.Suggestion.String(); {
case strings.Contains(s, "\n"):
fmt.Fprintln(out)
for _, line := range strings.Split(s, "\n") {
fmt.Fprintln(out, indent+" "+line)
}
case len(s) > 0:
fmt.Fprintln(out, indent+" try: "+s)
}
}
}
printMarkerSuggestions(infoMarkers, d.Suggest, out, indent)
}

// We print errors by default and warnings if -v is used. If we get none,
Expand Down Expand Up @@ -391,6 +349,32 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
})
}

// printMarkerSuggestions prints a formatted list of marker suggestions
// and returns the amount of suggestions printed
func printMarkerSuggestions(markers []osgraph.Marker, suggest bool, out *tabwriter.Writer, indent string) int {
suggestionAmount := 0
for _, marker := range markers {
if len(marker.Suggestion) > 0 {
suggestionAmount++
}
if len(marker.Suggestion) > 0 || len(marker.Message) > 0 {
if suggest {
fmt.Fprintln(out, indent+"* "+marker.Message)
switch s := marker.Suggestion.String(); {
case strings.Contains(s, "\n"):
fmt.Fprintln(out)
for _, line := range strings.Split(s, "\n") {
fmt.Fprintln(out, indent+" "+line)
}
case len(s) > 0:
fmt.Fprintln(out, indent+" try: "+s)
}
}
}
}
return suggestionAmount
}

func createForbiddenMarkers(forbiddenResources sets.String) []osgraph.Marker {
markers := []osgraph.Marker{}
for forbiddenResource := range forbiddenResources {
Expand Down

0 comments on commit 2ce9162

Please sign in to comment.