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 rest = argResults!.rest;
  if (rest.isEmpty) throw CliError('usage: preset save <preset.json>');
  final file = File(rest.first);
  if (!file.existsSync()) {
    throw CliError('preset file not found: ${rest.first}');
  }
  final preset = jsonDecode(file.readAsStringSync());

  final client = _apiClientFrom(argResults!);
  try {
    final saved = await client.post('/presets', preset) as Map;
    stdout.writeln(
      'saved "${saved['id']}" (${saved['steps']} steps) — apply it anywhere '
      'with: preset apply ${saved['id']} --label …',
    );
  } finally {
    client.close();
  }
}