feat(shorebird_cli): add --force flag to apps delete command (#812)

This commit is contained in:
Bryan Oltman
2023-07-11 10:56:31 -04:00
committed by GitHub
parent 1dcf9f32d9
commit b4983cf892
2 changed files with 29 additions and 6 deletions
@@ -17,12 +17,20 @@ class DeleteAppCommand extends ShorebirdCommand
with ShorebirdConfigMixin, ShorebirdValidationMixin {
/// {@macro delete_app_command}
DeleteAppCommand({super.buildCodePushClient}) {
argParser.addOption(
'app-id',
help: '''
argParser
..addOption(
'app-id',
help: '''
The unique application identifier.
Defaults to the app_id in "shorebird.yaml".''',
);
)
..addFlag(
'force',
abbr: 'f',
help: 'Release without confirmation if there are no errors.',
negatable: false,
);
;
}
@override
@@ -42,6 +50,7 @@ Defaults to the app_id in "shorebird.yaml".''',
}
final appIdArg = results['app-id'] as String?;
final force = results['force'] == true;
late final String appId;
if (appIdArg == null) {
@@ -63,8 +72,9 @@ Defaults to the app_id in "shorebird.yaml".''',
hostedUri: ShorebirdEnvironment.hostedUri,
);
final confirm = logger.confirm('Deleting an app is permanent. Continue?');
if (!confirm) {
final shouldProceed =
force || logger.confirm('Deleting an app is permanent. Continue?');
if (!shouldProceed) {
logger.info('Aborted.');
return ExitCode.success.code;
}
@@ -98,6 +98,19 @@ void main() {
verify(() => logger.info('Aborted.')).called(1);
});
test('does not prompt for confirmation when force flag is provided',
() async {
when(() => argResults['app-id']).thenReturn(appId);
when(() => argResults['force']).thenReturn(true);
when(
() => codePushClient.deleteApp(appId: appId),
).thenAnswer((_) async {});
final result = await runWithOverrides(command.run);
expect(result, ExitCode.success.code);
verify(() => codePushClient.deleteApp(appId: appId));
verifyNever(() => logger.confirm(any()));
});
test('returns success when app is deleted', () async {
when(() => logger.confirm(any())).thenReturn(true);
when(() => argResults['app-id']).thenReturn(appId);