run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<int> run() async {
final args = argResults!;
final statusFilter = args.option(_statusOption) ?? 'all';
final outputJson = args.flag(_jsonFlag);
final siteFilter = _context.resolveOptionalSiteFilter(args);
final store = _context.resolveStore(args);
final allComments = store.loadComments();
final siteScoped = [
for (final item in allComments)
if (siteFilter == null || item.site == siteFilter) item,
];
final filtered = [
for (final item in siteScoped)
if (statusFilter == 'all' || item.status == statusFilter) item,
];
final counts = computeCommentCounts(siteScoped);
if (outputJson) {
final payload = {
'ok': true,
'comments': [for (final item in filtered) item.toJson()],
'counts': counts,
'feedbackFile': store.feedbackRelativePath,
};
_context.out.writeln(const JsonEncoder.withIndent(' ').convert(payload));
return 0;
}
_context.out.writeln(
'Review comments '
'(open: ${counts['open']}, resolved: ${counts['resolved']}, '
'total: ${counts['total']})',
);
if (filtered.isEmpty) {
_context.out.writeln('No matching review comments.');
return 0;
}
for (final item in filtered) {
final statusBadge = item.status == 'resolved' ? 'RESOLVED' : 'OPEN';
final summary = item.comment.replaceAll(RegExp(r'\s+'), ' ').trim();
final scopeLabel = item.site.isNotEmpty
? '${item.site} ${item.pageUrl}'
: item.pageUrl;
_context.out.writeln(
'[$statusBadge] ${item.id} ${item.locationLabel} ($scopeLabel)',
);
if (item.selectedText.trim().isNotEmpty) {
final quote = item.selectedText.replaceAll(RegExp(r'\s+'), ' ').trim();
_context.out.writeln(' Quote: "$quote"');
}
_context.out.writeln(' Note: $summary');
}
return 0;
}