renderText method
The report as text; verbose lists the repositories with nothing to
do and every changed file (else the first 20 per repository); width
aligns the codes on the right.
Implementation
String renderText({bool verbose = false, int width = 100}) {
final b = StringBuffer();
final changedPaths = {for (final d in done) d.repository};
final unchanged = (lookedAt.toList()..sort())
.where((p) => !changedPaths.contains(p))
.toList();
final errors = _at(MessageLevel.error).toList();
final warnings = _at(MessageLevel.warning).toList();
final refusals = _at(MessageLevel.refusal).toList();
final notes = _at(MessageLevel.note).toList();
b
..writeln('$tool $command')
..writeln(' Root: $root')
..writeln(' Host: $host')
..writeln(' Started: ${_stamp(started)}')
..writeln(
' Options: ${given.isEmpty ? '(none)' : given.map(shellQuote).join(' ')}',
)
..writeln()
..writeln(
'${lookedAt.length} repositories looked at, ${done.length} changed, '
'${errors.length} need${errors.length == 1 ? 's' : ''} you, '
'${warnings.length} warning${warnings.length == 1 ? '' : 's'}: '
'exit $exitCode',
);
void section(String title, List<ReportMessage> list) {
if (list.isEmpty) return;
b
..writeln()
..writeln(title);
for (final m in list) {
b
..writeln()
..write(_block(m, width));
}
}
section('Refused', refusals);
section('Needs you', errors);
section('Warnings', warnings);
section('Notes', notes);
if (done.isNotEmpty || unchanged.isNotEmpty) {
b
..writeln()
..writeln('Done');
final pad = done.fold(
0,
(w, d) => _repoLabel(d.repository).length > w
? _repoLabel(d.repository).length
: w,
);
for (final d in done) {
b.writeln(
' ${_repoLabel(d.repository).padRight(pad)} ${d.actions.join(', ')}',
);
final shown = verbose ? d.files : d.files.take(20);
for (final f in shown) {
b.writeln(' $f');
}
if (!verbose && d.files.length > 20) {
b.writeln(' ... ${d.files.length - 20} more (-v lists them)');
}
}
if (unchanged.isNotEmpty) {
if (verbose) {
b.writeln(' Nothing to do:');
for (final p in unchanged) {
b.writeln(' ${_repoLabel(p)}');
}
} else {
b.writeln(
' ${unchanged.length} '
'${unchanged.length == 1 ? 'repository' : 'repositories'} with '
'nothing to do (-v lists them)',
);
}
}
}
final help = helpCommand ?? '$tool help <topic>';
b
..writeln()
..writeln('Exit $exitCode: ${ReportExitCode.meaning(exitCode)}.');
if (refusals.isNotEmpty ||
errors.isNotEmpty ||
exitCode == ReportExitCode.decision) {
b.writeln(
'Repeat with one of the command lines above; `$help` explains each '
'message.',
);
}
return b.toString();
}