@trenskow/arguments-parser 0.3.141 → 0.3.142
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/autocomplete/index.js +11 -5
- package/lib/plugins/autocomplete.js +35 -3
- package/package.json +1 -1
|
@@ -202,10 +202,7 @@ const autocomplete = () => {
|
|
|
202
202
|
return (async () => {
|
|
203
203
|
|
|
204
204
|
const {
|
|
205
|
-
variadic
|
|
206
|
-
autocomplete = () => [{
|
|
207
|
-
type: 'files'
|
|
208
|
-
}]
|
|
205
|
+
variadic
|
|
209
206
|
} = options.validationOptions;
|
|
210
207
|
|
|
211
208
|
if (args
|
|
@@ -272,8 +269,17 @@ const autocomplete = () => {
|
|
|
272
269
|
}]);
|
|
273
270
|
}
|
|
274
271
|
|
|
272
|
+
let autocomplete = [];
|
|
273
|
+
|
|
274
|
+
if (typeof schemas[autocompleteIndex].autocomplete !== 'undefined') {
|
|
275
|
+
autocomplete = schemas[autocompleteIndex].autocomplete;
|
|
276
|
+
if (typeof autocomplete === 'function') {
|
|
277
|
+
autocomplete = await autocomplete(current);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
275
281
|
output(
|
|
276
|
-
|
|
282
|
+
autocomplete);
|
|
277
283
|
|
|
278
284
|
} else {
|
|
279
285
|
|
|
@@ -15,9 +15,41 @@ export default () => ({
|
|
|
15
15
|
validate: (data) => data,
|
|
16
16
|
formalize: (data) => {
|
|
17
17
|
|
|
18
|
-
if (!
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if (!Array.isArray(data)) data = [data];
|
|
19
|
+
|
|
20
|
+
data
|
|
21
|
+
.forEach((item) => {
|
|
22
|
+
|
|
23
|
+
if (typeof item === 'string') {
|
|
24
|
+
item = {
|
|
25
|
+
type: 'option',
|
|
26
|
+
argument: item
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeof item?.type !== 'string') {
|
|
31
|
+
throw new Error('Autocomplete item must have a type.');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!['command', 'option', 'files'].includes(item.type)) {
|
|
35
|
+
throw new Error('Autocomplete item type must be one of: command, option, files.');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (item.type !== 'files') {
|
|
39
|
+
|
|
40
|
+
if (typeof item?.argument !== 'string') {
|
|
41
|
+
throw new Error('Autocomplete item must have an argument.');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (typeof item?.description !== 'undefined' && typeof item?.description !== 'string') {
|
|
45
|
+
throw new Error('Autocomplete item description must be a string.');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return item;
|
|
51
|
+
|
|
52
|
+
});
|
|
21
53
|
|
|
22
54
|
return data;
|
|
23
55
|
|