selectPlan static method

Future<void> selectPlan(
  1. Client cloudApiClient,
  2. CommandLogger logger,
  3. ProjectLaunch projectSetup
)

Implementation

static Future<void> selectPlan(
  final Client cloudApiClient,
  final CommandLogger logger,
  final ProjectLaunch projectSetup,
) async {
  final validPlanNames = PlanProfile.values
      .map((final p) => p.name)
      .join(', ');

  var planProfile = projectSetup.plan;

  do {
    if (planProfile != null) {
      projectSetup.plan = planProfile;
      return;
    }

    final projectPlanName = await logger.input('Enter the plan');

    if (projectPlanName.isEmpty) {
      logger.error('Plan is required. Must be one of: $validPlanNames');
      continue;
    }

    planProfile = PlanProfile.values
        .where((final p) => p.name == projectPlanName)
        .firstOrNull;
    if (planProfile == null) {
      logger.error('Invalid plan. Must be one of: $validPlanNames');
      continue;
    }
  } while (true);
}