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 dryRun = args['dry-run'] as bool;
  final async = args['async'] as bool;

  final client = _apiClientFrom(args);
  try {
    final nodes = await _selectNodes(client, args, positional: args.rest);
    await _fanOut(nodes, (node) async {
      if (async) {
        final operation = await client.reconcileAsync(node, dryRun: dryRun);
        return 'dispatched — ops show ${operation.id}';
      }
      final reply = await client.reconcile(node, dryRun: dryRun);
      if (!reply.success) {
        return 'FAILED — ${reply.changed} changed, ${reply.skipped} skipped';
      }
      return dryRun
          ? 'would change ${reply.changed}'
          : 'applied — ${reply.changed} changed';
    });
  } finally {
    client.close();
  }
}