lastCounts function
Takes a list of all the progress messages and finds the last line which containts the counts. It then parses the counts and returns the result in the Counts object.
Implementation
Counts lastCounts(List<String> lines) {
for (var line in lines.reversed) {
line = Ansi.strip(line);
final regexWithErrors =
RegExp('.+Errors: ([0-9]*), Success: ([0-9]*), Skipped: ([0-9]*)');
if (regexWithErrors.hasMatch(line)) {
final errors = regexWithErrors.firstMatch(line)!.group(1);
final success = regexWithErrors.firstMatch(line)!.group(2);
final skipped = regexWithErrors.firstMatch(line)!.group(3);
return Counts.withValues(
int.parse(success!), int.parse(errors!), int.parse(skipped!));
}
final regexNoErrors = RegExp('.+Success: ([0-9]*), Skipped: ([0-9]*)');
if (regexNoErrors.hasMatch(line)) {
final success = regexNoErrors.firstMatch(line)!.group(1);
final skipped = regexNoErrors.firstMatch(line)!.group(2);
return Counts.withValues(int.parse(success!), 0, int.parse(skipped!));
}
}
throw Exception('No counts found');
}