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