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 args = argResults!;
  final client = _apiClientFrom(args);
  try {
    final nodes = await _selectNodes(client, args, positional: args.rest);
    final async = args['async'] as bool;
    await _fanOut(nodes, (node) async {
      if (async) {
        final operation = await client.reconcileAsync(node);
        return 'dispatched — ops show ${operation.id}';
      }
      final reply = await client.reconcile(node);
      // A node declared by preset steps reports per-step results; one
      // declared by a blueprint reports counted changes. `ConvergeResult`
      // answers both the same way.
      final ran = reply.results.isEmpty
          ? reply.changed
          : reply.results.length;
      if (ran == 0) return 'already converged — nothing to do';
      final failed = reply.results.where((r) => !r.success).length;
      return reply.success ? 'converged ($ran ran)' : 'FAILED $failed/$ran';
    });
  } finally {
    client.close();
  }
}