npm-pkg-lint 5.1.11 → 5.2.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/dist/index.js +182 -3259
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38,3172 +38,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
38
38
|
mod
|
|
39
39
|
));
|
|
40
40
|
|
|
41
|
-
// node_modules/argparse/lib/sub.js
|
|
42
|
-
var require_sub = __commonJS({
|
|
43
|
-
"node_modules/argparse/lib/sub.js"(exports, module) {
|
|
44
|
-
"use strict";
|
|
45
|
-
var { inspect } = __require("util");
|
|
46
|
-
module.exports = function sub(pattern, ...values) {
|
|
47
|
-
let regex = /%(?:(%)|(-)?(\*)?(?:\((\w+)\))?([A-Za-z]))/g;
|
|
48
|
-
let result = pattern.replace(regex, function(_2, is_literal, is_left_align, is_padded, name, format) {
|
|
49
|
-
if (is_literal) return "%";
|
|
50
|
-
let padded_count = 0;
|
|
51
|
-
if (is_padded) {
|
|
52
|
-
if (values.length === 0) throw new TypeError("not enough arguments for format string");
|
|
53
|
-
padded_count = values.shift();
|
|
54
|
-
if (!Number.isInteger(padded_count)) throw new TypeError("* wants int");
|
|
55
|
-
}
|
|
56
|
-
let str;
|
|
57
|
-
if (name !== void 0) {
|
|
58
|
-
let dict = values[0];
|
|
59
|
-
if (typeof dict !== "object" || dict === null) throw new TypeError("format requires a mapping");
|
|
60
|
-
if (!(name in dict)) throw new TypeError(`no such key: '${name}'`);
|
|
61
|
-
str = dict[name];
|
|
62
|
-
} else {
|
|
63
|
-
if (values.length === 0) throw new TypeError("not enough arguments for format string");
|
|
64
|
-
str = values.shift();
|
|
65
|
-
}
|
|
66
|
-
switch (format) {
|
|
67
|
-
case "s":
|
|
68
|
-
str = String(str);
|
|
69
|
-
break;
|
|
70
|
-
case "r":
|
|
71
|
-
str = inspect(str);
|
|
72
|
-
break;
|
|
73
|
-
case "d":
|
|
74
|
-
case "i":
|
|
75
|
-
if (typeof str !== "number") {
|
|
76
|
-
throw new TypeError(`%${format} format: a number is required, not ${typeof str}`);
|
|
77
|
-
}
|
|
78
|
-
str = String(str.toFixed(0));
|
|
79
|
-
break;
|
|
80
|
-
default:
|
|
81
|
-
throw new TypeError(`unsupported format character '${format}'`);
|
|
82
|
-
}
|
|
83
|
-
if (padded_count > 0) {
|
|
84
|
-
return is_left_align ? str.padEnd(padded_count) : str.padStart(padded_count);
|
|
85
|
-
} else {
|
|
86
|
-
return str;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
if (values.length) {
|
|
90
|
-
if (values.length === 1 && typeof values[0] === "object" && values[0] !== null) {
|
|
91
|
-
} else {
|
|
92
|
-
throw new TypeError("not all arguments converted during string formatting");
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// node_modules/argparse/lib/textwrap.js
|
|
101
|
-
var require_textwrap = __commonJS({
|
|
102
|
-
"node_modules/argparse/lib/textwrap.js"(exports, module) {
|
|
103
|
-
"use strict";
|
|
104
|
-
var wordsep_simple_re = /([\t\n\x0b\x0c\r ]+)/;
|
|
105
|
-
var TextWrapper = class {
|
|
106
|
-
/*
|
|
107
|
-
* Object for wrapping/filling text. The public interface consists of
|
|
108
|
-
* the wrap() and fill() methods; the other methods are just there for
|
|
109
|
-
* subclasses to override in order to tweak the default behaviour.
|
|
110
|
-
* If you want to completely replace the main wrapping algorithm,
|
|
111
|
-
* you'll probably have to override _wrap_chunks().
|
|
112
|
-
*
|
|
113
|
-
* Several instance attributes control various aspects of wrapping:
|
|
114
|
-
* width (default: 70)
|
|
115
|
-
* the maximum width of wrapped lines (unless break_long_words
|
|
116
|
-
* is false)
|
|
117
|
-
* initial_indent (default: "")
|
|
118
|
-
* string that will be prepended to the first line of wrapped
|
|
119
|
-
* output. Counts towards the line's width.
|
|
120
|
-
* subsequent_indent (default: "")
|
|
121
|
-
* string that will be prepended to all lines save the first
|
|
122
|
-
* of wrapped output; also counts towards each line's width.
|
|
123
|
-
* expand_tabs (default: true)
|
|
124
|
-
* Expand tabs in input text to spaces before further processing.
|
|
125
|
-
* Each tab will become 0 .. 'tabsize' spaces, depending on its position
|
|
126
|
-
* in its line. If false, each tab is treated as a single character.
|
|
127
|
-
* tabsize (default: 8)
|
|
128
|
-
* Expand tabs in input text to 0 .. 'tabsize' spaces, unless
|
|
129
|
-
* 'expand_tabs' is false.
|
|
130
|
-
* replace_whitespace (default: true)
|
|
131
|
-
* Replace all whitespace characters in the input text by spaces
|
|
132
|
-
* after tab expansion. Note that if expand_tabs is false and
|
|
133
|
-
* replace_whitespace is true, every tab will be converted to a
|
|
134
|
-
* single space!
|
|
135
|
-
* fix_sentence_endings (default: false)
|
|
136
|
-
* Ensure that sentence-ending punctuation is always followed
|
|
137
|
-
* by two spaces. Off by default because the algorithm is
|
|
138
|
-
* (unavoidably) imperfect.
|
|
139
|
-
* break_long_words (default: true)
|
|
140
|
-
* Break words longer than 'width'. If false, those words will not
|
|
141
|
-
* be broken, and some lines might be longer than 'width'.
|
|
142
|
-
* break_on_hyphens (default: true)
|
|
143
|
-
* Allow breaking hyphenated words. If true, wrapping will occur
|
|
144
|
-
* preferably on whitespaces and right after hyphens part of
|
|
145
|
-
* compound words.
|
|
146
|
-
* drop_whitespace (default: true)
|
|
147
|
-
* Drop leading and trailing whitespace from lines.
|
|
148
|
-
* max_lines (default: None)
|
|
149
|
-
* Truncate wrapped lines.
|
|
150
|
-
* placeholder (default: ' [...]')
|
|
151
|
-
* Append to the last line of truncated text.
|
|
152
|
-
*/
|
|
153
|
-
constructor(options = {}) {
|
|
154
|
-
let {
|
|
155
|
-
width = 70,
|
|
156
|
-
initial_indent = "",
|
|
157
|
-
subsequent_indent = "",
|
|
158
|
-
expand_tabs = true,
|
|
159
|
-
replace_whitespace = true,
|
|
160
|
-
fix_sentence_endings = false,
|
|
161
|
-
break_long_words = true,
|
|
162
|
-
drop_whitespace = true,
|
|
163
|
-
break_on_hyphens = true,
|
|
164
|
-
tabsize = 8,
|
|
165
|
-
max_lines = void 0,
|
|
166
|
-
placeholder = " [...]"
|
|
167
|
-
} = options;
|
|
168
|
-
this.width = width;
|
|
169
|
-
this.initial_indent = initial_indent;
|
|
170
|
-
this.subsequent_indent = subsequent_indent;
|
|
171
|
-
this.expand_tabs = expand_tabs;
|
|
172
|
-
this.replace_whitespace = replace_whitespace;
|
|
173
|
-
this.fix_sentence_endings = fix_sentence_endings;
|
|
174
|
-
this.break_long_words = break_long_words;
|
|
175
|
-
this.drop_whitespace = drop_whitespace;
|
|
176
|
-
this.break_on_hyphens = break_on_hyphens;
|
|
177
|
-
this.tabsize = tabsize;
|
|
178
|
-
this.max_lines = max_lines;
|
|
179
|
-
this.placeholder = placeholder;
|
|
180
|
-
}
|
|
181
|
-
// -- Private methods -----------------------------------------------
|
|
182
|
-
// (possibly useful for subclasses to override)
|
|
183
|
-
_munge_whitespace(text) {
|
|
184
|
-
if (this.expand_tabs) {
|
|
185
|
-
text = text.replace(/\t/g, " ".repeat(this.tabsize));
|
|
186
|
-
}
|
|
187
|
-
if (this.replace_whitespace) {
|
|
188
|
-
text = text.replace(/[\t\n\x0b\x0c\r]/g, " ");
|
|
189
|
-
}
|
|
190
|
-
return text;
|
|
191
|
-
}
|
|
192
|
-
_split(text) {
|
|
193
|
-
let chunks = text.split(wordsep_simple_re);
|
|
194
|
-
chunks = chunks.filter(Boolean);
|
|
195
|
-
return chunks;
|
|
196
|
-
}
|
|
197
|
-
_handle_long_word(reversed_chunks, cur_line, cur_len, width) {
|
|
198
|
-
let space_left;
|
|
199
|
-
if (width < 1) {
|
|
200
|
-
space_left = 1;
|
|
201
|
-
} else {
|
|
202
|
-
space_left = width - cur_len;
|
|
203
|
-
}
|
|
204
|
-
if (this.break_long_words) {
|
|
205
|
-
cur_line.push(reversed_chunks[reversed_chunks.length - 1].slice(0, space_left));
|
|
206
|
-
reversed_chunks[reversed_chunks.length - 1] = reversed_chunks[reversed_chunks.length - 1].slice(space_left);
|
|
207
|
-
} else if (!cur_line) {
|
|
208
|
-
cur_line.push(...reversed_chunks.pop());
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
_wrap_chunks(chunks) {
|
|
212
|
-
let lines = [];
|
|
213
|
-
let indent;
|
|
214
|
-
if (this.width <= 0) {
|
|
215
|
-
throw Error(`invalid width ${this.width} (must be > 0)`);
|
|
216
|
-
}
|
|
217
|
-
if (this.max_lines !== void 0) {
|
|
218
|
-
if (this.max_lines > 1) {
|
|
219
|
-
indent = this.subsequent_indent;
|
|
220
|
-
} else {
|
|
221
|
-
indent = this.initial_indent;
|
|
222
|
-
}
|
|
223
|
-
if (indent.length + this.placeholder.trimStart().length > this.width) {
|
|
224
|
-
throw Error("placeholder too large for max width");
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
chunks = chunks.reverse();
|
|
228
|
-
while (chunks.length > 0) {
|
|
229
|
-
let cur_line = [];
|
|
230
|
-
let cur_len = 0;
|
|
231
|
-
let indent2;
|
|
232
|
-
if (lines) {
|
|
233
|
-
indent2 = this.subsequent_indent;
|
|
234
|
-
} else {
|
|
235
|
-
indent2 = this.initial_indent;
|
|
236
|
-
}
|
|
237
|
-
let width = this.width - indent2.length;
|
|
238
|
-
if (this.drop_whitespace && chunks[chunks.length - 1].trim() === "" && lines.length > 0) {
|
|
239
|
-
chunks.pop();
|
|
240
|
-
}
|
|
241
|
-
while (chunks.length > 0) {
|
|
242
|
-
let l = chunks[chunks.length - 1].length;
|
|
243
|
-
if (cur_len + l <= width) {
|
|
244
|
-
cur_line.push(chunks.pop());
|
|
245
|
-
cur_len += l;
|
|
246
|
-
} else {
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if (chunks.length && chunks[chunks.length - 1].length > width) {
|
|
251
|
-
this._handle_long_word(chunks, cur_line, cur_len, width);
|
|
252
|
-
cur_len = cur_line.map((l) => l.length).reduce((a, b2) => a + b2, 0);
|
|
253
|
-
}
|
|
254
|
-
if (this.drop_whitespace && cur_line.length > 0 && cur_line[cur_line.length - 1].trim() === "") {
|
|
255
|
-
cur_len -= cur_line[cur_line.length - 1].length;
|
|
256
|
-
cur_line.pop();
|
|
257
|
-
}
|
|
258
|
-
if (cur_line) {
|
|
259
|
-
if (this.max_lines === void 0 || lines.length + 1 < this.max_lines || (chunks.length === 0 || this.drop_whitespace && chunks.length === 1 && !chunks[0].trim()) && cur_len <= width) {
|
|
260
|
-
lines.push(indent2 + cur_line.join(""));
|
|
261
|
-
} else {
|
|
262
|
-
let had_break = false;
|
|
263
|
-
while (cur_line) {
|
|
264
|
-
if (cur_line[cur_line.length - 1].trim() && cur_len + this.placeholder.length <= width) {
|
|
265
|
-
cur_line.push(this.placeholder);
|
|
266
|
-
lines.push(indent2 + cur_line.join(""));
|
|
267
|
-
had_break = true;
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
cur_len -= cur_line[-1].length;
|
|
271
|
-
cur_line.pop();
|
|
272
|
-
}
|
|
273
|
-
if (!had_break) {
|
|
274
|
-
if (lines) {
|
|
275
|
-
let prev_line = lines[lines.length - 1].trimEnd();
|
|
276
|
-
if (prev_line.length + this.placeholder.length <= this.width) {
|
|
277
|
-
lines[lines.length - 1] = prev_line + this.placeholder;
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
lines.push(indent2 + this.placeholder.lstrip());
|
|
282
|
-
}
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return lines;
|
|
288
|
-
}
|
|
289
|
-
_split_chunks(text) {
|
|
290
|
-
text = this._munge_whitespace(text);
|
|
291
|
-
return this._split(text);
|
|
292
|
-
}
|
|
293
|
-
// -- Public interface ----------------------------------------------
|
|
294
|
-
wrap(text) {
|
|
295
|
-
let chunks = this._split_chunks(text);
|
|
296
|
-
return this._wrap_chunks(chunks);
|
|
297
|
-
}
|
|
298
|
-
fill(text) {
|
|
299
|
-
return this.wrap(text).join("\n");
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
function wrap(text, options = {}) {
|
|
303
|
-
let { width = 70, ...kwargs } = options;
|
|
304
|
-
let w2 = new TextWrapper(Object.assign({ width }, kwargs));
|
|
305
|
-
return w2.wrap(text);
|
|
306
|
-
}
|
|
307
|
-
function fill(text, options = {}) {
|
|
308
|
-
let { width = 70, ...kwargs } = options;
|
|
309
|
-
let w2 = new TextWrapper(Object.assign({ width }, kwargs));
|
|
310
|
-
return w2.fill(text);
|
|
311
|
-
}
|
|
312
|
-
var _whitespace_only_re = /^[ \t]+$/mg;
|
|
313
|
-
var _leading_whitespace_re = /(^[ \t]*)(?:[^ \t\n])/mg;
|
|
314
|
-
function dedent(text) {
|
|
315
|
-
let margin = void 0;
|
|
316
|
-
text = text.replace(_whitespace_only_re, "");
|
|
317
|
-
let indents = text.match(_leading_whitespace_re) || [];
|
|
318
|
-
for (let indent of indents) {
|
|
319
|
-
indent = indent.slice(0, -1);
|
|
320
|
-
if (margin === void 0) {
|
|
321
|
-
margin = indent;
|
|
322
|
-
} else if (indent.startsWith(margin)) {
|
|
323
|
-
} else if (margin.startsWith(indent)) {
|
|
324
|
-
margin = indent;
|
|
325
|
-
} else {
|
|
326
|
-
for (let i = 0; i < margin.length && i < indent.length; i++) {
|
|
327
|
-
if (margin[i] !== indent[i]) {
|
|
328
|
-
margin = margin.slice(0, i);
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
if (margin) {
|
|
335
|
-
text = text.replace(new RegExp("^" + margin, "mg"), "");
|
|
336
|
-
}
|
|
337
|
-
return text;
|
|
338
|
-
}
|
|
339
|
-
module.exports = { wrap, fill, dedent };
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
// node_modules/argparse/argparse.js
|
|
344
|
-
var require_argparse = __commonJS({
|
|
345
|
-
"node_modules/argparse/argparse.js"(exports, module) {
|
|
346
|
-
"use strict";
|
|
347
|
-
var SUPPRESS = "==SUPPRESS==";
|
|
348
|
-
var OPTIONAL = "?";
|
|
349
|
-
var ZERO_OR_MORE = "*";
|
|
350
|
-
var ONE_OR_MORE = "+";
|
|
351
|
-
var PARSER = "A...";
|
|
352
|
-
var REMAINDER = "...";
|
|
353
|
-
var _UNRECOGNIZED_ARGS_ATTR = "_unrecognized_args";
|
|
354
|
-
var assert = __require("assert");
|
|
355
|
-
var util = __require("util");
|
|
356
|
-
var fs8 = __require("fs");
|
|
357
|
-
var sub = require_sub();
|
|
358
|
-
var path8 = __require("path");
|
|
359
|
-
var repr = util.inspect;
|
|
360
|
-
function get_argv() {
|
|
361
|
-
return process.argv.slice(1);
|
|
362
|
-
}
|
|
363
|
-
function get_terminal_size() {
|
|
364
|
-
return {
|
|
365
|
-
columns: +process.env.COLUMNS || process.stdout.columns || 80
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
function hasattr(object, name) {
|
|
369
|
-
return Object.prototype.hasOwnProperty.call(object, name);
|
|
370
|
-
}
|
|
371
|
-
function getattr(object, name, value) {
|
|
372
|
-
return hasattr(object, name) ? object[name] : value;
|
|
373
|
-
}
|
|
374
|
-
function setattr(object, name, value) {
|
|
375
|
-
object[name] = value;
|
|
376
|
-
}
|
|
377
|
-
function setdefault(object, name, value) {
|
|
378
|
-
if (!hasattr(object, name)) object[name] = value;
|
|
379
|
-
return object[name];
|
|
380
|
-
}
|
|
381
|
-
function delattr(object, name) {
|
|
382
|
-
delete object[name];
|
|
383
|
-
}
|
|
384
|
-
function range(from, to2, step = 1) {
|
|
385
|
-
if (arguments.length === 1) [to2, from] = [from, 0];
|
|
386
|
-
if (typeof from !== "number" || typeof to2 !== "number" || typeof step !== "number") {
|
|
387
|
-
throw new TypeError("argument cannot be interpreted as an integer");
|
|
388
|
-
}
|
|
389
|
-
if (step === 0) throw new TypeError("range() arg 3 must not be zero");
|
|
390
|
-
let result = [];
|
|
391
|
-
if (step > 0) {
|
|
392
|
-
for (let i = from; i < to2; i += step) result.push(i);
|
|
393
|
-
} else {
|
|
394
|
-
for (let i = from; i > to2; i += step) result.push(i);
|
|
395
|
-
}
|
|
396
|
-
return result;
|
|
397
|
-
}
|
|
398
|
-
function splitlines(str, keepends = false) {
|
|
399
|
-
let result;
|
|
400
|
-
if (!keepends) {
|
|
401
|
-
result = str.split(/\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029]/);
|
|
402
|
-
} else {
|
|
403
|
-
result = [];
|
|
404
|
-
let parts = str.split(/(\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029])/);
|
|
405
|
-
for (let i = 0; i < parts.length; i += 2) {
|
|
406
|
-
result.push(parts[i] + (i + 1 < parts.length ? parts[i + 1] : ""));
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
if (!result[result.length - 1]) result.pop();
|
|
410
|
-
return result;
|
|
411
|
-
}
|
|
412
|
-
function _string_lstrip(string, prefix_chars) {
|
|
413
|
-
let idx = 0;
|
|
414
|
-
while (idx < string.length && prefix_chars.includes(string[idx])) idx++;
|
|
415
|
-
return idx ? string.slice(idx) : string;
|
|
416
|
-
}
|
|
417
|
-
function _string_split(string, sep, maxsplit) {
|
|
418
|
-
let result = string.split(sep);
|
|
419
|
-
if (result.length > maxsplit) {
|
|
420
|
-
result = result.slice(0, maxsplit).concat([result.slice(maxsplit).join(sep)]);
|
|
421
|
-
}
|
|
422
|
-
return result;
|
|
423
|
-
}
|
|
424
|
-
function _array_equal(array1, array2) {
|
|
425
|
-
if (array1.length !== array2.length) return false;
|
|
426
|
-
for (let i = 0; i < array1.length; i++) {
|
|
427
|
-
if (array1[i] !== array2[i]) return false;
|
|
428
|
-
}
|
|
429
|
-
return true;
|
|
430
|
-
}
|
|
431
|
-
function _array_remove(array, item) {
|
|
432
|
-
let idx = array.indexOf(item);
|
|
433
|
-
if (idx === -1) throw new TypeError(sub("%r not in list", item));
|
|
434
|
-
array.splice(idx, 1);
|
|
435
|
-
}
|
|
436
|
-
function _choices_to_array(choices) {
|
|
437
|
-
if (choices === void 0) {
|
|
438
|
-
return [];
|
|
439
|
-
} else if (Array.isArray(choices)) {
|
|
440
|
-
return choices;
|
|
441
|
-
} else if (choices !== null && typeof choices[Symbol.iterator] === "function") {
|
|
442
|
-
return Array.from(choices);
|
|
443
|
-
} else if (typeof choices === "object" && choices !== null) {
|
|
444
|
-
return Object.keys(choices);
|
|
445
|
-
} else {
|
|
446
|
-
throw new Error(sub("invalid choices value: %r", choices));
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
function _callable(cls) {
|
|
450
|
-
let result = {
|
|
451
|
-
// object is needed for inferred class name
|
|
452
|
-
[cls.name]: function(...args) {
|
|
453
|
-
let this_class = new.target === result || !new.target;
|
|
454
|
-
return Reflect.construct(cls, args, this_class ? cls : new.target);
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
result[cls.name].prototype = cls.prototype;
|
|
458
|
-
cls.prototype[Symbol.toStringTag] = cls.name;
|
|
459
|
-
return result[cls.name];
|
|
460
|
-
}
|
|
461
|
-
function _alias(object, from, to2) {
|
|
462
|
-
try {
|
|
463
|
-
let name = object.constructor.name;
|
|
464
|
-
Object.defineProperty(object, from, {
|
|
465
|
-
value: util.deprecate(object[to2], sub(
|
|
466
|
-
"%s.%s() is renamed to %s.%s()",
|
|
467
|
-
name,
|
|
468
|
-
from,
|
|
469
|
-
name,
|
|
470
|
-
to2
|
|
471
|
-
)),
|
|
472
|
-
enumerable: false
|
|
473
|
-
});
|
|
474
|
-
} catch {
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
function _camelcase_alias(_class) {
|
|
478
|
-
for (let name of Object.getOwnPropertyNames(_class.prototype)) {
|
|
479
|
-
let camelcase = name.replace(/\w_[a-z]/g, (s3) => s3[0] + s3[2].toUpperCase());
|
|
480
|
-
if (camelcase !== name) _alias(_class.prototype, camelcase, name);
|
|
481
|
-
}
|
|
482
|
-
return _class;
|
|
483
|
-
}
|
|
484
|
-
function _to_legacy_name(key) {
|
|
485
|
-
key = key.replace(/\w_[a-z]/g, (s3) => s3[0] + s3[2].toUpperCase());
|
|
486
|
-
if (key === "default") key = "defaultValue";
|
|
487
|
-
if (key === "const") key = "constant";
|
|
488
|
-
return key;
|
|
489
|
-
}
|
|
490
|
-
function _to_new_name(key) {
|
|
491
|
-
if (key === "defaultValue") key = "default";
|
|
492
|
-
if (key === "constant") key = "const";
|
|
493
|
-
key = key.replace(/[A-Z]/g, (c) => "_" + c.toLowerCase());
|
|
494
|
-
return key;
|
|
495
|
-
}
|
|
496
|
-
var no_default = /* @__PURE__ */ Symbol("no_default_value");
|
|
497
|
-
function _parse_opts(args, descriptor) {
|
|
498
|
-
function get_name() {
|
|
499
|
-
let stack = new Error().stack.split("\n").map((x) => x.match(/^ at (.*) \(.*\)$/)).filter(Boolean).map((m2) => m2[1]).map((fn) => fn.match(/[^ .]*$/)[0]);
|
|
500
|
-
if (stack.length && stack[0] === get_name.name) stack.shift();
|
|
501
|
-
if (stack.length && stack[0] === _parse_opts.name) stack.shift();
|
|
502
|
-
return stack.length ? stack[0] : "";
|
|
503
|
-
}
|
|
504
|
-
args = Array.from(args);
|
|
505
|
-
let kwargs = {};
|
|
506
|
-
let result = [];
|
|
507
|
-
let last_opt = args.length && args[args.length - 1];
|
|
508
|
-
if (typeof last_opt === "object" && last_opt !== null && !Array.isArray(last_opt) && (!last_opt.constructor || last_opt.constructor.name === "Object")) {
|
|
509
|
-
kwargs = Object.assign({}, args.pop());
|
|
510
|
-
}
|
|
511
|
-
let renames = [];
|
|
512
|
-
for (let key of Object.keys(descriptor)) {
|
|
513
|
-
let old_name = _to_legacy_name(key);
|
|
514
|
-
if (old_name !== key && old_name in kwargs) {
|
|
515
|
-
if (key in kwargs) {
|
|
516
|
-
} else {
|
|
517
|
-
kwargs[key] = kwargs[old_name];
|
|
518
|
-
}
|
|
519
|
-
renames.push([old_name, key]);
|
|
520
|
-
delete kwargs[old_name];
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
if (renames.length) {
|
|
524
|
-
let name = get_name();
|
|
525
|
-
deprecate("camelcase_" + name, sub(
|
|
526
|
-
"%s(): following options are renamed: %s",
|
|
527
|
-
name,
|
|
528
|
-
renames.map(([a, b2]) => sub("%r -> %r", a, b2))
|
|
529
|
-
));
|
|
530
|
-
}
|
|
531
|
-
let missing_positionals = [];
|
|
532
|
-
let positional_count = args.length;
|
|
533
|
-
for (let [key, def] of Object.entries(descriptor)) {
|
|
534
|
-
if (key[0] === "*") {
|
|
535
|
-
if (key.length > 0 && key[1] === "*") {
|
|
536
|
-
let renames2 = [];
|
|
537
|
-
for (let key2 of Object.keys(kwargs)) {
|
|
538
|
-
let new_name = _to_new_name(key2);
|
|
539
|
-
if (new_name !== key2 && key2 in kwargs) {
|
|
540
|
-
if (new_name in kwargs) {
|
|
541
|
-
} else {
|
|
542
|
-
kwargs[new_name] = kwargs[key2];
|
|
543
|
-
}
|
|
544
|
-
renames2.push([key2, new_name]);
|
|
545
|
-
delete kwargs[key2];
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
if (renames2.length) {
|
|
549
|
-
let name = get_name();
|
|
550
|
-
deprecate("camelcase_" + name, sub(
|
|
551
|
-
"%s(): following options are renamed: %s",
|
|
552
|
-
name,
|
|
553
|
-
renames2.map(([a, b2]) => sub("%r -> %r", a, b2))
|
|
554
|
-
));
|
|
555
|
-
}
|
|
556
|
-
result.push(kwargs);
|
|
557
|
-
kwargs = {};
|
|
558
|
-
} else {
|
|
559
|
-
result.push(args);
|
|
560
|
-
args = [];
|
|
561
|
-
}
|
|
562
|
-
} else if (key in kwargs && args.length > 0) {
|
|
563
|
-
throw new TypeError(sub("%s() got multiple values for argument %r", get_name(), key));
|
|
564
|
-
} else if (key in kwargs) {
|
|
565
|
-
result.push(kwargs[key]);
|
|
566
|
-
delete kwargs[key];
|
|
567
|
-
} else if (args.length > 0) {
|
|
568
|
-
result.push(args.shift());
|
|
569
|
-
} else if (def !== no_default) {
|
|
570
|
-
result.push(def);
|
|
571
|
-
} else {
|
|
572
|
-
missing_positionals.push(key);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
if (Object.keys(kwargs).length) {
|
|
576
|
-
throw new TypeError(sub(
|
|
577
|
-
"%s() got an unexpected keyword argument %r",
|
|
578
|
-
get_name(),
|
|
579
|
-
Object.keys(kwargs)[0]
|
|
580
|
-
));
|
|
581
|
-
}
|
|
582
|
-
if (args.length) {
|
|
583
|
-
let from = Object.entries(descriptor).filter(([k2, v2]) => k2[0] !== "*" && v2 !== no_default).length;
|
|
584
|
-
let to2 = Object.entries(descriptor).filter(([k2]) => k2[0] !== "*").length;
|
|
585
|
-
throw new TypeError(sub(
|
|
586
|
-
"%s() takes %s positional argument%s but %s %s given",
|
|
587
|
-
get_name(),
|
|
588
|
-
from === to2 ? sub("from %s to %s", from, to2) : to2,
|
|
589
|
-
from === to2 && to2 === 1 ? "" : "s",
|
|
590
|
-
positional_count,
|
|
591
|
-
positional_count === 1 ? "was" : "were"
|
|
592
|
-
));
|
|
593
|
-
}
|
|
594
|
-
if (missing_positionals.length) {
|
|
595
|
-
let strs = missing_positionals.map(repr);
|
|
596
|
-
if (strs.length > 1) strs[strs.length - 1] = "and " + strs[strs.length - 1];
|
|
597
|
-
let str_joined = strs.join(strs.length === 2 ? "" : ", ");
|
|
598
|
-
throw new TypeError(sub(
|
|
599
|
-
"%s() missing %i required positional argument%s: %s",
|
|
600
|
-
get_name(),
|
|
601
|
-
strs.length,
|
|
602
|
-
strs.length === 1 ? "" : "s",
|
|
603
|
-
str_joined
|
|
604
|
-
));
|
|
605
|
-
}
|
|
606
|
-
return result;
|
|
607
|
-
}
|
|
608
|
-
var _deprecations = {};
|
|
609
|
-
function deprecate(id, string) {
|
|
610
|
-
_deprecations[id] = _deprecations[id] || util.deprecate(() => {
|
|
611
|
-
}, string);
|
|
612
|
-
_deprecations[id]();
|
|
613
|
-
}
|
|
614
|
-
function _AttributeHolder(cls = Object) {
|
|
615
|
-
return class _AttributeHolder extends cls {
|
|
616
|
-
[util.inspect.custom]() {
|
|
617
|
-
let type_name = this.constructor.name;
|
|
618
|
-
let arg_strings = [];
|
|
619
|
-
let star_args = {};
|
|
620
|
-
for (let arg of this._get_args()) {
|
|
621
|
-
arg_strings.push(repr(arg));
|
|
622
|
-
}
|
|
623
|
-
for (let [name, value] of this._get_kwargs()) {
|
|
624
|
-
if (/^[a-z_][a-z0-9_$]*$/i.test(name)) {
|
|
625
|
-
arg_strings.push(sub("%s=%r", name, value));
|
|
626
|
-
} else {
|
|
627
|
-
star_args[name] = value;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
if (Object.keys(star_args).length) {
|
|
631
|
-
arg_strings.push(sub("**%s", repr(star_args)));
|
|
632
|
-
}
|
|
633
|
-
return sub("%s(%s)", type_name, arg_strings.join(", "));
|
|
634
|
-
}
|
|
635
|
-
toString() {
|
|
636
|
-
return this[util.inspect.custom]();
|
|
637
|
-
}
|
|
638
|
-
_get_kwargs() {
|
|
639
|
-
return Object.entries(this);
|
|
640
|
-
}
|
|
641
|
-
_get_args() {
|
|
642
|
-
return [];
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
function _copy_items(items) {
|
|
647
|
-
if (items === void 0) {
|
|
648
|
-
return [];
|
|
649
|
-
}
|
|
650
|
-
return items.slice(0);
|
|
651
|
-
}
|
|
652
|
-
var HelpFormatter = _camelcase_alias(_callable(class HelpFormatter {
|
|
653
|
-
/*
|
|
654
|
-
* Formatter for generating usage messages and argument help strings.
|
|
655
|
-
*
|
|
656
|
-
* Only the name of this class is considered a public API. All the methods
|
|
657
|
-
* provided by the class are considered an implementation detail.
|
|
658
|
-
*/
|
|
659
|
-
constructor() {
|
|
660
|
-
let [
|
|
661
|
-
prog,
|
|
662
|
-
indent_increment,
|
|
663
|
-
max_help_position,
|
|
664
|
-
width
|
|
665
|
-
] = _parse_opts(arguments, {
|
|
666
|
-
prog: no_default,
|
|
667
|
-
indent_increment: 2,
|
|
668
|
-
max_help_position: 24,
|
|
669
|
-
width: void 0
|
|
670
|
-
});
|
|
671
|
-
if (width === void 0) {
|
|
672
|
-
width = get_terminal_size().columns;
|
|
673
|
-
width -= 2;
|
|
674
|
-
}
|
|
675
|
-
this._prog = prog;
|
|
676
|
-
this._indent_increment = indent_increment;
|
|
677
|
-
this._max_help_position = Math.min(
|
|
678
|
-
max_help_position,
|
|
679
|
-
Math.max(width - 20, indent_increment * 2)
|
|
680
|
-
);
|
|
681
|
-
this._width = width;
|
|
682
|
-
this._current_indent = 0;
|
|
683
|
-
this._level = 0;
|
|
684
|
-
this._action_max_length = 0;
|
|
685
|
-
this._root_section = this._Section(this, void 0);
|
|
686
|
-
this._current_section = this._root_section;
|
|
687
|
-
this._whitespace_matcher = /[ \t\n\r\f\v]+/g;
|
|
688
|
-
this._long_break_matcher = /\n\n\n+/g;
|
|
689
|
-
}
|
|
690
|
-
// ===============================
|
|
691
|
-
// Section and indentation methods
|
|
692
|
-
// ===============================
|
|
693
|
-
_indent() {
|
|
694
|
-
this._current_indent += this._indent_increment;
|
|
695
|
-
this._level += 1;
|
|
696
|
-
}
|
|
697
|
-
_dedent() {
|
|
698
|
-
this._current_indent -= this._indent_increment;
|
|
699
|
-
assert(this._current_indent >= 0, "Indent decreased below 0.");
|
|
700
|
-
this._level -= 1;
|
|
701
|
-
}
|
|
702
|
-
_add_item(func, args) {
|
|
703
|
-
this._current_section.items.push([func, args]);
|
|
704
|
-
}
|
|
705
|
-
// ========================
|
|
706
|
-
// Message building methods
|
|
707
|
-
// ========================
|
|
708
|
-
start_section(heading) {
|
|
709
|
-
this._indent();
|
|
710
|
-
let section = this._Section(this, this._current_section, heading);
|
|
711
|
-
this._add_item(section.format_help.bind(section), []);
|
|
712
|
-
this._current_section = section;
|
|
713
|
-
}
|
|
714
|
-
end_section() {
|
|
715
|
-
this._current_section = this._current_section.parent;
|
|
716
|
-
this._dedent();
|
|
717
|
-
}
|
|
718
|
-
add_text(text) {
|
|
719
|
-
if (text !== SUPPRESS && text !== void 0) {
|
|
720
|
-
this._add_item(this._format_text.bind(this), [text]);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
add_usage(usage, actions, groups, prefix2 = void 0) {
|
|
724
|
-
if (usage !== SUPPRESS) {
|
|
725
|
-
let args = [usage, actions, groups, prefix2];
|
|
726
|
-
this._add_item(this._format_usage.bind(this), args);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
add_argument(action) {
|
|
730
|
-
if (action.help !== SUPPRESS) {
|
|
731
|
-
let invocations = [this._format_action_invocation(action)];
|
|
732
|
-
for (let subaction of this._iter_indented_subactions(action)) {
|
|
733
|
-
invocations.push(this._format_action_invocation(subaction));
|
|
734
|
-
}
|
|
735
|
-
let invocation_length = Math.max(...invocations.map((invocation) => invocation.length));
|
|
736
|
-
let action_length = invocation_length + this._current_indent;
|
|
737
|
-
this._action_max_length = Math.max(
|
|
738
|
-
this._action_max_length,
|
|
739
|
-
action_length
|
|
740
|
-
);
|
|
741
|
-
this._add_item(this._format_action.bind(this), [action]);
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
add_arguments(actions) {
|
|
745
|
-
for (let action of actions) {
|
|
746
|
-
this.add_argument(action);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
// =======================
|
|
750
|
-
// Help-formatting methods
|
|
751
|
-
// =======================
|
|
752
|
-
format_help() {
|
|
753
|
-
let help = this._root_section.format_help();
|
|
754
|
-
if (help) {
|
|
755
|
-
help = help.replace(this._long_break_matcher, "\n\n");
|
|
756
|
-
help = help.replace(/^\n+|\n+$/g, "") + "\n";
|
|
757
|
-
}
|
|
758
|
-
return help;
|
|
759
|
-
}
|
|
760
|
-
_join_parts(part_strings) {
|
|
761
|
-
return part_strings.filter((part) => part && part !== SUPPRESS).join("");
|
|
762
|
-
}
|
|
763
|
-
_format_usage(usage, actions, groups, prefix2) {
|
|
764
|
-
if (prefix2 === void 0) {
|
|
765
|
-
prefix2 = "usage: ";
|
|
766
|
-
}
|
|
767
|
-
if (usage !== void 0) {
|
|
768
|
-
usage = sub(usage, { prog: this._prog });
|
|
769
|
-
} else if (usage === void 0 && !actions.length) {
|
|
770
|
-
usage = sub("%(prog)s", { prog: this._prog });
|
|
771
|
-
} else if (usage === void 0) {
|
|
772
|
-
let prog = sub("%(prog)s", { prog: this._prog });
|
|
773
|
-
let optionals = [];
|
|
774
|
-
let positionals = [];
|
|
775
|
-
for (let action of actions) {
|
|
776
|
-
if (action.option_strings.length) {
|
|
777
|
-
optionals.push(action);
|
|
778
|
-
} else {
|
|
779
|
-
positionals.push(action);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
let action_usage = this._format_actions_usage([].concat(optionals).concat(positionals), groups);
|
|
783
|
-
usage = [prog, action_usage].map(String).join(" ");
|
|
784
|
-
let text_width = this._width - this._current_indent;
|
|
785
|
-
if (prefix2.length + usage.length > text_width) {
|
|
786
|
-
let part_regexp = /\(.*?\)+(?=\s|$)|\[.*?\]+(?=\s|$)|\S+/g;
|
|
787
|
-
let opt_usage = this._format_actions_usage(optionals, groups);
|
|
788
|
-
let pos_usage = this._format_actions_usage(positionals, groups);
|
|
789
|
-
let opt_parts = opt_usage.match(part_regexp) || [];
|
|
790
|
-
let pos_parts = pos_usage.match(part_regexp) || [];
|
|
791
|
-
assert(opt_parts.join(" ") === opt_usage);
|
|
792
|
-
assert(pos_parts.join(" ") === pos_usage);
|
|
793
|
-
let get_lines = (parts, indent, prefix3 = void 0) => {
|
|
794
|
-
let lines2 = [];
|
|
795
|
-
let line = [];
|
|
796
|
-
let line_len;
|
|
797
|
-
if (prefix3 !== void 0) {
|
|
798
|
-
line_len = prefix3.length - 1;
|
|
799
|
-
} else {
|
|
800
|
-
line_len = indent.length - 1;
|
|
801
|
-
}
|
|
802
|
-
for (let part of parts) {
|
|
803
|
-
if (line_len + 1 + part.length > text_width && line) {
|
|
804
|
-
lines2.push(indent + line.join(" "));
|
|
805
|
-
line = [];
|
|
806
|
-
line_len = indent.length - 1;
|
|
807
|
-
}
|
|
808
|
-
line.push(part);
|
|
809
|
-
line_len += part.length + 1;
|
|
810
|
-
}
|
|
811
|
-
if (line.length) {
|
|
812
|
-
lines2.push(indent + line.join(" "));
|
|
813
|
-
}
|
|
814
|
-
if (prefix3 !== void 0) {
|
|
815
|
-
lines2[0] = lines2[0].slice(indent.length);
|
|
816
|
-
}
|
|
817
|
-
return lines2;
|
|
818
|
-
};
|
|
819
|
-
let lines;
|
|
820
|
-
if (prefix2.length + prog.length <= 0.75 * text_width) {
|
|
821
|
-
let indent = " ".repeat(prefix2.length + prog.length + 1);
|
|
822
|
-
if (opt_parts.length) {
|
|
823
|
-
lines = get_lines([prog].concat(opt_parts), indent, prefix2);
|
|
824
|
-
lines = lines.concat(get_lines(pos_parts, indent));
|
|
825
|
-
} else if (pos_parts.length) {
|
|
826
|
-
lines = get_lines([prog].concat(pos_parts), indent, prefix2);
|
|
827
|
-
} else {
|
|
828
|
-
lines = [prog];
|
|
829
|
-
}
|
|
830
|
-
} else {
|
|
831
|
-
let indent = " ".repeat(prefix2.length);
|
|
832
|
-
let parts = [].concat(opt_parts).concat(pos_parts);
|
|
833
|
-
lines = get_lines(parts, indent);
|
|
834
|
-
if (lines.length > 1) {
|
|
835
|
-
lines = [];
|
|
836
|
-
lines = lines.concat(get_lines(opt_parts, indent));
|
|
837
|
-
lines = lines.concat(get_lines(pos_parts, indent));
|
|
838
|
-
}
|
|
839
|
-
lines = [prog].concat(lines);
|
|
840
|
-
}
|
|
841
|
-
usage = lines.join("\n");
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
return sub("%s%s\n\n", prefix2, usage);
|
|
845
|
-
}
|
|
846
|
-
_format_actions_usage(actions, groups) {
|
|
847
|
-
let group_actions = /* @__PURE__ */ new Set();
|
|
848
|
-
let inserts = {};
|
|
849
|
-
for (let group of groups) {
|
|
850
|
-
let start = actions.indexOf(group._group_actions[0]);
|
|
851
|
-
if (start === -1) {
|
|
852
|
-
continue;
|
|
853
|
-
} else {
|
|
854
|
-
let end = start + group._group_actions.length;
|
|
855
|
-
if (_array_equal(actions.slice(start, end), group._group_actions)) {
|
|
856
|
-
for (let action of group._group_actions) {
|
|
857
|
-
group_actions.add(action);
|
|
858
|
-
}
|
|
859
|
-
if (!group.required) {
|
|
860
|
-
if (start in inserts) {
|
|
861
|
-
inserts[start] += " [";
|
|
862
|
-
} else {
|
|
863
|
-
inserts[start] = "[";
|
|
864
|
-
}
|
|
865
|
-
if (end in inserts) {
|
|
866
|
-
inserts[end] += "]";
|
|
867
|
-
} else {
|
|
868
|
-
inserts[end] = "]";
|
|
869
|
-
}
|
|
870
|
-
} else {
|
|
871
|
-
if (start in inserts) {
|
|
872
|
-
inserts[start] += " (";
|
|
873
|
-
} else {
|
|
874
|
-
inserts[start] = "(";
|
|
875
|
-
}
|
|
876
|
-
if (end in inserts) {
|
|
877
|
-
inserts[end] += ")";
|
|
878
|
-
} else {
|
|
879
|
-
inserts[end] = ")";
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
for (let i of range(start + 1, end)) {
|
|
883
|
-
inserts[i] = "|";
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
let parts = [];
|
|
889
|
-
for (let [i, action] of Object.entries(actions)) {
|
|
890
|
-
if (action.help === SUPPRESS) {
|
|
891
|
-
parts.push(void 0);
|
|
892
|
-
if (inserts[+i] === "|") {
|
|
893
|
-
delete inserts[+i];
|
|
894
|
-
} else if (inserts[+i + 1] === "|") {
|
|
895
|
-
delete inserts[+i + 1];
|
|
896
|
-
}
|
|
897
|
-
} else if (!action.option_strings.length) {
|
|
898
|
-
let default_value = this._get_default_metavar_for_positional(action);
|
|
899
|
-
let part = this._format_args(action, default_value);
|
|
900
|
-
if (group_actions.has(action)) {
|
|
901
|
-
if (part[0] === "[" && part[part.length - 1] === "]") {
|
|
902
|
-
part = part.slice(1, -1);
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
parts.push(part);
|
|
906
|
-
} else {
|
|
907
|
-
let option_string = action.option_strings[0];
|
|
908
|
-
let part;
|
|
909
|
-
if (action.nargs === 0) {
|
|
910
|
-
part = action.format_usage();
|
|
911
|
-
} else {
|
|
912
|
-
let default_value = this._get_default_metavar_for_optional(action);
|
|
913
|
-
let args_string = this._format_args(action, default_value);
|
|
914
|
-
part = sub("%s %s", option_string, args_string);
|
|
915
|
-
}
|
|
916
|
-
if (!action.required && !group_actions.has(action)) {
|
|
917
|
-
part = sub("[%s]", part);
|
|
918
|
-
}
|
|
919
|
-
parts.push(part);
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
for (let i of Object.keys(inserts).map(Number).sort((a, b2) => b2 - a)) {
|
|
923
|
-
parts.splice(+i, 0, inserts[+i]);
|
|
924
|
-
}
|
|
925
|
-
let text = parts.filter(Boolean).join(" ");
|
|
926
|
-
text = text.replace(/([\[(]) /g, "$1");
|
|
927
|
-
text = text.replace(/ ([\])])/g, "$1");
|
|
928
|
-
text = text.replace(/[\[(] *[\])]/g, "");
|
|
929
|
-
text = text.replace(/\(([^|]*)\)/g, "$1", text);
|
|
930
|
-
text = text.trim();
|
|
931
|
-
return text;
|
|
932
|
-
}
|
|
933
|
-
_format_text(text) {
|
|
934
|
-
if (text.includes("%(prog)")) {
|
|
935
|
-
text = sub(text, { prog: this._prog });
|
|
936
|
-
}
|
|
937
|
-
let text_width = Math.max(this._width - this._current_indent, 11);
|
|
938
|
-
let indent = " ".repeat(this._current_indent);
|
|
939
|
-
return this._fill_text(text, text_width, indent) + "\n\n";
|
|
940
|
-
}
|
|
941
|
-
_format_action(action) {
|
|
942
|
-
let help_position = Math.min(
|
|
943
|
-
this._action_max_length + 2,
|
|
944
|
-
this._max_help_position
|
|
945
|
-
);
|
|
946
|
-
let help_width = Math.max(this._width - help_position, 11);
|
|
947
|
-
let action_width = help_position - this._current_indent - 2;
|
|
948
|
-
let action_header = this._format_action_invocation(action);
|
|
949
|
-
let indent_first;
|
|
950
|
-
if (!action.help) {
|
|
951
|
-
let tup = [this._current_indent, "", action_header];
|
|
952
|
-
action_header = sub("%*s%s\n", ...tup);
|
|
953
|
-
} else if (action_header.length <= action_width) {
|
|
954
|
-
let tup = [this._current_indent, "", action_width, action_header];
|
|
955
|
-
action_header = sub("%*s%-*s ", ...tup);
|
|
956
|
-
indent_first = 0;
|
|
957
|
-
} else {
|
|
958
|
-
let tup = [this._current_indent, "", action_header];
|
|
959
|
-
action_header = sub("%*s%s\n", ...tup);
|
|
960
|
-
indent_first = help_position;
|
|
961
|
-
}
|
|
962
|
-
let parts = [action_header];
|
|
963
|
-
if (action.help) {
|
|
964
|
-
let help_text = this._expand_help(action);
|
|
965
|
-
let help_lines = this._split_lines(help_text, help_width);
|
|
966
|
-
parts.push(sub("%*s%s\n", indent_first, "", help_lines[0]));
|
|
967
|
-
for (let line of help_lines.slice(1)) {
|
|
968
|
-
parts.push(sub("%*s%s\n", help_position, "", line));
|
|
969
|
-
}
|
|
970
|
-
} else if (!action_header.endsWith("\n")) {
|
|
971
|
-
parts.push("\n");
|
|
972
|
-
}
|
|
973
|
-
for (let subaction of this._iter_indented_subactions(action)) {
|
|
974
|
-
parts.push(this._format_action(subaction));
|
|
975
|
-
}
|
|
976
|
-
return this._join_parts(parts);
|
|
977
|
-
}
|
|
978
|
-
_format_action_invocation(action) {
|
|
979
|
-
if (!action.option_strings.length) {
|
|
980
|
-
let default_value = this._get_default_metavar_for_positional(action);
|
|
981
|
-
let metavar = this._metavar_formatter(action, default_value)(1)[0];
|
|
982
|
-
return metavar;
|
|
983
|
-
} else {
|
|
984
|
-
let parts = [];
|
|
985
|
-
if (action.nargs === 0) {
|
|
986
|
-
parts = parts.concat(action.option_strings);
|
|
987
|
-
} else {
|
|
988
|
-
let default_value = this._get_default_metavar_for_optional(action);
|
|
989
|
-
let args_string = this._format_args(action, default_value);
|
|
990
|
-
for (let option_string of action.option_strings) {
|
|
991
|
-
parts.push(sub("%s %s", option_string, args_string));
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
return parts.join(", ");
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
_metavar_formatter(action, default_metavar) {
|
|
998
|
-
let result;
|
|
999
|
-
if (action.metavar !== void 0) {
|
|
1000
|
-
result = action.metavar;
|
|
1001
|
-
} else if (action.choices !== void 0) {
|
|
1002
|
-
let choice_strs = _choices_to_array(action.choices).map(String);
|
|
1003
|
-
result = sub("{%s}", choice_strs.join(","));
|
|
1004
|
-
} else {
|
|
1005
|
-
result = default_metavar;
|
|
1006
|
-
}
|
|
1007
|
-
function format(tuple_size) {
|
|
1008
|
-
if (Array.isArray(result)) {
|
|
1009
|
-
return result;
|
|
1010
|
-
} else {
|
|
1011
|
-
return Array(tuple_size).fill(result);
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
return format;
|
|
1015
|
-
}
|
|
1016
|
-
_format_args(action, default_metavar) {
|
|
1017
|
-
let get_metavar = this._metavar_formatter(action, default_metavar);
|
|
1018
|
-
let result;
|
|
1019
|
-
if (action.nargs === void 0) {
|
|
1020
|
-
result = sub("%s", ...get_metavar(1));
|
|
1021
|
-
} else if (action.nargs === OPTIONAL) {
|
|
1022
|
-
result = sub("[%s]", ...get_metavar(1));
|
|
1023
|
-
} else if (action.nargs === ZERO_OR_MORE) {
|
|
1024
|
-
let metavar = get_metavar(1);
|
|
1025
|
-
if (metavar.length === 2) {
|
|
1026
|
-
result = sub("[%s [%s ...]]", ...metavar);
|
|
1027
|
-
} else {
|
|
1028
|
-
result = sub("[%s ...]", ...metavar);
|
|
1029
|
-
}
|
|
1030
|
-
} else if (action.nargs === ONE_OR_MORE) {
|
|
1031
|
-
result = sub("%s [%s ...]", ...get_metavar(2));
|
|
1032
|
-
} else if (action.nargs === REMAINDER) {
|
|
1033
|
-
result = "...";
|
|
1034
|
-
} else if (action.nargs === PARSER) {
|
|
1035
|
-
result = sub("%s ...", ...get_metavar(1));
|
|
1036
|
-
} else if (action.nargs === SUPPRESS) {
|
|
1037
|
-
result = "";
|
|
1038
|
-
} else {
|
|
1039
|
-
let formats;
|
|
1040
|
-
try {
|
|
1041
|
-
formats = range(action.nargs).map(() => "%s");
|
|
1042
|
-
} catch (err) {
|
|
1043
|
-
throw new TypeError("invalid nargs value");
|
|
1044
|
-
}
|
|
1045
|
-
result = sub(formats.join(" "), ...get_metavar(action.nargs));
|
|
1046
|
-
}
|
|
1047
|
-
return result;
|
|
1048
|
-
}
|
|
1049
|
-
_expand_help(action) {
|
|
1050
|
-
let params = Object.assign({ prog: this._prog }, action);
|
|
1051
|
-
for (let name of Object.keys(params)) {
|
|
1052
|
-
if (params[name] === SUPPRESS) {
|
|
1053
|
-
delete params[name];
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
for (let name of Object.keys(params)) {
|
|
1057
|
-
if (params[name] && params[name].name) {
|
|
1058
|
-
params[name] = params[name].name;
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
if (params.choices !== void 0) {
|
|
1062
|
-
let choices_str = _choices_to_array(params.choices).map(String).join(", ");
|
|
1063
|
-
params.choices = choices_str;
|
|
1064
|
-
}
|
|
1065
|
-
for (let key of Object.keys(params)) {
|
|
1066
|
-
let old_name = _to_legacy_name(key);
|
|
1067
|
-
if (old_name !== key) {
|
|
1068
|
-
params[old_name] = params[key];
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
return sub(this._get_help_string(action), params);
|
|
1072
|
-
}
|
|
1073
|
-
*_iter_indented_subactions(action) {
|
|
1074
|
-
if (typeof action._get_subactions === "function") {
|
|
1075
|
-
this._indent();
|
|
1076
|
-
yield* action._get_subactions();
|
|
1077
|
-
this._dedent();
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
_split_lines(text, width) {
|
|
1081
|
-
text = text.replace(this._whitespace_matcher, " ").trim();
|
|
1082
|
-
let textwrap = require_textwrap();
|
|
1083
|
-
return textwrap.wrap(text, { width });
|
|
1084
|
-
}
|
|
1085
|
-
_fill_text(text, width, indent) {
|
|
1086
|
-
text = text.replace(this._whitespace_matcher, " ").trim();
|
|
1087
|
-
let textwrap = require_textwrap();
|
|
1088
|
-
return textwrap.fill(text, {
|
|
1089
|
-
width,
|
|
1090
|
-
initial_indent: indent,
|
|
1091
|
-
subsequent_indent: indent
|
|
1092
|
-
});
|
|
1093
|
-
}
|
|
1094
|
-
_get_help_string(action) {
|
|
1095
|
-
return action.help;
|
|
1096
|
-
}
|
|
1097
|
-
_get_default_metavar_for_optional(action) {
|
|
1098
|
-
return action.dest.toUpperCase();
|
|
1099
|
-
}
|
|
1100
|
-
_get_default_metavar_for_positional(action) {
|
|
1101
|
-
return action.dest;
|
|
1102
|
-
}
|
|
1103
|
-
}));
|
|
1104
|
-
HelpFormatter.prototype._Section = _callable(class _Section {
|
|
1105
|
-
constructor(formatter, parent, heading = void 0) {
|
|
1106
|
-
this.formatter = formatter;
|
|
1107
|
-
this.parent = parent;
|
|
1108
|
-
this.heading = heading;
|
|
1109
|
-
this.items = [];
|
|
1110
|
-
}
|
|
1111
|
-
format_help() {
|
|
1112
|
-
if (this.parent !== void 0) {
|
|
1113
|
-
this.formatter._indent();
|
|
1114
|
-
}
|
|
1115
|
-
let item_help = this.formatter._join_parts(this.items.map(([func, args]) => func.apply(null, args)));
|
|
1116
|
-
if (this.parent !== void 0) {
|
|
1117
|
-
this.formatter._dedent();
|
|
1118
|
-
}
|
|
1119
|
-
if (!item_help) {
|
|
1120
|
-
return "";
|
|
1121
|
-
}
|
|
1122
|
-
let heading;
|
|
1123
|
-
if (this.heading !== SUPPRESS && this.heading !== void 0) {
|
|
1124
|
-
let current_indent = this.formatter._current_indent;
|
|
1125
|
-
heading = sub("%*s%s:\n", current_indent, "", this.heading);
|
|
1126
|
-
} else {
|
|
1127
|
-
heading = "";
|
|
1128
|
-
}
|
|
1129
|
-
return this.formatter._join_parts(["\n", heading, item_help, "\n"]);
|
|
1130
|
-
}
|
|
1131
|
-
});
|
|
1132
|
-
var RawDescriptionHelpFormatter = _camelcase_alias(_callable(class RawDescriptionHelpFormatter extends HelpFormatter {
|
|
1133
|
-
/*
|
|
1134
|
-
* Help message formatter which retains any formatting in descriptions.
|
|
1135
|
-
*
|
|
1136
|
-
* Only the name of this class is considered a public API. All the methods
|
|
1137
|
-
* provided by the class are considered an implementation detail.
|
|
1138
|
-
*/
|
|
1139
|
-
_fill_text(text, width, indent) {
|
|
1140
|
-
return splitlines(text, true).map((line) => indent + line).join("");
|
|
1141
|
-
}
|
|
1142
|
-
}));
|
|
1143
|
-
var RawTextHelpFormatter = _camelcase_alias(_callable(class RawTextHelpFormatter extends RawDescriptionHelpFormatter {
|
|
1144
|
-
/*
|
|
1145
|
-
* Help message formatter which retains formatting of all help text.
|
|
1146
|
-
*
|
|
1147
|
-
* Only the name of this class is considered a public API. All the methods
|
|
1148
|
-
* provided by the class are considered an implementation detail.
|
|
1149
|
-
*/
|
|
1150
|
-
_split_lines(text) {
|
|
1151
|
-
return splitlines(text);
|
|
1152
|
-
}
|
|
1153
|
-
}));
|
|
1154
|
-
var ArgumentDefaultsHelpFormatter = _camelcase_alias(_callable(class ArgumentDefaultsHelpFormatter extends HelpFormatter {
|
|
1155
|
-
/*
|
|
1156
|
-
* Help message formatter which adds default values to argument help.
|
|
1157
|
-
*
|
|
1158
|
-
* Only the name of this class is considered a public API. All the methods
|
|
1159
|
-
* provided by the class are considered an implementation detail.
|
|
1160
|
-
*/
|
|
1161
|
-
_get_help_string(action) {
|
|
1162
|
-
let help = action.help;
|
|
1163
|
-
if (!action.help.includes("%(default)") && !action.help.includes("%(defaultValue)")) {
|
|
1164
|
-
if (action.default !== SUPPRESS) {
|
|
1165
|
-
let defaulting_nargs = [OPTIONAL, ZERO_OR_MORE];
|
|
1166
|
-
if (action.option_strings.length || defaulting_nargs.includes(action.nargs)) {
|
|
1167
|
-
help += " (default: %(default)s)";
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
return help;
|
|
1172
|
-
}
|
|
1173
|
-
}));
|
|
1174
|
-
var MetavarTypeHelpFormatter = _camelcase_alias(_callable(class MetavarTypeHelpFormatter extends HelpFormatter {
|
|
1175
|
-
/*
|
|
1176
|
-
* Help message formatter which uses the argument 'type' as the default
|
|
1177
|
-
* metavar value (instead of the argument 'dest')
|
|
1178
|
-
*
|
|
1179
|
-
* Only the name of this class is considered a public API. All the methods
|
|
1180
|
-
* provided by the class are considered an implementation detail.
|
|
1181
|
-
*/
|
|
1182
|
-
_get_default_metavar_for_optional(action) {
|
|
1183
|
-
return typeof action.type === "function" ? action.type.name : action.type;
|
|
1184
|
-
}
|
|
1185
|
-
_get_default_metavar_for_positional(action) {
|
|
1186
|
-
return typeof action.type === "function" ? action.type.name : action.type;
|
|
1187
|
-
}
|
|
1188
|
-
}));
|
|
1189
|
-
function _get_action_name(argument) {
|
|
1190
|
-
if (argument === void 0) {
|
|
1191
|
-
return void 0;
|
|
1192
|
-
} else if (argument.option_strings.length) {
|
|
1193
|
-
return argument.option_strings.join("/");
|
|
1194
|
-
} else if (![void 0, SUPPRESS].includes(argument.metavar)) {
|
|
1195
|
-
return argument.metavar;
|
|
1196
|
-
} else if (![void 0, SUPPRESS].includes(argument.dest)) {
|
|
1197
|
-
return argument.dest;
|
|
1198
|
-
} else {
|
|
1199
|
-
return void 0;
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
var ArgumentError = _callable(class ArgumentError extends Error {
|
|
1203
|
-
/*
|
|
1204
|
-
* An error from creating or using an argument (optional or positional).
|
|
1205
|
-
*
|
|
1206
|
-
* The string value of this exception is the message, augmented with
|
|
1207
|
-
* information about the argument that caused it.
|
|
1208
|
-
*/
|
|
1209
|
-
constructor(argument, message) {
|
|
1210
|
-
super();
|
|
1211
|
-
this.name = "ArgumentError";
|
|
1212
|
-
this._argument_name = _get_action_name(argument);
|
|
1213
|
-
this._message = message;
|
|
1214
|
-
this.message = this.str();
|
|
1215
|
-
}
|
|
1216
|
-
str() {
|
|
1217
|
-
let format;
|
|
1218
|
-
if (this._argument_name === void 0) {
|
|
1219
|
-
format = "%(message)s";
|
|
1220
|
-
} else {
|
|
1221
|
-
format = "argument %(argument_name)s: %(message)s";
|
|
1222
|
-
}
|
|
1223
|
-
return sub(format, {
|
|
1224
|
-
message: this._message,
|
|
1225
|
-
argument_name: this._argument_name
|
|
1226
|
-
});
|
|
1227
|
-
}
|
|
1228
|
-
});
|
|
1229
|
-
var ArgumentTypeError = _callable(class ArgumentTypeError extends Error {
|
|
1230
|
-
/*
|
|
1231
|
-
* An error from trying to convert a command line string to a type.
|
|
1232
|
-
*/
|
|
1233
|
-
constructor(message) {
|
|
1234
|
-
super(message);
|
|
1235
|
-
this.name = "ArgumentTypeError";
|
|
1236
|
-
}
|
|
1237
|
-
});
|
|
1238
|
-
var Action = _camelcase_alias(_callable(class Action extends _AttributeHolder(Function) {
|
|
1239
|
-
/*
|
|
1240
|
-
* Information about how to convert command line strings to Python objects.
|
|
1241
|
-
*
|
|
1242
|
-
* Action objects are used by an ArgumentParser to represent the information
|
|
1243
|
-
* needed to parse a single argument from one or more strings from the
|
|
1244
|
-
* command line. The keyword arguments to the Action constructor are also
|
|
1245
|
-
* all attributes of Action instances.
|
|
1246
|
-
*
|
|
1247
|
-
* Keyword Arguments:
|
|
1248
|
-
*
|
|
1249
|
-
* - option_strings -- A list of command-line option strings which
|
|
1250
|
-
* should be associated with this action.
|
|
1251
|
-
*
|
|
1252
|
-
* - dest -- The name of the attribute to hold the created object(s)
|
|
1253
|
-
*
|
|
1254
|
-
* - nargs -- The number of command-line arguments that should be
|
|
1255
|
-
* consumed. By default, one argument will be consumed and a single
|
|
1256
|
-
* value will be produced. Other values include:
|
|
1257
|
-
* - N (an integer) consumes N arguments (and produces a list)
|
|
1258
|
-
* - '?' consumes zero or one arguments
|
|
1259
|
-
* - '*' consumes zero or more arguments (and produces a list)
|
|
1260
|
-
* - '+' consumes one or more arguments (and produces a list)
|
|
1261
|
-
* Note that the difference between the default and nargs=1 is that
|
|
1262
|
-
* with the default, a single value will be produced, while with
|
|
1263
|
-
* nargs=1, a list containing a single value will be produced.
|
|
1264
|
-
*
|
|
1265
|
-
* - const -- The value to be produced if the option is specified and the
|
|
1266
|
-
* option uses an action that takes no values.
|
|
1267
|
-
*
|
|
1268
|
-
* - default -- The value to be produced if the option is not specified.
|
|
1269
|
-
*
|
|
1270
|
-
* - type -- A callable that accepts a single string argument, and
|
|
1271
|
-
* returns the converted value. The standard Python types str, int,
|
|
1272
|
-
* float, and complex are useful examples of such callables. If None,
|
|
1273
|
-
* str is used.
|
|
1274
|
-
*
|
|
1275
|
-
* - choices -- A container of values that should be allowed. If not None,
|
|
1276
|
-
* after a command-line argument has been converted to the appropriate
|
|
1277
|
-
* type, an exception will be raised if it is not a member of this
|
|
1278
|
-
* collection.
|
|
1279
|
-
*
|
|
1280
|
-
* - required -- True if the action must always be specified at the
|
|
1281
|
-
* command line. This is only meaningful for optional command-line
|
|
1282
|
-
* arguments.
|
|
1283
|
-
*
|
|
1284
|
-
* - help -- The help string describing the argument.
|
|
1285
|
-
*
|
|
1286
|
-
* - metavar -- The name to be used for the option's argument with the
|
|
1287
|
-
* help string. If None, the 'dest' value will be used as the name.
|
|
1288
|
-
*/
|
|
1289
|
-
constructor() {
|
|
1290
|
-
let [
|
|
1291
|
-
option_strings,
|
|
1292
|
-
dest,
|
|
1293
|
-
nargs,
|
|
1294
|
-
const_value,
|
|
1295
|
-
default_value,
|
|
1296
|
-
type,
|
|
1297
|
-
choices,
|
|
1298
|
-
required,
|
|
1299
|
-
help,
|
|
1300
|
-
metavar
|
|
1301
|
-
] = _parse_opts(arguments, {
|
|
1302
|
-
option_strings: no_default,
|
|
1303
|
-
dest: no_default,
|
|
1304
|
-
nargs: void 0,
|
|
1305
|
-
const: void 0,
|
|
1306
|
-
default: void 0,
|
|
1307
|
-
type: void 0,
|
|
1308
|
-
choices: void 0,
|
|
1309
|
-
required: false,
|
|
1310
|
-
help: void 0,
|
|
1311
|
-
metavar: void 0
|
|
1312
|
-
});
|
|
1313
|
-
super("return arguments.callee.call.apply(arguments.callee, arguments)");
|
|
1314
|
-
this.option_strings = option_strings;
|
|
1315
|
-
this.dest = dest;
|
|
1316
|
-
this.nargs = nargs;
|
|
1317
|
-
this.const = const_value;
|
|
1318
|
-
this.default = default_value;
|
|
1319
|
-
this.type = type;
|
|
1320
|
-
this.choices = choices;
|
|
1321
|
-
this.required = required;
|
|
1322
|
-
this.help = help;
|
|
1323
|
-
this.metavar = metavar;
|
|
1324
|
-
}
|
|
1325
|
-
_get_kwargs() {
|
|
1326
|
-
let names = [
|
|
1327
|
-
"option_strings",
|
|
1328
|
-
"dest",
|
|
1329
|
-
"nargs",
|
|
1330
|
-
"const",
|
|
1331
|
-
"default",
|
|
1332
|
-
"type",
|
|
1333
|
-
"choices",
|
|
1334
|
-
"help",
|
|
1335
|
-
"metavar"
|
|
1336
|
-
];
|
|
1337
|
-
return names.map((name) => [name, getattr(this, name)]);
|
|
1338
|
-
}
|
|
1339
|
-
format_usage() {
|
|
1340
|
-
return this.option_strings[0];
|
|
1341
|
-
}
|
|
1342
|
-
call() {
|
|
1343
|
-
throw new Error(".call() not defined");
|
|
1344
|
-
}
|
|
1345
|
-
}));
|
|
1346
|
-
var BooleanOptionalAction = _camelcase_alias(_callable(class BooleanOptionalAction extends Action {
|
|
1347
|
-
constructor() {
|
|
1348
|
-
let [
|
|
1349
|
-
option_strings,
|
|
1350
|
-
dest,
|
|
1351
|
-
default_value,
|
|
1352
|
-
type,
|
|
1353
|
-
choices,
|
|
1354
|
-
required,
|
|
1355
|
-
help,
|
|
1356
|
-
metavar
|
|
1357
|
-
] = _parse_opts(arguments, {
|
|
1358
|
-
option_strings: no_default,
|
|
1359
|
-
dest: no_default,
|
|
1360
|
-
default: void 0,
|
|
1361
|
-
type: void 0,
|
|
1362
|
-
choices: void 0,
|
|
1363
|
-
required: false,
|
|
1364
|
-
help: void 0,
|
|
1365
|
-
metavar: void 0
|
|
1366
|
-
});
|
|
1367
|
-
let _option_strings = [];
|
|
1368
|
-
for (let option_string of option_strings) {
|
|
1369
|
-
_option_strings.push(option_string);
|
|
1370
|
-
if (option_string.startsWith("--")) {
|
|
1371
|
-
option_string = "--no-" + option_string.slice(2);
|
|
1372
|
-
_option_strings.push(option_string);
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
if (help !== void 0 && default_value !== void 0) {
|
|
1376
|
-
help += ` (default: ${default_value})`;
|
|
1377
|
-
}
|
|
1378
|
-
super({
|
|
1379
|
-
option_strings: _option_strings,
|
|
1380
|
-
dest,
|
|
1381
|
-
nargs: 0,
|
|
1382
|
-
default: default_value,
|
|
1383
|
-
type,
|
|
1384
|
-
choices,
|
|
1385
|
-
required,
|
|
1386
|
-
help,
|
|
1387
|
-
metavar
|
|
1388
|
-
});
|
|
1389
|
-
}
|
|
1390
|
-
call(parser, namespace, values, option_string = void 0) {
|
|
1391
|
-
if (this.option_strings.includes(option_string)) {
|
|
1392
|
-
setattr(namespace, this.dest, !option_string.startsWith("--no-"));
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
format_usage() {
|
|
1396
|
-
return this.option_strings.join(" | ");
|
|
1397
|
-
}
|
|
1398
|
-
}));
|
|
1399
|
-
var _StoreAction = _callable(class _StoreAction extends Action {
|
|
1400
|
-
constructor() {
|
|
1401
|
-
let [
|
|
1402
|
-
option_strings,
|
|
1403
|
-
dest,
|
|
1404
|
-
nargs,
|
|
1405
|
-
const_value,
|
|
1406
|
-
default_value,
|
|
1407
|
-
type,
|
|
1408
|
-
choices,
|
|
1409
|
-
required,
|
|
1410
|
-
help,
|
|
1411
|
-
metavar
|
|
1412
|
-
] = _parse_opts(arguments, {
|
|
1413
|
-
option_strings: no_default,
|
|
1414
|
-
dest: no_default,
|
|
1415
|
-
nargs: void 0,
|
|
1416
|
-
const: void 0,
|
|
1417
|
-
default: void 0,
|
|
1418
|
-
type: void 0,
|
|
1419
|
-
choices: void 0,
|
|
1420
|
-
required: false,
|
|
1421
|
-
help: void 0,
|
|
1422
|
-
metavar: void 0
|
|
1423
|
-
});
|
|
1424
|
-
if (nargs === 0) {
|
|
1425
|
-
throw new TypeError("nargs for store actions must be != 0; if you have nothing to store, actions such as store true or store const may be more appropriate");
|
|
1426
|
-
}
|
|
1427
|
-
if (const_value !== void 0 && nargs !== OPTIONAL) {
|
|
1428
|
-
throw new TypeError(sub("nargs must be %r to supply const", OPTIONAL));
|
|
1429
|
-
}
|
|
1430
|
-
super({
|
|
1431
|
-
option_strings,
|
|
1432
|
-
dest,
|
|
1433
|
-
nargs,
|
|
1434
|
-
const: const_value,
|
|
1435
|
-
default: default_value,
|
|
1436
|
-
type,
|
|
1437
|
-
choices,
|
|
1438
|
-
required,
|
|
1439
|
-
help,
|
|
1440
|
-
metavar
|
|
1441
|
-
});
|
|
1442
|
-
}
|
|
1443
|
-
call(parser, namespace, values) {
|
|
1444
|
-
setattr(namespace, this.dest, values);
|
|
1445
|
-
}
|
|
1446
|
-
});
|
|
1447
|
-
var _StoreConstAction = _callable(class _StoreConstAction extends Action {
|
|
1448
|
-
constructor() {
|
|
1449
|
-
let [
|
|
1450
|
-
option_strings,
|
|
1451
|
-
dest,
|
|
1452
|
-
const_value,
|
|
1453
|
-
default_value,
|
|
1454
|
-
required,
|
|
1455
|
-
help
|
|
1456
|
-
//, metavar
|
|
1457
|
-
] = _parse_opts(arguments, {
|
|
1458
|
-
option_strings: no_default,
|
|
1459
|
-
dest: no_default,
|
|
1460
|
-
const: no_default,
|
|
1461
|
-
default: void 0,
|
|
1462
|
-
required: false,
|
|
1463
|
-
help: void 0,
|
|
1464
|
-
metavar: void 0
|
|
1465
|
-
});
|
|
1466
|
-
super({
|
|
1467
|
-
option_strings,
|
|
1468
|
-
dest,
|
|
1469
|
-
nargs: 0,
|
|
1470
|
-
const: const_value,
|
|
1471
|
-
default: default_value,
|
|
1472
|
-
required,
|
|
1473
|
-
help
|
|
1474
|
-
});
|
|
1475
|
-
}
|
|
1476
|
-
call(parser, namespace) {
|
|
1477
|
-
setattr(namespace, this.dest, this.const);
|
|
1478
|
-
}
|
|
1479
|
-
});
|
|
1480
|
-
var _StoreTrueAction = _callable(class _StoreTrueAction extends _StoreConstAction {
|
|
1481
|
-
constructor() {
|
|
1482
|
-
let [
|
|
1483
|
-
option_strings,
|
|
1484
|
-
dest,
|
|
1485
|
-
default_value,
|
|
1486
|
-
required,
|
|
1487
|
-
help
|
|
1488
|
-
] = _parse_opts(arguments, {
|
|
1489
|
-
option_strings: no_default,
|
|
1490
|
-
dest: no_default,
|
|
1491
|
-
default: false,
|
|
1492
|
-
required: false,
|
|
1493
|
-
help: void 0
|
|
1494
|
-
});
|
|
1495
|
-
super({
|
|
1496
|
-
option_strings,
|
|
1497
|
-
dest,
|
|
1498
|
-
const: true,
|
|
1499
|
-
default: default_value,
|
|
1500
|
-
required,
|
|
1501
|
-
help
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
});
|
|
1505
|
-
var _StoreFalseAction = _callable(class _StoreFalseAction extends _StoreConstAction {
|
|
1506
|
-
constructor() {
|
|
1507
|
-
let [
|
|
1508
|
-
option_strings,
|
|
1509
|
-
dest,
|
|
1510
|
-
default_value,
|
|
1511
|
-
required,
|
|
1512
|
-
help
|
|
1513
|
-
] = _parse_opts(arguments, {
|
|
1514
|
-
option_strings: no_default,
|
|
1515
|
-
dest: no_default,
|
|
1516
|
-
default: true,
|
|
1517
|
-
required: false,
|
|
1518
|
-
help: void 0
|
|
1519
|
-
});
|
|
1520
|
-
super({
|
|
1521
|
-
option_strings,
|
|
1522
|
-
dest,
|
|
1523
|
-
const: false,
|
|
1524
|
-
default: default_value,
|
|
1525
|
-
required,
|
|
1526
|
-
help
|
|
1527
|
-
});
|
|
1528
|
-
}
|
|
1529
|
-
});
|
|
1530
|
-
var _AppendAction = _callable(class _AppendAction extends Action {
|
|
1531
|
-
constructor() {
|
|
1532
|
-
let [
|
|
1533
|
-
option_strings,
|
|
1534
|
-
dest,
|
|
1535
|
-
nargs,
|
|
1536
|
-
const_value,
|
|
1537
|
-
default_value,
|
|
1538
|
-
type,
|
|
1539
|
-
choices,
|
|
1540
|
-
required,
|
|
1541
|
-
help,
|
|
1542
|
-
metavar
|
|
1543
|
-
] = _parse_opts(arguments, {
|
|
1544
|
-
option_strings: no_default,
|
|
1545
|
-
dest: no_default,
|
|
1546
|
-
nargs: void 0,
|
|
1547
|
-
const: void 0,
|
|
1548
|
-
default: void 0,
|
|
1549
|
-
type: void 0,
|
|
1550
|
-
choices: void 0,
|
|
1551
|
-
required: false,
|
|
1552
|
-
help: void 0,
|
|
1553
|
-
metavar: void 0
|
|
1554
|
-
});
|
|
1555
|
-
if (nargs === 0) {
|
|
1556
|
-
throw new TypeError("nargs for append actions must be != 0; if arg strings are not supplying the value to append, the append const action may be more appropriate");
|
|
1557
|
-
}
|
|
1558
|
-
if (const_value !== void 0 && nargs !== OPTIONAL) {
|
|
1559
|
-
throw new TypeError(sub("nargs must be %r to supply const", OPTIONAL));
|
|
1560
|
-
}
|
|
1561
|
-
super({
|
|
1562
|
-
option_strings,
|
|
1563
|
-
dest,
|
|
1564
|
-
nargs,
|
|
1565
|
-
const: const_value,
|
|
1566
|
-
default: default_value,
|
|
1567
|
-
type,
|
|
1568
|
-
choices,
|
|
1569
|
-
required,
|
|
1570
|
-
help,
|
|
1571
|
-
metavar
|
|
1572
|
-
});
|
|
1573
|
-
}
|
|
1574
|
-
call(parser, namespace, values) {
|
|
1575
|
-
let items = getattr(namespace, this.dest, void 0);
|
|
1576
|
-
items = _copy_items(items);
|
|
1577
|
-
items.push(values);
|
|
1578
|
-
setattr(namespace, this.dest, items);
|
|
1579
|
-
}
|
|
1580
|
-
});
|
|
1581
|
-
var _AppendConstAction = _callable(class _AppendConstAction extends Action {
|
|
1582
|
-
constructor() {
|
|
1583
|
-
let [
|
|
1584
|
-
option_strings,
|
|
1585
|
-
dest,
|
|
1586
|
-
const_value,
|
|
1587
|
-
default_value,
|
|
1588
|
-
required,
|
|
1589
|
-
help,
|
|
1590
|
-
metavar
|
|
1591
|
-
] = _parse_opts(arguments, {
|
|
1592
|
-
option_strings: no_default,
|
|
1593
|
-
dest: no_default,
|
|
1594
|
-
const: no_default,
|
|
1595
|
-
default: void 0,
|
|
1596
|
-
required: false,
|
|
1597
|
-
help: void 0,
|
|
1598
|
-
metavar: void 0
|
|
1599
|
-
});
|
|
1600
|
-
super({
|
|
1601
|
-
option_strings,
|
|
1602
|
-
dest,
|
|
1603
|
-
nargs: 0,
|
|
1604
|
-
const: const_value,
|
|
1605
|
-
default: default_value,
|
|
1606
|
-
required,
|
|
1607
|
-
help,
|
|
1608
|
-
metavar
|
|
1609
|
-
});
|
|
1610
|
-
}
|
|
1611
|
-
call(parser, namespace) {
|
|
1612
|
-
let items = getattr(namespace, this.dest, void 0);
|
|
1613
|
-
items = _copy_items(items);
|
|
1614
|
-
items.push(this.const);
|
|
1615
|
-
setattr(namespace, this.dest, items);
|
|
1616
|
-
}
|
|
1617
|
-
});
|
|
1618
|
-
var _CountAction = _callable(class _CountAction extends Action {
|
|
1619
|
-
constructor() {
|
|
1620
|
-
let [
|
|
1621
|
-
option_strings,
|
|
1622
|
-
dest,
|
|
1623
|
-
default_value,
|
|
1624
|
-
required,
|
|
1625
|
-
help
|
|
1626
|
-
] = _parse_opts(arguments, {
|
|
1627
|
-
option_strings: no_default,
|
|
1628
|
-
dest: no_default,
|
|
1629
|
-
default: void 0,
|
|
1630
|
-
required: false,
|
|
1631
|
-
help: void 0
|
|
1632
|
-
});
|
|
1633
|
-
super({
|
|
1634
|
-
option_strings,
|
|
1635
|
-
dest,
|
|
1636
|
-
nargs: 0,
|
|
1637
|
-
default: default_value,
|
|
1638
|
-
required,
|
|
1639
|
-
help
|
|
1640
|
-
});
|
|
1641
|
-
}
|
|
1642
|
-
call(parser, namespace) {
|
|
1643
|
-
let count = getattr(namespace, this.dest, void 0);
|
|
1644
|
-
if (count === void 0) {
|
|
1645
|
-
count = 0;
|
|
1646
|
-
}
|
|
1647
|
-
setattr(namespace, this.dest, count + 1);
|
|
1648
|
-
}
|
|
1649
|
-
});
|
|
1650
|
-
var _HelpAction = _callable(class _HelpAction extends Action {
|
|
1651
|
-
constructor() {
|
|
1652
|
-
let [
|
|
1653
|
-
option_strings,
|
|
1654
|
-
dest,
|
|
1655
|
-
default_value,
|
|
1656
|
-
help
|
|
1657
|
-
] = _parse_opts(arguments, {
|
|
1658
|
-
option_strings: no_default,
|
|
1659
|
-
dest: SUPPRESS,
|
|
1660
|
-
default: SUPPRESS,
|
|
1661
|
-
help: void 0
|
|
1662
|
-
});
|
|
1663
|
-
super({
|
|
1664
|
-
option_strings,
|
|
1665
|
-
dest,
|
|
1666
|
-
default: default_value,
|
|
1667
|
-
nargs: 0,
|
|
1668
|
-
help
|
|
1669
|
-
});
|
|
1670
|
-
}
|
|
1671
|
-
call(parser) {
|
|
1672
|
-
parser.print_help();
|
|
1673
|
-
parser.exit();
|
|
1674
|
-
}
|
|
1675
|
-
});
|
|
1676
|
-
var _VersionAction = _callable(class _VersionAction extends Action {
|
|
1677
|
-
constructor() {
|
|
1678
|
-
let [
|
|
1679
|
-
option_strings,
|
|
1680
|
-
version2,
|
|
1681
|
-
dest,
|
|
1682
|
-
default_value,
|
|
1683
|
-
help
|
|
1684
|
-
] = _parse_opts(arguments, {
|
|
1685
|
-
option_strings: no_default,
|
|
1686
|
-
version: void 0,
|
|
1687
|
-
dest: SUPPRESS,
|
|
1688
|
-
default: SUPPRESS,
|
|
1689
|
-
help: "show program's version number and exit"
|
|
1690
|
-
});
|
|
1691
|
-
super({
|
|
1692
|
-
option_strings,
|
|
1693
|
-
dest,
|
|
1694
|
-
default: default_value,
|
|
1695
|
-
nargs: 0,
|
|
1696
|
-
help
|
|
1697
|
-
});
|
|
1698
|
-
this.version = version2;
|
|
1699
|
-
}
|
|
1700
|
-
call(parser) {
|
|
1701
|
-
let version2 = this.version;
|
|
1702
|
-
if (version2 === void 0) {
|
|
1703
|
-
version2 = parser.version;
|
|
1704
|
-
}
|
|
1705
|
-
let formatter = parser._get_formatter();
|
|
1706
|
-
formatter.add_text(version2);
|
|
1707
|
-
parser._print_message(formatter.format_help(), process.stdout);
|
|
1708
|
-
parser.exit();
|
|
1709
|
-
}
|
|
1710
|
-
});
|
|
1711
|
-
var _SubParsersAction = _camelcase_alias(_callable(class _SubParsersAction extends Action {
|
|
1712
|
-
constructor() {
|
|
1713
|
-
let [
|
|
1714
|
-
option_strings,
|
|
1715
|
-
prog,
|
|
1716
|
-
parser_class,
|
|
1717
|
-
dest,
|
|
1718
|
-
required,
|
|
1719
|
-
help,
|
|
1720
|
-
metavar
|
|
1721
|
-
] = _parse_opts(arguments, {
|
|
1722
|
-
option_strings: no_default,
|
|
1723
|
-
prog: no_default,
|
|
1724
|
-
parser_class: no_default,
|
|
1725
|
-
dest: SUPPRESS,
|
|
1726
|
-
required: false,
|
|
1727
|
-
help: void 0,
|
|
1728
|
-
metavar: void 0
|
|
1729
|
-
});
|
|
1730
|
-
let name_parser_map = {};
|
|
1731
|
-
super({
|
|
1732
|
-
option_strings,
|
|
1733
|
-
dest,
|
|
1734
|
-
nargs: PARSER,
|
|
1735
|
-
choices: name_parser_map,
|
|
1736
|
-
required,
|
|
1737
|
-
help,
|
|
1738
|
-
metavar
|
|
1739
|
-
});
|
|
1740
|
-
this._prog_prefix = prog;
|
|
1741
|
-
this._parser_class = parser_class;
|
|
1742
|
-
this._name_parser_map = name_parser_map;
|
|
1743
|
-
this._choices_actions = [];
|
|
1744
|
-
}
|
|
1745
|
-
add_parser() {
|
|
1746
|
-
let [
|
|
1747
|
-
name,
|
|
1748
|
-
kwargs
|
|
1749
|
-
] = _parse_opts(arguments, {
|
|
1750
|
-
name: no_default,
|
|
1751
|
-
"**kwargs": no_default
|
|
1752
|
-
});
|
|
1753
|
-
if (kwargs.prog === void 0) {
|
|
1754
|
-
kwargs.prog = sub("%s %s", this._prog_prefix, name);
|
|
1755
|
-
}
|
|
1756
|
-
let aliases = getattr(kwargs, "aliases", []);
|
|
1757
|
-
delete kwargs.aliases;
|
|
1758
|
-
if ("help" in kwargs) {
|
|
1759
|
-
let help = kwargs.help;
|
|
1760
|
-
delete kwargs.help;
|
|
1761
|
-
let choice_action = this._ChoicesPseudoAction(name, aliases, help);
|
|
1762
|
-
this._choices_actions.push(choice_action);
|
|
1763
|
-
}
|
|
1764
|
-
let parser = new this._parser_class(kwargs);
|
|
1765
|
-
this._name_parser_map[name] = parser;
|
|
1766
|
-
for (let alias of aliases) {
|
|
1767
|
-
this._name_parser_map[alias] = parser;
|
|
1768
|
-
}
|
|
1769
|
-
return parser;
|
|
1770
|
-
}
|
|
1771
|
-
_get_subactions() {
|
|
1772
|
-
return this._choices_actions;
|
|
1773
|
-
}
|
|
1774
|
-
call(parser, namespace, values) {
|
|
1775
|
-
let parser_name = values[0];
|
|
1776
|
-
let arg_strings = values.slice(1);
|
|
1777
|
-
if (this.dest !== SUPPRESS) {
|
|
1778
|
-
setattr(namespace, this.dest, parser_name);
|
|
1779
|
-
}
|
|
1780
|
-
if (hasattr(this._name_parser_map, parser_name)) {
|
|
1781
|
-
parser = this._name_parser_map[parser_name];
|
|
1782
|
-
} else {
|
|
1783
|
-
let args = {
|
|
1784
|
-
parser_name,
|
|
1785
|
-
choices: this._name_parser_map.join(", ")
|
|
1786
|
-
};
|
|
1787
|
-
let msg = sub("unknown parser %(parser_name)r (choices: %(choices)s)", args);
|
|
1788
|
-
throw new ArgumentError(this, msg);
|
|
1789
|
-
}
|
|
1790
|
-
let subnamespace;
|
|
1791
|
-
[subnamespace, arg_strings] = parser.parse_known_args(arg_strings, void 0);
|
|
1792
|
-
for (let [key, value] of Object.entries(subnamespace)) {
|
|
1793
|
-
setattr(namespace, key, value);
|
|
1794
|
-
}
|
|
1795
|
-
if (arg_strings.length) {
|
|
1796
|
-
setdefault(namespace, _UNRECOGNIZED_ARGS_ATTR, []);
|
|
1797
|
-
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).push(...arg_strings);
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
}));
|
|
1801
|
-
_SubParsersAction.prototype._ChoicesPseudoAction = _callable(class _ChoicesPseudoAction extends Action {
|
|
1802
|
-
constructor(name, aliases, help) {
|
|
1803
|
-
let metavar = name, dest = name;
|
|
1804
|
-
if (aliases.length) {
|
|
1805
|
-
metavar += sub(" (%s)", aliases.join(", "));
|
|
1806
|
-
}
|
|
1807
|
-
super({ option_strings: [], dest, help, metavar });
|
|
1808
|
-
}
|
|
1809
|
-
});
|
|
1810
|
-
var _ExtendAction = _callable(class _ExtendAction extends _AppendAction {
|
|
1811
|
-
call(parser, namespace, values) {
|
|
1812
|
-
let items = getattr(namespace, this.dest, void 0);
|
|
1813
|
-
items = _copy_items(items);
|
|
1814
|
-
items = items.concat(values);
|
|
1815
|
-
setattr(namespace, this.dest, items);
|
|
1816
|
-
}
|
|
1817
|
-
});
|
|
1818
|
-
var FileType = _callable(class FileType extends Function {
|
|
1819
|
-
/*
|
|
1820
|
-
* Factory for creating file object types
|
|
1821
|
-
*
|
|
1822
|
-
* Instances of FileType are typically passed as type= arguments to the
|
|
1823
|
-
* ArgumentParser add_argument() method.
|
|
1824
|
-
*
|
|
1825
|
-
* Keyword Arguments:
|
|
1826
|
-
* - mode -- A string indicating how the file is to be opened. Accepts the
|
|
1827
|
-
* same values as the builtin open() function.
|
|
1828
|
-
* - bufsize -- The file's desired buffer size. Accepts the same values as
|
|
1829
|
-
* the builtin open() function.
|
|
1830
|
-
* - encoding -- The file's encoding. Accepts the same values as the
|
|
1831
|
-
* builtin open() function.
|
|
1832
|
-
* - errors -- A string indicating how encoding and decoding errors are to
|
|
1833
|
-
* be handled. Accepts the same value as the builtin open() function.
|
|
1834
|
-
*/
|
|
1835
|
-
constructor() {
|
|
1836
|
-
let [
|
|
1837
|
-
flags,
|
|
1838
|
-
encoding,
|
|
1839
|
-
mode,
|
|
1840
|
-
autoClose,
|
|
1841
|
-
emitClose,
|
|
1842
|
-
start,
|
|
1843
|
-
end,
|
|
1844
|
-
highWaterMark,
|
|
1845
|
-
fs9
|
|
1846
|
-
] = _parse_opts(arguments, {
|
|
1847
|
-
flags: "r",
|
|
1848
|
-
encoding: void 0,
|
|
1849
|
-
mode: void 0,
|
|
1850
|
-
// 0o666
|
|
1851
|
-
autoClose: void 0,
|
|
1852
|
-
// true
|
|
1853
|
-
emitClose: void 0,
|
|
1854
|
-
// false
|
|
1855
|
-
start: void 0,
|
|
1856
|
-
// 0
|
|
1857
|
-
end: void 0,
|
|
1858
|
-
// Infinity
|
|
1859
|
-
highWaterMark: void 0,
|
|
1860
|
-
// 64 * 1024
|
|
1861
|
-
fs: void 0
|
|
1862
|
-
});
|
|
1863
|
-
super("return arguments.callee.call.apply(arguments.callee, arguments)");
|
|
1864
|
-
Object.defineProperty(this, "name", {
|
|
1865
|
-
get() {
|
|
1866
|
-
return sub("FileType(%r)", flags);
|
|
1867
|
-
}
|
|
1868
|
-
});
|
|
1869
|
-
this._flags = flags;
|
|
1870
|
-
this._options = {};
|
|
1871
|
-
if (encoding !== void 0) this._options.encoding = encoding;
|
|
1872
|
-
if (mode !== void 0) this._options.mode = mode;
|
|
1873
|
-
if (autoClose !== void 0) this._options.autoClose = autoClose;
|
|
1874
|
-
if (emitClose !== void 0) this._options.emitClose = emitClose;
|
|
1875
|
-
if (start !== void 0) this._options.start = start;
|
|
1876
|
-
if (end !== void 0) this._options.end = end;
|
|
1877
|
-
if (highWaterMark !== void 0) this._options.highWaterMark = highWaterMark;
|
|
1878
|
-
if (fs9 !== void 0) this._options.fs = fs9;
|
|
1879
|
-
}
|
|
1880
|
-
call(string) {
|
|
1881
|
-
if (string === "-") {
|
|
1882
|
-
if (this._flags.includes("r")) {
|
|
1883
|
-
return process.stdin;
|
|
1884
|
-
} else if (this._flags.includes("w")) {
|
|
1885
|
-
return process.stdout;
|
|
1886
|
-
} else {
|
|
1887
|
-
let msg = sub('argument "-" with mode %r', this._flags);
|
|
1888
|
-
throw new TypeError(msg);
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
let fd;
|
|
1892
|
-
try {
|
|
1893
|
-
fd = fs8.openSync(string, this._flags, this._options.mode);
|
|
1894
|
-
} catch (e) {
|
|
1895
|
-
let args = { filename: string, error: e.message };
|
|
1896
|
-
let message = "can't open '%(filename)s': %(error)s";
|
|
1897
|
-
throw new ArgumentTypeError(sub(message, args));
|
|
1898
|
-
}
|
|
1899
|
-
let options = Object.assign({ fd, flags: this._flags }, this._options);
|
|
1900
|
-
if (this._flags.includes("r")) {
|
|
1901
|
-
return fs8.createReadStream(void 0, options);
|
|
1902
|
-
} else if (this._flags.includes("w")) {
|
|
1903
|
-
return fs8.createWriteStream(void 0, options);
|
|
1904
|
-
} else {
|
|
1905
|
-
let msg = sub('argument "%s" with mode %r', string, this._flags);
|
|
1906
|
-
throw new TypeError(msg);
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
[util.inspect.custom]() {
|
|
1910
|
-
let args = [this._flags];
|
|
1911
|
-
let kwargs = Object.entries(this._options).map(([k2, v2]) => {
|
|
1912
|
-
if (k2 === "mode") v2 = { value: v2, [util.inspect.custom]() {
|
|
1913
|
-
return "0o" + this.value.toString(8);
|
|
1914
|
-
} };
|
|
1915
|
-
return [k2, v2];
|
|
1916
|
-
});
|
|
1917
|
-
let args_str = [].concat(args.filter((arg) => arg !== -1).map(repr)).concat(kwargs.filter(([, arg]) => arg !== void 0).map(([kw, arg]) => sub("%s=%r", kw, arg))).join(", ");
|
|
1918
|
-
return sub("%s(%s)", this.constructor.name, args_str);
|
|
1919
|
-
}
|
|
1920
|
-
toString() {
|
|
1921
|
-
return this[util.inspect.custom]();
|
|
1922
|
-
}
|
|
1923
|
-
});
|
|
1924
|
-
var Namespace = _callable(class Namespace extends _AttributeHolder() {
|
|
1925
|
-
/*
|
|
1926
|
-
* Simple object for storing attributes.
|
|
1927
|
-
*
|
|
1928
|
-
* Implements equality by attribute names and values, and provides a simple
|
|
1929
|
-
* string representation.
|
|
1930
|
-
*/
|
|
1931
|
-
constructor(options = {}) {
|
|
1932
|
-
super();
|
|
1933
|
-
Object.assign(this, options);
|
|
1934
|
-
}
|
|
1935
|
-
});
|
|
1936
|
-
Namespace.prototype[Symbol.toStringTag] = void 0;
|
|
1937
|
-
var _ActionsContainer = _camelcase_alias(_callable(class _ActionsContainer {
|
|
1938
|
-
constructor() {
|
|
1939
|
-
let [
|
|
1940
|
-
description,
|
|
1941
|
-
prefix_chars,
|
|
1942
|
-
argument_default,
|
|
1943
|
-
conflict_handler
|
|
1944
|
-
] = _parse_opts(arguments, {
|
|
1945
|
-
description: no_default,
|
|
1946
|
-
prefix_chars: no_default,
|
|
1947
|
-
argument_default: no_default,
|
|
1948
|
-
conflict_handler: no_default
|
|
1949
|
-
});
|
|
1950
|
-
this.description = description;
|
|
1951
|
-
this.argument_default = argument_default;
|
|
1952
|
-
this.prefix_chars = prefix_chars;
|
|
1953
|
-
this.conflict_handler = conflict_handler;
|
|
1954
|
-
this._registries = {};
|
|
1955
|
-
this.register("action", void 0, _StoreAction);
|
|
1956
|
-
this.register("action", "store", _StoreAction);
|
|
1957
|
-
this.register("action", "store_const", _StoreConstAction);
|
|
1958
|
-
this.register("action", "store_true", _StoreTrueAction);
|
|
1959
|
-
this.register("action", "store_false", _StoreFalseAction);
|
|
1960
|
-
this.register("action", "append", _AppendAction);
|
|
1961
|
-
this.register("action", "append_const", _AppendConstAction);
|
|
1962
|
-
this.register("action", "count", _CountAction);
|
|
1963
|
-
this.register("action", "help", _HelpAction);
|
|
1964
|
-
this.register("action", "version", _VersionAction);
|
|
1965
|
-
this.register("action", "parsers", _SubParsersAction);
|
|
1966
|
-
this.register("action", "extend", _ExtendAction);
|
|
1967
|
-
["storeConst", "storeTrue", "storeFalse", "appendConst"].forEach((old_name) => {
|
|
1968
|
-
let new_name = _to_new_name(old_name);
|
|
1969
|
-
this.register("action", old_name, util.deprecate(
|
|
1970
|
-
this._registry_get("action", new_name),
|
|
1971
|
-
sub('{action: "%s"} is renamed to {action: "%s"}', old_name, new_name)
|
|
1972
|
-
));
|
|
1973
|
-
});
|
|
1974
|
-
this._get_handler();
|
|
1975
|
-
this._actions = [];
|
|
1976
|
-
this._option_string_actions = {};
|
|
1977
|
-
this._action_groups = [];
|
|
1978
|
-
this._mutually_exclusive_groups = [];
|
|
1979
|
-
this._defaults = {};
|
|
1980
|
-
this._negative_number_matcher = /^-\d+$|^-\d*\.\d+$/;
|
|
1981
|
-
this._has_negative_number_optionals = [];
|
|
1982
|
-
}
|
|
1983
|
-
// ====================
|
|
1984
|
-
// Registration methods
|
|
1985
|
-
// ====================
|
|
1986
|
-
register(registry_name, value, object) {
|
|
1987
|
-
let registry = setdefault(this._registries, registry_name, {});
|
|
1988
|
-
registry[value] = object;
|
|
1989
|
-
}
|
|
1990
|
-
_registry_get(registry_name, value, default_value = void 0) {
|
|
1991
|
-
return getattr(this._registries[registry_name], value, default_value);
|
|
1992
|
-
}
|
|
1993
|
-
// ==================================
|
|
1994
|
-
// Namespace default accessor methods
|
|
1995
|
-
// ==================================
|
|
1996
|
-
set_defaults(kwargs) {
|
|
1997
|
-
Object.assign(this._defaults, kwargs);
|
|
1998
|
-
for (let action of this._actions) {
|
|
1999
|
-
if (action.dest in kwargs) {
|
|
2000
|
-
action.default = kwargs[action.dest];
|
|
2001
|
-
}
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
get_default(dest) {
|
|
2005
|
-
for (let action of this._actions) {
|
|
2006
|
-
if (action.dest === dest && action.default !== void 0) {
|
|
2007
|
-
return action.default;
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
return this._defaults[dest];
|
|
2011
|
-
}
|
|
2012
|
-
// =======================
|
|
2013
|
-
// Adding argument actions
|
|
2014
|
-
// =======================
|
|
2015
|
-
add_argument() {
|
|
2016
|
-
let [
|
|
2017
|
-
args,
|
|
2018
|
-
kwargs
|
|
2019
|
-
] = _parse_opts(arguments, {
|
|
2020
|
-
"*args": no_default,
|
|
2021
|
-
"**kwargs": no_default
|
|
2022
|
-
});
|
|
2023
|
-
if (args.length === 1 && Array.isArray(args[0])) {
|
|
2024
|
-
args = args[0];
|
|
2025
|
-
deprecate(
|
|
2026
|
-
"argument-array",
|
|
2027
|
-
sub("use add_argument(%(args)s, {...}) instead of add_argument([ %(args)s ], { ... })", {
|
|
2028
|
-
args: args.map(repr).join(", ")
|
|
2029
|
-
})
|
|
2030
|
-
);
|
|
2031
|
-
}
|
|
2032
|
-
let chars = this.prefix_chars;
|
|
2033
|
-
if (!args.length || args.length === 1 && !chars.includes(args[0][0])) {
|
|
2034
|
-
if (args.length && "dest" in kwargs) {
|
|
2035
|
-
throw new TypeError("dest supplied twice for positional argument");
|
|
2036
|
-
}
|
|
2037
|
-
kwargs = this._get_positional_kwargs(...args, kwargs);
|
|
2038
|
-
} else {
|
|
2039
|
-
kwargs = this._get_optional_kwargs(...args, kwargs);
|
|
2040
|
-
}
|
|
2041
|
-
if (!("default" in kwargs)) {
|
|
2042
|
-
let dest = kwargs.dest;
|
|
2043
|
-
if (dest in this._defaults) {
|
|
2044
|
-
kwargs.default = this._defaults[dest];
|
|
2045
|
-
} else if (this.argument_default !== void 0) {
|
|
2046
|
-
kwargs.default = this.argument_default;
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
let action_class = this._pop_action_class(kwargs);
|
|
2050
|
-
if (typeof action_class !== "function") {
|
|
2051
|
-
throw new TypeError(sub('unknown action "%s"', action_class));
|
|
2052
|
-
}
|
|
2053
|
-
let action = new action_class(kwargs);
|
|
2054
|
-
let type_func = this._registry_get("type", action.type, action.type);
|
|
2055
|
-
if (typeof type_func !== "function") {
|
|
2056
|
-
throw new TypeError(sub("%r is not callable", type_func));
|
|
2057
|
-
}
|
|
2058
|
-
if (type_func === FileType) {
|
|
2059
|
-
throw new TypeError(sub("%r is a FileType class object, instance of it must be passed", type_func));
|
|
2060
|
-
}
|
|
2061
|
-
if ("_get_formatter" in this) {
|
|
2062
|
-
try {
|
|
2063
|
-
this._get_formatter()._format_args(action, void 0);
|
|
2064
|
-
} catch (err) {
|
|
2065
|
-
if (err instanceof TypeError && err.message !== "invalid nargs value") {
|
|
2066
|
-
throw new TypeError("length of metavar tuple does not match nargs");
|
|
2067
|
-
} else {
|
|
2068
|
-
throw err;
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
return this._add_action(action);
|
|
2073
|
-
}
|
|
2074
|
-
add_argument_group() {
|
|
2075
|
-
let group = _ArgumentGroup(this, ...arguments);
|
|
2076
|
-
this._action_groups.push(group);
|
|
2077
|
-
return group;
|
|
2078
|
-
}
|
|
2079
|
-
add_mutually_exclusive_group() {
|
|
2080
|
-
let group = _MutuallyExclusiveGroup(this, ...arguments);
|
|
2081
|
-
this._mutually_exclusive_groups.push(group);
|
|
2082
|
-
return group;
|
|
2083
|
-
}
|
|
2084
|
-
_add_action(action) {
|
|
2085
|
-
this._check_conflict(action);
|
|
2086
|
-
this._actions.push(action);
|
|
2087
|
-
action.container = this;
|
|
2088
|
-
for (let option_string of action.option_strings) {
|
|
2089
|
-
this._option_string_actions[option_string] = action;
|
|
2090
|
-
}
|
|
2091
|
-
for (let option_string of action.option_strings) {
|
|
2092
|
-
if (this._negative_number_matcher.test(option_string)) {
|
|
2093
|
-
if (!this._has_negative_number_optionals.length) {
|
|
2094
|
-
this._has_negative_number_optionals.push(true);
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
return action;
|
|
2099
|
-
}
|
|
2100
|
-
_remove_action(action) {
|
|
2101
|
-
_array_remove(this._actions, action);
|
|
2102
|
-
}
|
|
2103
|
-
_add_container_actions(container) {
|
|
2104
|
-
let title_group_map = {};
|
|
2105
|
-
for (let group of this._action_groups) {
|
|
2106
|
-
if (group.title in title_group_map) {
|
|
2107
|
-
let msg = "cannot merge actions - two groups are named %r";
|
|
2108
|
-
throw new TypeError(sub(msg, group.title));
|
|
2109
|
-
}
|
|
2110
|
-
title_group_map[group.title] = group;
|
|
2111
|
-
}
|
|
2112
|
-
let group_map = /* @__PURE__ */ new Map();
|
|
2113
|
-
for (let group of container._action_groups) {
|
|
2114
|
-
if (!(group.title in title_group_map)) {
|
|
2115
|
-
title_group_map[group.title] = this.add_argument_group({
|
|
2116
|
-
title: group.title,
|
|
2117
|
-
description: group.description,
|
|
2118
|
-
conflict_handler: group.conflict_handler
|
|
2119
|
-
});
|
|
2120
|
-
}
|
|
2121
|
-
for (let action of group._group_actions) {
|
|
2122
|
-
group_map.set(action, title_group_map[group.title]);
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
for (let group of container._mutually_exclusive_groups) {
|
|
2126
|
-
let mutex_group = this.add_mutually_exclusive_group({
|
|
2127
|
-
required: group.required
|
|
2128
|
-
});
|
|
2129
|
-
for (let action of group._group_actions) {
|
|
2130
|
-
group_map.set(action, mutex_group);
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
for (let action of container._actions) {
|
|
2134
|
-
group_map.get(action)._add_action(action);
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
_get_positional_kwargs() {
|
|
2138
|
-
let [
|
|
2139
|
-
dest,
|
|
2140
|
-
kwargs
|
|
2141
|
-
] = _parse_opts(arguments, {
|
|
2142
|
-
dest: no_default,
|
|
2143
|
-
"**kwargs": no_default
|
|
2144
|
-
});
|
|
2145
|
-
if ("required" in kwargs) {
|
|
2146
|
-
let msg = "'required' is an invalid argument for positionals";
|
|
2147
|
-
throw new TypeError(msg);
|
|
2148
|
-
}
|
|
2149
|
-
if (![OPTIONAL, ZERO_OR_MORE].includes(kwargs.nargs)) {
|
|
2150
|
-
kwargs.required = true;
|
|
2151
|
-
}
|
|
2152
|
-
if (kwargs.nargs === ZERO_OR_MORE && !("default" in kwargs)) {
|
|
2153
|
-
kwargs.required = true;
|
|
2154
|
-
}
|
|
2155
|
-
return Object.assign(kwargs, { dest, option_strings: [] });
|
|
2156
|
-
}
|
|
2157
|
-
_get_optional_kwargs() {
|
|
2158
|
-
let [
|
|
2159
|
-
args,
|
|
2160
|
-
kwargs
|
|
2161
|
-
] = _parse_opts(arguments, {
|
|
2162
|
-
"*args": no_default,
|
|
2163
|
-
"**kwargs": no_default
|
|
2164
|
-
});
|
|
2165
|
-
let option_strings = [];
|
|
2166
|
-
let long_option_strings = [];
|
|
2167
|
-
let option_string;
|
|
2168
|
-
for (option_string of args) {
|
|
2169
|
-
if (!this.prefix_chars.includes(option_string[0])) {
|
|
2170
|
-
let args2 = {
|
|
2171
|
-
option: option_string,
|
|
2172
|
-
prefix_chars: this.prefix_chars
|
|
2173
|
-
};
|
|
2174
|
-
let msg = "invalid option string %(option)r: must start with a character %(prefix_chars)r";
|
|
2175
|
-
throw new TypeError(sub(msg, args2));
|
|
2176
|
-
}
|
|
2177
|
-
option_strings.push(option_string);
|
|
2178
|
-
if (option_string.length > 1 && this.prefix_chars.includes(option_string[1])) {
|
|
2179
|
-
long_option_strings.push(option_string);
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
|
-
let dest = kwargs.dest;
|
|
2183
|
-
delete kwargs.dest;
|
|
2184
|
-
if (dest === void 0) {
|
|
2185
|
-
let dest_option_string;
|
|
2186
|
-
if (long_option_strings.length) {
|
|
2187
|
-
dest_option_string = long_option_strings[0];
|
|
2188
|
-
} else {
|
|
2189
|
-
dest_option_string = option_strings[0];
|
|
2190
|
-
}
|
|
2191
|
-
dest = _string_lstrip(dest_option_string, this.prefix_chars);
|
|
2192
|
-
if (!dest) {
|
|
2193
|
-
let msg = "dest= is required for options like %r";
|
|
2194
|
-
throw new TypeError(sub(msg, option_string));
|
|
2195
|
-
}
|
|
2196
|
-
dest = dest.replace(/-/g, "_");
|
|
2197
|
-
}
|
|
2198
|
-
return Object.assign(kwargs, { dest, option_strings });
|
|
2199
|
-
}
|
|
2200
|
-
_pop_action_class(kwargs, default_value = void 0) {
|
|
2201
|
-
let action = getattr(kwargs, "action", default_value);
|
|
2202
|
-
delete kwargs.action;
|
|
2203
|
-
return this._registry_get("action", action, action);
|
|
2204
|
-
}
|
|
2205
|
-
_get_handler() {
|
|
2206
|
-
let handler_func_name = sub("_handle_conflict_%s", this.conflict_handler);
|
|
2207
|
-
if (typeof this[handler_func_name] === "function") {
|
|
2208
|
-
return this[handler_func_name];
|
|
2209
|
-
} else {
|
|
2210
|
-
let msg = "invalid conflict_resolution value: %r";
|
|
2211
|
-
throw new TypeError(sub(msg, this.conflict_handler));
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
_check_conflict(action) {
|
|
2215
|
-
let confl_optionals = [];
|
|
2216
|
-
for (let option_string of action.option_strings) {
|
|
2217
|
-
if (hasattr(this._option_string_actions, option_string)) {
|
|
2218
|
-
let confl_optional = this._option_string_actions[option_string];
|
|
2219
|
-
confl_optionals.push([option_string, confl_optional]);
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
if (confl_optionals.length) {
|
|
2223
|
-
let conflict_handler = this._get_handler();
|
|
2224
|
-
conflict_handler.call(this, action, confl_optionals);
|
|
2225
|
-
}
|
|
2226
|
-
}
|
|
2227
|
-
_handle_conflict_error(action, conflicting_actions) {
|
|
2228
|
-
let message = conflicting_actions.length === 1 ? "conflicting option string: %s" : "conflicting option strings: %s";
|
|
2229
|
-
let conflict_string = conflicting_actions.map(([
|
|
2230
|
-
option_string
|
|
2231
|
-
/*, action*/
|
|
2232
|
-
]) => option_string).join(", ");
|
|
2233
|
-
throw new ArgumentError(action, sub(message, conflict_string));
|
|
2234
|
-
}
|
|
2235
|
-
_handle_conflict_resolve(action, conflicting_actions) {
|
|
2236
|
-
for (let [option_string, action2] of conflicting_actions) {
|
|
2237
|
-
_array_remove(action2.option_strings, option_string);
|
|
2238
|
-
delete this._option_string_actions[option_string];
|
|
2239
|
-
if (!action2.option_strings.length) {
|
|
2240
|
-
action2.container._remove_action(action2);
|
|
2241
|
-
}
|
|
2242
|
-
}
|
|
2243
|
-
}
|
|
2244
|
-
}));
|
|
2245
|
-
var _ArgumentGroup = _callable(class _ArgumentGroup extends _ActionsContainer {
|
|
2246
|
-
constructor() {
|
|
2247
|
-
let [
|
|
2248
|
-
container,
|
|
2249
|
-
title,
|
|
2250
|
-
description,
|
|
2251
|
-
kwargs
|
|
2252
|
-
] = _parse_opts(arguments, {
|
|
2253
|
-
container: no_default,
|
|
2254
|
-
title: void 0,
|
|
2255
|
-
description: void 0,
|
|
2256
|
-
"**kwargs": no_default
|
|
2257
|
-
});
|
|
2258
|
-
setdefault(kwargs, "conflict_handler", container.conflict_handler);
|
|
2259
|
-
setdefault(kwargs, "prefix_chars", container.prefix_chars);
|
|
2260
|
-
setdefault(kwargs, "argument_default", container.argument_default);
|
|
2261
|
-
super(Object.assign({ description }, kwargs));
|
|
2262
|
-
this.title = title;
|
|
2263
|
-
this._group_actions = [];
|
|
2264
|
-
this._registries = container._registries;
|
|
2265
|
-
this._actions = container._actions;
|
|
2266
|
-
this._option_string_actions = container._option_string_actions;
|
|
2267
|
-
this._defaults = container._defaults;
|
|
2268
|
-
this._has_negative_number_optionals = container._has_negative_number_optionals;
|
|
2269
|
-
this._mutually_exclusive_groups = container._mutually_exclusive_groups;
|
|
2270
|
-
}
|
|
2271
|
-
_add_action(action) {
|
|
2272
|
-
action = super._add_action(action);
|
|
2273
|
-
this._group_actions.push(action);
|
|
2274
|
-
return action;
|
|
2275
|
-
}
|
|
2276
|
-
_remove_action(action) {
|
|
2277
|
-
super._remove_action(action);
|
|
2278
|
-
_array_remove(this._group_actions, action);
|
|
2279
|
-
}
|
|
2280
|
-
});
|
|
2281
|
-
var _MutuallyExclusiveGroup = _callable(class _MutuallyExclusiveGroup extends _ArgumentGroup {
|
|
2282
|
-
constructor() {
|
|
2283
|
-
let [
|
|
2284
|
-
container,
|
|
2285
|
-
required
|
|
2286
|
-
] = _parse_opts(arguments, {
|
|
2287
|
-
container: no_default,
|
|
2288
|
-
required: false
|
|
2289
|
-
});
|
|
2290
|
-
super(container);
|
|
2291
|
-
this.required = required;
|
|
2292
|
-
this._container = container;
|
|
2293
|
-
}
|
|
2294
|
-
_add_action(action) {
|
|
2295
|
-
if (action.required) {
|
|
2296
|
-
let msg = "mutually exclusive arguments must be optional";
|
|
2297
|
-
throw new TypeError(msg);
|
|
2298
|
-
}
|
|
2299
|
-
action = this._container._add_action(action);
|
|
2300
|
-
this._group_actions.push(action);
|
|
2301
|
-
return action;
|
|
2302
|
-
}
|
|
2303
|
-
_remove_action(action) {
|
|
2304
|
-
this._container._remove_action(action);
|
|
2305
|
-
_array_remove(this._group_actions, action);
|
|
2306
|
-
}
|
|
2307
|
-
});
|
|
2308
|
-
var ArgumentParser2 = _camelcase_alias(_callable(class ArgumentParser extends _AttributeHolder(_ActionsContainer) {
|
|
2309
|
-
/*
|
|
2310
|
-
* Object for parsing command line strings into Python objects.
|
|
2311
|
-
*
|
|
2312
|
-
* Keyword Arguments:
|
|
2313
|
-
* - prog -- The name of the program (default: sys.argv[0])
|
|
2314
|
-
* - usage -- A usage message (default: auto-generated from arguments)
|
|
2315
|
-
* - description -- A description of what the program does
|
|
2316
|
-
* - epilog -- Text following the argument descriptions
|
|
2317
|
-
* - parents -- Parsers whose arguments should be copied into this one
|
|
2318
|
-
* - formatter_class -- HelpFormatter class for printing help messages
|
|
2319
|
-
* - prefix_chars -- Characters that prefix optional arguments
|
|
2320
|
-
* - fromfile_prefix_chars -- Characters that prefix files containing
|
|
2321
|
-
* additional arguments
|
|
2322
|
-
* - argument_default -- The default value for all arguments
|
|
2323
|
-
* - conflict_handler -- String indicating how to handle conflicts
|
|
2324
|
-
* - add_help -- Add a -h/-help option
|
|
2325
|
-
* - allow_abbrev -- Allow long options to be abbreviated unambiguously
|
|
2326
|
-
* - exit_on_error -- Determines whether or not ArgumentParser exits with
|
|
2327
|
-
* error info when an error occurs
|
|
2328
|
-
*/
|
|
2329
|
-
constructor() {
|
|
2330
|
-
let [
|
|
2331
|
-
prog,
|
|
2332
|
-
usage,
|
|
2333
|
-
description,
|
|
2334
|
-
epilog,
|
|
2335
|
-
parents,
|
|
2336
|
-
formatter_class,
|
|
2337
|
-
prefix_chars,
|
|
2338
|
-
fromfile_prefix_chars,
|
|
2339
|
-
argument_default,
|
|
2340
|
-
conflict_handler,
|
|
2341
|
-
add_help,
|
|
2342
|
-
allow_abbrev,
|
|
2343
|
-
exit_on_error,
|
|
2344
|
-
debug,
|
|
2345
|
-
// LEGACY (v1 compatibility), debug mode
|
|
2346
|
-
version2
|
|
2347
|
-
// LEGACY (v1 compatibility), version
|
|
2348
|
-
] = _parse_opts(arguments, {
|
|
2349
|
-
prog: void 0,
|
|
2350
|
-
usage: void 0,
|
|
2351
|
-
description: void 0,
|
|
2352
|
-
epilog: void 0,
|
|
2353
|
-
parents: [],
|
|
2354
|
-
formatter_class: HelpFormatter,
|
|
2355
|
-
prefix_chars: "-",
|
|
2356
|
-
fromfile_prefix_chars: void 0,
|
|
2357
|
-
argument_default: void 0,
|
|
2358
|
-
conflict_handler: "error",
|
|
2359
|
-
add_help: true,
|
|
2360
|
-
allow_abbrev: true,
|
|
2361
|
-
exit_on_error: true,
|
|
2362
|
-
debug: void 0,
|
|
2363
|
-
// LEGACY (v1 compatibility), debug mode
|
|
2364
|
-
version: void 0
|
|
2365
|
-
// LEGACY (v1 compatibility), version
|
|
2366
|
-
});
|
|
2367
|
-
if (debug !== void 0) {
|
|
2368
|
-
deprecate(
|
|
2369
|
-
"debug",
|
|
2370
|
-
'The "debug" argument to ArgumentParser is deprecated. Please override ArgumentParser.exit function instead.'
|
|
2371
|
-
);
|
|
2372
|
-
}
|
|
2373
|
-
if (version2 !== void 0) {
|
|
2374
|
-
deprecate(
|
|
2375
|
-
"version",
|
|
2376
|
-
`The "version" argument to ArgumentParser is deprecated. Please use add_argument(..., { action: 'version', version: 'N', ... }) instead.`
|
|
2377
|
-
);
|
|
2378
|
-
}
|
|
2379
|
-
super({
|
|
2380
|
-
description,
|
|
2381
|
-
prefix_chars,
|
|
2382
|
-
argument_default,
|
|
2383
|
-
conflict_handler
|
|
2384
|
-
});
|
|
2385
|
-
if (prog === void 0) {
|
|
2386
|
-
prog = path8.basename(get_argv()[0] || "");
|
|
2387
|
-
}
|
|
2388
|
-
this.prog = prog;
|
|
2389
|
-
this.usage = usage;
|
|
2390
|
-
this.epilog = epilog;
|
|
2391
|
-
this.formatter_class = formatter_class;
|
|
2392
|
-
this.fromfile_prefix_chars = fromfile_prefix_chars;
|
|
2393
|
-
this.add_help = add_help;
|
|
2394
|
-
this.allow_abbrev = allow_abbrev;
|
|
2395
|
-
this.exit_on_error = exit_on_error;
|
|
2396
|
-
this.debug = debug;
|
|
2397
|
-
this._positionals = this.add_argument_group("positional arguments");
|
|
2398
|
-
this._optionals = this.add_argument_group("optional arguments");
|
|
2399
|
-
this._subparsers = void 0;
|
|
2400
|
-
function identity(string) {
|
|
2401
|
-
return string;
|
|
2402
|
-
}
|
|
2403
|
-
this.register("type", void 0, identity);
|
|
2404
|
-
this.register("type", null, identity);
|
|
2405
|
-
this.register("type", "auto", identity);
|
|
2406
|
-
this.register("type", "int", function(x) {
|
|
2407
|
-
let result = Number(x);
|
|
2408
|
-
if (!Number.isInteger(result)) {
|
|
2409
|
-
throw new TypeError(sub("could not convert string to int: %r", x));
|
|
2410
|
-
}
|
|
2411
|
-
return result;
|
|
2412
|
-
});
|
|
2413
|
-
this.register("type", "float", function(x) {
|
|
2414
|
-
let result = Number(x);
|
|
2415
|
-
if (isNaN(result)) {
|
|
2416
|
-
throw new TypeError(sub("could not convert string to float: %r", x));
|
|
2417
|
-
}
|
|
2418
|
-
return result;
|
|
2419
|
-
});
|
|
2420
|
-
this.register("type", "str", String);
|
|
2421
|
-
this.register(
|
|
2422
|
-
"type",
|
|
2423
|
-
"string",
|
|
2424
|
-
util.deprecate(String, 'use {type:"str"} or {type:String} instead of {type:"string"}')
|
|
2425
|
-
);
|
|
2426
|
-
let default_prefix = prefix_chars.includes("-") ? "-" : prefix_chars[0];
|
|
2427
|
-
if (this.add_help) {
|
|
2428
|
-
this.add_argument(
|
|
2429
|
-
default_prefix + "h",
|
|
2430
|
-
default_prefix.repeat(2) + "help",
|
|
2431
|
-
{
|
|
2432
|
-
action: "help",
|
|
2433
|
-
default: SUPPRESS,
|
|
2434
|
-
help: "show this help message and exit"
|
|
2435
|
-
}
|
|
2436
|
-
);
|
|
2437
|
-
}
|
|
2438
|
-
if (version2) {
|
|
2439
|
-
this.add_argument(
|
|
2440
|
-
default_prefix + "v",
|
|
2441
|
-
default_prefix.repeat(2) + "version",
|
|
2442
|
-
{
|
|
2443
|
-
action: "version",
|
|
2444
|
-
default: SUPPRESS,
|
|
2445
|
-
version: this.version,
|
|
2446
|
-
help: "show program's version number and exit"
|
|
2447
|
-
}
|
|
2448
|
-
);
|
|
2449
|
-
}
|
|
2450
|
-
for (let parent of parents) {
|
|
2451
|
-
this._add_container_actions(parent);
|
|
2452
|
-
Object.assign(this._defaults, parent._defaults);
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
// =======================
|
|
2456
|
-
// Pretty __repr__ methods
|
|
2457
|
-
// =======================
|
|
2458
|
-
_get_kwargs() {
|
|
2459
|
-
let names = [
|
|
2460
|
-
"prog",
|
|
2461
|
-
"usage",
|
|
2462
|
-
"description",
|
|
2463
|
-
"formatter_class",
|
|
2464
|
-
"conflict_handler",
|
|
2465
|
-
"add_help"
|
|
2466
|
-
];
|
|
2467
|
-
return names.map((name) => [name, getattr(this, name)]);
|
|
2468
|
-
}
|
|
2469
|
-
// ==================================
|
|
2470
|
-
// Optional/Positional adding methods
|
|
2471
|
-
// ==================================
|
|
2472
|
-
add_subparsers() {
|
|
2473
|
-
let [
|
|
2474
|
-
kwargs
|
|
2475
|
-
] = _parse_opts(arguments, {
|
|
2476
|
-
"**kwargs": no_default
|
|
2477
|
-
});
|
|
2478
|
-
if (this._subparsers !== void 0) {
|
|
2479
|
-
this.error("cannot have multiple subparser arguments");
|
|
2480
|
-
}
|
|
2481
|
-
setdefault(kwargs, "parser_class", this.constructor);
|
|
2482
|
-
if ("title" in kwargs || "description" in kwargs) {
|
|
2483
|
-
let title = getattr(kwargs, "title", "subcommands");
|
|
2484
|
-
let description = getattr(kwargs, "description", void 0);
|
|
2485
|
-
delete kwargs.title;
|
|
2486
|
-
delete kwargs.description;
|
|
2487
|
-
this._subparsers = this.add_argument_group(title, description);
|
|
2488
|
-
} else {
|
|
2489
|
-
this._subparsers = this._positionals;
|
|
2490
|
-
}
|
|
2491
|
-
if (kwargs.prog === void 0) {
|
|
2492
|
-
let formatter = this._get_formatter();
|
|
2493
|
-
let positionals = this._get_positional_actions();
|
|
2494
|
-
let groups = this._mutually_exclusive_groups;
|
|
2495
|
-
formatter.add_usage(this.usage, positionals, groups, "");
|
|
2496
|
-
kwargs.prog = formatter.format_help().trim();
|
|
2497
|
-
}
|
|
2498
|
-
let parsers_class = this._pop_action_class(kwargs, "parsers");
|
|
2499
|
-
let action = new parsers_class(Object.assign({ option_strings: [] }, kwargs));
|
|
2500
|
-
this._subparsers._add_action(action);
|
|
2501
|
-
return action;
|
|
2502
|
-
}
|
|
2503
|
-
_add_action(action) {
|
|
2504
|
-
if (action.option_strings.length) {
|
|
2505
|
-
this._optionals._add_action(action);
|
|
2506
|
-
} else {
|
|
2507
|
-
this._positionals._add_action(action);
|
|
2508
|
-
}
|
|
2509
|
-
return action;
|
|
2510
|
-
}
|
|
2511
|
-
_get_optional_actions() {
|
|
2512
|
-
return this._actions.filter((action) => action.option_strings.length);
|
|
2513
|
-
}
|
|
2514
|
-
_get_positional_actions() {
|
|
2515
|
-
return this._actions.filter((action) => !action.option_strings.length);
|
|
2516
|
-
}
|
|
2517
|
-
// =====================================
|
|
2518
|
-
// Command line argument parsing methods
|
|
2519
|
-
// =====================================
|
|
2520
|
-
parse_args(args = void 0, namespace = void 0) {
|
|
2521
|
-
let argv;
|
|
2522
|
-
[args, argv] = this.parse_known_args(args, namespace);
|
|
2523
|
-
if (argv && argv.length > 0) {
|
|
2524
|
-
let msg = "unrecognized arguments: %s";
|
|
2525
|
-
this.error(sub(msg, argv.join(" ")));
|
|
2526
|
-
}
|
|
2527
|
-
return args;
|
|
2528
|
-
}
|
|
2529
|
-
parse_known_args(args = void 0, namespace = void 0) {
|
|
2530
|
-
if (args === void 0) {
|
|
2531
|
-
args = get_argv().slice(1);
|
|
2532
|
-
}
|
|
2533
|
-
if (namespace === void 0) {
|
|
2534
|
-
namespace = new Namespace();
|
|
2535
|
-
}
|
|
2536
|
-
for (let action of this._actions) {
|
|
2537
|
-
if (action.dest !== SUPPRESS) {
|
|
2538
|
-
if (!hasattr(namespace, action.dest)) {
|
|
2539
|
-
if (action.default !== SUPPRESS) {
|
|
2540
|
-
setattr(namespace, action.dest, action.default);
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2544
|
-
}
|
|
2545
|
-
for (let dest of Object.keys(this._defaults)) {
|
|
2546
|
-
if (!hasattr(namespace, dest)) {
|
|
2547
|
-
setattr(namespace, dest, this._defaults[dest]);
|
|
2548
|
-
}
|
|
2549
|
-
}
|
|
2550
|
-
if (this.exit_on_error) {
|
|
2551
|
-
try {
|
|
2552
|
-
[namespace, args] = this._parse_known_args(args, namespace);
|
|
2553
|
-
} catch (err) {
|
|
2554
|
-
if (err instanceof ArgumentError) {
|
|
2555
|
-
this.error(err.message);
|
|
2556
|
-
} else {
|
|
2557
|
-
throw err;
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
} else {
|
|
2561
|
-
[namespace, args] = this._parse_known_args(args, namespace);
|
|
2562
|
-
}
|
|
2563
|
-
if (hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR)) {
|
|
2564
|
-
args = args.concat(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR));
|
|
2565
|
-
delattr(namespace, _UNRECOGNIZED_ARGS_ATTR);
|
|
2566
|
-
}
|
|
2567
|
-
return [namespace, args];
|
|
2568
|
-
}
|
|
2569
|
-
_parse_known_args(arg_strings, namespace) {
|
|
2570
|
-
if (this.fromfile_prefix_chars !== void 0) {
|
|
2571
|
-
arg_strings = this._read_args_from_files(arg_strings);
|
|
2572
|
-
}
|
|
2573
|
-
let action_conflicts = /* @__PURE__ */ new Map();
|
|
2574
|
-
for (let mutex_group of this._mutually_exclusive_groups) {
|
|
2575
|
-
let group_actions = mutex_group._group_actions;
|
|
2576
|
-
for (let [i, mutex_action] of Object.entries(mutex_group._group_actions)) {
|
|
2577
|
-
let conflicts = action_conflicts.get(mutex_action) || [];
|
|
2578
|
-
conflicts = conflicts.concat(group_actions.slice(0, +i));
|
|
2579
|
-
conflicts = conflicts.concat(group_actions.slice(+i + 1));
|
|
2580
|
-
action_conflicts.set(mutex_action, conflicts);
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
let option_string_indices = {};
|
|
2584
|
-
let arg_string_pattern_parts = [];
|
|
2585
|
-
let arg_strings_iter = Object.entries(arg_strings)[Symbol.iterator]();
|
|
2586
|
-
for (let [i, arg_string] of arg_strings_iter) {
|
|
2587
|
-
if (arg_string === "--") {
|
|
2588
|
-
arg_string_pattern_parts.push("-");
|
|
2589
|
-
for ([i, arg_string] of arg_strings_iter) {
|
|
2590
|
-
arg_string_pattern_parts.push("A");
|
|
2591
|
-
}
|
|
2592
|
-
} else {
|
|
2593
|
-
let option_tuple = this._parse_optional(arg_string);
|
|
2594
|
-
let pattern;
|
|
2595
|
-
if (option_tuple === void 0) {
|
|
2596
|
-
pattern = "A";
|
|
2597
|
-
} else {
|
|
2598
|
-
option_string_indices[i] = option_tuple;
|
|
2599
|
-
pattern = "O";
|
|
2600
|
-
}
|
|
2601
|
-
arg_string_pattern_parts.push(pattern);
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
let arg_strings_pattern = arg_string_pattern_parts.join("");
|
|
2605
|
-
let seen_actions = /* @__PURE__ */ new Set();
|
|
2606
|
-
let seen_non_default_actions = /* @__PURE__ */ new Set();
|
|
2607
|
-
let extras;
|
|
2608
|
-
let take_action = (action, argument_strings, option_string = void 0) => {
|
|
2609
|
-
seen_actions.add(action);
|
|
2610
|
-
let argument_values = this._get_values(action, argument_strings);
|
|
2611
|
-
if (argument_values !== action.default) {
|
|
2612
|
-
seen_non_default_actions.add(action);
|
|
2613
|
-
for (let conflict_action of action_conflicts.get(action) || []) {
|
|
2614
|
-
if (seen_non_default_actions.has(conflict_action)) {
|
|
2615
|
-
let msg = "not allowed with argument %s";
|
|
2616
|
-
let action_name = _get_action_name(conflict_action);
|
|
2617
|
-
throw new ArgumentError(action, sub(msg, action_name));
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
}
|
|
2621
|
-
if (argument_values !== SUPPRESS) {
|
|
2622
|
-
action(this, namespace, argument_values, option_string);
|
|
2623
|
-
}
|
|
2624
|
-
};
|
|
2625
|
-
let consume_optional = (start_index2) => {
|
|
2626
|
-
let option_tuple = option_string_indices[start_index2];
|
|
2627
|
-
let [action, option_string, explicit_arg] = option_tuple;
|
|
2628
|
-
let action_tuples = [];
|
|
2629
|
-
let stop;
|
|
2630
|
-
for (; ; ) {
|
|
2631
|
-
if (action === void 0) {
|
|
2632
|
-
extras.push(arg_strings[start_index2]);
|
|
2633
|
-
return start_index2 + 1;
|
|
2634
|
-
}
|
|
2635
|
-
if (explicit_arg !== void 0) {
|
|
2636
|
-
let arg_count = this._match_argument(action, "A");
|
|
2637
|
-
let chars = this.prefix_chars;
|
|
2638
|
-
if (arg_count === 0 && !chars.includes(option_string[1])) {
|
|
2639
|
-
action_tuples.push([action, [], option_string]);
|
|
2640
|
-
let char = option_string[0];
|
|
2641
|
-
option_string = char + explicit_arg[0];
|
|
2642
|
-
let new_explicit_arg = explicit_arg.slice(1) || void 0;
|
|
2643
|
-
let optionals_map = this._option_string_actions;
|
|
2644
|
-
if (hasattr(optionals_map, option_string)) {
|
|
2645
|
-
action = optionals_map[option_string];
|
|
2646
|
-
explicit_arg = new_explicit_arg;
|
|
2647
|
-
} else {
|
|
2648
|
-
let msg = "ignored explicit argument %r";
|
|
2649
|
-
throw new ArgumentError(action, sub(msg, explicit_arg));
|
|
2650
|
-
}
|
|
2651
|
-
} else if (arg_count === 1) {
|
|
2652
|
-
stop = start_index2 + 1;
|
|
2653
|
-
let args = [explicit_arg];
|
|
2654
|
-
action_tuples.push([action, args, option_string]);
|
|
2655
|
-
break;
|
|
2656
|
-
} else {
|
|
2657
|
-
let msg = "ignored explicit argument %r";
|
|
2658
|
-
throw new ArgumentError(action, sub(msg, explicit_arg));
|
|
2659
|
-
}
|
|
2660
|
-
} else {
|
|
2661
|
-
let start = start_index2 + 1;
|
|
2662
|
-
let selected_patterns = arg_strings_pattern.slice(start);
|
|
2663
|
-
let arg_count = this._match_argument(action, selected_patterns);
|
|
2664
|
-
stop = start + arg_count;
|
|
2665
|
-
let args = arg_strings.slice(start, stop);
|
|
2666
|
-
action_tuples.push([action, args, option_string]);
|
|
2667
|
-
break;
|
|
2668
|
-
}
|
|
2669
|
-
}
|
|
2670
|
-
assert(action_tuples.length);
|
|
2671
|
-
for (let [action2, args, option_string2] of action_tuples) {
|
|
2672
|
-
take_action(action2, args, option_string2);
|
|
2673
|
-
}
|
|
2674
|
-
return stop;
|
|
2675
|
-
};
|
|
2676
|
-
let positionals = this._get_positional_actions();
|
|
2677
|
-
let consume_positionals = (start_index2) => {
|
|
2678
|
-
let selected_pattern = arg_strings_pattern.slice(start_index2);
|
|
2679
|
-
let arg_counts = this._match_arguments_partial(positionals, selected_pattern);
|
|
2680
|
-
for (let i = 0; i < positionals.length && i < arg_counts.length; i++) {
|
|
2681
|
-
let action = positionals[i];
|
|
2682
|
-
let arg_count = arg_counts[i];
|
|
2683
|
-
let args = arg_strings.slice(start_index2, start_index2 + arg_count);
|
|
2684
|
-
start_index2 += arg_count;
|
|
2685
|
-
take_action(action, args);
|
|
2686
|
-
}
|
|
2687
|
-
positionals = positionals.slice(arg_counts.length);
|
|
2688
|
-
return start_index2;
|
|
2689
|
-
};
|
|
2690
|
-
extras = [];
|
|
2691
|
-
let start_index = 0;
|
|
2692
|
-
let max_option_string_index = Math.max(-1, ...Object.keys(option_string_indices).map(Number));
|
|
2693
|
-
while (start_index <= max_option_string_index) {
|
|
2694
|
-
let next_option_string_index = Math.min(
|
|
2695
|
-
...Object.keys(option_string_indices).map(Number).filter((index) => index >= start_index)
|
|
2696
|
-
);
|
|
2697
|
-
if (start_index !== next_option_string_index) {
|
|
2698
|
-
let positionals_end_index = consume_positionals(start_index);
|
|
2699
|
-
if (positionals_end_index > start_index) {
|
|
2700
|
-
start_index = positionals_end_index;
|
|
2701
|
-
continue;
|
|
2702
|
-
} else {
|
|
2703
|
-
start_index = positionals_end_index;
|
|
2704
|
-
}
|
|
2705
|
-
}
|
|
2706
|
-
if (!(start_index in option_string_indices)) {
|
|
2707
|
-
let strings = arg_strings.slice(start_index, next_option_string_index);
|
|
2708
|
-
extras = extras.concat(strings);
|
|
2709
|
-
start_index = next_option_string_index;
|
|
2710
|
-
}
|
|
2711
|
-
start_index = consume_optional(start_index);
|
|
2712
|
-
}
|
|
2713
|
-
let stop_index = consume_positionals(start_index);
|
|
2714
|
-
extras = extras.concat(arg_strings.slice(stop_index));
|
|
2715
|
-
let required_actions = [];
|
|
2716
|
-
for (let action of this._actions) {
|
|
2717
|
-
if (!seen_actions.has(action)) {
|
|
2718
|
-
if (action.required) {
|
|
2719
|
-
required_actions.push(_get_action_name(action));
|
|
2720
|
-
} else {
|
|
2721
|
-
if (action.default !== void 0 && typeof action.default === "string" && hasattr(namespace, action.dest) && action.default === getattr(namespace, action.dest)) {
|
|
2722
|
-
setattr(
|
|
2723
|
-
namespace,
|
|
2724
|
-
action.dest,
|
|
2725
|
-
this._get_value(action, action.default)
|
|
2726
|
-
);
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
}
|
|
2730
|
-
}
|
|
2731
|
-
if (required_actions.length) {
|
|
2732
|
-
this.error(sub(
|
|
2733
|
-
"the following arguments are required: %s",
|
|
2734
|
-
required_actions.join(", ")
|
|
2735
|
-
));
|
|
2736
|
-
}
|
|
2737
|
-
for (let group of this._mutually_exclusive_groups) {
|
|
2738
|
-
if (group.required) {
|
|
2739
|
-
let no_actions_used = true;
|
|
2740
|
-
for (let action of group._group_actions) {
|
|
2741
|
-
if (seen_non_default_actions.has(action)) {
|
|
2742
|
-
no_actions_used = false;
|
|
2743
|
-
break;
|
|
2744
|
-
}
|
|
2745
|
-
}
|
|
2746
|
-
if (no_actions_used) {
|
|
2747
|
-
let names = group._group_actions.filter((action) => action.help !== SUPPRESS).map((action) => _get_action_name(action));
|
|
2748
|
-
let msg = "one of the arguments %s is required";
|
|
2749
|
-
this.error(sub(msg, names.join(" ")));
|
|
2750
|
-
}
|
|
2751
|
-
}
|
|
2752
|
-
}
|
|
2753
|
-
return [namespace, extras];
|
|
2754
|
-
}
|
|
2755
|
-
_read_args_from_files(arg_strings) {
|
|
2756
|
-
let new_arg_strings = [];
|
|
2757
|
-
for (let arg_string of arg_strings) {
|
|
2758
|
-
if (!arg_string || !this.fromfile_prefix_chars.includes(arg_string[0])) {
|
|
2759
|
-
new_arg_strings.push(arg_string);
|
|
2760
|
-
} else {
|
|
2761
|
-
try {
|
|
2762
|
-
let args_file = fs8.readFileSync(arg_string.slice(1), "utf8");
|
|
2763
|
-
let arg_strings2 = [];
|
|
2764
|
-
for (let arg_line of splitlines(args_file)) {
|
|
2765
|
-
for (let arg of this.convert_arg_line_to_args(arg_line)) {
|
|
2766
|
-
arg_strings2.push(arg);
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
arg_strings2 = this._read_args_from_files(arg_strings2);
|
|
2770
|
-
new_arg_strings = new_arg_strings.concat(arg_strings2);
|
|
2771
|
-
} catch (err) {
|
|
2772
|
-
this.error(err.message);
|
|
2773
|
-
}
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
return new_arg_strings;
|
|
2777
|
-
}
|
|
2778
|
-
convert_arg_line_to_args(arg_line) {
|
|
2779
|
-
return [arg_line];
|
|
2780
|
-
}
|
|
2781
|
-
_match_argument(action, arg_strings_pattern) {
|
|
2782
|
-
let nargs_pattern = this._get_nargs_pattern(action);
|
|
2783
|
-
let match2 = arg_strings_pattern.match(new RegExp("^" + nargs_pattern));
|
|
2784
|
-
if (match2 === null) {
|
|
2785
|
-
let nargs_errors = {
|
|
2786
|
-
undefined: "expected one argument",
|
|
2787
|
-
[OPTIONAL]: "expected at most one argument",
|
|
2788
|
-
[ONE_OR_MORE]: "expected at least one argument"
|
|
2789
|
-
};
|
|
2790
|
-
let msg = nargs_errors[action.nargs];
|
|
2791
|
-
if (msg === void 0) {
|
|
2792
|
-
msg = sub(action.nargs === 1 ? "expected %s argument" : "expected %s arguments", action.nargs);
|
|
2793
|
-
}
|
|
2794
|
-
throw new ArgumentError(action, msg);
|
|
2795
|
-
}
|
|
2796
|
-
return match2[1].length;
|
|
2797
|
-
}
|
|
2798
|
-
_match_arguments_partial(actions, arg_strings_pattern) {
|
|
2799
|
-
let result = [];
|
|
2800
|
-
for (let i of range(actions.length, 0, -1)) {
|
|
2801
|
-
let actions_slice = actions.slice(0, i);
|
|
2802
|
-
let pattern = actions_slice.map((action) => this._get_nargs_pattern(action)).join("");
|
|
2803
|
-
let match2 = arg_strings_pattern.match(new RegExp("^" + pattern));
|
|
2804
|
-
if (match2 !== null) {
|
|
2805
|
-
result = result.concat(match2.slice(1).map((string) => string.length));
|
|
2806
|
-
break;
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
return result;
|
|
2810
|
-
}
|
|
2811
|
-
_parse_optional(arg_string) {
|
|
2812
|
-
if (!arg_string) {
|
|
2813
|
-
return void 0;
|
|
2814
|
-
}
|
|
2815
|
-
if (!this.prefix_chars.includes(arg_string[0])) {
|
|
2816
|
-
return void 0;
|
|
2817
|
-
}
|
|
2818
|
-
if (arg_string in this._option_string_actions) {
|
|
2819
|
-
let action = this._option_string_actions[arg_string];
|
|
2820
|
-
return [action, arg_string, void 0];
|
|
2821
|
-
}
|
|
2822
|
-
if (arg_string.length === 1) {
|
|
2823
|
-
return void 0;
|
|
2824
|
-
}
|
|
2825
|
-
if (arg_string.includes("=")) {
|
|
2826
|
-
let [option_string, explicit_arg] = _string_split(arg_string, "=", 1);
|
|
2827
|
-
if (option_string in this._option_string_actions) {
|
|
2828
|
-
let action = this._option_string_actions[option_string];
|
|
2829
|
-
return [action, option_string, explicit_arg];
|
|
2830
|
-
}
|
|
2831
|
-
}
|
|
2832
|
-
let option_tuples = this._get_option_tuples(arg_string);
|
|
2833
|
-
if (option_tuples.length > 1) {
|
|
2834
|
-
let options = option_tuples.map(([
|
|
2835
|
-
,
|
|
2836
|
-
option_string
|
|
2837
|
-
/*, explicit_arg*/
|
|
2838
|
-
]) => option_string).join(", ");
|
|
2839
|
-
let args = { option: arg_string, matches: options };
|
|
2840
|
-
let msg = "ambiguous option: %(option)s could match %(matches)s";
|
|
2841
|
-
this.error(sub(msg, args));
|
|
2842
|
-
} else if (option_tuples.length === 1) {
|
|
2843
|
-
let [option_tuple] = option_tuples;
|
|
2844
|
-
return option_tuple;
|
|
2845
|
-
}
|
|
2846
|
-
if (this._negative_number_matcher.test(arg_string)) {
|
|
2847
|
-
if (!this._has_negative_number_optionals.length) {
|
|
2848
|
-
return void 0;
|
|
2849
|
-
}
|
|
2850
|
-
}
|
|
2851
|
-
if (arg_string.includes(" ")) {
|
|
2852
|
-
return void 0;
|
|
2853
|
-
}
|
|
2854
|
-
return [void 0, arg_string, void 0];
|
|
2855
|
-
}
|
|
2856
|
-
_get_option_tuples(option_string) {
|
|
2857
|
-
let result = [];
|
|
2858
|
-
let chars = this.prefix_chars;
|
|
2859
|
-
if (chars.includes(option_string[0]) && chars.includes(option_string[1])) {
|
|
2860
|
-
if (this.allow_abbrev) {
|
|
2861
|
-
let option_prefix, explicit_arg;
|
|
2862
|
-
if (option_string.includes("=")) {
|
|
2863
|
-
[option_prefix, explicit_arg] = _string_split(option_string, "=", 1);
|
|
2864
|
-
} else {
|
|
2865
|
-
option_prefix = option_string;
|
|
2866
|
-
explicit_arg = void 0;
|
|
2867
|
-
}
|
|
2868
|
-
for (let option_string2 of Object.keys(this._option_string_actions)) {
|
|
2869
|
-
if (option_string2.startsWith(option_prefix)) {
|
|
2870
|
-
let action = this._option_string_actions[option_string2];
|
|
2871
|
-
let tup = [action, option_string2, explicit_arg];
|
|
2872
|
-
result.push(tup);
|
|
2873
|
-
}
|
|
2874
|
-
}
|
|
2875
|
-
}
|
|
2876
|
-
} else if (chars.includes(option_string[0]) && !chars.includes(option_string[1])) {
|
|
2877
|
-
let option_prefix = option_string;
|
|
2878
|
-
let explicit_arg = void 0;
|
|
2879
|
-
let short_option_prefix = option_string.slice(0, 2);
|
|
2880
|
-
let short_explicit_arg = option_string.slice(2);
|
|
2881
|
-
for (let option_string2 of Object.keys(this._option_string_actions)) {
|
|
2882
|
-
if (option_string2 === short_option_prefix) {
|
|
2883
|
-
let action = this._option_string_actions[option_string2];
|
|
2884
|
-
let tup = [action, option_string2, short_explicit_arg];
|
|
2885
|
-
result.push(tup);
|
|
2886
|
-
} else if (option_string2.startsWith(option_prefix)) {
|
|
2887
|
-
let action = this._option_string_actions[option_string2];
|
|
2888
|
-
let tup = [action, option_string2, explicit_arg];
|
|
2889
|
-
result.push(tup);
|
|
2890
|
-
}
|
|
2891
|
-
}
|
|
2892
|
-
} else {
|
|
2893
|
-
this.error(sub("unexpected option string: %s", option_string));
|
|
2894
|
-
}
|
|
2895
|
-
return result;
|
|
2896
|
-
}
|
|
2897
|
-
_get_nargs_pattern(action) {
|
|
2898
|
-
let nargs = action.nargs;
|
|
2899
|
-
let nargs_pattern;
|
|
2900
|
-
if (nargs === void 0) {
|
|
2901
|
-
nargs_pattern = "(-*A-*)";
|
|
2902
|
-
} else if (nargs === OPTIONAL) {
|
|
2903
|
-
nargs_pattern = "(-*A?-*)";
|
|
2904
|
-
} else if (nargs === ZERO_OR_MORE) {
|
|
2905
|
-
nargs_pattern = "(-*[A-]*)";
|
|
2906
|
-
} else if (nargs === ONE_OR_MORE) {
|
|
2907
|
-
nargs_pattern = "(-*A[A-]*)";
|
|
2908
|
-
} else if (nargs === REMAINDER) {
|
|
2909
|
-
nargs_pattern = "([-AO]*)";
|
|
2910
|
-
} else if (nargs === PARSER) {
|
|
2911
|
-
nargs_pattern = "(-*A[-AO]*)";
|
|
2912
|
-
} else if (nargs === SUPPRESS) {
|
|
2913
|
-
nargs_pattern = "(-*-*)";
|
|
2914
|
-
} else {
|
|
2915
|
-
nargs_pattern = sub("(-*%s-*)", "A".repeat(nargs).split("").join("-*"));
|
|
2916
|
-
}
|
|
2917
|
-
if (action.option_strings.length) {
|
|
2918
|
-
nargs_pattern = nargs_pattern.replace(/-\*/g, "");
|
|
2919
|
-
nargs_pattern = nargs_pattern.replace(/-/g, "");
|
|
2920
|
-
}
|
|
2921
|
-
return nargs_pattern;
|
|
2922
|
-
}
|
|
2923
|
-
// ========================
|
|
2924
|
-
// Alt command line argument parsing, allowing free intermix
|
|
2925
|
-
// ========================
|
|
2926
|
-
parse_intermixed_args(args = void 0, namespace = void 0) {
|
|
2927
|
-
let argv;
|
|
2928
|
-
[args, argv] = this.parse_known_intermixed_args(args, namespace);
|
|
2929
|
-
if (argv.length) {
|
|
2930
|
-
let msg = "unrecognized arguments: %s";
|
|
2931
|
-
this.error(sub(msg, argv.join(" ")));
|
|
2932
|
-
}
|
|
2933
|
-
return args;
|
|
2934
|
-
}
|
|
2935
|
-
parse_known_intermixed_args(args = void 0, namespace = void 0) {
|
|
2936
|
-
let extras;
|
|
2937
|
-
let positionals = this._get_positional_actions();
|
|
2938
|
-
let a = positionals.filter((action) => [PARSER, REMAINDER].includes(action.nargs));
|
|
2939
|
-
if (a.length) {
|
|
2940
|
-
throw new TypeError(sub("parse_intermixed_args: positional arg with nargs=%s", a[0].nargs));
|
|
2941
|
-
}
|
|
2942
|
-
for (let group of this._mutually_exclusive_groups) {
|
|
2943
|
-
for (let action of group._group_actions) {
|
|
2944
|
-
if (positionals.includes(action)) {
|
|
2945
|
-
throw new TypeError("parse_intermixed_args: positional in mutuallyExclusiveGroup");
|
|
2946
|
-
}
|
|
2947
|
-
}
|
|
2948
|
-
}
|
|
2949
|
-
let save_usage;
|
|
2950
|
-
try {
|
|
2951
|
-
save_usage = this.usage;
|
|
2952
|
-
let remaining_args;
|
|
2953
|
-
try {
|
|
2954
|
-
if (this.usage === void 0) {
|
|
2955
|
-
this.usage = this.format_usage().slice(7);
|
|
2956
|
-
}
|
|
2957
|
-
for (let action of positionals) {
|
|
2958
|
-
action.save_nargs = action.nargs;
|
|
2959
|
-
action.nargs = SUPPRESS;
|
|
2960
|
-
action.save_default = action.default;
|
|
2961
|
-
action.default = SUPPRESS;
|
|
2962
|
-
}
|
|
2963
|
-
[namespace, remaining_args] = this.parse_known_args(
|
|
2964
|
-
args,
|
|
2965
|
-
namespace
|
|
2966
|
-
);
|
|
2967
|
-
for (let action of positionals) {
|
|
2968
|
-
let attr = getattr(namespace, action.dest);
|
|
2969
|
-
if (Array.isArray(attr) && attr.length === 0) {
|
|
2970
|
-
console.warn(sub("Do not expect %s in %s", action.dest, namespace));
|
|
2971
|
-
delattr(namespace, action.dest);
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
2974
|
-
} finally {
|
|
2975
|
-
for (let action of positionals) {
|
|
2976
|
-
action.nargs = action.save_nargs;
|
|
2977
|
-
action.default = action.save_default;
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
let optionals = this._get_optional_actions();
|
|
2981
|
-
try {
|
|
2982
|
-
for (let action of optionals) {
|
|
2983
|
-
action.save_required = action.required;
|
|
2984
|
-
action.required = false;
|
|
2985
|
-
}
|
|
2986
|
-
for (let group of this._mutually_exclusive_groups) {
|
|
2987
|
-
group.save_required = group.required;
|
|
2988
|
-
group.required = false;
|
|
2989
|
-
}
|
|
2990
|
-
[namespace, extras] = this.parse_known_args(
|
|
2991
|
-
remaining_args,
|
|
2992
|
-
namespace
|
|
2993
|
-
);
|
|
2994
|
-
} finally {
|
|
2995
|
-
for (let action of optionals) {
|
|
2996
|
-
action.required = action.save_required;
|
|
2997
|
-
}
|
|
2998
|
-
for (let group of this._mutually_exclusive_groups) {
|
|
2999
|
-
group.required = group.save_required;
|
|
3000
|
-
}
|
|
3001
|
-
}
|
|
3002
|
-
} finally {
|
|
3003
|
-
this.usage = save_usage;
|
|
3004
|
-
}
|
|
3005
|
-
return [namespace, extras];
|
|
3006
|
-
}
|
|
3007
|
-
// ========================
|
|
3008
|
-
// Value conversion methods
|
|
3009
|
-
// ========================
|
|
3010
|
-
_get_values(action, arg_strings) {
|
|
3011
|
-
if (![PARSER, REMAINDER].includes(action.nargs)) {
|
|
3012
|
-
try {
|
|
3013
|
-
_array_remove(arg_strings, "--");
|
|
3014
|
-
} catch (err) {
|
|
3015
|
-
}
|
|
3016
|
-
}
|
|
3017
|
-
let value;
|
|
3018
|
-
if (!arg_strings.length && action.nargs === OPTIONAL) {
|
|
3019
|
-
if (action.option_strings.length) {
|
|
3020
|
-
value = action.const;
|
|
3021
|
-
} else {
|
|
3022
|
-
value = action.default;
|
|
3023
|
-
}
|
|
3024
|
-
if (typeof value === "string") {
|
|
3025
|
-
value = this._get_value(action, value);
|
|
3026
|
-
this._check_value(action, value);
|
|
3027
|
-
}
|
|
3028
|
-
} else if (!arg_strings.length && action.nargs === ZERO_OR_MORE && !action.option_strings.length) {
|
|
3029
|
-
if (action.default !== void 0) {
|
|
3030
|
-
value = action.default;
|
|
3031
|
-
} else {
|
|
3032
|
-
value = arg_strings;
|
|
3033
|
-
}
|
|
3034
|
-
this._check_value(action, value);
|
|
3035
|
-
} else if (arg_strings.length === 1 && [void 0, OPTIONAL].includes(action.nargs)) {
|
|
3036
|
-
let arg_string = arg_strings[0];
|
|
3037
|
-
value = this._get_value(action, arg_string);
|
|
3038
|
-
this._check_value(action, value);
|
|
3039
|
-
} else if (action.nargs === REMAINDER) {
|
|
3040
|
-
value = arg_strings.map((v2) => this._get_value(action, v2));
|
|
3041
|
-
} else if (action.nargs === PARSER) {
|
|
3042
|
-
value = arg_strings.map((v2) => this._get_value(action, v2));
|
|
3043
|
-
this._check_value(action, value[0]);
|
|
3044
|
-
} else if (action.nargs === SUPPRESS) {
|
|
3045
|
-
value = SUPPRESS;
|
|
3046
|
-
} else {
|
|
3047
|
-
value = arg_strings.map((v2) => this._get_value(action, v2));
|
|
3048
|
-
for (let v2 of value) {
|
|
3049
|
-
this._check_value(action, v2);
|
|
3050
|
-
}
|
|
3051
|
-
}
|
|
3052
|
-
return value;
|
|
3053
|
-
}
|
|
3054
|
-
_get_value(action, arg_string) {
|
|
3055
|
-
let type_func = this._registry_get("type", action.type, action.type);
|
|
3056
|
-
if (typeof type_func !== "function") {
|
|
3057
|
-
let msg = "%r is not callable";
|
|
3058
|
-
throw new ArgumentError(action, sub(msg, type_func));
|
|
3059
|
-
}
|
|
3060
|
-
let result;
|
|
3061
|
-
try {
|
|
3062
|
-
try {
|
|
3063
|
-
result = type_func(arg_string);
|
|
3064
|
-
} catch (err) {
|
|
3065
|
-
if (err instanceof TypeError && /Class constructor .* cannot be invoked without 'new'/.test(err.message)) {
|
|
3066
|
-
result = new type_func(arg_string);
|
|
3067
|
-
} else {
|
|
3068
|
-
throw err;
|
|
3069
|
-
}
|
|
3070
|
-
}
|
|
3071
|
-
} catch (err) {
|
|
3072
|
-
if (err instanceof ArgumentTypeError) {
|
|
3073
|
-
let msg = err.message;
|
|
3074
|
-
throw new ArgumentError(action, msg);
|
|
3075
|
-
} else if (err instanceof TypeError) {
|
|
3076
|
-
let name = getattr(action.type, "name", repr(action.type));
|
|
3077
|
-
let args = { type: name, value: arg_string };
|
|
3078
|
-
let msg = "invalid %(type)s value: %(value)r";
|
|
3079
|
-
throw new ArgumentError(action, sub(msg, args));
|
|
3080
|
-
} else {
|
|
3081
|
-
throw err;
|
|
3082
|
-
}
|
|
3083
|
-
}
|
|
3084
|
-
return result;
|
|
3085
|
-
}
|
|
3086
|
-
_check_value(action, value) {
|
|
3087
|
-
if (action.choices !== void 0 && !_choices_to_array(action.choices).includes(value)) {
|
|
3088
|
-
let args = {
|
|
3089
|
-
value,
|
|
3090
|
-
choices: _choices_to_array(action.choices).map(repr).join(", ")
|
|
3091
|
-
};
|
|
3092
|
-
let msg = "invalid choice: %(value)r (choose from %(choices)s)";
|
|
3093
|
-
throw new ArgumentError(action, sub(msg, args));
|
|
3094
|
-
}
|
|
3095
|
-
}
|
|
3096
|
-
// =======================
|
|
3097
|
-
// Help-formatting methods
|
|
3098
|
-
// =======================
|
|
3099
|
-
format_usage() {
|
|
3100
|
-
let formatter = this._get_formatter();
|
|
3101
|
-
formatter.add_usage(
|
|
3102
|
-
this.usage,
|
|
3103
|
-
this._actions,
|
|
3104
|
-
this._mutually_exclusive_groups
|
|
3105
|
-
);
|
|
3106
|
-
return formatter.format_help();
|
|
3107
|
-
}
|
|
3108
|
-
format_help() {
|
|
3109
|
-
let formatter = this._get_formatter();
|
|
3110
|
-
formatter.add_usage(
|
|
3111
|
-
this.usage,
|
|
3112
|
-
this._actions,
|
|
3113
|
-
this._mutually_exclusive_groups
|
|
3114
|
-
);
|
|
3115
|
-
formatter.add_text(this.description);
|
|
3116
|
-
for (let action_group of this._action_groups) {
|
|
3117
|
-
formatter.start_section(action_group.title);
|
|
3118
|
-
formatter.add_text(action_group.description);
|
|
3119
|
-
formatter.add_arguments(action_group._group_actions);
|
|
3120
|
-
formatter.end_section();
|
|
3121
|
-
}
|
|
3122
|
-
formatter.add_text(this.epilog);
|
|
3123
|
-
return formatter.format_help();
|
|
3124
|
-
}
|
|
3125
|
-
_get_formatter() {
|
|
3126
|
-
return new this.formatter_class({ prog: this.prog });
|
|
3127
|
-
}
|
|
3128
|
-
// =====================
|
|
3129
|
-
// Help-printing methods
|
|
3130
|
-
// =====================
|
|
3131
|
-
print_usage(file = void 0) {
|
|
3132
|
-
if (file === void 0) file = process.stdout;
|
|
3133
|
-
this._print_message(this.format_usage(), file);
|
|
3134
|
-
}
|
|
3135
|
-
print_help(file = void 0) {
|
|
3136
|
-
if (file === void 0) file = process.stdout;
|
|
3137
|
-
this._print_message(this.format_help(), file);
|
|
3138
|
-
}
|
|
3139
|
-
_print_message(message, file = void 0) {
|
|
3140
|
-
if (message) {
|
|
3141
|
-
if (file === void 0) file = process.stderr;
|
|
3142
|
-
file.write(message);
|
|
3143
|
-
}
|
|
3144
|
-
}
|
|
3145
|
-
// ===============
|
|
3146
|
-
// Exiting methods
|
|
3147
|
-
// ===============
|
|
3148
|
-
exit(status = 0, message = void 0) {
|
|
3149
|
-
if (message) {
|
|
3150
|
-
this._print_message(message, process.stderr);
|
|
3151
|
-
}
|
|
3152
|
-
process.exit(status);
|
|
3153
|
-
}
|
|
3154
|
-
error(message) {
|
|
3155
|
-
if (this.debug === true) throw new Error(message);
|
|
3156
|
-
this.print_usage(process.stderr);
|
|
3157
|
-
let args = { prog: this.prog, message };
|
|
3158
|
-
this.exit(2, sub("%(prog)s: error: %(message)s\n", args));
|
|
3159
|
-
}
|
|
3160
|
-
}));
|
|
3161
|
-
module.exports = {
|
|
3162
|
-
ArgumentParser: ArgumentParser2,
|
|
3163
|
-
ArgumentError,
|
|
3164
|
-
ArgumentTypeError,
|
|
3165
|
-
BooleanOptionalAction,
|
|
3166
|
-
FileType,
|
|
3167
|
-
HelpFormatter,
|
|
3168
|
-
ArgumentDefaultsHelpFormatter,
|
|
3169
|
-
RawDescriptionHelpFormatter,
|
|
3170
|
-
RawTextHelpFormatter,
|
|
3171
|
-
MetavarTypeHelpFormatter,
|
|
3172
|
-
Namespace,
|
|
3173
|
-
Action,
|
|
3174
|
-
ONE_OR_MORE,
|
|
3175
|
-
OPTIONAL,
|
|
3176
|
-
PARSER,
|
|
3177
|
-
REMAINDER,
|
|
3178
|
-
SUPPRESS,
|
|
3179
|
-
ZERO_OR_MORE
|
|
3180
|
-
};
|
|
3181
|
-
Object.defineProperty(module.exports, "Const", {
|
|
3182
|
-
get() {
|
|
3183
|
-
let result = {};
|
|
3184
|
-
Object.entries({ ONE_OR_MORE, OPTIONAL, PARSER, REMAINDER, SUPPRESS, ZERO_OR_MORE }).forEach(([n, v2]) => {
|
|
3185
|
-
Object.defineProperty(result, n, {
|
|
3186
|
-
get() {
|
|
3187
|
-
deprecate(n, sub("use argparse.%s instead of argparse.Const.%s", n, n));
|
|
3188
|
-
return v2;
|
|
3189
|
-
}
|
|
3190
|
-
});
|
|
3191
|
-
});
|
|
3192
|
-
Object.entries({ _UNRECOGNIZED_ARGS_ATTR }).forEach(([n, v2]) => {
|
|
3193
|
-
Object.defineProperty(result, n, {
|
|
3194
|
-
get() {
|
|
3195
|
-
deprecate(n, sub("argparse.Const.%s is an internal symbol and will no longer be available", n));
|
|
3196
|
-
return v2;
|
|
3197
|
-
}
|
|
3198
|
-
});
|
|
3199
|
-
});
|
|
3200
|
-
return result;
|
|
3201
|
-
},
|
|
3202
|
-
enumerable: false
|
|
3203
|
-
});
|
|
3204
|
-
}
|
|
3205
|
-
});
|
|
3206
|
-
|
|
3207
41
|
// node_modules/tmp/lib/tmp.js
|
|
3208
42
|
var require_tmp = __commonJS({
|
|
3209
43
|
"node_modules/tmp/lib/tmp.js"(exports, module) {
|
|
@@ -5576,6 +2410,7 @@ var require_semver2 = __commonJS({
|
|
|
5576
2410
|
import { createWriteStream, existsSync, promises as fs7, readFileSync } from "node:fs";
|
|
5577
2411
|
import path7 from "node:path";
|
|
5578
2412
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
2413
|
+
import { parseArgs } from "node:util";
|
|
5579
2414
|
|
|
5580
2415
|
// node_modules/@html-validate/stylish/dist/esm/node.js
|
|
5581
2416
|
import { styleText } from "node:util";
|
|
@@ -7261,9 +4096,6 @@ function parse(text, options) {
|
|
|
7261
4096
|
);
|
|
7262
4097
|
}
|
|
7263
4098
|
|
|
7264
|
-
// src/index.ts
|
|
7265
|
-
var import_argparse = __toESM(require_argparse(), 1);
|
|
7266
|
-
|
|
7267
4099
|
// node_modules/find-up/index.js
|
|
7268
4100
|
import path2 from "node:path";
|
|
7269
4101
|
|
|
@@ -7802,7 +4634,7 @@ var _ = /* @__PURE__ */ Symbol("bufferLength");
|
|
|
7802
4634
|
var bi = /* @__PURE__ */ Symbol("bufferPush");
|
|
7803
4635
|
var Ie = /* @__PURE__ */ Symbol("bufferShift");
|
|
7804
4636
|
var L = /* @__PURE__ */ Symbol("objectMode");
|
|
7805
|
-
var
|
|
4637
|
+
var S = /* @__PURE__ */ Symbol("destroyed");
|
|
7806
4638
|
var _i = /* @__PURE__ */ Symbol("error");
|
|
7807
4639
|
var Oi = /* @__PURE__ */ Symbol("emitData");
|
|
7808
4640
|
var Is = /* @__PURE__ */ Symbol("emitEnd");
|
|
@@ -7860,7 +4692,7 @@ var A = class extends Di {
|
|
|
7860
4692
|
[Ne] = false;
|
|
7861
4693
|
[qt] = null;
|
|
7862
4694
|
[_] = 0;
|
|
7863
|
-
[
|
|
4695
|
+
[S] = false;
|
|
7864
4696
|
[Jt];
|
|
7865
4697
|
[Ce] = false;
|
|
7866
4698
|
[Rt] = 0;
|
|
@@ -7909,7 +4741,7 @@ var A = class extends Di {
|
|
|
7909
4741
|
write(t, e, i) {
|
|
7910
4742
|
if (this[Ce]) return false;
|
|
7911
4743
|
if (this[Q]) throw new Error("write after end");
|
|
7912
|
-
if (this[
|
|
4744
|
+
if (this[S]) return this.emit("error", Object.assign(new Error("Cannot call write after a stream was destroyed"), { code: "ERR_STREAM_DESTROYED" })), true;
|
|
7913
4745
|
typeof e == "function" && (i = e, e = "utf8"), e || (e = "utf8");
|
|
7914
4746
|
let r = this[Z] ? jt : Yr;
|
|
7915
4747
|
if (!this[L] && !Buffer.isBuffer(t)) {
|
|
@@ -7920,7 +4752,7 @@ var A = class extends Di {
|
|
|
7920
4752
|
return this[L] ? (this[g] && this[_] !== 0 && this[Ae](true), this[g] ? this.emit("data", t) : this[bi](t), this[_] !== 0 && this.emit("readable"), i && r(i), this[g]) : t.length ? (typeof t == "string" && !(e === this[z] && !this[Mt]?.lastNeed) && (t = Buffer.from(t, e)), Buffer.isBuffer(t) && this[z] && (t = this[Mt].write(t)), this[g] && this[_] !== 0 && this[Ae](true), this[g] ? this.emit("data", t) : this[bi](t), this[_] !== 0 && this.emit("readable"), i && r(i), this[g]) : (this[_] !== 0 && this.emit("readable"), i && r(i), this[g]);
|
|
7921
4753
|
}
|
|
7922
4754
|
read(t) {
|
|
7923
|
-
if (this[
|
|
4755
|
+
if (this[S]) return null;
|
|
7924
4756
|
if (this[C] = false, this[_] === 0 || t === 0 || t && t > this[_]) return this[J](), null;
|
|
7925
4757
|
this[L] && (t = null), this[b].length > 1 && !this[L] && (this[b] = [this[z] ? this[b].join("") : Buffer.concat(this[b], this[_])]);
|
|
7926
4758
|
let e = this[Ns](t || null, this[b][0]);
|
|
@@ -7938,7 +4770,7 @@ var A = class extends Di {
|
|
|
7938
4770
|
return typeof t == "function" && (i = t, t = void 0), typeof e == "function" && (i = e, e = "utf8"), t !== void 0 && this.write(t, e), i && this.once("end", i), this[Q] = true, this.writable = false, (this[g] || !this[Qt]) && this[J](), this;
|
|
7939
4771
|
}
|
|
7940
4772
|
[Bt]() {
|
|
7941
|
-
this[
|
|
4773
|
+
this[S] || (!this[Rt] && !this[N].length && (this[C] = true), this[Qt] = false, this[g] = true, this.emit("resume"), this[b].length ? this[Ae]() : this[Q] ? this[J]() : this.emit("drain"));
|
|
7942
4774
|
}
|
|
7943
4775
|
resume() {
|
|
7944
4776
|
return this[Bt]();
|
|
@@ -7947,7 +4779,7 @@ var A = class extends Di {
|
|
|
7947
4779
|
this[g] = false, this[Qt] = true, this[C] = false;
|
|
7948
4780
|
}
|
|
7949
4781
|
get destroyed() {
|
|
7950
|
-
return this[
|
|
4782
|
+
return this[S];
|
|
7951
4783
|
}
|
|
7952
4784
|
get flowing() {
|
|
7953
4785
|
return this[g];
|
|
@@ -7971,7 +4803,7 @@ var A = class extends Di {
|
|
|
7971
4803
|
return this.emit("data", t), this[g];
|
|
7972
4804
|
}
|
|
7973
4805
|
pipe(t, e) {
|
|
7974
|
-
if (this[
|
|
4806
|
+
if (this[S]) return t;
|
|
7975
4807
|
this[C] = false;
|
|
7976
4808
|
let i = this[nt];
|
|
7977
4809
|
return e = e || {}, t === Ds.stdout || t === Ds.stderr ? e.end = false : e.end = e.end !== false, e.proxyErrors = !!e.proxyErrors, i ? e.end && t.end() : (this[N].push(e.proxyErrors ? new Li(this, t, e) : new Fe(this, t, e)), this[Z] ? jt(() => this[Bt]()) : this[Bt]()), t;
|
|
@@ -8009,15 +4841,15 @@ var A = class extends Di {
|
|
|
8009
4841
|
return this[nt];
|
|
8010
4842
|
}
|
|
8011
4843
|
[J]() {
|
|
8012
|
-
!this[De] && !this[nt] && !this[
|
|
4844
|
+
!this[De] && !this[nt] && !this[S] && this[b].length === 0 && this[Q] && (this[De] = true, this.emit("end"), this.emit("prefinish"), this.emit("finish"), this[Ne] && this.emit("close"), this[De] = false);
|
|
8013
4845
|
}
|
|
8014
4846
|
emit(t, ...e) {
|
|
8015
4847
|
let i = e[0];
|
|
8016
|
-
if (t !== "error" && t !== "close" && t !==
|
|
4848
|
+
if (t !== "error" && t !== "close" && t !== S && this[S]) return false;
|
|
8017
4849
|
if (t === "data") return !this[L] && !i ? false : this[Z] ? (jt(() => this[Oi](i)), true) : this[Oi](i);
|
|
8018
4850
|
if (t === "end") return this[Is]();
|
|
8019
4851
|
if (t === "close") {
|
|
8020
|
-
if (this[Ne] = true, !this[nt] && !this[
|
|
4852
|
+
if (this[Ne] = true, !this[nt] && !this[S]) return false;
|
|
8021
4853
|
let n = super.emit("close");
|
|
8022
4854
|
return this.removeAllListeners("close"), n;
|
|
8023
4855
|
} else if (t === "error") {
|
|
@@ -8069,7 +4901,7 @@ var A = class extends Di {
|
|
|
8069
4901
|
}
|
|
8070
4902
|
async promise() {
|
|
8071
4903
|
return new Promise((t, e) => {
|
|
8072
|
-
this.on(
|
|
4904
|
+
this.on(S, () => e(new Error("stream destroyed"))), this.on("error", (i) => e(i)), this.on("end", () => t());
|
|
8073
4905
|
});
|
|
8074
4906
|
}
|
|
8075
4907
|
[Symbol.asyncIterator]() {
|
|
@@ -8081,14 +4913,14 @@ var A = class extends Di {
|
|
|
8081
4913
|
if (r !== null) return Promise.resolve({ done: false, value: r });
|
|
8082
4914
|
if (this[Q]) return e();
|
|
8083
4915
|
let n, o, h = (d) => {
|
|
8084
|
-
this.off("data", a), this.off("end", l), this.off(
|
|
4916
|
+
this.off("data", a), this.off("end", l), this.off(S, c), e(), o(d);
|
|
8085
4917
|
}, a = (d) => {
|
|
8086
|
-
this.off("error", h), this.off("end", l), this.off(
|
|
4918
|
+
this.off("error", h), this.off("end", l), this.off(S, c), this.pause(), n({ value: d, done: !!this[Q] });
|
|
8087
4919
|
}, l = () => {
|
|
8088
|
-
this.off("error", h), this.off("data", a), this.off(
|
|
4920
|
+
this.off("error", h), this.off("data", a), this.off(S, c), e(), n({ done: true, value: void 0 });
|
|
8089
4921
|
}, c = () => h(new Error("stream destroyed"));
|
|
8090
|
-
return new Promise((d,
|
|
8091
|
-
o =
|
|
4922
|
+
return new Promise((d, y) => {
|
|
4923
|
+
o = y, n = d, this.once(S, c), this.once("error", h), this.once("end", l), this.once("data", a);
|
|
8092
4924
|
});
|
|
8093
4925
|
}, throw: e, return: e, [Symbol.asyncIterator]() {
|
|
8094
4926
|
return this;
|
|
@@ -8097,21 +4929,21 @@ var A = class extends Di {
|
|
|
8097
4929
|
}
|
|
8098
4930
|
[Symbol.iterator]() {
|
|
8099
4931
|
this[C] = false;
|
|
8100
|
-
let t = false, e = () => (this.pause(), this.off(_i, e), this.off(
|
|
4932
|
+
let t = false, e = () => (this.pause(), this.off(_i, e), this.off(S, e), this.off("end", e), t = true, { done: true, value: void 0 }), i = () => {
|
|
8101
4933
|
if (t) return e();
|
|
8102
4934
|
let r = this.read();
|
|
8103
4935
|
return r === null ? e() : { done: false, value: r };
|
|
8104
4936
|
};
|
|
8105
|
-
return this.once("end", e), this.once(_i, e), this.once(
|
|
4937
|
+
return this.once("end", e), this.once(_i, e), this.once(S, e), { next: i, throw: e, return: e, [Symbol.iterator]() {
|
|
8106
4938
|
return this;
|
|
8107
4939
|
}, [Symbol.dispose]: () => {
|
|
8108
4940
|
} };
|
|
8109
4941
|
}
|
|
8110
4942
|
destroy(t) {
|
|
8111
|
-
if (this[
|
|
8112
|
-
this[
|
|
4943
|
+
if (this[S]) return t ? this.emit("error", t) : this.emit(S), this;
|
|
4944
|
+
this[S] = true, this[C] = true, this[b].length = 0, this[_] = 0;
|
|
8113
4945
|
let e = this;
|
|
8114
|
-
return typeof e.close == "function" && !this[Ne] && e.close(), t ? this.emit("error", t) : this.emit(
|
|
4946
|
+
return typeof e.close == "function" && !this[Ne] && e.close(), t ? this.emit("error", t) : this.emit(S), this;
|
|
8115
4947
|
}
|
|
8116
4948
|
static get isStream() {
|
|
8117
4949
|
return Wr;
|
|
@@ -8862,7 +5694,7 @@ var st = /* @__PURE__ */ Symbol("queue");
|
|
|
8862
5694
|
var mt = /* @__PURE__ */ Symbol("ended");
|
|
8863
5695
|
var Yi = /* @__PURE__ */ Symbol("emittedEnd");
|
|
8864
5696
|
var At = /* @__PURE__ */ Symbol("emit");
|
|
8865
|
-
var
|
|
5697
|
+
var w = /* @__PURE__ */ Symbol("unzip");
|
|
8866
5698
|
var Xe = /* @__PURE__ */ Symbol("consumeChunk");
|
|
8867
5699
|
var qe = /* @__PURE__ */ Symbol("consumeChunkSub");
|
|
8868
5700
|
var Ki = /* @__PURE__ */ Symbol("consumeBody");
|
|
@@ -8902,7 +5734,7 @@ var rt = class extends Dn {
|
|
|
8902
5734
|
[V];
|
|
8903
5735
|
[he];
|
|
8904
5736
|
[mt] = false;
|
|
8905
|
-
[
|
|
5737
|
+
[w];
|
|
8906
5738
|
[$] = false;
|
|
8907
5739
|
[It];
|
|
8908
5740
|
[je] = false;
|
|
@@ -9012,7 +5844,13 @@ var rt = class extends Dn {
|
|
|
9012
5844
|
}
|
|
9013
5845
|
}
|
|
9014
5846
|
abort(t) {
|
|
9015
|
-
|
|
5847
|
+
if (!this[$]) {
|
|
5848
|
+
if (this[w]) {
|
|
5849
|
+
let e = this[w];
|
|
5850
|
+
e.write = () => true, e.end = () => e, e.emit = () => false, e.destroy?.();
|
|
5851
|
+
}
|
|
5852
|
+
this[$] = true, this.emit("abort", t), this.warn("TAR_ABORT", t, { recoverable: false });
|
|
5853
|
+
}
|
|
9016
5854
|
}
|
|
9017
5855
|
[Xs](t) {
|
|
9018
5856
|
this[$i] += t.length;
|
|
@@ -9021,11 +5859,11 @@ var rt = class extends Dn {
|
|
|
9021
5859
|
}
|
|
9022
5860
|
write(t, e, i) {
|
|
9023
5861
|
if (typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8")), this[$]) return i?.(), false;
|
|
9024
|
-
if ((this[
|
|
5862
|
+
if ((this[w] === void 0 || this.brotli === void 0 && this[w] === false) && t) {
|
|
9025
5863
|
if (this[p] && (t = Buffer.concat([this[p], t]), this[p] = void 0), t.length < An) return this[p] = t, i?.(), true;
|
|
9026
|
-
for (let a = 0; this[
|
|
5864
|
+
for (let a = 0; this[w] === void 0 && a < Xi.length; a++) t[a] !== Xi[a] && (this[w] = false);
|
|
9027
5865
|
let o = false;
|
|
9028
|
-
if (this[
|
|
5866
|
+
if (this[w] === false && this.zstd !== false) {
|
|
9029
5867
|
o = true;
|
|
9030
5868
|
for (let a = 0; a < qi.length; a++) if (t[a] !== qi[a]) {
|
|
9031
5869
|
o = false;
|
|
@@ -9033,27 +5871,27 @@ var rt = class extends Dn {
|
|
|
9033
5871
|
}
|
|
9034
5872
|
}
|
|
9035
5873
|
let h = this.brotli === void 0 && !o;
|
|
9036
|
-
if (this[
|
|
5874
|
+
if (this[w] === false && h) if (t.length < 512) if (this[mt]) this.brotli = true;
|
|
9037
5875
|
else return this[p] = t, i?.(), true;
|
|
9038
5876
|
else try {
|
|
9039
5877
|
new F(t.subarray(0, 512)), this.brotli = false;
|
|
9040
5878
|
} catch {
|
|
9041
5879
|
this.brotli = true;
|
|
9042
5880
|
}
|
|
9043
|
-
if (this[
|
|
5881
|
+
if (this[w] === void 0 || this[w] === false && (this.brotli || o)) {
|
|
9044
5882
|
let a = this[mt];
|
|
9045
|
-
this[mt] = false, this[
|
|
5883
|
+
this[mt] = false, this[w] = this[w] === void 0 ? new Ue({}) : o ? new Ke({}) : new Ge({}), this[w].on("data", (c) => {
|
|
9046
5884
|
this[Xs](c) && this[Xe](c);
|
|
9047
|
-
}), this[
|
|
5885
|
+
}), this[w].on("error", (c) => {
|
|
9048
5886
|
this[$] || this.abort(c);
|
|
9049
|
-
}), this[
|
|
5887
|
+
}), this[w].on("end", () => {
|
|
9050
5888
|
this[mt] = true, this[Xe]();
|
|
9051
5889
|
}), this[Yt] = true, this[le] += t.length;
|
|
9052
|
-
let l = !!this[
|
|
5890
|
+
let l = !!this[w][a ? "end" : "write"](t);
|
|
9053
5891
|
return this[Yt] = false, i?.(), l;
|
|
9054
5892
|
}
|
|
9055
5893
|
}
|
|
9056
|
-
this[Yt] = true, this[
|
|
5894
|
+
this[Yt] = true, this[w] ? (this[le] += t.length, this[w].write(t)) : this[Xe](t), this[Yt] = false;
|
|
9057
5895
|
let n = this[st].length > 0 ? false : this[it] ? this[it].flowing : true;
|
|
9058
5896
|
return !n && this[st].length === 0 && this[it]?.once("drain", () => this.emit("drain")), i?.(), n;
|
|
9059
5897
|
}
|
|
@@ -9108,7 +5946,7 @@ var rt = class extends Dn {
|
|
|
9108
5946
|
e < i && (this[p] = this[p] ? Buffer.concat([t.subarray(e), this[p]]) : t.subarray(e));
|
|
9109
5947
|
}
|
|
9110
5948
|
end(t, e, i) {
|
|
9111
|
-
return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, e)), i && this.once("finish", i), this[$] || (this[
|
|
5949
|
+
return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, e)), i && this.once("finish", i), this[$] || (this[w] ? (t && (this[le] += t.length, this[w].write(t)), this[w].end()) : (this[mt] = true, (this.brotli === void 0 || this.zstd === void 0) && (t = t || Buffer.alloc(0)), t && this.write(t), this[Qe]())), this;
|
|
9112
5950
|
}
|
|
9113
5951
|
};
|
|
9114
5952
|
var ut = (s3) => {
|
|
@@ -9997,13 +6835,13 @@ var no = (s3, t) => {
|
|
|
9997
6835
|
};
|
|
9998
6836
|
var gr = (s3, t, e) => {
|
|
9999
6837
|
s3 = f(s3);
|
|
10000
|
-
let i = t.umask ?? 18, r = t.mode | 448, n = (r & i) !== 0, o = t.uid, h = t.gid, a = typeof o == "number" && typeof h == "number" && (o !== t.processUid || h !== t.processGid), l = t.preserve, c = t.unlink, d = f(t.cwd),
|
|
10001
|
-
E ? e(E) : x && a ? Es(x, o, h, (Le) =>
|
|
6838
|
+
let i = t.umask ?? 18, r = t.mode | 448, n = (r & i) !== 0, o = t.uid, h = t.gid, a = typeof o == "number" && typeof h == "number" && (o !== t.processUid || h !== t.processGid), l = t.preserve, c = t.unlink, d = f(t.cwd), y = (E, x) => {
|
|
6839
|
+
E ? e(E) : x && a ? Es(x, o, h, (Le) => y(Le)) : n ? k.chmod(s3, r, e) : e();
|
|
10002
6840
|
};
|
|
10003
|
-
if (s3 === d) return no(s3,
|
|
10004
|
-
if (l) return ro.mkdir(s3, { mode: r, recursive: true }).then((E) =>
|
|
6841
|
+
if (s3 === d) return no(s3, y);
|
|
6842
|
+
if (l) return ro.mkdir(s3, { mode: r, recursive: true }).then((E) => y(null, E ?? void 0), y);
|
|
10005
6843
|
let D = f(Si.relative(d, s3)).split("/");
|
|
10006
|
-
Ss(d, D, r, c, d, void 0,
|
|
6844
|
+
Ss(d, D, r, c, d, void 0, y);
|
|
10007
6845
|
};
|
|
10008
6846
|
var Ss = (s3, t, e, i, r, n, o) => {
|
|
10009
6847
|
if (t.length === 0) return o(null, n);
|
|
@@ -10313,12 +7151,12 @@ var Xt = class extends rt {
|
|
|
10313
7151
|
if (typeof l == "number" && t.mtime && !this.noMtime) {
|
|
10314
7152
|
n++;
|
|
10315
7153
|
let c = t.atime || /* @__PURE__ */ new Date(), d = t.mtime;
|
|
10316
|
-
m.futimes(l, c, d, (
|
|
7154
|
+
m.futimes(l, c, d, (y) => y ? m.utimes(a, c, d, (T) => o(T && y)) : o());
|
|
10317
7155
|
}
|
|
10318
7156
|
if (typeof l == "number" && this[ge](t)) {
|
|
10319
7157
|
n++;
|
|
10320
7158
|
let c = this[be](t), d = this[_e](t);
|
|
10321
|
-
typeof c == "number" && typeof d == "number" && m.fchown(l, c, d, (
|
|
7159
|
+
typeof c == "number" && typeof d == "number" && m.fchown(l, c, d, (y) => y ? m.chown(a, c, d, (T) => o(T && y)) : o());
|
|
10322
7160
|
}
|
|
10323
7161
|
o();
|
|
10324
7162
|
});
|
|
@@ -10645,27 +7483,27 @@ var go = (s3, t) => {
|
|
|
10645
7483
|
T ? v.close(n, (E) => h(T)) : h(null, D);
|
|
10646
7484
|
}, l = 0;
|
|
10647
7485
|
if (o === 0) return a(null, 0);
|
|
10648
|
-
let c = 0, d = Buffer.alloc(512),
|
|
7486
|
+
let c = 0, d = Buffer.alloc(512), y = (T, D) => {
|
|
10649
7487
|
if (T || D === void 0) return a(T);
|
|
10650
|
-
if (c += D, c < 512 && D) return v.read(n, d, c, d.length - c, l + c,
|
|
7488
|
+
if (c += D, c < 512 && D) return v.read(n, d, c, d.length - c, l + c, y);
|
|
10651
7489
|
if (l === 0 && d[0] === 31 && d[1] === 139) return a(new Error("cannot append to compressed archives"));
|
|
10652
7490
|
if (c < 512) return a(null, l);
|
|
10653
7491
|
let E = new F(d);
|
|
10654
7492
|
if (!E.cksumValid) return a(null, l);
|
|
10655
7493
|
let x = 512 * Math.ceil((E.size ?? 0) / 512);
|
|
10656
7494
|
if (l + x + 512 > o || (l += x + 512, l >= o)) return a(null, l);
|
|
10657
|
-
s3.mtimeCache && E.mtime && s3.mtimeCache.set(String(E.path), E.mtime), c = 0, v.read(n, d, 0, 512, l,
|
|
7495
|
+
s3.mtimeCache && E.mtime && s3.mtimeCache.set(String(E.path), E.mtime), c = 0, v.read(n, d, 0, 512, l, y);
|
|
10658
7496
|
};
|
|
10659
|
-
v.read(n, d, 0, 512, l,
|
|
7497
|
+
v.read(n, d, 0, 512, l, y);
|
|
10660
7498
|
};
|
|
10661
7499
|
return new Promise((n, o) => {
|
|
10662
7500
|
e.on("error", o);
|
|
10663
7501
|
let h = "r+", a = (l, c) => {
|
|
10664
7502
|
if (l && l.code === "ENOENT" && h === "r+") return h = "w+", v.open(s3.file, h, a);
|
|
10665
7503
|
if (l || !c) return o(l);
|
|
10666
|
-
v.fstat(c, (d,
|
|
7504
|
+
v.fstat(c, (d, y) => {
|
|
10667
7505
|
if (d) return v.close(c, () => o(d));
|
|
10668
|
-
i(c,
|
|
7506
|
+
i(c, y.size, (T, D) => {
|
|
10669
7507
|
if (T) return o(T);
|
|
10670
7508
|
let E = new et(s3.file, { fd: c, start: D });
|
|
10671
7509
|
e.pipe(E), E.on("error", o), E.on("close", n), _o(e, t);
|
|
@@ -12476,6 +9314,31 @@ async function verify(pkg, pkgAst, pkgPath, tarball, options) {
|
|
|
12476
9314
|
var pkgFilepath = fileURLToPath4(new URL("../package.json", import.meta.url));
|
|
12477
9315
|
var { version } = JSON.parse(readFileSync(pkgFilepath, "utf-8"));
|
|
12478
9316
|
var PACKAGE_JSON = "package.json";
|
|
9317
|
+
var HELP_TEXT = `usage: index.js [-h] [-v] [-t TARBALL] [-p PKGFILE] [--cache CACHE]
|
|
9318
|
+
[--allow-dependency DEPENDENCY] [--allow-types-dependencies]
|
|
9319
|
+
[--ignore-missing-fields] [--ignore-node-version [MAJOR]]
|
|
9320
|
+
|
|
9321
|
+
Opiniated linter for NPM package tarball and package.json metadata
|
|
9322
|
+
|
|
9323
|
+
options:
|
|
9324
|
+
-h, --help show this help message and exit
|
|
9325
|
+
-v, --version show program's version number and exit
|
|
9326
|
+
-t, --tarball TARBALL
|
|
9327
|
+
specify tarball location
|
|
9328
|
+
-p, --pkgfile PKGFILE
|
|
9329
|
+
specify package.json location
|
|
9330
|
+
--cache CACHE specify cache directory
|
|
9331
|
+
--allow-dependency DEPENDENCY
|
|
9332
|
+
explicitly allow given dependency (can be given
|
|
9333
|
+
multiple times or as a comma-separated list)
|
|
9334
|
+
--allow-types-dependencies
|
|
9335
|
+
allow production dependencies to \`@types/*\`
|
|
9336
|
+
--ignore-missing-fields
|
|
9337
|
+
ignore errors for missing fields (but still checks for
|
|
9338
|
+
empty and valid)
|
|
9339
|
+
--ignore-node-version [MAJOR]
|
|
9340
|
+
ignore error for outdated node version (restricted to MAJOR version if given)
|
|
9341
|
+
`;
|
|
12479
9342
|
async function preloadStdin() {
|
|
12480
9343
|
return new Promise((resolve, reject) => {
|
|
12481
9344
|
import_tmp.default.file((err, path8, fd) => {
|
|
@@ -12532,51 +9395,77 @@ async function getPackageJson(args, regenerateReportName) {
|
|
|
12532
9395
|
}
|
|
12533
9396
|
return { pkg: void 0, pkgAst: void 0, pkgPath: void 0 };
|
|
12534
9397
|
}
|
|
12535
|
-
|
|
12536
|
-
const
|
|
12537
|
-
|
|
12538
|
-
|
|
12539
|
-
|
|
12540
|
-
|
|
12541
|
-
|
|
12542
|
-
|
|
12543
|
-
|
|
12544
|
-
|
|
12545
|
-
|
|
12546
|
-
|
|
12547
|
-
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
|
|
12553
|
-
|
|
12554
|
-
|
|
12555
|
-
|
|
12556
|
-
}
|
|
12557
|
-
|
|
12558
|
-
|
|
12559
|
-
|
|
12560
|
-
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
|
|
9398
|
+
function extractIgnoreNodeVersion(argv) {
|
|
9399
|
+
const FLAG = "--ignore-node-version";
|
|
9400
|
+
const rest = [];
|
|
9401
|
+
let value = false;
|
|
9402
|
+
for (let i = 0; i < argv.length; i++) {
|
|
9403
|
+
const arg = argv[i];
|
|
9404
|
+
if (arg === FLAG) {
|
|
9405
|
+
const next = argv[i + 1];
|
|
9406
|
+
if (typeof next === "string" && !next.startsWith("-")) {
|
|
9407
|
+
value = parseIgnoreNodeVersionValue(next);
|
|
9408
|
+
i++;
|
|
9409
|
+
} else {
|
|
9410
|
+
value = true;
|
|
9411
|
+
}
|
|
9412
|
+
continue;
|
|
9413
|
+
}
|
|
9414
|
+
if (arg.startsWith(`${FLAG}=`)) {
|
|
9415
|
+
value = parseIgnoreNodeVersionValue(arg.slice(FLAG.length + 1));
|
|
9416
|
+
continue;
|
|
9417
|
+
}
|
|
9418
|
+
rest.push(arg);
|
|
9419
|
+
}
|
|
9420
|
+
return { value, rest };
|
|
9421
|
+
}
|
|
9422
|
+
function parseIgnoreNodeVersionValue(raw) {
|
|
9423
|
+
const parsed = Number(raw);
|
|
9424
|
+
if (!Number.isSafeInteger(parsed)) {
|
|
9425
|
+
throw new TypeError(`argument --ignore-node-version: invalid int value: '${raw}'`);
|
|
9426
|
+
}
|
|
9427
|
+
return parsed;
|
|
9428
|
+
}
|
|
9429
|
+
function parseCliArgs(argv) {
|
|
9430
|
+
const { value: ignoreNodeVersion, rest } = extractIgnoreNodeVersion(argv);
|
|
9431
|
+
const { values } = parseArgs({
|
|
9432
|
+
args: rest,
|
|
9433
|
+
options: {
|
|
9434
|
+
help: { type: "boolean", short: "h" },
|
|
9435
|
+
version: { type: "boolean", short: "v" },
|
|
9436
|
+
tarball: { type: "string", short: "t" },
|
|
9437
|
+
pkgfile: { type: "string", short: "p" },
|
|
9438
|
+
cache: { type: "string" },
|
|
9439
|
+
"allow-dependency": { type: "string", multiple: true, default: [] },
|
|
9440
|
+
"allow-types-dependencies": { type: "boolean" },
|
|
9441
|
+
"ignore-missing-fields": { type: "boolean" }
|
|
9442
|
+
},
|
|
9443
|
+
strict: true
|
|
12564
9444
|
});
|
|
12565
|
-
|
|
12566
|
-
|
|
12567
|
-
if (args.cache) {
|
|
12568
|
-
await setCacheDirecory(args.cache);
|
|
9445
|
+
if (values.help) {
|
|
9446
|
+
return { action: "help" };
|
|
12569
9447
|
}
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
args.tarball = await preloadStdin();
|
|
12573
|
-
regenerateReportName = true;
|
|
9448
|
+
if (values.version) {
|
|
9449
|
+
return { action: "version" };
|
|
12574
9450
|
}
|
|
9451
|
+
return {
|
|
9452
|
+
action: "run",
|
|
9453
|
+
args: {
|
|
9454
|
+
cache: values.cache,
|
|
9455
|
+
pkgfile: values.pkgfile,
|
|
9456
|
+
tarball: values.tarball,
|
|
9457
|
+
ignoreMissingFields: values["ignore-missing-fields"],
|
|
9458
|
+
ignoreNodeVersion,
|
|
9459
|
+
allowDependency: values["allow-dependency"],
|
|
9460
|
+
allowTypesDependencies: values["allow-types-dependencies"]
|
|
9461
|
+
}
|
|
9462
|
+
};
|
|
9463
|
+
}
|
|
9464
|
+
async function loadPackage(args, regenerateReportName) {
|
|
12575
9465
|
const { pkg, pkgAst, pkgPath } = await getPackageJson(args, regenerateReportName);
|
|
12576
9466
|
if (!pkg) {
|
|
12577
9467
|
console.error("Failed to locate package.json and no location was specificed with `--pkgfile'");
|
|
12578
|
-
|
|
12579
|
-
return;
|
|
9468
|
+
return void 0;
|
|
12580
9469
|
}
|
|
12581
9470
|
const tarball = {
|
|
12582
9471
|
filePath: args.tarball ?? tarballLocation(pkg, pkgPath),
|
|
@@ -12584,15 +9473,49 @@ async function run() {
|
|
|
12584
9473
|
};
|
|
12585
9474
|
if (!existsSync(tarball.filePath)) {
|
|
12586
9475
|
console.error(`"${tarball.filePath}" does not exist, did you forget to run \`npm pack'?`);
|
|
9476
|
+
return void 0;
|
|
9477
|
+
}
|
|
9478
|
+
return { pkg, pkgAst, pkgPath, tarball };
|
|
9479
|
+
}
|
|
9480
|
+
async function run() {
|
|
9481
|
+
let cli;
|
|
9482
|
+
try {
|
|
9483
|
+
cli = parseCliArgs(process.argv.slice(2));
|
|
9484
|
+
} catch (err) {
|
|
9485
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
9486
|
+
process.exitCode = 1;
|
|
9487
|
+
return;
|
|
9488
|
+
}
|
|
9489
|
+
if (cli.action === "help") {
|
|
9490
|
+
console.log(HELP_TEXT);
|
|
9491
|
+
return;
|
|
9492
|
+
}
|
|
9493
|
+
if (cli.action === "version") {
|
|
9494
|
+
console.log(version);
|
|
9495
|
+
return;
|
|
9496
|
+
}
|
|
9497
|
+
const { args } = cli;
|
|
9498
|
+
const allowedDependencies2 = new Set(args.allowDependency.flatMap((it2) => it2.split(",")));
|
|
9499
|
+
if (args.cache) {
|
|
9500
|
+
await setCacheDirecory(args.cache);
|
|
9501
|
+
}
|
|
9502
|
+
let regenerateReportName = false;
|
|
9503
|
+
if (args.tarball === "-") {
|
|
9504
|
+
args.tarball = await preloadStdin();
|
|
9505
|
+
regenerateReportName = true;
|
|
9506
|
+
}
|
|
9507
|
+
const loaded = await loadPackage(args, regenerateReportName);
|
|
9508
|
+
if (!loaded) {
|
|
12587
9509
|
process.exitCode = 1;
|
|
12588
9510
|
return;
|
|
12589
9511
|
}
|
|
9512
|
+
const { pkg, pkgAst, pkgPath, tarball } = loaded;
|
|
12590
9513
|
setupBlacklist(pkg.name);
|
|
12591
9514
|
const options = {
|
|
12592
9515
|
allowedDependencies: allowedDependencies2,
|
|
12593
|
-
allowTypesDependencies: args.
|
|
12594
|
-
ignoreMissingFields: args.
|
|
12595
|
-
ignoreNodeVersion: args.
|
|
9516
|
+
allowTypesDependencies: args.allowTypesDependencies,
|
|
9517
|
+
ignoreMissingFields: args.ignoreMissingFields,
|
|
9518
|
+
ignoreNodeVersion: args.ignoreNodeVersion
|
|
12596
9519
|
};
|
|
12597
9520
|
const results = await verify(pkg, pkgAst, pkgPath, tarball, options);
|
|
12598
9521
|
for (const result of results) {
|