runWithConfig method

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

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

Implementation

@override
Future<void> runWithConfig(
    final Configuration<DeleteEnvCommandConfig> commandConfig) async {
  final projectId = commandConfig.value(DeleteEnvCommandConfig.projectId);
  final variableName =
      commandConfig.value(DeleteEnvCommandConfig.variableName);

  final shouldDelete = await logger.confirm(
    'Are you sure you want to delete the environment variable "$variableName"?',
    defaultValue: false,
  );

  if (!shouldDelete) {
    throw UserAbortException();
  }

  final apiCloudClient = runner.serviceProvider.cloudApiClient;

  try {
    await apiCloudClient.environmentVariables.delete(
      name: variableName,
      cloudCapsuleId: projectId,
    );
  } on Exception catch (e, s) {
    throw FailureException.nested(
        e, s, 'Failed to delete the environment variable');
  }

  logger.success('Successfully deleted environment variable: $variableName.');
}