runWithConfig method
Runs this command with prepared configuration (options). Subclasses should override this method.
Implementation
@override
Future<void> runWithConfig(
final Configuration<SetVariableCommandConfig> commandConfig,
) async {
final projectId = commandConfig.value(SetVariableCommandConfig.projectId);
final variableName = commandConfig.value(
SetVariableCommandConfig.variableName,
);
final valueToSet = commandConfig.valueOrFileContent(
value: SetVariableCommandConfig.variableValue,
valueFile: SetVariableCommandConfig.valueFile,
);
final apiCloudClient = runner.serviceProvider.cloudApiClient;
try {
await apiCloudClient.environmentVariables.create(
variableName,
valueToSet,
projectId,
);
} on DuplicateEntryException {
try {
await apiCloudClient.environmentVariables.update(
name: variableName,
value: valueToSet,
cloudCapsuleId: projectId,
);
} on Exception catch (e, s) {
throw FailureException.nested(
e,
s,
'Failed to set the environment variable',
);
}
} on Exception catch (e, s) {
throw FailureException.nested(
e,
s,
'Failed to set the environment variable',
);
}
logger.success('Successfully set environment variable: $variableName.');
}