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: blueprint show <id>');

  final client = _apiClientFrom(argResults!);
  try {
    final blueprint = await client.blueprint(rest.first);
    // A blueprint authored as YAML comes back as that YAML, comments intact.
    // Printing the parsed JSON instead would hand back a different document
    // from the one in the author's editor.
    if (blueprint.source case final source?) {
      stdout.write(source.text);
      return;
    }
    stdout.writeln(
      const JsonEncoder.withIndent('  ').convert(blueprint.toJson()),
    );
  } finally {
    client.close();
  }
}