run method

  1. @override
int run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
int run() {
  final rest = argResults!.rest;
  if (rest.length != 1) {
    return _error(
      ExitReporter.usageError,
      'MISSING_PLAN_ID',
      'Expected exactly one plan ID.',
    );
  }
  final plan = planStore.loadPlan(rest.single);
  if (plan == null) {
    return _error(
      ExitReporter.planNotFoundOrStateForbids,
      'PLAN_NOT_FOUND',
      'Change Plan "${rest.single}" was not found.',
    );
  }
  final location = planStore.loadPlanLocation(plan.planId);
  final availability = availabilityReader(plan, location);
  out(
    _json
        ? renderPlanJson(plan, location?.canonicalDestination, availability)
        : renderPlanText(plan, location?.canonicalDestination, availability),
  );
  return ExitReporter.success;
}