diff --git a/lib/src/commands/create/commands/flutter_app.dart b/lib/src/commands/create/commands/flutter_app.dart index 85f3e1a75..04e44ed0e 100644 --- a/lib/src/commands/create/commands/flutter_app.dart +++ b/lib/src/commands/create/commands/flutter_app.dart @@ -11,12 +11,28 @@ class CreateFlutterApp extends CreateSubCommand with OrgName, MultiTemplates { required super.generatorFromBundle, required super.generatorFromBrick, }) { - argParser.addOption( - 'application-id', - help: - 'The bundle identifier on iOS or application id on Android. ' - '(defaults to .)', - ); + argParser + ..addOption( + 'application-id', + help: + 'The bundle identifier on iOS or application id on Android. ' + '(defaults to .)', + ) + ..addMultiOption( + 'platforms', + help: + 'The platforms supported by the app. By default, all platforms ' + 'are enabled. Example: --platforms=android,ios', + defaultsTo: ['android', 'ios', 'macos', 'web', 'windows'], + allowed: ['android', 'ios', 'macos', 'web', 'windows'], + allowedHelp: { + 'android': 'The app supports the Android platform.', + 'ios': 'The app supports the iOS platform.', + 'macos': 'The app supports the macOS platform.', + 'web': 'The app supports the Web platform.', + 'windows': 'The app supports the Windows platform.', + }, + ); } @override @@ -34,6 +50,9 @@ class CreateFlutterApp extends CreateSubCommand with OrgName, MultiTemplates { vars['application_id'] = applicationId; } + final platforms = argResults['platforms'] as List; + vars['platforms'] = platforms; + return vars; } diff --git a/test/src/commands/create/commands/flutter_app_test.dart b/test/src/commands/create/commands/flutter_app_test.dart index 482dd7e71..34326ee25 100644 --- a/test/src/commands/create/commands/flutter_app_test.dart +++ b/test/src/commands/create/commands/flutter_app_test.dart @@ -27,17 +27,24 @@ final expectedUsage = [ Generate a Very Good Flutter application. Usage: very_good create flutter_app [arguments] --h, --help Print this usage information. --o, --output-directory The desired output directory when creating a new project. - --description The description for this new project. - (defaults to "A Very Good Project created by Very Good CLI.") --t, --template The template used to generate this new project. +-h, --help Print this usage information. +-o, --output-directory The desired output directory when creating a new project. + --description The description for this new project. + (defaults to "A Very Good Project created by Very Good CLI.") +-t, --template The template used to generate this new project. - [core] (default) Generate a Very Good Flutter application. + [core] (default) Generate a Very Good Flutter application. - --org-name The organization for this new project. - (defaults to "com.example.verygoodcore") - --application-id The bundle identifier on iOS or application id on Android. (defaults to .) + --org-name The organization for this new project. + (defaults to "com.example.verygoodcore") + --application-id The bundle identifier on iOS or application id on Android. (defaults to .) + --platforms The platforms supported by the app. By default, all platforms are enabled. Example: --platforms=android,ios + + [android] (default) The app supports the Android platform. + [ios] (default) The app supports the iOS platform. + [macos] (default) The app supports the macOS platform. + [web] (default) The app supports the Web platform. + [windows] (default) The app supports the Windows platform. Run "very_good help" to see global options.''', ]; @@ -169,12 +176,54 @@ void main() { hooks: hooks, generator: generator, templateName: 'core', - mockArgs: {'application-id': 'xyz.app.my_app'}, + mockArgs: { + 'application-id': 'xyz.app.my_app', + 'platforms': const [ + 'android', + 'ios', + 'macos', + 'web', + 'windows', + ], + }, + expectedVars: { + 'project_name': 'my_app', + 'description': '', + 'org_name': 'com.example.verygoodcore', + 'application_id': 'xyz.app.my_app', + 'platforms': const [ + 'android', + 'ios', + 'macos', + 'web', + 'windows', + ], + }, + expectedLogSummary: 'Created a Very Good App! 🦄', + ); + }); + + test('generates successfully with custom platforms', () async { + await testMultiTemplateCommand( + multiTemplatesCommand: CreateFlutterApp( + logger: logger, + generatorFromBundle: (_) async => throw Exception('oops'), + generatorFromBrick: (_) async => generator, + ), + logger: logger, + hooks: hooks, + generator: generator, + templateName: 'core', + mockArgs: { + 'application-id': 'xyz.app.my_app', + 'platforms': const ['android', 'ios'], + }, expectedVars: { 'project_name': 'my_app', 'description': '', 'org_name': 'com.example.verygoodcore', 'application_id': 'xyz.app.my_app', + 'platforms': const ['android', 'ios'], }, expectedLogSummary: 'Created a Very Good App! 🦄', ); @@ -195,12 +244,28 @@ void main() { hooks: hooks, generator: generator, templateName: 'core', - mockArgs: {'application-id': 'xyz.app.my_app'}, + mockArgs: { + 'application-id': 'xyz.app.my_app', + 'platforms': const [ + 'android', + 'ios', + 'macos', + 'web', + 'windows', + ], + }, expectedVars: { 'project_name': 'my_app', 'description': '', 'org_name': 'com.example.verygoodcore', 'application_id': 'xyz.app.my_app', + 'platforms': const [ + 'android', + 'ios', + 'macos', + 'web', + 'windows', + ], }, expectedLogSummary: 'Created a Very Good App! 🦄', );