run method

  1. @override
Future<void> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<void> run() async {
  config = ConfigService(projectDir);

  final shouldClear = argResults?['clear'] as bool? ?? false;
  if (shouldClear) {
    await _clearHistory();
    return;
  }

  final clientFilter = argResults?['client'] as String?;
  final limit = int.tryParse(argResults?['limit'] as String? ?? '10') ?? 10;

  var entries = await config.loadBuildHistory();

  if (clientFilter != null) {
    entries = entries.where((e) => e['client'] == clientFilter).toList();
  }

  if (entries.isEmpty) {
    Logger.info(
        'No build history recorded yet. Run "udara_cli build" to create some.');
    return;
  }

  Logger.phase('Build History (showing ${entries.length.clamp(0, limit)} '
      'of ${entries.length})');

  for (final entry in entries.take(limit)) {
    _printEntry(entry);
  }
}