runWithConfig method
Runs this command with prepared configuration (options). Subclasses should override this method.
Implementation
@override
Future<void> runWithConfig(
final Configuration<UpdateVariableCommandConfig> commandConfig,
) async {
final projectId = commandConfig.value(
UpdateVariableCommandConfig.projectId,
);
final variableName = commandConfig.value(
UpdateVariableCommandConfig.variableName,
);
final variableValue = commandConfig.optionalValue(
UpdateVariableCommandConfig.variableValue,
);
final valueFile = commandConfig.optionalValue(
UpdateVariableCommandConfig.valueFile,
);
String valueToSet;
if (variableValue != null) {
valueToSet = variableValue;
} else if (valueFile != null) {
valueToSet = valueFile.readAsStringSync();
} else {
throw StateError('Expected one of the value options to be set.');
}
final apiCloudClient = runner.serviceProvider.cloudApiClient;
try {
await apiCloudClient.environmentVariables.update(
name: variableName,
value: valueToSet,
cloudCapsuleId: projectId,
);
} on Exception catch (e, s) {
throw FailureException.nested(
e,
s,
'Failed to update the environment variable',
);
}
logger.success('Successfully updated environment variable: $variableName.');
}