feat(shorebird_cli): add --no-confirm to release and patch commands (#2707)

This commit is contained in:
Felix Angelov
2024-12-18 12:41:52 -06:00
committed by GitHub
parent 9cd7f0ff01
commit de8df504e1
5 changed files with 48 additions and 2 deletions
@@ -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) {
@@ -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) {
@@ -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.
''',
);
}
@@ -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);
@@ -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);