From b4983cf8922e9da2e1aa08f45ae75914d2397499 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Tue, 11 Jul 2023 10:56:31 -0400 Subject: [PATCH] feat(shorebird_cli): add `--force` flag to `apps delete` command (#812) --- .../commands/apps/delete_apps_command.dart | 22 ++++++++++++++----- .../apps/delete_apps_command_test.dart | 13 +++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/apps/delete_apps_command.dart b/packages/shorebird_cli/lib/src/commands/apps/delete_apps_command.dart index a2d821f9..348b9043 100644 --- a/packages/shorebird_cli/lib/src/commands/apps/delete_apps_command.dart +++ b/packages/shorebird_cli/lib/src/commands/apps/delete_apps_command.dart @@ -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; } diff --git a/packages/shorebird_cli/test/src/commands/apps/delete_apps_command_test.dart b/packages/shorebird_cli/test/src/commands/apps/delete_apps_command_test.dart index d5ac87d0..1e48ff1c 100644 --- a/packages/shorebird_cli/test/src/commands/apps/delete_apps_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/apps/delete_apps_command_test.dart @@ -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);