diff --git a/packages/shorebird_cli/lib/src/commands/preview_command.dart b/packages/shorebird_cli/lib/src/commands/preview_command.dart index 7a28dc387..9b28c83af 100644 --- a/packages/shorebird_cli/lib/src/commands/preview_command.dart +++ b/packages/shorebird_cli/lib/src/commands/preview_command.dart @@ -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( + 'Which app flavor?', + choices: flavorOptions, + ); + appId = flavors[choosenFlavor]; } else { appId = await promptForApp(); } diff --git a/packages/shorebird_cli/test/src/commands/preview_command_test.dart b/packages/shorebird_cli/test/src/commands/preview_command_test.dart index 020a10e75..0b50085a8 100644 --- a/packages/shorebird_cli/test/src/commands/preview_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/preview_command_test.dart @@ -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( + () => logger.chooseOne( any(), choices: any(named: 'choices'), - display: any(named: 'display'), ), - ).thenReturn(app); + ).thenReturn('dev'); await runWithOverrides(command.run); verify( - () => logger.chooseOne( - 'Which app would you like to preview?', - choices: any(named: 'choices'), - display: any(named: 'display'), + () => logger.chooseOne( + any(), + choices: ['dev', 'prod'], ), ).called(1); });