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 rest = args.rest;
if (rest.isEmpty) {
throw CliError('usage: state set <preset.json> [<node>] [--label …]');
}
final file = File(rest.first);
if (!await file.exists()) {
throw CliError('preset file not found: ${rest.first}');
}
final preset = Preset.fromJson(
(jsonDecode(await file.readAsString()) as Map).cast<String, dynamic>(),
);
final client = _apiClientFrom(args);
try {
final nodes = await _selectNodes(
client,
args,
positional: rest.skip(1).toList(),
);
await _fanOut(nodes, (node) async {
await client.declarePreset(node, preset);
// Said plainly, because "declared" and "applied" are easy to confuse and
// the difference is the whole feature.
return 'declared ${preset.steps.length} steps (nothing has run yet)';
});
} finally {
client.close();
}
}