Skip to content

Commit 11bd085

Browse files
feat: add --platforms flag support to flutter_app template (#1620)
* feat: add --platforms flag support to flutter_app template Closes #1617 Co-authored-by: marcossevilla <marcossevilla@users.noreply.github.com> * chore: run analyze --------- Co-authored-by: very-good-code-bot[bot] <269805761+very-good-code-bot[bot]@users.noreply.github.com> Co-authored-by: marcossevilla <marcossevilla@users.noreply.github.com> Co-authored-by: Marcos Sevilla <me@marcossevilla.dev>
1 parent 547d291 commit 11bd085

2 files changed

Lines changed: 101 additions & 17 deletions

File tree

lib/src/commands/create/commands/flutter_app.dart

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,28 @@ class CreateFlutterApp extends CreateSubCommand with OrgName, MultiTemplates {
1111
required super.generatorFromBundle,
1212
required super.generatorFromBrick,
1313
}) {
14-
argParser.addOption(
15-
'application-id',
16-
help:
17-
'The bundle identifier on iOS or application id on Android. '
18-
'(defaults to <org-name>.<project-name>)',
19-
);
14+
argParser
15+
..addOption(
16+
'application-id',
17+
help:
18+
'The bundle identifier on iOS or application id on Android. '
19+
'(defaults to <org-name>.<project-name>)',
20+
)
21+
..addMultiOption(
22+
'platforms',
23+
help:
24+
'The platforms supported by the app. By default, all platforms '
25+
'are enabled. Example: --platforms=android,ios',
26+
defaultsTo: ['android', 'ios', 'macos', 'web', 'windows'],
27+
allowed: ['android', 'ios', 'macos', 'web', 'windows'],
28+
allowedHelp: {
29+
'android': 'The app supports the Android platform.',
30+
'ios': 'The app supports the iOS platform.',
31+
'macos': 'The app supports the macOS platform.',
32+
'web': 'The app supports the Web platform.',
33+
'windows': 'The app supports the Windows platform.',
34+
},
35+
);
2036
}
2137

2238
@override
@@ -34,6 +50,9 @@ class CreateFlutterApp extends CreateSubCommand with OrgName, MultiTemplates {
3450
vars['application_id'] = applicationId;
3551
}
3652

53+
final platforms = argResults['platforms'] as List<String>;
54+
vars['platforms'] = platforms;
55+
3756
return vars;
3857
}
3958

test/src/commands/create/commands/flutter_app_test.dart

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ final expectedUsage = [
2727
Generate a Very Good Flutter application.
2828
2929
Usage: very_good create flutter_app <project-name> [arguments]
30-
-h, --help Print this usage information.
31-
-o, --output-directory The desired output directory when creating a new project.
32-
--description The description for this new project.
33-
(defaults to "A Very Good Project created by Very Good CLI.")
34-
-t, --template The template used to generate this new project.
30+
-h, --help Print this usage information.
31+
-o, --output-directory The desired output directory when creating a new project.
32+
--description The description for this new project.
33+
(defaults to "A Very Good Project created by Very Good CLI.")
34+
-t, --template The template used to generate this new project.
3535
36-
[core] (default) Generate a Very Good Flutter application.
36+
[core] (default) Generate a Very Good Flutter application.
3737
38-
--org-name The organization for this new project.
39-
(defaults to "com.example.verygoodcore")
40-
--application-id The bundle identifier on iOS or application id on Android. (defaults to <org-name>.<project-name>)
38+
--org-name The organization for this new project.
39+
(defaults to "com.example.verygoodcore")
40+
--application-id The bundle identifier on iOS or application id on Android. (defaults to <org-name>.<project-name>)
41+
--platforms The platforms supported by the app. By default, all platforms are enabled. Example: --platforms=android,ios
42+
43+
[android] (default) The app supports the Android platform.
44+
[ios] (default) The app supports the iOS platform.
45+
[macos] (default) The app supports the macOS platform.
46+
[web] (default) The app supports the Web platform.
47+
[windows] (default) The app supports the Windows platform.
4148
4249
Run "very_good help" to see global options.''',
4350
];
@@ -169,12 +176,54 @@ void main() {
169176
hooks: hooks,
170177
generator: generator,
171178
templateName: 'core',
172-
mockArgs: {'application-id': 'xyz.app.my_app'},
179+
mockArgs: {
180+
'application-id': 'xyz.app.my_app',
181+
'platforms': const [
182+
'android',
183+
'ios',
184+
'macos',
185+
'web',
186+
'windows',
187+
],
188+
},
189+
expectedVars: {
190+
'project_name': 'my_app',
191+
'description': '',
192+
'org_name': 'com.example.verygoodcore',
193+
'application_id': 'xyz.app.my_app',
194+
'platforms': const [
195+
'android',
196+
'ios',
197+
'macos',
198+
'web',
199+
'windows',
200+
],
201+
},
202+
expectedLogSummary: 'Created a Very Good App! 🦄',
203+
);
204+
});
205+
206+
test('generates successfully with custom platforms', () async {
207+
await testMultiTemplateCommand(
208+
multiTemplatesCommand: CreateFlutterApp(
209+
logger: logger,
210+
generatorFromBundle: (_) async => throw Exception('oops'),
211+
generatorFromBrick: (_) async => generator,
212+
),
213+
logger: logger,
214+
hooks: hooks,
215+
generator: generator,
216+
templateName: 'core',
217+
mockArgs: {
218+
'application-id': 'xyz.app.my_app',
219+
'platforms': const ['android', 'ios'],
220+
},
173221
expectedVars: {
174222
'project_name': 'my_app',
175223
'description': '',
176224
'org_name': 'com.example.verygoodcore',
177225
'application_id': 'xyz.app.my_app',
226+
'platforms': const ['android', 'ios'],
178227
},
179228
expectedLogSummary: 'Created a Very Good App! 🦄',
180229
);
@@ -195,12 +244,28 @@ void main() {
195244
hooks: hooks,
196245
generator: generator,
197246
templateName: 'core',
198-
mockArgs: {'application-id': 'xyz.app.my_app'},
247+
mockArgs: {
248+
'application-id': 'xyz.app.my_app',
249+
'platforms': const [
250+
'android',
251+
'ios',
252+
'macos',
253+
'web',
254+
'windows',
255+
],
256+
},
199257
expectedVars: {
200258
'project_name': 'my_app',
201259
'description': '',
202260
'org_name': 'com.example.verygoodcore',
203261
'application_id': 'xyz.app.my_app',
262+
'platforms': const [
263+
'android',
264+
'ios',
265+
'macos',
266+
'web',
267+
'windows',
268+
],
204269
},
205270
expectedLogSummary: 'Created a Very Good App! 🦄',
206271
);

0 commit comments

Comments
 (0)