@trenskow/arguments-parser 0.3.142 → 0.3.144
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 +48 -12
- package/lib/plugins/autocomplete.js +0 -34
- package/package.json +4 -4
|
@@ -89,10 +89,50 @@ const autocomplete = () => {
|
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
if (typeof item?.type !== 'string') {
|
|
93
|
+
throw new Error('Autocomplete item must have a type.');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!['command', 'option', 'files'].includes(item.type)) {
|
|
97
|
+
throw new Error('Autocomplete item type must be one of: `command`, `option`, `files`.');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (item.type !== 'files') {
|
|
101
|
+
|
|
102
|
+
if (typeof item?.argument !== 'string') {
|
|
103
|
+
throw new Error('Autocomplete item must have an argument.');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (typeof item?.description !== 'undefined' && typeof item?.description !== 'string') {
|
|
107
|
+
throw new Error('Autocomplete item description must be a string.');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
92
112
|
return item;
|
|
93
113
|
|
|
94
114
|
});
|
|
95
115
|
|
|
116
|
+
const resolveExternal = async (external, current) => {
|
|
117
|
+
|
|
118
|
+
let autocomplete = [{
|
|
119
|
+
type: 'files'
|
|
120
|
+
}];
|
|
121
|
+
|
|
122
|
+
if (typeof external !== 'undefined') {
|
|
123
|
+
|
|
124
|
+
autocomplete = external;
|
|
125
|
+
|
|
126
|
+
if (typeof autocomplete === 'function') {
|
|
127
|
+
autocomplete = await autocomplete(current);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return autocomplete;
|
|
133
|
+
|
|
134
|
+
};
|
|
135
|
+
|
|
96
136
|
const filter = (items) => normalize(items)
|
|
97
137
|
.filter((item) => {
|
|
98
138
|
switch (item.type) {
|
|
@@ -202,7 +242,8 @@ const autocomplete = () => {
|
|
|
202
242
|
return (async () => {
|
|
203
243
|
|
|
204
244
|
const {
|
|
205
|
-
variadic
|
|
245
|
+
variadic,
|
|
246
|
+
autocomplete: variadicAutocomplete
|
|
206
247
|
} = options.validationOptions;
|
|
207
248
|
|
|
208
249
|
if (args
|
|
@@ -269,17 +310,10 @@ const autocomplete = () => {
|
|
|
269
310
|
}]);
|
|
270
311
|
}
|
|
271
312
|
|
|
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
|
-
|
|
281
313
|
output(
|
|
282
|
-
|
|
314
|
+
await resolveExternal(
|
|
315
|
+
schemas[autocompleteIndex].autocomplete,
|
|
316
|
+
current));
|
|
283
317
|
|
|
284
318
|
} else {
|
|
285
319
|
|
|
@@ -287,7 +321,9 @@ const autocomplete = () => {
|
|
|
287
321
|
|
|
288
322
|
if (variadic === 'allow') {
|
|
289
323
|
items = items.concat(
|
|
290
|
-
await
|
|
324
|
+
await resolveExternal(
|
|
325
|
+
variadicAutocomplete,
|
|
326
|
+
current));
|
|
291
327
|
}
|
|
292
328
|
|
|
293
329
|
if (!current.startsWith('--')) {
|
|
@@ -17,40 +17,6 @@ export default () => ({
|
|
|
17
17
|
|
|
18
18
|
if (!Array.isArray(data)) data = [data];
|
|
19
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
|
-
});
|
|
53
|
-
|
|
54
20
|
return data;
|
|
55
21
|
|
|
56
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trenskow/arguments-parser",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.144",
|
|
4
4
|
"description": "Yet another arguments parser.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"isvalid": "^5.0.21"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@eslint/eslintrc": "^3.3.
|
|
33
|
+
"@eslint/eslintrc": "^3.3.7",
|
|
34
34
|
"@eslint/js": "^10.0.1",
|
|
35
|
-
"eslint": "^10.
|
|
36
|
-
"globals": "^17.
|
|
35
|
+
"eslint": "^10.10.0",
|
|
36
|
+
"globals": "^17.12.0"
|
|
37
37
|
}
|
|
38
38
|
}
|