@bemoje/cli 2.1.2 → 2.1.4
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/index.d.ts +926 -28
- package/index.mjs +573 -412
- package/package.json +1 -1
- package/index.mjs.map +0 -7
- package/lib/Command.d.ts +0 -149
- package/lib/Help.d.ts +0 -178
- package/lib/helpers/findCommand.d.ts +0 -6
- package/lib/helpers/findOption.d.ts +0 -6
- package/lib/helpers/getCommandAncestors.d.ts +0 -5
- package/lib/helpers/getCommandAndAncestors.d.ts +0 -5
- package/lib/helpers/parseOptionFlags.d.ts +0 -11
- package/lib/internal/collectVariadicOptionValues.d.ts +0 -7
- package/lib/internal/mergeOptionDefaults.d.ts +0 -3
- package/lib/internal/normalizeArgv.d.ts +0 -3
- package/lib/internal/resolveArguments.d.ts +0 -3
- package/lib/internal/validateParsed.d.ts +0 -4
- package/lib/types.d.ts +0 -386
package/index.mjs
CHANGED
|
@@ -1,51 +1,39 @@
|
|
|
1
|
+
import C from 'ansi-colors';
|
|
2
|
+
import humanizeDuration from 'humanize-duration';
|
|
3
|
+
import { inspect } from 'util';
|
|
4
|
+
import { isFunction } from 'es-toolkit/predicate';
|
|
5
|
+
import { isPrimitive } from 'es-toolkit/predicate';
|
|
6
|
+
import { isPromise } from 'util/types';
|
|
7
|
+
import { isString } from 'es-toolkit/predicate';
|
|
8
|
+
import { kebabCase } from 'es-toolkit/string';
|
|
9
|
+
import memoizee from 'memoizee';
|
|
10
|
+
import { ms } from 'enhanced-ms';
|
|
11
|
+
import { parseArgs } from 'util';
|
|
12
|
+
|
|
1
13
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var __export = (target, all) => {
|
|
5
|
-
for (var name in all)
|
|
6
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
-
};
|
|
8
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
9
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
10
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
11
|
-
if (decorator = decorators[i])
|
|
12
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
13
|
-
if (kind && result) __defProp(target, key, result);
|
|
14
|
-
return result;
|
|
14
|
+
var __name = (target, value) => {
|
|
15
|
+
return __defProp(target, 'name', { value, configurable: true });
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
// src/lib/Command.ts
|
|
18
|
-
var Command_exports = {};
|
|
19
|
-
__export(Command_exports, {
|
|
20
|
-
Command: () => Command
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// src/lib/Help.ts
|
|
24
|
-
var Help_exports = {};
|
|
25
|
-
__export(Help_exports, {
|
|
26
|
-
Help: () => Help
|
|
27
|
-
});
|
|
28
|
-
import C from "ansi-colors";
|
|
29
|
-
|
|
30
18
|
// ../decorators/src/assertDescriptorValueIsFunction.ts
|
|
31
19
|
function assertDescriptorValueIsFunction(key, descriptor) {
|
|
32
|
-
if (!(typeof descriptor.value ===
|
|
20
|
+
if (!(typeof descriptor.value === 'function' && descriptor.value !== Function.prototype)) {
|
|
33
21
|
throw new TypeError(`"value" not a function for ${key} with descriptor: ${JSON.stringify(descriptor)}.`);
|
|
34
22
|
}
|
|
35
23
|
}
|
|
36
|
-
__name(assertDescriptorValueIsFunction,
|
|
24
|
+
__name(assertDescriptorValueIsFunction, 'assertDescriptorValueIsFunction');
|
|
37
25
|
|
|
38
26
|
// ../object/src/entriesOf.ts
|
|
39
27
|
function entriesOf(obj) {
|
|
40
28
|
return Object.entries(obj);
|
|
41
29
|
}
|
|
42
|
-
__name(entriesOf,
|
|
30
|
+
__name(entriesOf, 'entriesOf');
|
|
43
31
|
|
|
44
32
|
// ../object/src/keysOf.ts
|
|
45
33
|
function keysOf(obj) {
|
|
46
34
|
return Object.keys(obj);
|
|
47
35
|
}
|
|
48
|
-
__name(keysOf,
|
|
36
|
+
__name(keysOf, 'keysOf');
|
|
49
37
|
|
|
50
38
|
// ../object/src/filterObject.ts
|
|
51
39
|
function filterObject(obj, predicate) {
|
|
@@ -57,7 +45,7 @@ function filterObject(obj, predicate) {
|
|
|
57
45
|
}
|
|
58
46
|
return accum;
|
|
59
47
|
}
|
|
60
|
-
__name(filterObject,
|
|
48
|
+
__name(filterObject, 'filterObject');
|
|
61
49
|
|
|
62
50
|
// ../object/src/objSortKeys.ts
|
|
63
51
|
function objSortKeys(o, compare) {
|
|
@@ -71,13 +59,13 @@ function objSortKeys(o, compare) {
|
|
|
71
59
|
}
|
|
72
60
|
return Object.fromEntries(entries);
|
|
73
61
|
}
|
|
74
|
-
__name(objSortKeys,
|
|
62
|
+
__name(objSortKeys, 'objSortKeys');
|
|
75
63
|
|
|
76
64
|
// ../object/src/valuesOf.ts
|
|
77
65
|
function valuesOf(obj) {
|
|
78
66
|
return Object.values(obj);
|
|
79
67
|
}
|
|
80
|
-
__name(valuesOf,
|
|
68
|
+
__name(valuesOf, 'valuesOf');
|
|
81
69
|
|
|
82
70
|
// ../map/src/mapGetOrDefault.ts
|
|
83
71
|
function mapGetOrDefault(map, key, factory) {
|
|
@@ -89,20 +77,21 @@ function mapGetOrDefault(map, key, factory) {
|
|
|
89
77
|
map.set(key, value);
|
|
90
78
|
return value;
|
|
91
79
|
}
|
|
92
|
-
__name(mapGetOrDefault,
|
|
80
|
+
__name(mapGetOrDefault, 'mapGetOrDefault');
|
|
93
81
|
|
|
94
82
|
// ../map/src/TimeoutWeakMap.ts
|
|
95
83
|
var TimeoutWeakMap = class {
|
|
84
|
+
static {
|
|
85
|
+
__name(this, 'TimeoutWeakMap');
|
|
86
|
+
}
|
|
87
|
+
timeoutMs;
|
|
88
|
+
wmap = /* @__PURE__ */ new WeakMap();
|
|
96
89
|
/**
|
|
97
90
|
* @param timeoutMs Default timeout in milliseconds for entries
|
|
98
91
|
*/
|
|
99
92
|
constructor(timeoutMs) {
|
|
100
93
|
this.timeoutMs = timeoutMs;
|
|
101
94
|
}
|
|
102
|
-
static {
|
|
103
|
-
__name(this, "TimeoutWeakMap");
|
|
104
|
-
}
|
|
105
|
-
wmap = /* @__PURE__ */ new WeakMap();
|
|
106
95
|
/**
|
|
107
96
|
* Retrieves the value for the given key and refreshes its timeout.
|
|
108
97
|
*
|
|
@@ -131,7 +120,7 @@ var TimeoutWeakMap = class {
|
|
|
131
120
|
value,
|
|
132
121
|
setTimeout(() => {
|
|
133
122
|
this.delete(key);
|
|
134
|
-
}, timeoutMs ?? this.timeoutMs).unref()
|
|
123
|
+
}, timeoutMs ?? this.timeoutMs).unref(),
|
|
135
124
|
]);
|
|
136
125
|
return this;
|
|
137
126
|
}
|
|
@@ -205,28 +194,29 @@ var TimeoutWeakMap = class {
|
|
|
205
194
|
}
|
|
206
195
|
}
|
|
207
196
|
};
|
|
208
|
-
|
|
209
|
-
// ../decorators/src/lazyProp.ts
|
|
210
|
-
import { isFunction } from "es-toolkit/predicate";
|
|
211
|
-
|
|
212
|
-
// ../decorators/src/memoizeSync.ts
|
|
213
|
-
import memoizee from "memoizee";
|
|
214
|
-
import { ms } from "enhanced-ms";
|
|
215
197
|
function memoizeSync(arg = {}) {
|
|
216
|
-
const opts =
|
|
198
|
+
const opts =
|
|
199
|
+
typeof arg === 'object'
|
|
200
|
+
? arg
|
|
201
|
+
: {
|
|
202
|
+
maxAge: typeof arg === 'number' ? arg : ms(arg),
|
|
203
|
+
};
|
|
217
204
|
return /* @__PURE__ */ __name(function decorator(target, key, descriptor) {
|
|
218
205
|
if (!descriptor) {
|
|
219
|
-
throw new TypeError(
|
|
206
|
+
throw new TypeError('descriptor is undefined');
|
|
220
207
|
}
|
|
221
208
|
const orig = descriptor.value;
|
|
222
209
|
assertDescriptorValueIsFunction(key, descriptor);
|
|
223
|
-
const options = {
|
|
210
|
+
const options = {
|
|
211
|
+
length: false,
|
|
212
|
+
...opts,
|
|
213
|
+
};
|
|
224
214
|
if (opts.instancesShareCache) {
|
|
225
|
-
Reflect.deleteProperty(options,
|
|
215
|
+
Reflect.deleteProperty(options, 'instancesShareCache');
|
|
226
216
|
descriptor.value = memoizee(orig, options);
|
|
227
217
|
} else {
|
|
228
218
|
const wmap = /* @__PURE__ */ new WeakMap();
|
|
229
|
-
descriptor.value = function(...args) {
|
|
219
|
+
descriptor.value = function (...args) {
|
|
230
220
|
const memoized = mapGetOrDefault(wmap, this, () => {
|
|
231
221
|
return memoizee(orig, options);
|
|
232
222
|
});
|
|
@@ -234,27 +224,24 @@ function memoizeSync(arg = {}) {
|
|
|
234
224
|
};
|
|
235
225
|
}
|
|
236
226
|
return descriptor;
|
|
237
|
-
},
|
|
227
|
+
}, 'decorator');
|
|
238
228
|
}
|
|
239
|
-
__name(memoizeSync,
|
|
240
|
-
|
|
241
|
-
// ../decorators/src/lazyProp.ts
|
|
242
|
-
import { ms as ms2 } from "enhanced-ms";
|
|
229
|
+
__name(memoizeSync, 'memoizeSync');
|
|
243
230
|
function lazyProp(targetOrTimeout, key, descriptor) {
|
|
244
|
-
if (typeof targetOrTimeout ===
|
|
245
|
-
const maxAge = typeof targetOrTimeout ===
|
|
231
|
+
if (typeof targetOrTimeout === 'number' || typeof targetOrTimeout === 'string') {
|
|
232
|
+
const maxAge = typeof targetOrTimeout === 'number' ? targetOrTimeout : ms(targetOrTimeout);
|
|
246
233
|
return createLazyPropDecorator(new TimeoutWeakMap(maxAge));
|
|
247
234
|
} else {
|
|
248
235
|
const decorator = createLazyPropDecorator(/* @__PURE__ */ new WeakMap());
|
|
249
236
|
return decorator(targetOrTimeout, key, descriptor);
|
|
250
237
|
}
|
|
251
238
|
}
|
|
252
|
-
__name(lazyProp,
|
|
239
|
+
__name(lazyProp, 'lazyProp');
|
|
253
240
|
function createLazyPropDecorator(map) {
|
|
254
|
-
return function(target, key, descriptor) {
|
|
241
|
+
return function (target, key, descriptor) {
|
|
255
242
|
const { get, value } = descriptor;
|
|
256
243
|
if (isFunction(get)) {
|
|
257
|
-
descriptor.get = function() {
|
|
244
|
+
descriptor.get = function () {
|
|
258
245
|
return mapGetOrDefault(map, this, () => {
|
|
259
246
|
return get.call(this);
|
|
260
247
|
});
|
|
@@ -267,12 +254,34 @@ function createLazyPropDecorator(map) {
|
|
|
267
254
|
throw new TypeError('neither "get" nor "value" are functions');
|
|
268
255
|
};
|
|
269
256
|
}
|
|
270
|
-
__name(createLazyPropDecorator,
|
|
257
|
+
__name(createLazyPropDecorator, 'createLazyPropDecorator');
|
|
271
258
|
|
|
272
259
|
// src/lib/Help.ts
|
|
260
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
261
|
+
var c = arguments.length,
|
|
262
|
+
r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
|
|
263
|
+
d;
|
|
264
|
+
if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') {
|
|
265
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
266
|
+
} else {
|
|
267
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
268
|
+
if ((d = decorators[i])) {
|
|
269
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return (c > 3 && r && Object.defineProperty(target, key, r), r);
|
|
274
|
+
}
|
|
275
|
+
__name(_ts_decorate, '_ts_decorate');
|
|
276
|
+
function _ts_metadata(k, v) {
|
|
277
|
+
if (typeof Reflect === 'object' && typeof Reflect.metadata === 'function') {
|
|
278
|
+
return Reflect.metadata(k, v);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
__name(_ts_metadata, '_ts_metadata');
|
|
273
282
|
var Help = class {
|
|
274
283
|
static {
|
|
275
|
-
__name(this,
|
|
284
|
+
__name(this, 'Help');
|
|
276
285
|
}
|
|
277
286
|
cmd;
|
|
278
287
|
/** output helpWidth, long lines are wrapped to fit */
|
|
@@ -280,12 +289,17 @@ var Help = class {
|
|
|
280
289
|
minWidthToWrap = 40;
|
|
281
290
|
sortSubcommands = true;
|
|
282
291
|
sortOptions = true;
|
|
283
|
-
usageDisplayOptionsAs =
|
|
284
|
-
usageDisplaySubcommandAs =
|
|
292
|
+
usageDisplayOptionsAs = '[opts]';
|
|
293
|
+
usageDisplaySubcommandAs = '[cmd]';
|
|
285
294
|
constructor(cmd) {
|
|
286
295
|
this.cmd = cmd;
|
|
287
|
-
Object.defineProperty(this,
|
|
296
|
+
Object.defineProperty(this, 'cmd', {
|
|
297
|
+
enumerable: false,
|
|
298
|
+
});
|
|
288
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
302
|
+
*/
|
|
289
303
|
visibleCommands() {
|
|
290
304
|
const res = Object.values(this.cmd.commands).filter((c) => {
|
|
291
305
|
return !c.hidden;
|
|
@@ -302,10 +316,13 @@ var Help = class {
|
|
|
302
316
|
*/
|
|
303
317
|
compareOptions(a, b) {
|
|
304
318
|
const getSortKey = /* @__PURE__ */ __name((option) => {
|
|
305
|
-
return option.short ? option.short.replace(/^-/,
|
|
306
|
-
},
|
|
319
|
+
return option.short ? option.short.replace(/^-/, '') : option.long.replace(/^--/, '');
|
|
320
|
+
}, 'getSortKey');
|
|
307
321
|
return getSortKey(a).localeCompare(getSortKey(b));
|
|
308
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
325
|
+
*/
|
|
309
326
|
visibleOptions() {
|
|
310
327
|
const res = this.cmd.options.filter((option) => {
|
|
311
328
|
return !option.hidden;
|
|
@@ -315,6 +332,9 @@ var Help = class {
|
|
|
315
332
|
}
|
|
316
333
|
return res;
|
|
317
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Get an array of the arguments if any have a description.
|
|
337
|
+
*/
|
|
318
338
|
visibleArguments() {
|
|
319
339
|
return this.cmd.arguments.slice();
|
|
320
340
|
}
|
|
@@ -322,11 +342,17 @@ var Help = class {
|
|
|
322
342
|
* Get the command term to show in the list of subcommands.
|
|
323
343
|
*/
|
|
324
344
|
subcommandTerm(sub) {
|
|
325
|
-
const args = sub.arguments
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
345
|
+
const args = sub.arguments
|
|
346
|
+
.map((arg) => {
|
|
347
|
+
return arg.usage;
|
|
348
|
+
})
|
|
349
|
+
.join(' ');
|
|
350
|
+
return (
|
|
351
|
+
(sub.aliases[0] ? `${sub.aliases[0].padEnd(this.longestSubcommandAliasLength(), ' ')} | ` : '') +
|
|
352
|
+
sub.name +
|
|
353
|
+
(sub.options.length ? ` ${this.usageDisplayOptionsAs}` : '') + // simplistic check for non-help option
|
|
354
|
+
(args ? ` ${args}` : '')
|
|
355
|
+
);
|
|
330
356
|
}
|
|
331
357
|
/**
|
|
332
358
|
* Get the option term to show in the list of options.
|
|
@@ -340,24 +366,36 @@ var Help = class {
|
|
|
340
366
|
argumentTerm(argument) {
|
|
341
367
|
return argument.usage;
|
|
342
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* Get the longest subcommand primary alias length.
|
|
371
|
+
*/
|
|
343
372
|
longestSubcommandAliasLength() {
|
|
344
373
|
return Math.max(
|
|
345
374
|
0,
|
|
346
375
|
...this.visibleCommands().map((c) => {
|
|
347
376
|
return c.aliases[0]?.length || 0;
|
|
348
|
-
})
|
|
377
|
+
}),
|
|
349
378
|
);
|
|
350
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Get the longest subcommand term length.
|
|
382
|
+
*/
|
|
351
383
|
longestSubcommandTermLength() {
|
|
352
384
|
return this.visibleCommands().reduce((max, command) => {
|
|
353
385
|
return Math.max(max, this.displayWidth(this.styleSubcommandTerm(this.subcommandTerm(command))));
|
|
354
386
|
}, 0);
|
|
355
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Get the longest option term length.
|
|
390
|
+
*/
|
|
356
391
|
longestOptionTermLength() {
|
|
357
392
|
return this.visibleOptions().reduce((max, option) => {
|
|
358
393
|
return Math.max(max, this.displayWidth(this.styleOptionTerm(this.optionTerm(option))));
|
|
359
394
|
}, 0);
|
|
360
395
|
}
|
|
396
|
+
/**
|
|
397
|
+
* Get the longest argument term length.
|
|
398
|
+
*/
|
|
361
399
|
longestArgumentTermLength() {
|
|
362
400
|
return this.visibleArguments().reduce((max, argument) => {
|
|
363
401
|
return Math.max(max, this.displayWidth(this.styleArgumentTerm(this.argumentTerm(argument))));
|
|
@@ -367,26 +405,32 @@ var Help = class {
|
|
|
367
405
|
* Get the command usage to be displayed at the top of the built-in help.
|
|
368
406
|
*/
|
|
369
407
|
commandUsage() {
|
|
370
|
-
let path =
|
|
408
|
+
let path = '';
|
|
371
409
|
for (let ancestor = this.cmd.parent; ancestor; ancestor = ancestor.parent) {
|
|
372
410
|
path = `${ancestor.name} ${path}`;
|
|
373
411
|
}
|
|
374
412
|
return `${path + this.cmd.name} ${[
|
|
375
|
-
...Object.keys(this.cmd.commands).length ? [this.usageDisplaySubcommandAs] : [],
|
|
376
|
-
...this.cmd.options.length ? [this.usageDisplayOptionsAs] : [],
|
|
413
|
+
...(Object.keys(this.cmd.commands).length ? [this.usageDisplaySubcommandAs] : []),
|
|
414
|
+
...(this.cmd.options.length ? [this.usageDisplayOptionsAs] : []),
|
|
377
415
|
...this.cmd.arguments.map((arg) => {
|
|
378
|
-
return arg.required
|
|
379
|
-
|
|
380
|
-
|
|
416
|
+
return arg.required
|
|
417
|
+
? arg.variadic
|
|
418
|
+
? `<${arg.name}...>`
|
|
419
|
+
: `<${arg.name}>`
|
|
420
|
+
: arg.variadic
|
|
421
|
+
? `[${arg.name}...]`
|
|
422
|
+
: `[${arg.name}]`;
|
|
423
|
+
}),
|
|
424
|
+
].join(' ')}`.trim();
|
|
381
425
|
}
|
|
382
426
|
/**
|
|
383
427
|
* Get the description for the command.
|
|
384
428
|
*/
|
|
385
429
|
commandDescription() {
|
|
386
|
-
let res =
|
|
430
|
+
let res = '';
|
|
387
431
|
if (this.cmd.aliases.length) {
|
|
388
|
-
res += `Aliases: ${this.cmd.aliases.join(
|
|
389
|
-
res +=
|
|
432
|
+
res += `Aliases: ${this.cmd.aliases.join(', ')}`;
|
|
433
|
+
res += '\n\n';
|
|
390
434
|
}
|
|
391
435
|
res += this.cmd.description;
|
|
392
436
|
return res;
|
|
@@ -396,7 +440,10 @@ var Help = class {
|
|
|
396
440
|
* (Fallback to description for backwards compatibility.)
|
|
397
441
|
*/
|
|
398
442
|
subcommandDescription(sub) {
|
|
399
|
-
return
|
|
443
|
+
return (
|
|
444
|
+
sub.summary ||
|
|
445
|
+
(sub.description?.includes('\n') ? sub.description.trim().split('\n')[0] : sub.description.trim())
|
|
446
|
+
);
|
|
400
447
|
}
|
|
401
448
|
/**
|
|
402
449
|
* Get the option description to show in the list of options.
|
|
@@ -406,9 +453,11 @@ var Help = class {
|
|
|
406
453
|
if (option.choices) {
|
|
407
454
|
extraInfo.push(
|
|
408
455
|
// use stringify to match the display of the default value
|
|
409
|
-
`choices: ${option.choices
|
|
410
|
-
|
|
411
|
-
|
|
456
|
+
`choices: ${option.choices
|
|
457
|
+
.map((choice) => {
|
|
458
|
+
return String(choice);
|
|
459
|
+
})
|
|
460
|
+
.join(', ')}`,
|
|
412
461
|
);
|
|
413
462
|
}
|
|
414
463
|
if (option.defaultValue && !(Array.isArray(option.defaultValue) && option.defaultValue.length === 0)) {
|
|
@@ -418,13 +467,13 @@ var Help = class {
|
|
|
418
467
|
extraInfo.push(`env: ${option.env}`);
|
|
419
468
|
}
|
|
420
469
|
if (extraInfo.length > 0) {
|
|
421
|
-
const extraDescription = `(${extraInfo.join(
|
|
470
|
+
const extraDescription = `(${extraInfo.join(', ')})`;
|
|
422
471
|
if (option.description) {
|
|
423
472
|
return `${option.description} ${extraDescription}`;
|
|
424
473
|
}
|
|
425
474
|
return extraDescription;
|
|
426
475
|
}
|
|
427
|
-
return option.description ??
|
|
476
|
+
return option.description ?? '';
|
|
428
477
|
}
|
|
429
478
|
/**
|
|
430
479
|
* Get the argument description to show in the list of arguments.
|
|
@@ -434,22 +483,24 @@ var Help = class {
|
|
|
434
483
|
if (argument.choices) {
|
|
435
484
|
extraInfo.push(
|
|
436
485
|
// use stringify to match the display of the default value
|
|
437
|
-
`choices: ${argument.choices
|
|
438
|
-
|
|
439
|
-
|
|
486
|
+
`choices: ${argument.choices
|
|
487
|
+
.map((choice) => {
|
|
488
|
+
return String(choice);
|
|
489
|
+
})
|
|
490
|
+
.join(', ')}`,
|
|
440
491
|
);
|
|
441
492
|
}
|
|
442
493
|
if (argument.defaultValue && !(Array.isArray(argument.defaultValue) && argument.defaultValue.length === 0)) {
|
|
443
494
|
extraInfo.push(`default: ${argument.defaultValueDescription || String(argument.defaultValue)}`);
|
|
444
495
|
}
|
|
445
496
|
if (extraInfo.length > 0) {
|
|
446
|
-
const extraDescription = `(${extraInfo.join(
|
|
497
|
+
const extraDescription = `(${extraInfo.join(', ')})`;
|
|
447
498
|
if (argument.description) {
|
|
448
499
|
return `${argument.description} ${extraDescription}`;
|
|
449
500
|
}
|
|
450
501
|
return extraDescription;
|
|
451
502
|
}
|
|
452
|
-
return argument.description ??
|
|
503
|
+
return argument.description ?? '';
|
|
453
504
|
}
|
|
454
505
|
/**
|
|
455
506
|
* Format a list of items, given a heading and an array of formatted items.
|
|
@@ -458,7 +509,7 @@ var Help = class {
|
|
|
458
509
|
if (items.length === 0) {
|
|
459
510
|
return [];
|
|
460
511
|
}
|
|
461
|
-
return [this.styleTitle(heading), ...items,
|
|
512
|
+
return [this.styleTitle(heading), ...items, ''];
|
|
462
513
|
}
|
|
463
514
|
/**
|
|
464
515
|
* Group items by their help group heading.
|
|
@@ -485,7 +536,7 @@ var Help = class {
|
|
|
485
536
|
*/
|
|
486
537
|
displayWidth(str) {
|
|
487
538
|
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
488
|
-
return str.replace(sgrPattern,
|
|
539
|
+
return str.replace(sgrPattern, '').length;
|
|
489
540
|
}
|
|
490
541
|
/**
|
|
491
542
|
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
@@ -497,24 +548,27 @@ var Help = class {
|
|
|
497
548
|
* Style the usage line for displaying in the help. Applies specific styling to different parts like options, commands, and arguments.
|
|
498
549
|
*/
|
|
499
550
|
styleUsage(str) {
|
|
500
|
-
return str
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
551
|
+
return str
|
|
552
|
+
.split(' ')
|
|
553
|
+
.map((word, index, arr) => {
|
|
554
|
+
if (word === this.usageDisplaySubcommandAs) {
|
|
555
|
+
return C.green(word);
|
|
556
|
+
}
|
|
557
|
+
if (word === this.usageDisplayOptionsAs) {
|
|
558
|
+
return C.blue(word);
|
|
559
|
+
}
|
|
560
|
+
if (word[0] === '<') {
|
|
561
|
+
return C.red(word);
|
|
562
|
+
}
|
|
563
|
+
if (word[0] === '[') {
|
|
564
|
+
return C.cyan(word);
|
|
565
|
+
}
|
|
566
|
+
if (arr[index + 1]?.startsWith('[')) {
|
|
567
|
+
return C.magenta(word);
|
|
568
|
+
}
|
|
569
|
+
return this.styleCommandText(word);
|
|
570
|
+
})
|
|
571
|
+
.join(' ');
|
|
518
572
|
}
|
|
519
573
|
/**
|
|
520
574
|
* Style command descriptions for display in help output.
|
|
@@ -556,21 +610,24 @@ var Help = class {
|
|
|
556
610
|
* Style subcommand terms for display in help output. Applies specific styling to different parts like options and arguments.
|
|
557
611
|
*/
|
|
558
612
|
styleSubcommandTerm(str) {
|
|
559
|
-
const res = str
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
613
|
+
const res = str
|
|
614
|
+
.split(' ')
|
|
615
|
+
.map((word) => {
|
|
616
|
+
if (word === this.usageDisplayOptionsAs) {
|
|
617
|
+
return C.dim(word);
|
|
618
|
+
}
|
|
619
|
+
if (word[0] === '[' || word[0] === '<') {
|
|
620
|
+
return C.dim(word);
|
|
621
|
+
}
|
|
622
|
+
return this.styleSubcommandText(word);
|
|
623
|
+
})
|
|
624
|
+
.join(' ');
|
|
625
|
+
const split = res.split('|');
|
|
569
626
|
if (split.length === 1) {
|
|
570
627
|
return res;
|
|
571
628
|
}
|
|
572
629
|
split[0] = C.green(split[0]);
|
|
573
|
-
return split.join(
|
|
630
|
+
return split.join('|');
|
|
574
631
|
}
|
|
575
632
|
/**
|
|
576
633
|
* Style argument terms for display in help output.
|
|
@@ -602,11 +659,14 @@ var Help = class {
|
|
|
602
659
|
styleCommandText(str) {
|
|
603
660
|
return str;
|
|
604
661
|
}
|
|
662
|
+
/**
|
|
663
|
+
* Calculate the pad width from the maximum term length.
|
|
664
|
+
*/
|
|
605
665
|
padWidth() {
|
|
606
666
|
return Math.max(
|
|
607
667
|
this.longestOptionTermLength(),
|
|
608
668
|
this.longestSubcommandTermLength(),
|
|
609
|
-
this.longestArgumentTermLength()
|
|
669
|
+
this.longestArgumentTermLength(),
|
|
610
670
|
);
|
|
611
671
|
}
|
|
612
672
|
/**
|
|
@@ -624,7 +684,7 @@ var Help = class {
|
|
|
624
684
|
*/
|
|
625
685
|
formatItem(term, termWidth, description) {
|
|
626
686
|
const itemIndent = 2;
|
|
627
|
-
const itemIndentStr =
|
|
687
|
+
const itemIndentStr = ' '.repeat(itemIndent);
|
|
628
688
|
if (!description) {
|
|
629
689
|
return itemIndentStr + term;
|
|
630
690
|
}
|
|
@@ -637,11 +697,22 @@ var Help = class {
|
|
|
637
697
|
formattedDescription = description;
|
|
638
698
|
} else {
|
|
639
699
|
const wrappedDescription = this.boxWrap(description, remainingWidth);
|
|
640
|
-
formattedDescription = wrappedDescription.replace(
|
|
641
|
-
|
|
700
|
+
formattedDescription = wrappedDescription.replace(
|
|
701
|
+
/\n/g,
|
|
702
|
+
`
|
|
703
|
+
${' '.repeat(termWidth + spacerWidth)}`,
|
|
704
|
+
);
|
|
642
705
|
}
|
|
643
|
-
return
|
|
644
|
-
|
|
706
|
+
return (
|
|
707
|
+
itemIndentStr +
|
|
708
|
+
paddedTerm +
|
|
709
|
+
' '.repeat(spacerWidth) +
|
|
710
|
+
formattedDescription.replace(
|
|
711
|
+
/\n/g,
|
|
712
|
+
`
|
|
713
|
+
${itemIndentStr}`,
|
|
714
|
+
)
|
|
715
|
+
);
|
|
645
716
|
}
|
|
646
717
|
/**
|
|
647
718
|
* Wrap a string at whitespace, preserving existing line breaks.
|
|
@@ -657,7 +728,7 @@ ${itemIndentStr}`);
|
|
|
657
728
|
rawLines.forEach((line) => {
|
|
658
729
|
const chunks = line.match(chunkPattern);
|
|
659
730
|
if (chunks === null) {
|
|
660
|
-
wrappedLines.push(
|
|
731
|
+
wrappedLines.push('');
|
|
661
732
|
return;
|
|
662
733
|
}
|
|
663
734
|
let sumChunks = [chunks.shift()];
|
|
@@ -669,121 +740,181 @@ ${itemIndentStr}`);
|
|
|
669
740
|
sumWidth += visibleWidth;
|
|
670
741
|
return;
|
|
671
742
|
}
|
|
672
|
-
wrappedLines.push(sumChunks.join(
|
|
743
|
+
wrappedLines.push(sumChunks.join(''));
|
|
673
744
|
const nextChunk = chunk.trimStart();
|
|
674
745
|
sumChunks = [nextChunk];
|
|
675
746
|
sumWidth = this.displayWidth(nextChunk);
|
|
676
747
|
});
|
|
677
|
-
wrappedLines.push(sumChunks.join(
|
|
748
|
+
wrappedLines.push(sumChunks.join(''));
|
|
678
749
|
});
|
|
679
|
-
return wrappedLines.join(
|
|
750
|
+
return wrappedLines.join('\n');
|
|
680
751
|
}
|
|
681
752
|
/**
|
|
682
753
|
* Generate the built-in help text.
|
|
683
754
|
*/
|
|
684
755
|
render() {
|
|
685
|
-
let output = [`${this.styleTitle(
|
|
756
|
+
let output = [`${this.styleTitle('Usage:')} ${this.styleUsage(this.commandUsage())}`, ''];
|
|
686
757
|
const des = this.commandDescription();
|
|
687
758
|
if (des.length > 0) {
|
|
688
|
-
output = output.concat([this.boxWrap(this.styleCommandDescription(des), this.helpWidth),
|
|
759
|
+
output = output.concat([this.boxWrap(this.styleCommandDescription(des), this.helpWidth), '']);
|
|
689
760
|
}
|
|
690
761
|
const argumentList = this.visibleArguments().map((argument) => {
|
|
691
762
|
return this.formatItem(
|
|
692
763
|
this.styleArgumentTerm(this.argumentTerm(argument)),
|
|
693
764
|
this.padWidth(),
|
|
694
|
-
this.styleArgumentDescription(this.argumentDescription(argument))
|
|
765
|
+
this.styleArgumentDescription(this.argumentDescription(argument)),
|
|
695
766
|
);
|
|
696
767
|
});
|
|
697
|
-
output = output.concat(this.formatItemList(
|
|
768
|
+
output = output.concat(this.formatItemList('Arguments:', argumentList));
|
|
698
769
|
const optionGroups = this.groupItems(this.cmd.options, this.visibleOptions(), (option) => {
|
|
699
|
-
return option.group ??
|
|
770
|
+
return option.group ?? 'Options:';
|
|
700
771
|
});
|
|
701
772
|
optionGroups.forEach((options, group) => {
|
|
702
773
|
const optionList = options.map((option) => {
|
|
703
774
|
return this.formatItem(
|
|
704
775
|
this.styleOptionTerm(this.optionTerm(option)),
|
|
705
776
|
this.padWidth(),
|
|
706
|
-
this.styleOptionDescription(this.optionDescription(option))
|
|
777
|
+
this.styleOptionDescription(this.optionDescription(option)),
|
|
707
778
|
);
|
|
708
779
|
});
|
|
709
780
|
output = output.concat(this.formatItemList(group, optionList));
|
|
710
781
|
});
|
|
711
|
-
const commandGroups = this.groupItems(
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
(sub) => {
|
|
715
|
-
return sub.group || "Commands:";
|
|
716
|
-
}
|
|
717
|
-
);
|
|
782
|
+
const commandGroups = this.groupItems(Object.values(this.cmd.commands), this.visibleCommands(), (sub) => {
|
|
783
|
+
return sub.group || 'Commands:';
|
|
784
|
+
});
|
|
718
785
|
commandGroups.forEach((commands, group) => {
|
|
719
786
|
const commandList = commands.map((sub) => {
|
|
720
787
|
return this.formatItem(
|
|
721
788
|
this.styleSubcommandTerm(this.subcommandTerm(sub)),
|
|
722
789
|
this.padWidth(),
|
|
723
|
-
this.styleSubcommandDescription(this.subcommandDescription(sub))
|
|
790
|
+
this.styleSubcommandDescription(this.subcommandDescription(sub)),
|
|
724
791
|
);
|
|
725
792
|
});
|
|
726
793
|
output = output.concat(this.formatItemList(group, commandList));
|
|
727
794
|
});
|
|
728
|
-
return output.join(
|
|
795
|
+
return output.join('\n');
|
|
729
796
|
}
|
|
730
797
|
};
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
],
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
798
|
+
_ts_decorate(
|
|
799
|
+
[
|
|
800
|
+
lazyProp,
|
|
801
|
+
_ts_metadata('design:type', Function),
|
|
802
|
+
_ts_metadata('design:paramtypes', []),
|
|
803
|
+
_ts_metadata('design:returntype', Array),
|
|
804
|
+
],
|
|
805
|
+
Help.prototype,
|
|
806
|
+
'visibleCommands',
|
|
807
|
+
null,
|
|
808
|
+
);
|
|
809
|
+
_ts_decorate(
|
|
810
|
+
[
|
|
811
|
+
lazyProp,
|
|
812
|
+
_ts_metadata('design:type', Function),
|
|
813
|
+
_ts_metadata('design:paramtypes', []),
|
|
814
|
+
_ts_metadata('design:returntype', Array),
|
|
815
|
+
],
|
|
816
|
+
Help.prototype,
|
|
817
|
+
'visibleOptions',
|
|
818
|
+
null,
|
|
819
|
+
);
|
|
820
|
+
_ts_decorate(
|
|
821
|
+
[
|
|
822
|
+
lazyProp,
|
|
823
|
+
_ts_metadata('design:type', Function),
|
|
824
|
+
_ts_metadata('design:paramtypes', []),
|
|
825
|
+
_ts_metadata('design:returntype', Array),
|
|
826
|
+
],
|
|
827
|
+
Help.prototype,
|
|
828
|
+
'visibleArguments',
|
|
829
|
+
null,
|
|
830
|
+
);
|
|
831
|
+
_ts_decorate(
|
|
832
|
+
[
|
|
833
|
+
lazyProp,
|
|
834
|
+
_ts_metadata('design:type', Function),
|
|
835
|
+
_ts_metadata('design:paramtypes', []),
|
|
836
|
+
_ts_metadata('design:returntype', Number),
|
|
837
|
+
],
|
|
838
|
+
Help.prototype,
|
|
839
|
+
'longestSubcommandAliasLength',
|
|
840
|
+
null,
|
|
841
|
+
);
|
|
842
|
+
_ts_decorate(
|
|
843
|
+
[
|
|
844
|
+
lazyProp,
|
|
845
|
+
_ts_metadata('design:type', Function),
|
|
846
|
+
_ts_metadata('design:paramtypes', []),
|
|
847
|
+
_ts_metadata('design:returntype', Number),
|
|
848
|
+
],
|
|
849
|
+
Help.prototype,
|
|
850
|
+
'longestSubcommandTermLength',
|
|
851
|
+
null,
|
|
852
|
+
);
|
|
853
|
+
_ts_decorate(
|
|
854
|
+
[
|
|
855
|
+
lazyProp,
|
|
856
|
+
_ts_metadata('design:type', Function),
|
|
857
|
+
_ts_metadata('design:paramtypes', []),
|
|
858
|
+
_ts_metadata('design:returntype', Number),
|
|
859
|
+
],
|
|
860
|
+
Help.prototype,
|
|
861
|
+
'longestOptionTermLength',
|
|
862
|
+
null,
|
|
863
|
+
);
|
|
864
|
+
_ts_decorate(
|
|
865
|
+
[
|
|
866
|
+
lazyProp,
|
|
867
|
+
_ts_metadata('design:type', Function),
|
|
868
|
+
_ts_metadata('design:paramtypes', []),
|
|
869
|
+
_ts_metadata('design:returntype', Number),
|
|
870
|
+
],
|
|
871
|
+
Help.prototype,
|
|
872
|
+
'longestArgumentTermLength',
|
|
873
|
+
null,
|
|
874
|
+
);
|
|
875
|
+
_ts_decorate(
|
|
876
|
+
[
|
|
877
|
+
lazyProp,
|
|
878
|
+
_ts_metadata('design:type', Function),
|
|
879
|
+
_ts_metadata('design:paramtypes', []),
|
|
880
|
+
_ts_metadata('design:returntype', Number),
|
|
881
|
+
],
|
|
882
|
+
Help.prototype,
|
|
883
|
+
'padWidth',
|
|
884
|
+
null,
|
|
885
|
+
);
|
|
755
886
|
|
|
756
|
-
// ../array/src/arrLast.ts
|
|
887
|
+
// ../array/src/lib/arrLast.ts
|
|
757
888
|
function arrLast(array) {
|
|
758
889
|
if (!array.length) {
|
|
759
|
-
throw new Error(
|
|
890
|
+
throw new Error('Cannot get last element of empty array.');
|
|
760
891
|
}
|
|
761
892
|
return array[array.length - 1];
|
|
762
893
|
}
|
|
763
|
-
__name(arrLast,
|
|
894
|
+
__name(arrLast, 'arrLast');
|
|
764
895
|
|
|
765
|
-
// ../array/src/arrRemoveDuplicates.ts
|
|
896
|
+
// ../array/src/lib/arrRemoveDuplicates.ts
|
|
766
897
|
function arrRemoveDuplicates(array) {
|
|
767
898
|
return Array.from(new Set(array));
|
|
768
899
|
}
|
|
769
|
-
__name(arrRemoveDuplicates,
|
|
900
|
+
__name(arrRemoveDuplicates, 'arrRemoveDuplicates');
|
|
770
901
|
|
|
771
902
|
// src/lib/internal/collectVariadicOptionValues.ts
|
|
772
903
|
function collectVariadicOptionValues(parsed, options) {
|
|
773
904
|
for (let i = 0; i < parsed.tokens.length; i++) {
|
|
774
905
|
const token = parsed.tokens[i];
|
|
775
|
-
if (token.kind !==
|
|
906
|
+
if (token.kind !== 'option') {
|
|
776
907
|
continue;
|
|
777
908
|
}
|
|
778
909
|
const def = options.find((o) => {
|
|
779
910
|
return o.name === token.name;
|
|
780
911
|
});
|
|
781
|
-
if (!def?.variadic || def.type !==
|
|
912
|
+
if (!def?.variadic || def.type !== 'string') {
|
|
782
913
|
continue;
|
|
783
914
|
}
|
|
784
915
|
const values = [token.value];
|
|
785
916
|
let j = i + 1;
|
|
786
|
-
while (j < parsed.tokens.length && parsed.tokens[j].kind ===
|
|
917
|
+
while (j < parsed.tokens.length && parsed.tokens[j].kind === 'positional') {
|
|
787
918
|
const positionalToken = parsed.tokens[j];
|
|
788
919
|
values.push(positionalToken.value);
|
|
789
920
|
const posIndex = parsed.positionals.indexOf(positionalToken.value);
|
|
@@ -797,54 +928,40 @@ function collectVariadicOptionValues(parsed, options) {
|
|
|
797
928
|
token.name,
|
|
798
929
|
values.filter((v) => {
|
|
799
930
|
return v !== void 0;
|
|
800
|
-
})
|
|
931
|
+
}),
|
|
801
932
|
);
|
|
802
933
|
}
|
|
803
934
|
}
|
|
804
|
-
__name(collectVariadicOptionValues,
|
|
805
|
-
|
|
806
|
-
// src/lib/Command.ts
|
|
807
|
-
import colors3 from "ansi-colors";
|
|
935
|
+
__name(collectVariadicOptionValues, 'collectVariadicOptionValues');
|
|
808
936
|
|
|
809
937
|
// src/lib/helpers/findCommand.ts
|
|
810
|
-
var findCommand_exports = {};
|
|
811
|
-
__export(findCommand_exports, {
|
|
812
|
-
findCommand: () => findCommand
|
|
813
|
-
});
|
|
814
938
|
function findCommand(cmd, nameOrAlias) {
|
|
815
|
-
return
|
|
816
|
-
|
|
817
|
-
|
|
939
|
+
return (
|
|
940
|
+
cmd.commands[nameOrAlias] ??
|
|
941
|
+
valuesOf(cmd.commands).find((c) => {
|
|
942
|
+
return c.aliases.includes(nameOrAlias);
|
|
943
|
+
})
|
|
944
|
+
);
|
|
818
945
|
}
|
|
819
|
-
__name(findCommand,
|
|
946
|
+
__name(findCommand, 'findCommand');
|
|
820
947
|
|
|
821
948
|
// src/lib/helpers/findOption.ts
|
|
822
|
-
var findOption_exports = {};
|
|
823
|
-
__export(findOption_exports, {
|
|
824
|
-
findOption: () => findOption
|
|
825
|
-
});
|
|
826
949
|
function findOption(cmd, nameOrShortOrLong) {
|
|
827
|
-
return nameOrShortOrLong.startsWith(
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
950
|
+
return nameOrShortOrLong.startsWith('--')
|
|
951
|
+
? cmd.options.find((o) => {
|
|
952
|
+
return o.long === nameOrShortOrLong.slice(2);
|
|
953
|
+
})
|
|
954
|
+
: nameOrShortOrLong.startsWith('-')
|
|
955
|
+
? cmd.options.find((o) => {
|
|
956
|
+
return o.short === nameOrShortOrLong.slice(1);
|
|
957
|
+
})
|
|
958
|
+
: cmd.options.find((o) => {
|
|
959
|
+
return o.name === nameOrShortOrLong;
|
|
960
|
+
});
|
|
834
961
|
}
|
|
835
|
-
__name(findOption,
|
|
836
|
-
|
|
837
|
-
// src/lib/helpers/getCommandAncestors.ts
|
|
838
|
-
var getCommandAncestors_exports = {};
|
|
839
|
-
__export(getCommandAncestors_exports, {
|
|
840
|
-
getCommandAncestors: () => getCommandAncestors
|
|
841
|
-
});
|
|
962
|
+
__name(findOption, 'findOption');
|
|
842
963
|
|
|
843
964
|
// src/lib/helpers/getCommandAndAncestors.ts
|
|
844
|
-
var getCommandAndAncestors_exports = {};
|
|
845
|
-
__export(getCommandAndAncestors_exports, {
|
|
846
|
-
getCommandAndAncestors: () => getCommandAndAncestors
|
|
847
|
-
});
|
|
848
965
|
function getCommandAndAncestors(cmd) {
|
|
849
966
|
const result = [];
|
|
850
967
|
let command = cmd;
|
|
@@ -853,17 +970,13 @@ function getCommandAndAncestors(cmd) {
|
|
|
853
970
|
}
|
|
854
971
|
return result;
|
|
855
972
|
}
|
|
856
|
-
__name(getCommandAndAncestors,
|
|
973
|
+
__name(getCommandAndAncestors, 'getCommandAndAncestors');
|
|
857
974
|
|
|
858
975
|
// src/lib/helpers/getCommandAncestors.ts
|
|
859
976
|
function getCommandAncestors(cmd) {
|
|
860
977
|
return getCommandAndAncestors(cmd).slice(1);
|
|
861
978
|
}
|
|
862
|
-
__name(getCommandAncestors,
|
|
863
|
-
|
|
864
|
-
// src/lib/Command.ts
|
|
865
|
-
import { inspect } from "node:util";
|
|
866
|
-
import { kebabCase } from "es-toolkit/string";
|
|
979
|
+
__name(getCommandAncestors, 'getCommandAncestors');
|
|
867
980
|
|
|
868
981
|
// src/lib/internal/mergeOptionDefaults.ts
|
|
869
982
|
function mergeOptionDefaults(values, options) {
|
|
@@ -873,7 +986,7 @@ function mergeOptionDefaults(values, options) {
|
|
|
873
986
|
}
|
|
874
987
|
}
|
|
875
988
|
}
|
|
876
|
-
__name(mergeOptionDefaults,
|
|
989
|
+
__name(mergeOptionDefaults, 'mergeOptionDefaults');
|
|
877
990
|
|
|
878
991
|
// src/lib/internal/normalizeArgv.ts
|
|
879
992
|
function normalizeArgv(argv, options) {
|
|
@@ -893,16 +1006,9 @@ function normalizeArgv(argv, options) {
|
|
|
893
1006
|
}
|
|
894
1007
|
return argv;
|
|
895
1008
|
}
|
|
896
|
-
__name(normalizeArgv,
|
|
897
|
-
|
|
898
|
-
// src/lib/Command.ts
|
|
899
|
-
import { parseArgs } from "node:util";
|
|
1009
|
+
__name(normalizeArgv, 'normalizeArgv');
|
|
900
1010
|
|
|
901
1011
|
// src/lib/helpers/parseOptionFlags.ts
|
|
902
|
-
var parseOptionFlags_exports = {};
|
|
903
|
-
__export(parseOptionFlags_exports, {
|
|
904
|
-
parseOptionFlags: () => parseOptionFlags
|
|
905
|
-
});
|
|
906
1012
|
function parseOptionFlags(flags) {
|
|
907
1013
|
const match = flags.match(/^-(.+?), --([a-zA-Z][\w-]*)(?:\s*(<(.+?)>|\[(.+?)\]))?$/);
|
|
908
1014
|
if (!match) {
|
|
@@ -913,13 +1019,18 @@ function parseOptionFlags(flags) {
|
|
|
913
1019
|
throw new Error(`Expected short name to be a single character. Got: -${short}`);
|
|
914
1020
|
}
|
|
915
1021
|
const long = match[2];
|
|
916
|
-
const argName = (match[4] || match[5])?.replace(/\.\.\.$/,
|
|
917
|
-
const name = long.split(
|
|
1022
|
+
const argName = (match[4] || match[5])?.replace(/\.\.\.$/, '') || void 0;
|
|
1023
|
+
const name = long.split('-').reduce((str, word) => {
|
|
918
1024
|
return str + word[0].toUpperCase() + word.slice(1);
|
|
919
1025
|
});
|
|
920
|
-
return {
|
|
1026
|
+
return {
|
|
1027
|
+
short,
|
|
1028
|
+
long,
|
|
1029
|
+
name,
|
|
1030
|
+
argName,
|
|
1031
|
+
};
|
|
921
1032
|
}
|
|
922
|
-
__name(parseOptionFlags,
|
|
1033
|
+
__name(parseOptionFlags, 'parseOptionFlags');
|
|
923
1034
|
|
|
924
1035
|
// src/lib/internal/resolveArguments.ts
|
|
925
1036
|
function resolveArguments(positionals, args) {
|
|
@@ -935,71 +1046,66 @@ function resolveArguments(positionals, args) {
|
|
|
935
1046
|
}
|
|
936
1047
|
return result;
|
|
937
1048
|
}
|
|
938
|
-
__name(resolveArguments,
|
|
1049
|
+
__name(resolveArguments, 'resolveArguments');
|
|
939
1050
|
|
|
940
1051
|
// ../fn/src/setName.ts
|
|
941
1052
|
function setName(name, target) {
|
|
942
|
-
return Object.defineProperty(target,
|
|
943
|
-
value: typeof name ===
|
|
1053
|
+
return Object.defineProperty(target, 'name', {
|
|
1054
|
+
value: typeof name === 'string' ? name : name.name,
|
|
944
1055
|
configurable: true,
|
|
945
|
-
enumerable: false
|
|
1056
|
+
enumerable: false,
|
|
946
1057
|
});
|
|
947
1058
|
}
|
|
948
|
-
__name(setName,
|
|
1059
|
+
__name(setName, 'setName');
|
|
949
1060
|
|
|
950
1061
|
// ../string/src/lib/strFirstCharToUpperCase.ts
|
|
951
1062
|
function strFirstCharToUpperCase(string) {
|
|
952
1063
|
return string.charAt(0).toUpperCase() + string.substring(1);
|
|
953
1064
|
}
|
|
954
|
-
__name(strFirstCharToUpperCase,
|
|
955
|
-
|
|
956
|
-
// ../node/src/createLogger.ts
|
|
957
|
-
import colors from "ansi-colors";
|
|
958
|
-
import { isPrimitive } from "es-toolkit/predicate";
|
|
959
|
-
import { isString } from "es-toolkit/predicate";
|
|
1065
|
+
__name(strFirstCharToUpperCase, 'strFirstCharToUpperCase');
|
|
960
1066
|
function createLogger(name) {
|
|
961
|
-
const NAME = name ?
|
|
962
|
-
const START = [NAME,
|
|
963
|
-
const DEBUG = [NAME,
|
|
964
|
-
const INFO = [NAME,
|
|
965
|
-
const DONE = [NAME,
|
|
966
|
-
const WARN = [NAME,
|
|
967
|
-
const ERROR = [NAME,
|
|
968
|
-
const grayArgs = createColoredArgs(
|
|
969
|
-
const cyanArgs = createColoredArgs(
|
|
970
|
-
const yellowArgs = createColoredArgs(
|
|
1067
|
+
const NAME = name ? C.dim.cyan(name) : name;
|
|
1068
|
+
const START = [NAME, C.dim.gray('[START]')].filter(Boolean);
|
|
1069
|
+
const DEBUG = [NAME, C.dim.magenta('[DEBUG]')].filter(Boolean);
|
|
1070
|
+
const INFO = [NAME, C.dim.gray('[INFO]')].filter(Boolean);
|
|
1071
|
+
const DONE = [NAME, C.dim.green('[DONE] ')].filter(Boolean);
|
|
1072
|
+
const WARN = [NAME, C.dim.yellow('[WARN] ')].filter(Boolean);
|
|
1073
|
+
const ERROR = [NAME, C.dim.red('[ERROR]')].filter(Boolean);
|
|
1074
|
+
const grayArgs = createColoredArgs(C.gray);
|
|
1075
|
+
const cyanArgs = createColoredArgs(C.cyan);
|
|
1076
|
+
const yellowArgs = createColoredArgs(C.yellow);
|
|
971
1077
|
return {
|
|
972
1078
|
start: /* @__PURE__ */ __name((...args) => {
|
|
973
1079
|
return console.info(...START, ...args);
|
|
974
|
-
},
|
|
1080
|
+
}, 'start'),
|
|
975
1081
|
done: /* @__PURE__ */ __name((...args) => {
|
|
976
1082
|
return console.info(...DONE, ...args);
|
|
977
|
-
},
|
|
1083
|
+
}, 'done'),
|
|
978
1084
|
info: /* @__PURE__ */ __name((...args) => {
|
|
979
1085
|
return console.info(...INFO, ...grayArgs(args));
|
|
980
|
-
},
|
|
1086
|
+
}, 'info'),
|
|
981
1087
|
log: /* @__PURE__ */ __name((...args) => {
|
|
982
|
-
return console.log(...NAME ? [NAME, ...args] : args);
|
|
983
|
-
},
|
|
1088
|
+
return console.log(...(NAME ? [NAME, ...args] : args));
|
|
1089
|
+
}, 'log'),
|
|
984
1090
|
warn: /* @__PURE__ */ __name((...args) => {
|
|
985
1091
|
return console.warn(...WARN, ...yellowArgs(args));
|
|
986
|
-
},
|
|
1092
|
+
}, 'warn'),
|
|
987
1093
|
debug: /* @__PURE__ */ __name((...args) => {
|
|
988
1094
|
return console.debug(...DEBUG, ...cyanArgs(args));
|
|
989
|
-
},
|
|
1095
|
+
}, 'debug'),
|
|
990
1096
|
error: /* @__PURE__ */ __name((...args) => {
|
|
991
1097
|
return args.forEach((arg) => {
|
|
992
1098
|
return console.error(...ERROR, arg);
|
|
993
1099
|
});
|
|
994
|
-
},
|
|
1100
|
+
}, 'error'),
|
|
995
1101
|
};
|
|
996
1102
|
}
|
|
997
|
-
__name(createLogger,
|
|
1103
|
+
__name(createLogger, 'createLogger');
|
|
998
1104
|
function createColoredArgs(colorFn) {
|
|
999
1105
|
return (args) => {
|
|
1000
1106
|
return args.map((arg) => {
|
|
1001
1107
|
if (isString(arg)) {
|
|
1002
|
-
if (arg ===
|
|
1108
|
+
if (arg === C.stripColor(arg)) {
|
|
1003
1109
|
return colorFn(arg);
|
|
1004
1110
|
} else {
|
|
1005
1111
|
return arg;
|
|
@@ -1012,15 +1118,10 @@ function createColoredArgs(colorFn) {
|
|
|
1012
1118
|
});
|
|
1013
1119
|
};
|
|
1014
1120
|
}
|
|
1015
|
-
__name(createColoredArgs,
|
|
1016
|
-
|
|
1017
|
-
// ../node/src/timer.ts
|
|
1018
|
-
import colors2 from "ansi-colors";
|
|
1019
|
-
import humanizeDuration from "humanize-duration";
|
|
1020
|
-
import { isPromise } from "node:util/types";
|
|
1121
|
+
__name(createColoredArgs, 'createColoredArgs');
|
|
1021
1122
|
function timer(arg, task) {
|
|
1022
1123
|
const t0 = process.hrtime.bigint();
|
|
1023
|
-
const [name, description] = Array.isArray(arg) ? arg : [arg,
|
|
1124
|
+
const [name, description] = Array.isArray(arg) ? arg : [arg, ''];
|
|
1024
1125
|
const log = createLogger(name);
|
|
1025
1126
|
if (name && description) {
|
|
1026
1127
|
log.start(description);
|
|
@@ -1038,64 +1139,97 @@ function timer(arg, task) {
|
|
|
1038
1139
|
}
|
|
1039
1140
|
const ns = process.hrtime.bigint() - t0;
|
|
1040
1141
|
const ms3 = Math.floor(Number(ns) / 1e6);
|
|
1041
|
-
log.done(
|
|
1142
|
+
log.done(C.dim(humanizeDuration(ms3)));
|
|
1042
1143
|
return retval2;
|
|
1043
1144
|
}
|
|
1044
|
-
__name(done, "done");
|
|
1045
1145
|
}
|
|
1046
|
-
__name(timer,
|
|
1146
|
+
__name(timer, 'timer');
|
|
1047
1147
|
|
|
1048
1148
|
// src/lib/internal/validateParsed.ts
|
|
1049
1149
|
function validateParsed(args, optionValues, argDefs, optionDefs) {
|
|
1050
|
-
return argDefs
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
if (def.
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
if (def.choices && value !== void 0) {
|
|
1058
|
-
if (![value].flat().every((v) => {
|
|
1059
|
-
return def.choices.includes(v);
|
|
1060
|
-
})) {
|
|
1061
|
-
return `Invalid argument [${index}] ${def.usage}: Got \`${value}\`. Accepted values: [${def.choices.map((c) => {
|
|
1062
|
-
return `\`${c}\``;
|
|
1063
|
-
}).join(",")}]`;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
}).concat(
|
|
1067
|
-
entriesOf(optionValues).map(([key, value]) => {
|
|
1068
|
-
const def = optionDefs.find((o) => {
|
|
1069
|
-
return o.name === key;
|
|
1070
|
-
});
|
|
1071
|
-
if (!def) {
|
|
1072
|
-
return `Unknown option --${key}`;
|
|
1150
|
+
return argDefs
|
|
1151
|
+
.map((def, index) => {
|
|
1152
|
+
const value = args[index];
|
|
1153
|
+
if (def.required) {
|
|
1154
|
+
if (def.variadic ? Array.isArray(value) && value.length === 0 : value === void 0) {
|
|
1155
|
+
return `Missing argument [${index}] ${def.usage}`;
|
|
1156
|
+
}
|
|
1073
1157
|
}
|
|
1074
1158
|
if (def.choices && value !== void 0) {
|
|
1075
|
-
if (
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
}
|
|
1159
|
+
if (
|
|
1160
|
+
![value].flat().every((v) => {
|
|
1161
|
+
return def.choices.includes(v);
|
|
1162
|
+
})
|
|
1163
|
+
) {
|
|
1164
|
+
return `Invalid argument [${index}] ${def.usage}: Got \`${value}\`. Accepted values: [${def.choices
|
|
1165
|
+
.map((c) => {
|
|
1166
|
+
return `\`${c}\``;
|
|
1167
|
+
})
|
|
1168
|
+
.join(',')}]`;
|
|
1081
1169
|
}
|
|
1082
1170
|
}
|
|
1083
1171
|
})
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1172
|
+
.concat(
|
|
1173
|
+
entriesOf(optionValues).map(([key, value]) => {
|
|
1174
|
+
const def = optionDefs.find((o) => {
|
|
1175
|
+
return o.name === key;
|
|
1176
|
+
});
|
|
1177
|
+
if (!def) {
|
|
1178
|
+
return `Unknown option --${key}`;
|
|
1179
|
+
}
|
|
1180
|
+
if (def.choices && value !== void 0) {
|
|
1181
|
+
if (
|
|
1182
|
+
!(def.variadic ? value : [value]).every((v) => {
|
|
1183
|
+
return def.choices.includes(v);
|
|
1184
|
+
})
|
|
1185
|
+
) {
|
|
1186
|
+
return `Invalid option value ${def.flags}: Got \`${value}\`. Accepted values: [${def.choices
|
|
1187
|
+
.map((c) => {
|
|
1188
|
+
return `\`${c}\``;
|
|
1189
|
+
})
|
|
1190
|
+
.join(',')}]`;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
}),
|
|
1194
|
+
)
|
|
1195
|
+
.filter((s) => {
|
|
1196
|
+
return s !== void 0;
|
|
1197
|
+
})
|
|
1198
|
+
.reduce(
|
|
1199
|
+
(acc, curr) => {
|
|
1200
|
+
return (acc ?? []).concat(curr);
|
|
1201
|
+
},
|
|
1202
|
+
void 0,
|
|
1203
|
+
);
|
|
1092
1204
|
}
|
|
1093
|
-
__name(validateParsed,
|
|
1205
|
+
__name(validateParsed, 'validateParsed');
|
|
1094
1206
|
|
|
1095
1207
|
// src/lib/Command.ts
|
|
1096
|
-
|
|
1208
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
1209
|
+
var c = arguments.length,
|
|
1210
|
+
r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
|
|
1211
|
+
d;
|
|
1212
|
+
if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function') {
|
|
1213
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1214
|
+
} else {
|
|
1215
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
1216
|
+
if ((d = decorators[i])) {
|
|
1217
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
return (c > 3 && r && Object.defineProperty(target, key, r), r);
|
|
1222
|
+
}
|
|
1223
|
+
__name(_ts_decorate2, '_ts_decorate');
|
|
1224
|
+
function _ts_metadata2(k, v) {
|
|
1225
|
+
if (typeof Reflect === 'object' && typeof Reflect.metadata === 'function') {
|
|
1226
|
+
return Reflect.metadata(k, v);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
__name(_ts_metadata2, '_ts_metadata');
|
|
1230
|
+
var Command = class _Command {
|
|
1097
1231
|
static {
|
|
1098
|
-
__name(this,
|
|
1232
|
+
__name(this, 'Command');
|
|
1099
1233
|
}
|
|
1100
1234
|
/** parent command in the hierarchy, undefined for root command */
|
|
1101
1235
|
parent;
|
|
@@ -1126,18 +1260,35 @@ var _Command = class _Command {
|
|
|
1126
1260
|
constructor(name, parent) {
|
|
1127
1261
|
this.name = name;
|
|
1128
1262
|
this.aliases = [];
|
|
1129
|
-
this.description =
|
|
1263
|
+
this.description = '';
|
|
1130
1264
|
this.arguments = [];
|
|
1131
1265
|
this.options = [];
|
|
1132
1266
|
this.commands = {};
|
|
1133
1267
|
this.hooks = [];
|
|
1134
|
-
Object.defineProperty(this,
|
|
1268
|
+
Object.defineProperty(this, 'parent', {
|
|
1269
|
+
value: parent,
|
|
1270
|
+
enumerable: false,
|
|
1271
|
+
});
|
|
1135
1272
|
if (!parent) {
|
|
1136
|
-
this.addOption(
|
|
1137
|
-
|
|
1138
|
-
|
|
1273
|
+
this.addOption('-D, --debug', {
|
|
1274
|
+
description: 'Display debug information',
|
|
1275
|
+
}).addOptionHook('debug', ({ cmd, ...data }) => {
|
|
1276
|
+
console.debug(
|
|
1277
|
+
inspect(cmd, {
|
|
1278
|
+
depth: 1,
|
|
1279
|
+
colors: true,
|
|
1280
|
+
}),
|
|
1281
|
+
);
|
|
1282
|
+
console.debug(
|
|
1283
|
+
inspect(data, {
|
|
1284
|
+
depth: 3,
|
|
1285
|
+
colors: true,
|
|
1286
|
+
}),
|
|
1287
|
+
);
|
|
1139
1288
|
});
|
|
1140
|
-
this.addOption(
|
|
1289
|
+
this.addOption('-h, --help', {
|
|
1290
|
+
description: 'Display help information',
|
|
1291
|
+
}).addOptionHook('help', ({ cmd }) => {
|
|
1141
1292
|
console.log(cmd.renderHelp());
|
|
1142
1293
|
process.exitCode = 0;
|
|
1143
1294
|
});
|
|
@@ -1155,7 +1306,7 @@ var _Command = class _Command {
|
|
|
1155
1306
|
/** renders formatted help text using provided help definition */
|
|
1156
1307
|
renderHelp(config = {}) {
|
|
1157
1308
|
const result = this.help.render();
|
|
1158
|
-
return config.noColor ?
|
|
1309
|
+
return config.noColor ? C.stripColor(result) : result;
|
|
1159
1310
|
}
|
|
1160
1311
|
/** sets the command name */
|
|
1161
1312
|
setName(name) {
|
|
@@ -1169,19 +1320,23 @@ var _Command = class _Command {
|
|
|
1169
1320
|
}
|
|
1170
1321
|
/** adds aliases to existing ones */
|
|
1171
1322
|
addAliases(...aliases) {
|
|
1172
|
-
const taken = this.parent
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1323
|
+
const taken = this.parent
|
|
1324
|
+
? valuesOf(this.parent.commands).flatMap((c) => {
|
|
1325
|
+
return [c.name, ...c.aliases];
|
|
1326
|
+
})
|
|
1327
|
+
: [];
|
|
1328
|
+
arrRemoveDuplicates(aliases.flat())
|
|
1329
|
+
.filter((a) => {
|
|
1330
|
+
return !this.aliases.includes(a) && a !== this.name;
|
|
1331
|
+
})
|
|
1332
|
+
.forEach((a) => {
|
|
1333
|
+
if (taken.includes(a)) {
|
|
1334
|
+
throw new Error(
|
|
1335
|
+
`Alias "${a}" is already used by a sibling command: ${findCommand(this.parent, a)?.name}`,
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
this.aliases.push(a);
|
|
1339
|
+
});
|
|
1185
1340
|
this.aliases.sort((a, b) => {
|
|
1186
1341
|
return a.length - b.length;
|
|
1187
1342
|
});
|
|
@@ -1190,14 +1345,16 @@ var _Command = class _Command {
|
|
|
1190
1345
|
/** sets the command version */
|
|
1191
1346
|
setVersion(version) {
|
|
1192
1347
|
this.version = version;
|
|
1193
|
-
if (findOption(this,
|
|
1348
|
+
if (findOption(this, 'version')) {
|
|
1194
1349
|
return this;
|
|
1195
1350
|
}
|
|
1196
|
-
return this.addOption(
|
|
1351
|
+
return this.addOption('-V, --version', {
|
|
1352
|
+
description: 'Display semver version',
|
|
1353
|
+
}).addOptionHook('version', ({ cmd }) => {
|
|
1197
1354
|
console.log(
|
|
1198
1355
|
getCommandAndAncestors(cmd).find((c) => {
|
|
1199
1356
|
return c.version;
|
|
1200
|
-
})?.version
|
|
1357
|
+
})?.version,
|
|
1201
1358
|
);
|
|
1202
1359
|
process.exitCode = 0;
|
|
1203
1360
|
});
|
|
@@ -1209,7 +1366,7 @@ var _Command = class _Command {
|
|
|
1209
1366
|
}
|
|
1210
1367
|
/** sets command description, joining variadic lines */
|
|
1211
1368
|
setDescription(...lines) {
|
|
1212
|
-
this.description = lines.join(
|
|
1369
|
+
this.description = lines.join('\n');
|
|
1213
1370
|
return this;
|
|
1214
1371
|
}
|
|
1215
1372
|
/** sets whether command is hidden from help */
|
|
@@ -1223,11 +1380,11 @@ var _Command = class _Command {
|
|
|
1223
1380
|
return this;
|
|
1224
1381
|
}
|
|
1225
1382
|
/** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
1226
|
-
|
|
1383
|
+
|
|
1227
1384
|
command(name, cb) {
|
|
1228
1385
|
if (this.arguments.length) {
|
|
1229
1386
|
throw new Error(
|
|
1230
|
-
`Cannot add subcommand "${name}" to "${this.name}" because it already has arguments defined
|
|
1387
|
+
`Cannot add subcommand "${name}" to "${this.name}" because it already has arguments defined.`,
|
|
1231
1388
|
);
|
|
1232
1389
|
}
|
|
1233
1390
|
const sub = this.createSubcommand(name);
|
|
@@ -1246,20 +1403,24 @@ var _Command = class _Command {
|
|
|
1246
1403
|
throw new Error(
|
|
1247
1404
|
`Command name "${getCommandAndAncestors(sub).map((c) => {
|
|
1248
1405
|
return c.name;
|
|
1249
|
-
})}" is already used by this command or its aliases: ${taken.join(
|
|
1406
|
+
})}" is already used by this command or its aliases: ${taken.join(', ')}`,
|
|
1250
1407
|
);
|
|
1251
1408
|
}
|
|
1252
1409
|
const kebab = kebabCase(name);
|
|
1253
|
-
const words = kebab.split(
|
|
1254
|
-
const initials = words
|
|
1255
|
-
|
|
1256
|
-
|
|
1410
|
+
const words = kebab.split('-');
|
|
1411
|
+
const initials = words
|
|
1412
|
+
.map((s) => {
|
|
1413
|
+
return s[0];
|
|
1414
|
+
})
|
|
1415
|
+
.join('');
|
|
1257
1416
|
if (!taken.includes(initials)) {
|
|
1258
1417
|
sub.addAliases(initials);
|
|
1259
1418
|
} else {
|
|
1260
|
-
const initials2 = words
|
|
1261
|
-
|
|
1262
|
-
|
|
1419
|
+
const initials2 = words
|
|
1420
|
+
.map((s) => {
|
|
1421
|
+
return s[0] + s[1];
|
|
1422
|
+
})
|
|
1423
|
+
.join('');
|
|
1263
1424
|
if (!taken.includes(initials2)) {
|
|
1264
1425
|
sub.addAliases(initials2);
|
|
1265
1426
|
}
|
|
@@ -1268,7 +1429,7 @@ var _Command = class _Command {
|
|
|
1268
1429
|
return cb ? cb(sub, this) : sub;
|
|
1269
1430
|
}
|
|
1270
1431
|
/** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
1271
|
-
|
|
1432
|
+
|
|
1272
1433
|
addCommand(name, cb) {
|
|
1273
1434
|
this.command(name, cb);
|
|
1274
1435
|
return this;
|
|
@@ -1278,9 +1439,9 @@ var _Command = class _Command {
|
|
|
1278
1439
|
if (!/^<(.*?)>$|^\[(.*?)\]$/.test(usage)) {
|
|
1279
1440
|
throw new Error(`Invalid argument format: ${usage}`);
|
|
1280
1441
|
}
|
|
1281
|
-
const name = usage.slice(1, -1).replace(/\.\.\.$/,
|
|
1282
|
-
const required = usage.startsWith(
|
|
1283
|
-
const variadic = usage.slice(0, -1).endsWith(
|
|
1442
|
+
const name = usage.slice(1, -1).replace(/\.\.\.$/, '');
|
|
1443
|
+
const required = usage.startsWith('<');
|
|
1444
|
+
const variadic = usage.slice(0, -1).endsWith('...');
|
|
1284
1445
|
const prevArg = this.arguments[this.arguments.length - 1];
|
|
1285
1446
|
if (prevArg?.variadic) {
|
|
1286
1447
|
throw new Error(`Cannot add argument ${usage} after variadic argument ${prevArg.usage}`);
|
|
@@ -1290,7 +1451,7 @@ var _Command = class _Command {
|
|
|
1290
1451
|
}
|
|
1291
1452
|
if (required && prevArg?.defaultValue) {
|
|
1292
1453
|
throw new Error(
|
|
1293
|
-
`Cannot add required argument ${usage} after optional argument with default value ${prevArg.usage}
|
|
1454
|
+
`Cannot add required argument ${usage} after optional argument with default value ${prevArg.usage}`,
|
|
1294
1455
|
);
|
|
1295
1456
|
}
|
|
1296
1457
|
const arg = {
|
|
@@ -1298,7 +1459,7 @@ var _Command = class _Command {
|
|
|
1298
1459
|
name,
|
|
1299
1460
|
required,
|
|
1300
1461
|
variadic,
|
|
1301
|
-
...options
|
|
1462
|
+
...options,
|
|
1302
1463
|
};
|
|
1303
1464
|
if (variadic && !arg.defaultValue) {
|
|
1304
1465
|
arg.defaultValue = [];
|
|
@@ -1324,21 +1485,21 @@ var _Command = class _Command {
|
|
|
1324
1485
|
ins.short = short;
|
|
1325
1486
|
ins.long = long;
|
|
1326
1487
|
ins.name = name;
|
|
1327
|
-
ins.description =
|
|
1488
|
+
ins.description = '';
|
|
1328
1489
|
if (!argName) {
|
|
1329
|
-
ins.type =
|
|
1490
|
+
ins.type = 'boolean';
|
|
1330
1491
|
} else {
|
|
1331
|
-
ins.type =
|
|
1492
|
+
ins.type = 'string';
|
|
1332
1493
|
ins.argName = argName;
|
|
1333
|
-
if (flags.endsWith(
|
|
1334
|
-
if (flags.endsWith(
|
|
1494
|
+
if (flags.endsWith('>')) {
|
|
1495
|
+
if (flags.endsWith('...>')) {
|
|
1335
1496
|
ins.required = true;
|
|
1336
1497
|
ins.variadic = true;
|
|
1337
1498
|
} else {
|
|
1338
1499
|
ins.required = true;
|
|
1339
1500
|
}
|
|
1340
|
-
} else if (flags.endsWith(
|
|
1341
|
-
if (flags.endsWith(
|
|
1501
|
+
} else if (flags.endsWith(']')) {
|
|
1502
|
+
if (flags.endsWith('...]')) {
|
|
1342
1503
|
ins.variadic = true;
|
|
1343
1504
|
ins.defaultValue = opts.defaultValue ?? [];
|
|
1344
1505
|
}
|
|
@@ -1349,15 +1510,18 @@ var _Command = class _Command {
|
|
|
1349
1510
|
Reflect.set(ins, key, value);
|
|
1350
1511
|
}
|
|
1351
1512
|
}
|
|
1352
|
-
if (ins.env && ins.defaultValue === void 0 && typeof process.env[ins.env] ===
|
|
1513
|
+
if (ins.env && ins.defaultValue === void 0 && typeof process.env[ins.env] === 'string') {
|
|
1353
1514
|
ins.required = false;
|
|
1354
|
-
ins.flags = ins.flags.replace(
|
|
1355
|
-
if (ins.type ===
|
|
1515
|
+
ins.flags = ins.flags.replace('<', '[').replace('>', ']');
|
|
1516
|
+
if (ins.type === 'boolean') {
|
|
1356
1517
|
ins.defaultValue = /^(t(rue)?|y(es)?|1)$/i.test(process.env[ins.env]);
|
|
1357
1518
|
} else if (ins.variadic) {
|
|
1358
|
-
ins.defaultValue = process.env[ins.env]
|
|
1359
|
-
|
|
1360
|
-
|
|
1519
|
+
ins.defaultValue = process.env[ins.env]
|
|
1520
|
+
.replace(/\]|\[/, '')
|
|
1521
|
+
.split(',')
|
|
1522
|
+
.map((v) => {
|
|
1523
|
+
return v.trim();
|
|
1524
|
+
});
|
|
1361
1525
|
} else {
|
|
1362
1526
|
ins.defaultValue = process.env[ins.env];
|
|
1363
1527
|
}
|
|
@@ -1375,14 +1539,18 @@ var _Command = class _Command {
|
|
|
1375
1539
|
addOptionHook(optionName, action) {
|
|
1376
1540
|
const def = findOption(this, optionName);
|
|
1377
1541
|
if (!def.group && /process\.exitCode ?= ?.+;?\s*\}$/.test(action.toString())) {
|
|
1378
|
-
def.group =
|
|
1542
|
+
def.group = 'Command Options';
|
|
1379
1543
|
}
|
|
1380
1544
|
this.hooks.push({
|
|
1381
1545
|
name: optionName,
|
|
1382
1546
|
predicate: setName(`has${strFirstCharToUpperCase(optionName)}`, ({ opts }) => {
|
|
1383
|
-
return
|
|
1547
|
+
return (
|
|
1548
|
+
opts[optionName] !== void 0 &&
|
|
1549
|
+
opts[optionName] !== false &&
|
|
1550
|
+
!(Array.isArray(opts[optionName]) && opts[optionName].length === 0)
|
|
1551
|
+
);
|
|
1384
1552
|
}),
|
|
1385
|
-
action: setName(optionName, action)
|
|
1553
|
+
action: setName(optionName, action),
|
|
1386
1554
|
});
|
|
1387
1555
|
return this;
|
|
1388
1556
|
}
|
|
@@ -1397,13 +1565,21 @@ var _Command = class _Command {
|
|
|
1397
1565
|
args: argv,
|
|
1398
1566
|
options: Object.fromEntries(
|
|
1399
1567
|
this.options.map((o) => {
|
|
1400
|
-
return [
|
|
1401
|
-
|
|
1568
|
+
return [
|
|
1569
|
+
o.name,
|
|
1570
|
+
{
|
|
1571
|
+
type: o.type,
|
|
1572
|
+
short: o.short,
|
|
1573
|
+
default: o.defaultValue,
|
|
1574
|
+
multiple: !!o.variadic,
|
|
1575
|
+
},
|
|
1576
|
+
];
|
|
1577
|
+
}),
|
|
1402
1578
|
),
|
|
1403
1579
|
allowPositionals: true,
|
|
1404
1580
|
tokens: true,
|
|
1405
1581
|
strict: false,
|
|
1406
|
-
allowNegative: true
|
|
1582
|
+
allowNegative: true,
|
|
1407
1583
|
});
|
|
1408
1584
|
collectVariadicOptionValues(parsed, this.options);
|
|
1409
1585
|
mergeOptionDefaults(parsed.values, this.options);
|
|
@@ -1425,7 +1601,7 @@ var _Command = class _Command {
|
|
|
1425
1601
|
args,
|
|
1426
1602
|
opts,
|
|
1427
1603
|
errors,
|
|
1428
|
-
cmd: this
|
|
1604
|
+
cmd: this,
|
|
1429
1605
|
};
|
|
1430
1606
|
const hooks = this.hooks.filter((t) => {
|
|
1431
1607
|
return t.predicate(data);
|
|
@@ -1437,10 +1613,10 @@ var _Command = class _Command {
|
|
|
1437
1613
|
return;
|
|
1438
1614
|
}
|
|
1439
1615
|
}
|
|
1440
|
-
await timer([[...path, this.name].join(
|
|
1616
|
+
await timer([[...path, this.name].join(' '), this.description], async (logger) => {
|
|
1441
1617
|
if (errors) {
|
|
1442
1618
|
errors.forEach((msg) => {
|
|
1443
|
-
return logger.error(
|
|
1619
|
+
return logger.error(C.red(msg));
|
|
1444
1620
|
});
|
|
1445
1621
|
process.exitCode = 1;
|
|
1446
1622
|
return;
|
|
@@ -1451,13 +1627,17 @@ var _Command = class _Command {
|
|
|
1451
1627
|
args,
|
|
1452
1628
|
opts,
|
|
1453
1629
|
cmd: this,
|
|
1454
|
-
logger
|
|
1630
|
+
logger,
|
|
1455
1631
|
});
|
|
1456
1632
|
}
|
|
1457
1633
|
console.log(this.renderHelp());
|
|
1458
1634
|
});
|
|
1459
|
-
},
|
|
1460
|
-
return {
|
|
1635
|
+
}, 'execute');
|
|
1636
|
+
return {
|
|
1637
|
+
...data,
|
|
1638
|
+
hooks,
|
|
1639
|
+
execute,
|
|
1640
|
+
};
|
|
1461
1641
|
}
|
|
1462
1642
|
/**
|
|
1463
1643
|
* sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
|
|
@@ -1472,34 +1652,15 @@ var _Command = class _Command {
|
|
|
1472
1652
|
return new _Command(name, this);
|
|
1473
1653
|
}
|
|
1474
1654
|
};
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1655
|
+
_ts_decorate2(
|
|
1656
|
+
[
|
|
1657
|
+
lazyProp,
|
|
1658
|
+
_ts_metadata2('design:type', typeof Help === 'undefined' ? Object : Help),
|
|
1659
|
+
_ts_metadata2('design:paramtypes', []),
|
|
1660
|
+
],
|
|
1661
|
+
Command.prototype,
|
|
1662
|
+
'help',
|
|
1663
|
+
null,
|
|
1664
|
+
);
|
|
1482
1665
|
|
|
1483
|
-
|
|
1484
|
-
var src_default = {
|
|
1485
|
-
...Command_exports,
|
|
1486
|
-
//
|
|
1487
|
-
...Help_exports,
|
|
1488
|
-
...findCommand_exports,
|
|
1489
|
-
...findOption_exports,
|
|
1490
|
-
...getCommandAncestors_exports,
|
|
1491
|
-
...getCommandAndAncestors_exports,
|
|
1492
|
-
...parseOptionFlags_exports,
|
|
1493
|
-
...types_exports
|
|
1494
|
-
};
|
|
1495
|
-
export {
|
|
1496
|
-
Command,
|
|
1497
|
-
Help,
|
|
1498
|
-
src_default as default,
|
|
1499
|
-
findCommand,
|
|
1500
|
-
findOption,
|
|
1501
|
-
getCommandAncestors,
|
|
1502
|
-
getCommandAndAncestors,
|
|
1503
|
-
parseOptionFlags
|
|
1504
|
-
};
|
|
1505
|
-
//# sourceMappingURL=index.mjs.map
|
|
1666
|
+
export { Command, Help, findCommand, findOption, getCommandAncestors, getCommandAndAncestors, parseOptionFlags };
|