run method
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);
var drifted = 0;
for (final node in nodes) {
try {
final plan = await client.get('/nodes/$node/drift') as Map;
if (plan['converged'] == true) {
stdout.writeln('${node.padRight(20)} converged');
continue;
}
drifted++;
final actions = (plan['actions'] as List).cast<Map>();
stdout.writeln(
'${node.padRight(20)} DRIFTED — ${actions.length} to run',
);
for (final step in actions) {
stdout.writeln(' ${step['action']} ${step['formula']}');
}
} on HubApiException catch (e) {
stderr.writeln('${node.padRight(20)} ${e.message}');
}
}
// Exit non-zero when anything has drifted, so this is usable as a check in
// a pipeline — "is the fleet still what we said it was?"
if (drifted > 0) exitCode = 1;
} finally {
client.close();
}
}