getDeployAttemptId static method

Future<UuidValue> getDeployAttemptId(
  1. Client cloudApiClient, {
  2. required String baseCommand,
  3. required CommandNames commandNames,
  4. required String projectId,
  5. String? deploymentArg,
})

Resolves deploymentArg, a deployment uuid or sequence number where 0 means the latest, to a deploy attempt id.

Throws FailureException if no such deployment exists.

Implementation

static Future<UuidValue> getDeployAttemptId(
  final Client cloudApiClient, {
  required final String baseCommand,
  required final CommandNames commandNames,
  required final String projectId,
  final String? deploymentArg,
}) async {
  final deployment = deploymentArg ?? '0';
  final attemptNumber = int.tryParse(deployment);
  if (attemptNumber == null) {
    try {
      return UuidValue.withValidation(deployment);
    } on FormatException catch (_) {
      throw FailureException(
        error: 'The requested resource did not exist.',
        hint: 'Validate the attempt id is correct.',
      );
    }
  }
  try {
    return await cloudApiClient.status.getDeployAttemptId(
      cloudCapsuleId: projectId,
      attemptNumber: attemptNumber,
    );
  } on NotFoundException catch (_) {
    if (deployment == '0') {
      throw FailureException(
        error: 'No deployment status found.',
        hint: 'Run this command to deploy: $baseCommand deploy',
      );
    }
    throw FailureException(
      error: 'No such deployment status found.',
      hint:
          'Run this command to see recent deployments: '
          '$baseCommand ${commandNames.deploymentList}',
    );
  }
}