From de8df504e159b4afb6acfec5cdebecd3591e3682 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 18 Dec 2024 12:41:52 -0600 Subject: [PATCH] feat(shorebird_cli): add `--no-confirm` to `release` and `patch` commands (#2707) --- .../lib/src/commands/patch/patch_command.dart | 10 +++++++++- .../lib/src/commands/release/release_command.dart | 10 +++++++++- packages/shorebird_cli/lib/src/common_arguments.dart | 8 ++++++++ .../test/src/commands/patch/patch_command_test.dart | 11 +++++++++++ .../src/commands/release/release_command_test.dart | 11 +++++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart b/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart index 1d96c6e2..d3176f5a 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/patch_command.dart @@ -99,6 +99,11 @@ of the iOS app that is using this module.''', [DEPRECATED] Whether to publish the patch to the staging environment. Use --track=staging instead.''', hide: true, ) + ..addFlag( + CommonArguments.noConfirmArg.name, + help: CommonArguments.noConfirmArg.description, + negatable: false, + ) ..addOption( CommonArguments.exportOptionsPlistArg.name, help: CommonArguments.exportOptionsPlistArg.description, @@ -169,6 +174,9 @@ NOTE: this is ${styleBold.wrap('not')} recommended. Asset changes cannot be incl /// Whether to allow changes in native code (--allow-native-diffs). bool get allowNativeDiffs => results['allow-native-diffs'] == true; + /// Whether --no-confirm was passed. + bool get noConfirm => results['no-confirm'] == true; + bool get isStaging => track == DeploymentTrack.staging; DeploymentTrack get track { @@ -493,7 +501,7 @@ ${summary.join('\n')} ''', ); - if (shorebirdEnv.canAcceptUserInput) { + if (shorebirdEnv.canAcceptUserInput && !noConfirm) { final confirm = logger.confirm('Would you like to continue?'); if (!confirm) { diff --git a/packages/shorebird_cli/lib/src/commands/release/release_command.dart b/packages/shorebird_cli/lib/src/commands/release/release_command.dart index a6e3bc49..5deddd66 100644 --- a/packages/shorebird_cli/lib/src/commands/release/release_command.dart +++ b/packages/shorebird_cli/lib/src/commands/release/release_command.dart @@ -116,6 +116,11 @@ class ReleaseCommand extends ShorebirdCommand { hide: true, negatable: false, ) + ..addFlag( + CommonArguments.noConfirmArg.name, + help: CommonArguments.noConfirmArg.description, + negatable: false, + ) ..addOption( 'release-version', help: ''' @@ -216,6 +221,9 @@ of the iOS app that is using this module. (aar and ios-framework only)''', /// The target script, if provided. late String? target = results.findOption('target', argParser: argParser); + /// Whether --no-confirm was passed. + bool get noConfirm => results['no-confirm'] == true; + /// The flutter version specified by the user, if any. late String? flutterVersionArg = results['flutter-version'] as String?; @@ -438,7 +446,7 @@ ${styleBold.wrap(lightGreen.wrap('🚀 Ready to create a new release!'))} ${summary.join('\n')} '''); - if (shorebirdEnv.canAcceptUserInput) { + if (shorebirdEnv.canAcceptUserInput && !noConfirm) { final confirm = logger.confirm('Would you like to continue?'); if (!confirm) { diff --git a/packages/shorebird_cli/lib/src/common_arguments.dart b/packages/shorebird_cli/lib/src/common_arguments.dart index 722fb13e..30009c39 100644 --- a/packages/shorebird_cli/lib/src/common_arguments.dart +++ b/packages/shorebird_cli/lib/src/common_arguments.dart @@ -127,6 +127,14 @@ In a release build, this flag reduces application size by storing Dart program s in the application. The value of the flag should be a directory where program symbol files can be stored for later use. These symbol files contain the information needed to symbolize Dart stack traces. For an app built with this flag, the "flutter symbolize" command with the right program symbol file is required to obtain a human readable stack trace. +''', + ); + + /// An argument that allows the user to bypass interactive confirmations. + static const noConfirmArg = ArgumentDescriber( + name: 'no-confirm', + description: ''' +Bypass all confirmation messages. It's generally not advised to use this unless running from a script. ''', ); } diff --git a/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart b/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart index d49cedc8..719bd1e2 100644 --- a/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/patch_command_test.dart @@ -938,6 +938,17 @@ void main() { }); }); + group('when --no-confirm is specified', () { + setUp(() { + when(() => argResults['no-confirm']).thenReturn(true); + }); + + test('does not prompt for confirmation', () async { + await runWithOverrides(command.run); + verifyNever(() => logger.confirm(any())); + }); + }); + group('when running on CI', () { test('does not prompt for confirmation', () async { when(() => shorebirdEnv.canAcceptUserInput).thenReturn(false); diff --git a/packages/shorebird_cli/test/src/commands/release/release_command_test.dart b/packages/shorebird_cli/test/src/commands/release/release_command_test.dart index 01a59772..039db00d 100644 --- a/packages/shorebird_cli/test/src/commands/release/release_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/release/release_command_test.dart @@ -291,6 +291,17 @@ Note: ${lightCyan.wrap('shorebird patch --platforms=android')} without the --rel }); }); + group('when --no-confirm is specified', () { + setUp(() { + when(() => argResults['no-confirm']).thenReturn(true); + }); + + test('does not prompt for confirmation', () async { + await runWithOverrides(command.run); + verifyNever(() => logger.confirm(any())); + }); + }); + group('when release version arg is required', () { setUp(() { when(() => releaser.requiresReleaseVersionArg).thenReturn(true);