runWithConfig method
Runs this command with prepared configuration (options). Subclasses should override this method.
Implementation
@override
Future<void> runWithConfig(
final Configuration<AddCustomDomainCommandConfig> commandConfig,
) async {
final projectId =
commandConfig.value(AddCustomDomainCommandConfig.projectId);
final domainName =
commandConfig.value(AddCustomDomainCommandConfig.domainName);
final target = commandConfig.value(AddCustomDomainCommandConfig.target);
final apiCloudClient = runner.serviceProvider.cloudApiClient;
late CustomDomainNameWithDefaultDomains customDomainNameWithDefaultDomains;
try {
customDomainNameWithDefaultDomains =
await apiCloudClient.customDomainName.add(
domainName: domainName,
target: target,
cloudCapsuleId: projectId,
);
} on Exception catch (e, stackTrace) {
throw FailureException.nested(
e, stackTrace, 'Could not add the custom domain');
}
logger.success('Custom domain added successfully!', newParagraph: true);
final targetDefaultDomain =
customDomainNameWithDefaultDomains.defaultDomainsByTarget[target];
if (targetDefaultDomain == null) {
throw FailureException(
error: 'Could not find the target domain for "$target".',
);
}
if (DomainUtils.isSubDomain(domainName)) {
_logDomainInstructions(
action: 'Add a CNAME record with the value "$targetDefaultDomain" '
'to the DNS configuration for this domain.',
logger: logger,
domainName: domainName,
projectId: projectId,
records: [
(type: 'CNAME', value: targetDefaultDomain),
],
);
return;
}
_logDomainInstructions(
action: 'Add a TXT record with the name "$targetDefaultDomain" and '
'value "${customDomainNameWithDefaultDomains.customDomainName.dnsRecordVerificationValue}".',
logger: logger,
domainName: domainName,
projectId: projectId,
records: [
(
type: 'ANAME',
value: targetDefaultDomain,
),
(
type: 'TXT',
value: customDomainNameWithDefaultDomains
.customDomainName.dnsRecordVerificationValue
),
],
);
}