fix(shorebird_cli): shorebird init should not prompt when --force or running in CI (#1489)
This commit is contained in:
@@ -152,10 +152,14 @@ Please make sure you are running "shorebird init" from the root of your Flutter
|
||||
final String appId;
|
||||
Map<String, String>? flavors;
|
||||
try {
|
||||
final displayName = logger.prompt(
|
||||
'${lightGreen.wrap('?')} How should we refer to this app?',
|
||||
defaultValue: shorebirdEnv.getPubspecYaml()?.name,
|
||||
);
|
||||
final needsConfirmation = !force && !shorebirdEnv.isRunningOnCI;
|
||||
final pubspecName = shorebirdEnv.getPubspecYaml()!.name;
|
||||
final displayName = needsConfirmation
|
||||
? logger.prompt(
|
||||
'${lightGreen.wrap('?')} How should we refer to this app?',
|
||||
defaultValue: pubspecName,
|
||||
)
|
||||
: pubspecName;
|
||||
final hasNoFlavors = productFlavors.isEmpty;
|
||||
final hasSomeFlavors = productFlavors.isNotEmpty &&
|
||||
((androidFlavors?.isEmpty ?? false) ||
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:mason_logger/mason_logger.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:platform/platform.dart';
|
||||
import 'package:pubspec_parse/pubspec_parse.dart';
|
||||
import 'package:scoped/scoped.dart';
|
||||
import 'package:shorebird_cli/src/code_push_client_wrapper.dart';
|
||||
import 'package:shorebird_cli/src/commands/init_command.dart';
|
||||
@@ -104,8 +105,12 @@ environment:
|
||||
when(() => gradlew.productFlavors(any())).thenAnswer((_) async => {});
|
||||
when(() => platform.isMacOS).thenReturn(true);
|
||||
when(() => shorebirdEnv.hasPubspecYaml).thenReturn(true);
|
||||
when(
|
||||
() => shorebirdEnv.getPubspecYaml(),
|
||||
).thenReturn(Pubspec.parse(pubspecYamlContent));
|
||||
when(() => shorebirdEnv.hasShorebirdYaml).thenReturn(false);
|
||||
when(() => shorebirdEnv.pubspecContainsShorebirdYaml).thenReturn(false);
|
||||
when(() => shorebirdEnv.isRunningOnCI).thenReturn(false);
|
||||
when(
|
||||
() => shorebirdValidator.validatePreconditions(
|
||||
checkUserIsAuthenticated: any(named: 'checkUserIsAuthenticated'),
|
||||
@@ -176,6 +181,28 @@ Please make sure you are running "shorebird init" from the root of your Flutter
|
||||
expect(exitCode, ExitCode.software.code);
|
||||
});
|
||||
|
||||
test('does not prompt for name when running on ci', () async {
|
||||
when(() => shorebirdEnv.isRunningOnCI).thenReturn(true);
|
||||
await runWithOverrides(command.run);
|
||||
verifyNever(
|
||||
() => logger.prompt(any(), defaultValue: any(named: 'defaultValue')),
|
||||
);
|
||||
verify(
|
||||
() => codePushClientWrapper.createApp(appName: appName),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('does not prompt for name when --force', () async {
|
||||
when(() => argResults['force']).thenReturn(true);
|
||||
await runWithOverrides(command.run);
|
||||
verifyNever(
|
||||
() => logger.prompt(any(), defaultValue: any(named: 'defaultValue')),
|
||||
);
|
||||
verify(
|
||||
() => codePushClientWrapper.createApp(appName: appName),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('--force overwrites existing shorebird.yaml', () async {
|
||||
when(() => shorebirdEnv.hasShorebirdYaml).thenReturn(true);
|
||||
when(() => argResults['force']).thenReturn(true);
|
||||
|
||||
Reference in New Issue
Block a user