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 purgeAdopted = args['purge-adopted'] as bool;

  final client = _apiClientFrom(args);
  try {
    final nodes = await _selectNodes(client, args, positional: args.rest);
    await _fanOut(nodes, (node) async {
      final result = await client.unassign(node, purgeAdopted: purgeAdopted);
      if (!result.success) {
        // Still assigned, on purpose: the declaration is the only record of
        // what is left to clean up.
        return 'FAILED — ${result.changed} removed, still assigned';
      }
      return 'unassigned — ${result.changed} removed';
    });
  } finally {
    client.close();
  }
}