Skip to content

Commit 13f5df6

Browse files
🧹 Improve cli printing when no checks are present.
Signed-off-by: Preslav <preslav@mondoo.com>
1 parent 74f1a93 commit 13f5df6

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

cli/reporter/print_compact.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,15 @@ func (r *defaultReporter) printAssetSections(orderedAssets []assetMrnName) {
259259
}
260260

261261
if r.Conf.printControls {
262-
r.printAssetControls(resolved, report, controls, assetMrn, asset)
262+
r.printAssetControls(resolved, report, controls)
263263
}
264264

265265
if r.Conf.printData || r.Conf.printChecks {
266-
r.printAssetQueries(resolved, report, queries, previewChecks, assetMrn, asset)
266+
r.printAssetQueries(resolved, report, queries, previewChecks)
267267
}
268268

269269
if r.Conf.printRisks {
270-
r.printAssetRisks(resolved, report, assetMrn, asset)
270+
r.printAssetRisks(report)
271271
}
272272
r.out(NewLineCharacter)
273273

@@ -284,7 +284,7 @@ func (r *defaultReporter) printAssetSections(orderedAssets []assetMrnName) {
284284
// Remove all this code and migrate it to tap or something
285285
// ============================= vv ============================================
286286

287-
func (r *defaultReporter) printAssetControls(resolved *policy.ResolvedPolicy, report *policy.Report, controls map[string]*policy.Control, assetMrn string, asset *inventory.Asset) {
287+
func (r *defaultReporter) printAssetControls(resolved *policy.ResolvedPolicy, report *policy.Report, controls map[string]*policy.Control) {
288288
var scores []*policy.Score
289289
for _, rj := range resolved.CollectorJob.ReportingJobs {
290290
if rj.Type != policy.ReportingJob_CONTROL {
@@ -309,22 +309,21 @@ func (r *defaultReporter) printAssetControls(resolved *policy.ResolvedPolicy, re
309309

310310
r.out("Compliance controls:" + NewLineCharacter)
311311

312-
for i := range scores {
313-
score := scores[i]
312+
for _, score := range scores {
314313
control, ok := controls[score.QrId]
315314
if !ok {
316315
r.out("Couldn't find any controls for " + score.QrId)
317316
r.out(NewLineCharacter)
318317
continue
319318
}
320319

321-
r.printControl(score, control, resolved, report)
320+
r.printControl(score, control)
322321
}
323322

324323
r.out(NewLineCharacter)
325324
}
326325

327-
func (r *defaultReporter) printControl(score *policy.Score, control *policy.Control, resolved *policy.ResolvedPolicy, report *policy.Report) {
326+
func (r *defaultReporter) printControl(score *policy.Score, control *policy.Control) {
328327
title := control.Title
329328
if title == "" {
330329
title = control.Mrn
@@ -344,12 +343,10 @@ func (r *defaultReporter) printControl(score *policy.Score, control *policy.Cont
344343
r.out(termenv.String(". Unknown: ").Foreground(r.Colors.Disabled).String())
345344
r.out(title)
346345
r.out(NewLineCharacter)
347-
348346
case policy.ScoreType_Skip:
349347
r.out(termenv.String(". Skipped: ").Foreground(r.Colors.Disabled).String())
350348
r.out(title)
351349
r.out(NewLineCharacter)
352-
353350
case policy.ScoreType_Result:
354351
var passfail string
355352
if score.Value == 100 {
@@ -358,7 +355,9 @@ func (r *defaultReporter) printControl(score *policy.Score, control *policy.Cont
358355
passfail = termenv.String("✕ Fail: ").Foreground(r.Colors.High).String()
359356
}
360357

361-
r.out(passfail + title + NewLineCharacter)
358+
r.out(passfail)
359+
r.out(title)
360+
r.out(NewLineCharacter)
362361

363362
default:
364363
r.out("unknown result for " + title + NewLineCharacter)
@@ -379,7 +378,7 @@ type previewGroup struct {
379378
sortedFailures []string
380379
}
381380

382-
func (r *defaultReporter) printAssetQueries(resolved *policy.ResolvedPolicy, report *policy.Report, queries map[string]*explorer.Mquery, checkToPreview map[string]*policy.PolicyGroup, assetMrn string, asset *inventory.Asset) {
381+
func (r *defaultReporter) printAssetQueries(resolved *policy.ResolvedPolicy, report *policy.Report, queries map[string]*explorer.Mquery, checkToPreview map[string]*policy.PolicyGroup) {
383382
results := report.RawResults()
384383

385384
if r.Conf.printData {
@@ -429,6 +428,7 @@ func (r *defaultReporter) printAssetQueries(resolved *policy.ResolvedPolicy, rep
429428
pscore, ok := report.Scores[query.Mrn]
430429
if !ok {
431430
r.out("Couldn't find any queries for score of " + id)
431+
r.out(NewLineCharacter)
432432
continue
433433
}
434434

@@ -497,15 +497,15 @@ func (r *defaultReporter) printAssetQueries(resolved *policy.ResolvedPolicy, rep
497497
})
498498

499499
prevPrinted := false
500-
if len(sortedPassed) != 0 {
500+
if len(sortedPassed) > 0 {
501501
r.out("Passing:" + NewLineCharacter)
502502
for _, id := range sortedPassed {
503503
r.printCheck(foundChecks[id], queries[id], resolved, report, results)
504504
}
505505
prevPrinted = true
506506
}
507507

508-
if len(sortedWarnings) != 0 {
508+
if len(sortedWarnings) > 0 {
509509
if prevPrinted {
510510
r.out(NewLineCharacter)
511511
}
@@ -559,7 +559,7 @@ func (r *defaultReporter) printAssetQueries(resolved *policy.ResolvedPolicy, rep
559559
prevPrinted = true
560560
}
561561

562-
if len(sortedFailed) != 0 {
562+
if len(sortedFailed) > 0 {
563563
if prevPrinted {
564564
r.out(NewLineCharacter)
565565
}
@@ -572,11 +572,11 @@ func (r *defaultReporter) printAssetQueries(resolved *policy.ResolvedPolicy, rep
572572
r.printCheck(foundChecks[id], queries[id], resolved, report, results)
573573
}
574574
}
575-
575+
r.out(NewLineCharacter)
576576
}
577577
}
578578

579-
func (r *defaultReporter) printAssetRisks(resolved *policy.ResolvedPolicy, report *policy.Report, assetMrn string, asset *inventory.Asset) {
579+
func (r *defaultReporter) printAssetRisks(report *policy.Report) {
580580
if report.Risks == nil || len(report.Risks.Items) == 0 {
581581
return
582582
}
@@ -625,7 +625,7 @@ func (r *defaultReporter) printAssetRisks(resolved *policy.ResolvedPolicy, repor
625625
}
626626
out := res.String()
627627

628-
r.out(NewLineCharacter + "Risks / Preventive Controls:" + NewLineCharacter)
628+
r.out("Risks / Preventive Controls:" + NewLineCharacter)
629629
if out != "" {
630630
r.out(out)
631631
} else {
@@ -679,7 +679,6 @@ func (r *defaultReporter) printCheck(score simpleScore, query *explorer.Mquery,
679679
r.out(termenv.String(checkStatus(".", "Unknown")).Foreground(r.Colors.Disabled).String())
680680
r.out(title)
681681
r.out(NewLineCharacter)
682-
683682
case policy.ScoreType_Skip:
684683
r.out(termenv.String(checkStatus(".", "Skipped")).Foreground(r.Colors.Disabled).String())
685684
r.out(title)

0 commit comments

Comments
 (0)