@@ -282,23 +282,7 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
282
282
errorSuggestions := 0
283
283
if len (errorMarkers ) > 0 {
284
284
fmt .Fprintln (out , "Errors:" )
285
- for _ , marker := range errorMarkers {
286
- fmt .Fprintln (out , indent + "* " + marker .Message )
287
- if len (marker .Suggestion ) > 0 {
288
- errorSuggestions ++
289
- if d .Suggest {
290
- switch s := marker .Suggestion .String (); {
291
- case strings .Contains (s , "\n " ):
292
- fmt .Fprintln (out )
293
- for _ , line := range strings .Split (s , "\n " ) {
294
- fmt .Fprintln (out , indent + " " + line )
295
- }
296
- case len (s ) > 0 :
297
- fmt .Fprintln (out , indent + " try: " + s )
298
- }
299
- }
300
- }
301
- }
285
+ errorSuggestions += printMarkerSuggestions (errorMarkers , d .Suggest , out , indent )
302
286
}
303
287
304
288
warningMarkers := allMarkers .BySeverity (osgraph .WarningSeverity )
@@ -310,45 +294,19 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
310
294
}
311
295
fmt .Fprintln (out , "Warnings:" )
312
296
}
313
- for _ , marker := range warningMarkers {
314
- if d .Suggest {
315
- fmt .Fprintln (out , indent + "* " + marker .Message )
316
- switch s := marker .Suggestion .String (); {
317
- case strings .Contains (s , "\n " ):
318
- fmt .Fprintln (out )
319
- for _ , line := range strings .Split (s , "\n " ) {
320
- fmt .Fprintln (out , indent + " " + line )
321
- }
322
- case len (s ) > 0 :
323
- fmt .Fprintln (out , indent + " try: " + s )
324
- }
325
- }
326
- }
297
+ printMarkerSuggestions (warningMarkers , d .Suggest , out , indent )
327
298
}
328
299
329
300
infoMarkers := allMarkers .BySeverity (osgraph .InfoSeverity )
330
301
if len (infoMarkers ) > 0 {
331
302
if d .Suggest {
332
303
// add linebreak between Warnings list and Info List
333
- if len (warningMarkers ) > 0 || len (warningMarkers ) > 0 {
304
+ if len (warningMarkers ) > 0 || len (errorMarkers ) > 0 {
334
305
fmt .Fprintln (out )
335
306
}
336
307
fmt .Fprintln (out , "Info:" )
337
308
}
338
- for _ , marker := range infoMarkers {
339
- if d .Suggest {
340
- fmt .Fprintln (out , indent + "* " + marker .Message )
341
- switch s := marker .Suggestion .String (); {
342
- case strings .Contains (s , "\n " ):
343
- fmt .Fprintln (out )
344
- for _ , line := range strings .Split (s , "\n " ) {
345
- fmt .Fprintln (out , indent + " " + line )
346
- }
347
- case len (s ) > 0 :
348
- fmt .Fprintln (out , indent + " try: " + s )
349
- }
350
- }
351
- }
309
+ printMarkerSuggestions (infoMarkers , d .Suggest , out , indent )
352
310
}
353
311
354
312
// We print errors by default and warnings if -v is used. If we get none,
@@ -391,6 +349,32 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
391
349
})
392
350
}
393
351
352
+ // printMarkerSuggestions prints a formatted list of marker suggestions
353
+ // and returns the amount of suggestions printed
354
+ func printMarkerSuggestions (markers []osgraph.Marker , suggest bool , out * tabwriter.Writer , indent string ) int {
355
+ suggestionAmount := 0
356
+ for _ , marker := range markers {
357
+ if len (marker .Suggestion ) > 0 {
358
+ suggestionAmount ++
359
+ }
360
+ if len (marker .Suggestion ) > 0 || len (marker .Message ) > 0 {
361
+ if suggest {
362
+ fmt .Fprintln (out , indent + "* " + marker .Message )
363
+ switch s := marker .Suggestion .String (); {
364
+ case strings .Contains (s , "\n " ):
365
+ fmt .Fprintln (out )
366
+ for _ , line := range strings .Split (s , "\n " ) {
367
+ fmt .Fprintln (out , indent + " " + line )
368
+ }
369
+ case len (s ) > 0 :
370
+ fmt .Fprintln (out , indent + " try: " + s )
371
+ }
372
+ }
373
+ }
374
+ }
375
+ return suggestionAmount
376
+ }
377
+
394
378
func createForbiddenMarkers (forbiddenResources sets.String ) []osgraph.Marker {
395
379
markers := []osgraph.Marker {}
396
380
for forbiddenResource := range forbiddenResources {
0 commit comments