Skip to content

Commit 1eb81b8

Browse files
luanpotterspydon
andauthored
fix: Fix extra-packages CLI parameters to be multi-option (#16)
* chore: Update dependency versions * Bump more versions * fix: Fix extra-packages CLI parameters to be multi-option * Update lib/utils.dart Co-authored-by: Lukas Klingsbo <[email protected]> --------- Co-authored-by: Lukas Klingsbo <[email protected]>
1 parent ea9d0b4 commit 1eb81b8

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-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: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ String getOption(
7575
return value;
7676
}
7777

78+
List<String> _unwrap(dynamic value) {
79+
return switch(value) {
80+
null => [],
81+
String _ => [value],
82+
List<String> _ => value,
83+
List _ => value.map((e) => e.toString()).toList(),
84+
_ => throw ArgumentError(
85+
'Invalid type for value (${value.runtimeType}): $value',
86+
),
87+
};
88+
}
89+
7890
List<String> getMultiOption(
7991
ArgResults results,
8092
String name,
@@ -85,7 +97,7 @@ List<String> getMultiOption(
8597
List<String> startingOptions = const [],
8698
String? desc,
8799
}) {
88-
var value = results[name] as List<String>? ?? [];
100+
var value = _unwrap(results[name]);
89101
if (!isInteractive) {
90102
if (value.isEmpty) {
91103
if (startingOptions.isNotEmpty) {
@@ -94,6 +106,8 @@ List<String> getMultiOption(
94106
print('Missing parameter $name is required.');
95107
exit(1);
96108
}
109+
} else {
110+
return value;
97111
}
98112
}
99113
if (value.any((e) => !options.contains(e))) {
@@ -103,7 +117,10 @@ List<String> getMultiOption(
103117
if (desc != null) {
104118
stdout.write(ansi.darkGray.wrap('\n$desc\u{1B}[1A\r'));
105119
}
106-
value = cbx(message, options, startingOptions);
120+
final selectedOptions = value.isEmpty
121+
? startingOptions
122+
: value;
123+
value = cbx(message, options, selectedOptions);
107124
if (desc != null) {
108125
stdout.write('\r\u{1B}[K');
109126
}

0 commit comments

Comments
 (0)