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 {
  final client = _apiClientFrom(argResults!);
  try {
    final entries = (await client.get('/audit') as List).cast<Map>();
    if (entries.isEmpty) {
      stdout.writeln('no audited actions yet');
      return;
    }
    // Local time, seconds precision: an ISO instant with microseconds is 27
    // characters of mostly noise, and it ran into the next column.
    stdout.writeln('AT                   PRINCIPAL     ACTION');
    for (final e in entries) {
      final at = DateTime.parse(
        e['at'] as String,
      ).toLocal().toString().split('.').first;
      final target = e['target'] == null ? '' : ' ${e['target']}';
      stdout.writeln(
        '${at.padRight(20)} '
        '${'${e['principal']}'.padRight(13)}'
        '${e['action']}$target  (${e['outcome']})',
      );
    }
  } finally {
    client.close();
  }
}