runWithOutput method

  1. @override
Future<void> runWithOutput(
  1. Configuration<OptionDefinition> commandConfig,
  2. CommandOutput output
)
override

Runs this command with prepared configuration and output.

Subclasses should override this method.

Implementation

@override
Future<void> runWithOutput(
  final Configuration commandConfig,
  final CommandOutput output,
) async {
  final projectId = commandConfig.value(ProjectCreateOption.projectId);
  final plan = commandConfig.optionalValue(ProjectCreateOption.plan);
  final enableDb = commandConfig.value(ProjectCreateOption.enableDb);

  await confirmToContinue(
    output,
    message:
        'Depending on your subscription, a new project may incur additional costs. Continue?',
    defaultValue: true,
  );

  final client = runner.serviceProvider.cloudApiClient;

  // final createdPlan = await ProjectCommands.createPlan(client, plan: plan);
  final planContext = await renderCommand(
    output,
    operation: () => ProjectCommands.createPlan(client, plan: plan),
    textOutputUi: const NilWidget(),
    jsonOutputUi: const NilWidget(),
    yamlOutputUi: const NilWidget(),
  );
  final createdPlan = planContext.get<CreatedPlan>();

  if (!output.format.isStructured) {
    await output.renderStatic(
      ui: InitTextWidget('Creating Serverpod Cloud project "$projectId".'),
    );
  }

  await renderCommand(
    output,
    operation: () async => Stream.fromFuture(
      ProjectCommands.createProject(
        client,
        projectId: projectId,
        subscriptionId: createdPlan.subscriptionId,
        plan: plan,
      ),
    ),
    textOutputUi: ProjectCreateTextUi(
      planDisplayName: createdPlan.planDisplayName,
      includeSuccess: !enableDb,
    ),
  );

  if (enableDb) {
    await renderCommand(
      output,
      operation: () async => Stream.fromFuture(
        ProjectCommands.createDatabase(client, projectId: projectId),
      ),
      textOutputUi: const ProjectCreateDatabaseTextUi(),
      jsonOutputUi: const NilWidget(),
      yamlOutputUi: const NilWidget(),
    );
  }
}