challenge: Colorize output.

* guix/scripts/challenge.scm (good-news, bad-news): New procedures.
(summarize-report, summarize-report-list): Use them and 'highlight'.
This commit is contained in:
Ludovic Courtès 2022-06-19 22:53:52 +02:00
parent 6337f62dde
commit ab174e16b5
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -18,6 +18,7 @@
(define-module (guix scripts challenge)
#:use-module (guix ui)
#:use-module (guix colors)
#:use-module (guix scripts)
#:use-module (guix store)
#:use-module (guix utils)
@ -388,6 +389,11 @@ (define* (report-differing-files/external comparison-report
(append command
(list directory1 directory2))))))
(define good-news
(coloring-procedure (color BOLD GREEN)))
(define bad-news
(coloring-procedure (color BOLD RED)))
(define* (summarize-report comparison-report
#:key
(report-differences (const #f))
@ -410,7 +416,7 @@ (define (report-hashes item local narinfos)
(match comparison-report
(($ <comparison-report> item 'mismatch local (narinfos ...))
(report (G_ "~a contents differ:~%") item)
(report (bad-news (G_ "~a contents differ:~%")) item)
(report-hashes item local narinfos)
(report-differences comparison-report))
(($ <comparison-report> item 'inconclusive #f narinfos)
@ -419,7 +425,7 @@ (define (report-hashes item local narinfos)
(warning (G_ "could not challenge '~a': no substitutes~%") item))
(($ <comparison-report> item 'match local (narinfos ...))
(when verbose?
(report (G_ "~a contents match:~%") item)
(report (good-news (G_ "~a contents match:~%")) item)
(report-hashes item local narinfos)))))
(define (summarize-report-list reports)
@ -428,10 +434,11 @@ (define (summarize-report-list reports)
(inconclusive (count comparison-report-inconclusive? reports))
(matches (count comparison-report-match? reports))
(discrepancies (count comparison-report-mismatch? reports)))
(report (G_ "~h store items were analyzed:~%") total)
(report (G_ " - ~h (~,1f%) were identical~%")
(report (highlight (G_ "~h store items were analyzed:~%")) total)
(report (highlight (G_ " - ~h (~,1f%) were identical~%"))
matches (* 100. (/ matches total)))
(report (G_ " - ~h (~,1f%) differed~%")
(report ((if (zero? discrepancies) good-news bad-news)
(G_ " - ~h (~,1f%) differed~%"))
discrepancies (* 100. (/ discrepancies total)))
(report (G_ " - ~h (~,1f%) were inconclusive~%")
inconclusive (* 100. (/ inconclusive total)))))