unsetVariable static method
Future<void>
unsetVariable(
- Client cloudApiClient, {
- required CommandLogger logger,
- required String baseCommand,
- required String projectId,
- required String name,
Implementation
static Future<void> unsetVariable(
final Client cloudApiClient, {
required final CommandLogger logger,
required final String baseCommand,
required final String projectId,
required final String name,
}) async {
_validateName(baseCommand, name);
final listed = await _fetch(cloudApiClient, projectId);
final existingStore = _storeOf(
name,
unmasked: listed.unmasked,
secrets: listed.secrets,
);
if (existingStore == null) {
throw FailureException(
error: 'The environment variable "$name" was not found.',
);
}
final shouldUnset = await logger.confirm(
'Are you sure you want to remove the environment variable "$name"?',
defaultValue: false,
);
if (!shouldUnset) {
throw UserAbortException();
}
try {
switch (existingStore) {
case _VariableStore.unmasked:
await cloudApiClient.environmentVariables.delete(
name: name,
cloudCapsuleId: projectId,
);
case _VariableStore.secret:
await cloudApiClient.secrets.delete(
key: name,
cloudCapsuleId: projectId,
);
}
} on Exception catch (e, s) {
throw FailureException.nested(
e,
s,
'Failed to remove the environment variable',
);
}
logger.success(
existingStore == _VariableStore.secret
? 'Successfully removed secret: $name.'
: 'Successfully removed environment variable: $name.',
);
}