@trenskow/arguments-parser 0.3.140 → 0.3.141
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/bash.js +0 -2
- package/lib/autocomplete/index.js +84 -88
- package/lib/autocomplete/zsh.js +0 -2
- package/package.json +1 -1
package/lib/autocomplete/bash.js
CHANGED
|
@@ -105,24 +105,30 @@ const autocomplete = () => {
|
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
const output = (items) =>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
grouped
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
108
|
+
const output = (items) => {
|
|
109
|
+
|
|
110
|
+
writer(
|
|
111
|
+
filter(items)
|
|
112
|
+
.reduce((grouped, item) => {
|
|
113
|
+
|
|
114
|
+
grouped[item.type] = grouped[item.type] || [];
|
|
115
|
+
|
|
116
|
+
switch (item.type) {
|
|
117
|
+
case 'option':
|
|
118
|
+
// fall through
|
|
119
|
+
case 'command':
|
|
120
|
+
grouped[item.type].push(item);
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
}
|
|
122
124
|
|
|
123
|
-
|
|
125
|
+
return grouped;
|
|
124
126
|
|
|
125
|
-
|
|
127
|
+
}, {}));
|
|
128
|
+
|
|
129
|
+
process.exit(0);
|
|
130
|
+
|
|
131
|
+
};
|
|
126
132
|
|
|
127
133
|
const result = {
|
|
128
134
|
get base() {
|
|
@@ -202,9 +208,14 @@ const autocomplete = () => {
|
|
|
202
208
|
}]
|
|
203
209
|
} = options.validationOptions;
|
|
204
210
|
|
|
205
|
-
|
|
211
|
+
if (args
|
|
206
212
|
.slice(0, autocompleteIndex)
|
|
207
|
-
.some((arg) => arg === '--')
|
|
213
|
+
.some((arg) => arg === '--')
|
|
214
|
+
) {
|
|
215
|
+
output([{
|
|
216
|
+
type: 'files'
|
|
217
|
+
}]);
|
|
218
|
+
}
|
|
208
219
|
|
|
209
220
|
const allKeyPaths = keyPaths(options.schema)
|
|
210
221
|
.all()
|
|
@@ -214,107 +225,92 @@ const autocomplete = () => {
|
|
|
214
225
|
let schemas = {};
|
|
215
226
|
let spent = [];
|
|
216
227
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (nonOptions) {
|
|
220
|
-
return [{
|
|
221
|
-
type: 'files'
|
|
222
|
-
}];
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
let key = current;
|
|
228
|
+
for (idx = 0; idx < autocompleteIndex || idx < args.length; idx++) {
|
|
226
229
|
|
|
227
|
-
|
|
228
|
-
key = key.slice(1);
|
|
229
|
-
}
|
|
230
|
+
if (!schemas[idx]) {
|
|
230
231
|
|
|
231
|
-
|
|
232
|
+
if (!(args[idx] || '').startsWith('-')) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
232
235
|
|
|
233
|
-
|
|
236
|
+
const [keyPath, schema] = allKeyPaths
|
|
237
|
+
.filter((keyPath) => !spent.includes(keyPath))
|
|
238
|
+
.map((keyPath) => [keyPath, keyPaths(options.schema).get(keyPath)])
|
|
239
|
+
.filter(([keyPath, schema]) => keyPath === args[idx] || `--${caseit(keyPath, 'kebab')}` === args[idx] || (schema.short && `-${schema.short}` === args[idx]))[0] || [];
|
|
234
240
|
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
.map((item) => ({
|
|
238
|
-
type: 'option',
|
|
239
|
-
argument: caseit(item, 'kebab')
|
|
240
|
-
}));
|
|
241
|
+
if (schema && schema.type !== Array) {
|
|
242
|
+
spent.push(keyPath);
|
|
241
243
|
}
|
|
242
244
|
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
type: 'files'
|
|
246
|
-
}];
|
|
245
|
+
if (schema && schema.type !== Boolean) {
|
|
246
|
+
schemas[idx + 1] = schema;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
}
|
|
250
252
|
|
|
251
|
-
|
|
253
|
+
let current = args[autocompleteIndex] || '';
|
|
252
254
|
|
|
253
|
-
|
|
255
|
+
while (current.startsWith('-')) {
|
|
256
|
+
current = current.slice(1);
|
|
257
|
+
}
|
|
254
258
|
|
|
255
|
-
|
|
256
|
-
items = items.concat(
|
|
257
|
-
await autocomplete?.(current) || []);
|
|
258
|
-
}
|
|
259
|
+
if (schemas[autocompleteIndex]) {
|
|
259
260
|
|
|
260
|
-
|
|
261
|
+
if (schemas[autocompleteIndex].enum) {
|
|
262
|
+
output(Object.keys(schemas[autocompleteIndex].enum)
|
|
263
|
+
.map((item) => ({
|
|
264
|
+
type: 'option',
|
|
265
|
+
argument: caseit(item, 'kebab')
|
|
266
|
+
})));
|
|
267
|
+
}
|
|
261
268
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
type: 'option',
|
|
268
|
-
argument: `-${caseit(keyPaths(options.schema).get(keyPath).short, 'kebab')}`,
|
|
269
|
-
description: keyPaths(options.schema).get(keyPath).description
|
|
270
|
-
})));
|
|
269
|
+
if (schemas[autocompleteIndex].type === String && !schemas[autocompleteIndex].autocomplete) {
|
|
270
|
+
output([{
|
|
271
|
+
type: 'files'
|
|
272
|
+
}]);
|
|
273
|
+
}
|
|
271
274
|
|
|
272
|
-
|
|
275
|
+
output(
|
|
276
|
+
await schemas[autocompleteIndex].autocomplete?.(current) || []);
|
|
277
|
+
|
|
278
|
+
} else {
|
|
279
|
+
|
|
280
|
+
let items = [];
|
|
281
|
+
|
|
282
|
+
if (variadic === 'allow') {
|
|
283
|
+
items = items.concat(
|
|
284
|
+
await autocomplete?.(current) || []);
|
|
285
|
+
}
|
|
273
286
|
|
|
287
|
+
if (!current.startsWith('--')) {
|
|
274
288
|
|
|
275
289
|
items = items.concat(
|
|
276
290
|
allKeyPaths
|
|
291
|
+
.filter((keyPath) => keyPaths(options.schema).get(keyPath).short)
|
|
277
292
|
.filter((keyPath) => !spent.includes(keyPath))
|
|
278
293
|
.map((keyPath) => ({
|
|
279
294
|
type: 'option',
|
|
280
|
-
argument:
|
|
295
|
+
argument: `-${caseit(keyPaths(options.schema).get(keyPath).short, 'kebab')}`,
|
|
281
296
|
description: keyPaths(options.schema).get(keyPath).description
|
|
282
297
|
})));
|
|
283
298
|
|
|
284
|
-
return items;
|
|
285
|
-
|
|
286
299
|
}
|
|
287
300
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
for (idx = 0; idx < autocompleteIndex || idx < args.length; idx++) {
|
|
291
|
-
|
|
292
|
-
if (!schemas[idx]) {
|
|
293
|
-
|
|
294
|
-
if (nonOptions || !(args[idx] || '').startsWith('-')) {
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const [keyPath, schema] = allKeyPaths
|
|
301
|
+
items = items.concat(
|
|
302
|
+
allKeyPaths
|
|
299
303
|
.filter((keyPath) => !spent.includes(keyPath))
|
|
300
|
-
.map((keyPath) =>
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (schema && schema.type !== Boolean) {
|
|
308
|
-
schemas[idx + 1] = schema;
|
|
309
|
-
}
|
|
304
|
+
.map((keyPath) => ({
|
|
305
|
+
type: 'option',
|
|
306
|
+
argument: `--${caseit(keyPath, 'kebab')}`,
|
|
307
|
+
description: keyPaths(options.schema).get(keyPath).description
|
|
308
|
+
})));
|
|
310
309
|
|
|
311
|
-
|
|
310
|
+
output(items);
|
|
312
311
|
|
|
313
312
|
}
|
|
314
313
|
|
|
315
|
-
return output(
|
|
316
|
-
await complete());
|
|
317
|
-
|
|
318
314
|
})().then(...resultArguments);
|
|
319
315
|
}
|
|
320
316
|
};
|
package/lib/autocomplete/zsh.js
CHANGED