runWithConfig method

  1. @override
Future<void> runWithConfig(
  1. Configuration<UpdateEnvCommandConfig> commandConfig
)
override

Runs this command with prepared configuration (options). Subclasses should override this method.

Implementation

@override
Future<void> runWithConfig(
    final Configuration<UpdateEnvCommandConfig> commandConfig) async {
  final projectId = commandConfig.value(UpdateEnvCommandConfig.projectId);
  final variableName =
      commandConfig.value(UpdateEnvCommandConfig.variableName);
  final variableValue =
      commandConfig.optionalValue(UpdateEnvCommandConfig.variableValue);
  final valueFile =
      commandConfig.optionalValue(UpdateEnvCommandConfig.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.');
}