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 rest = argResults!.rest;
if (rest.isEmpty) throw CliError('usage: preset save <preset.json>');
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(argResults!);
try {
await client.savePreset(preset);
stdout.writeln(
'saved "${preset.id}" (${preset.steps.length} steps) — apply it '
'anywhere with: preset apply ${preset.id} --label …',
);
} finally {
client.close();
}
}