Skip to content

Commit 09ebff9

Browse files
committed
fix: Fix extra-packages CLI parameters to be multi-option
1 parent 51838b6 commit 09ebff9

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Future<void> mainCommand(List<String> args) async {
4848
help: 'What Flame version you would like to use.',
4949
allowed: flameVersions.versions,
5050
);
51-
create.addOption(
51+
create.addMultiOption(
5252
'extra-packages',
5353
help: 'Which packages to use',
5454
allowed: packages.keys.map((e) => e.name).toList(),

lib/utils.dart

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ String getOption(
7575
return value;
7676
}
7777

78+
List<String> _unwrap(dynamic value) {
79+
if (value == null) {
80+
return [];
81+
} else if (value is String) {
82+
return [value];
83+
} else if (value is List<String>) {
84+
return value;
85+
} else if (value is List) {
86+
return value.map((e) => e.toString()).toList();
87+
} else {
88+
throw ArgumentError(
89+
'Invalid type for value (${value.runtimeType}): $value',
90+
);
91+
}
92+
}
93+
7894
List<String> getMultiOption(
7995
ArgResults results,
8096
String name,
@@ -85,7 +101,7 @@ List<String> getMultiOption(
85101
List<String> startingOptions = const [],
86102
String? desc,
87103
}) {
88-
var value = results[name] as List<String>? ?? [];
104+
var value = _unwrap(results[name]);
89105
if (!isInteractive) {
90106
if (value.isEmpty) {
91107
if (startingOptions.isNotEmpty) {
@@ -94,6 +110,8 @@ List<String> getMultiOption(
94110
print('Missing parameter $name is required.');
95111
exit(1);
96112
}
113+
} else {
114+
return value;
97115
}
98116
}
99117
if (value.any((e) => !options.contains(e))) {
@@ -103,7 +121,10 @@ List<String> getMultiOption(
103121
if (desc != null) {
104122
stdout.write(ansi.darkGray.wrap('\n$desc\u{1B}[1A\r'));
105123
}
106-
value = cbx(message, options, startingOptions);
124+
final selectedOptions = value.isEmpty
125+
? startingOptions
126+
: value;
127+
value = cbx(message, options, selectedOptions);
107128
if (desc != null) {
108129
stdout.write('\r\u{1B}[K');
109130
}

0 commit comments

Comments
 (0)