@@ -75,6 +75,22 @@ String getOption(
75
75
return value;
76
76
}
77
77
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
+
78
94
List <String > getMultiOption (
79
95
ArgResults results,
80
96
String name,
@@ -85,7 +101,7 @@ List<String> getMultiOption(
85
101
List <String > startingOptions = const [],
86
102
String ? desc,
87
103
}) {
88
- var value = results[name] as List < String > ? ?? [] ;
104
+ var value = _unwrap ( results[name]) ;
89
105
if (! isInteractive) {
90
106
if (value.isEmpty) {
91
107
if (startingOptions.isNotEmpty) {
@@ -94,6 +110,8 @@ List<String> getMultiOption(
94
110
print ('Missing parameter $name is required.' );
95
111
exit (1 );
96
112
}
113
+ } else {
114
+ return value;
97
115
}
98
116
}
99
117
if (value.any ((e) => ! options.contains (e))) {
@@ -103,7 +121,10 @@ List<String> getMultiOption(
103
121
if (desc != null ) {
104
122
stdout.write (ansi.darkGray.wrap ('\n $desc \u {1B}[1A\r ' ));
105
123
}
106
- value = cbx (message, options, startingOptions);
124
+ final selectedOptions = value.isEmpty
125
+ ? startingOptions
126
+ : value;
127
+ value = cbx (message, options, selectedOptions);
107
128
if (desc != null ) {
108
129
stdout.write ('\r\u {1B}[K' );
109
130
}
0 commit comments