Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: shorebird preview to identify shorebird projects with flavors #1854

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/shorebird_cli/lib/src/commands/preview_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,20 @@ class PreviewCommand extends ShorebirdCommand {

final shorebirdYaml = shorebirdEnv.getShorebirdYaml();
final String? appId;

final flavors = shorebirdYaml?.flavors;

if (results.wasParsed('app-id')) {
appId = results['app-id'] as String;
} else if (shorebirdYaml != null && shorebirdYaml.flavors == null) {
} else if (shorebirdYaml != null && flavors == null) {
appId = shorebirdYaml.appId;
} else if (shorebirdYaml != null && flavors != null) {
final flavorOptions = flavors.keys.toList();
final choosenFlavor = logger.chooseOne<String>(
'Which app flavor?',
choices: flavorOptions,
);
appId = flavors[choosenFlavor];
} else {
appId = await promptForApp();
}
Expand Down
19 changes: 10 additions & 9 deletions packages/shorebird_cli/test/src/commands/preview_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -712,31 +712,32 @@ channel: ${track.channel}
verifyNever(() => codePushClientWrapper.getApps());
});

test('prompts for app id when in shorebird project with flavors',
test('prompts for the flavor when in shorebird project with flavors',
() async {
when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(
const ShorebirdYaml(
appId: 'test-app-id',
flavors: {'dev': 'dev-app-id'},
flavors: {
'dev': 'dev-app-id',
'prod': 'prod-app-id',
},
),
);
when(() => argResults.wasParsed('app-id')).thenReturn(false);
when(() => argResults['app-id']).thenReturn(null);
when(
() => logger.chooseOne<AppMetadata>(
() => logger.chooseOne<String>(
any(),
choices: any(named: 'choices'),
display: any(named: 'display'),
),
).thenReturn(app);
).thenReturn('dev');

await runWithOverrides(command.run);

verify(
() => logger.chooseOne<AppMetadata>(
'Which app would you like to preview?',
choices: any(named: 'choices'),
display: any(named: 'display'),
() => logger.chooseOne<String>(
any(),
choices: ['dev', 'prod'],
),
).called(1);
});
Expand Down
Loading