@html-validate/puppeteer-fetch 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/index.js +2936 -0
- package/package.json +37 -0
- package/puppeteer-fetch.js +3 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2936 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __objRest = (source, exclude) => {
|
|
10
|
+
var target = {};
|
|
11
|
+
for (var prop in source)
|
|
12
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
13
|
+
target[prop] = source[prop];
|
|
14
|
+
if (source != null && __getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
16
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
17
|
+
target[prop] = source[prop];
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
22
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
33
|
+
|
|
34
|
+
// node_modules/argparse/lib/sub.js
|
|
35
|
+
var require_sub = __commonJS({
|
|
36
|
+
"node_modules/argparse/lib/sub.js"(exports, module2) {
|
|
37
|
+
"use strict";
|
|
38
|
+
var { inspect } = require("util");
|
|
39
|
+
module2.exports = function sub(pattern, ...values) {
|
|
40
|
+
let regex = /%(?:(%)|(-)?(\*)?(?:\((\w+)\))?([A-Za-z]))/g;
|
|
41
|
+
let result = pattern.replace(regex, function(_, is_literal, is_left_align, is_padded, name, format) {
|
|
42
|
+
if (is_literal)
|
|
43
|
+
return "%";
|
|
44
|
+
let padded_count = 0;
|
|
45
|
+
if (is_padded) {
|
|
46
|
+
if (values.length === 0)
|
|
47
|
+
throw new TypeError("not enough arguments for format string");
|
|
48
|
+
padded_count = values.shift();
|
|
49
|
+
if (!Number.isInteger(padded_count))
|
|
50
|
+
throw new TypeError("* wants int");
|
|
51
|
+
}
|
|
52
|
+
let str;
|
|
53
|
+
if (name !== void 0) {
|
|
54
|
+
let dict = values[0];
|
|
55
|
+
if (typeof dict !== "object" || dict === null)
|
|
56
|
+
throw new TypeError("format requires a mapping");
|
|
57
|
+
if (!(name in dict))
|
|
58
|
+
throw new TypeError(`no such key: '${name}'`);
|
|
59
|
+
str = dict[name];
|
|
60
|
+
} else {
|
|
61
|
+
if (values.length === 0)
|
|
62
|
+
throw new TypeError("not enough arguments for format string");
|
|
63
|
+
str = values.shift();
|
|
64
|
+
}
|
|
65
|
+
switch (format) {
|
|
66
|
+
case "s":
|
|
67
|
+
str = String(str);
|
|
68
|
+
break;
|
|
69
|
+
case "r":
|
|
70
|
+
str = inspect(str);
|
|
71
|
+
break;
|
|
72
|
+
case "d":
|
|
73
|
+
case "i":
|
|
74
|
+
if (typeof str !== "number") {
|
|
75
|
+
throw new TypeError(`%${format} format: a number is required, not ${typeof str}`);
|
|
76
|
+
}
|
|
77
|
+
str = String(str.toFixed(0));
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
throw new TypeError(`unsupported format character '${format}'`);
|
|
81
|
+
}
|
|
82
|
+
if (padded_count > 0) {
|
|
83
|
+
return is_left_align ? str.padEnd(padded_count) : str.padStart(padded_count);
|
|
84
|
+
} else {
|
|
85
|
+
return str;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
if (values.length) {
|
|
89
|
+
if (values.length === 1 && typeof values[0] === "object" && values[0] !== null) {
|
|
90
|
+
} else {
|
|
91
|
+
throw new TypeError("not all arguments converted during string formatting");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// node_modules/argparse/lib/textwrap.js
|
|
100
|
+
var require_textwrap = __commonJS({
|
|
101
|
+
"node_modules/argparse/lib/textwrap.js"(exports, module2) {
|
|
102
|
+
"use strict";
|
|
103
|
+
var wordsep_simple_re = /([\t\n\x0b\x0c\r ]+)/;
|
|
104
|
+
var TextWrapper = class {
|
|
105
|
+
constructor(options = {}) {
|
|
106
|
+
let {
|
|
107
|
+
width = 70,
|
|
108
|
+
initial_indent = "",
|
|
109
|
+
subsequent_indent = "",
|
|
110
|
+
expand_tabs = true,
|
|
111
|
+
replace_whitespace = true,
|
|
112
|
+
fix_sentence_endings = false,
|
|
113
|
+
break_long_words = true,
|
|
114
|
+
drop_whitespace = true,
|
|
115
|
+
break_on_hyphens = true,
|
|
116
|
+
tabsize = 8,
|
|
117
|
+
max_lines = void 0,
|
|
118
|
+
placeholder = " [...]"
|
|
119
|
+
} = options;
|
|
120
|
+
this.width = width;
|
|
121
|
+
this.initial_indent = initial_indent;
|
|
122
|
+
this.subsequent_indent = subsequent_indent;
|
|
123
|
+
this.expand_tabs = expand_tabs;
|
|
124
|
+
this.replace_whitespace = replace_whitespace;
|
|
125
|
+
this.fix_sentence_endings = fix_sentence_endings;
|
|
126
|
+
this.break_long_words = break_long_words;
|
|
127
|
+
this.drop_whitespace = drop_whitespace;
|
|
128
|
+
this.break_on_hyphens = break_on_hyphens;
|
|
129
|
+
this.tabsize = tabsize;
|
|
130
|
+
this.max_lines = max_lines;
|
|
131
|
+
this.placeholder = placeholder;
|
|
132
|
+
}
|
|
133
|
+
_munge_whitespace(text) {
|
|
134
|
+
if (this.expand_tabs) {
|
|
135
|
+
text = text.replace(/\t/g, " ".repeat(this.tabsize));
|
|
136
|
+
}
|
|
137
|
+
if (this.replace_whitespace) {
|
|
138
|
+
text = text.replace(/[\t\n\x0b\x0c\r]/g, " ");
|
|
139
|
+
}
|
|
140
|
+
return text;
|
|
141
|
+
}
|
|
142
|
+
_split(text) {
|
|
143
|
+
let chunks = text.split(wordsep_simple_re);
|
|
144
|
+
chunks = chunks.filter(Boolean);
|
|
145
|
+
return chunks;
|
|
146
|
+
}
|
|
147
|
+
_handle_long_word(reversed_chunks, cur_line, cur_len, width) {
|
|
148
|
+
let space_left;
|
|
149
|
+
if (width < 1) {
|
|
150
|
+
space_left = 1;
|
|
151
|
+
} else {
|
|
152
|
+
space_left = width - cur_len;
|
|
153
|
+
}
|
|
154
|
+
if (this.break_long_words) {
|
|
155
|
+
cur_line.push(reversed_chunks[reversed_chunks.length - 1].slice(0, space_left));
|
|
156
|
+
reversed_chunks[reversed_chunks.length - 1] = reversed_chunks[reversed_chunks.length - 1].slice(space_left);
|
|
157
|
+
} else if (!cur_line) {
|
|
158
|
+
cur_line.push(...reversed_chunks.pop());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
_wrap_chunks(chunks) {
|
|
162
|
+
let lines = [];
|
|
163
|
+
let indent;
|
|
164
|
+
if (this.width <= 0) {
|
|
165
|
+
throw Error(`invalid width ${this.width} (must be > 0)`);
|
|
166
|
+
}
|
|
167
|
+
if (this.max_lines !== void 0) {
|
|
168
|
+
if (this.max_lines > 1) {
|
|
169
|
+
indent = this.subsequent_indent;
|
|
170
|
+
} else {
|
|
171
|
+
indent = this.initial_indent;
|
|
172
|
+
}
|
|
173
|
+
if (indent.length + this.placeholder.trimStart().length > this.width) {
|
|
174
|
+
throw Error("placeholder too large for max width");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
chunks = chunks.reverse();
|
|
178
|
+
while (chunks.length > 0) {
|
|
179
|
+
let cur_line = [];
|
|
180
|
+
let cur_len = 0;
|
|
181
|
+
let indent2;
|
|
182
|
+
if (lines) {
|
|
183
|
+
indent2 = this.subsequent_indent;
|
|
184
|
+
} else {
|
|
185
|
+
indent2 = this.initial_indent;
|
|
186
|
+
}
|
|
187
|
+
let width = this.width - indent2.length;
|
|
188
|
+
if (this.drop_whitespace && chunks[chunks.length - 1].trim() === "" && lines.length > 0) {
|
|
189
|
+
chunks.pop();
|
|
190
|
+
}
|
|
191
|
+
while (chunks.length > 0) {
|
|
192
|
+
let l = chunks[chunks.length - 1].length;
|
|
193
|
+
if (cur_len + l <= width) {
|
|
194
|
+
cur_line.push(chunks.pop());
|
|
195
|
+
cur_len += l;
|
|
196
|
+
} else {
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (chunks.length && chunks[chunks.length - 1].length > width) {
|
|
201
|
+
this._handle_long_word(chunks, cur_line, cur_len, width);
|
|
202
|
+
cur_len = cur_line.map((l) => l.length).reduce((a, b) => a + b, 0);
|
|
203
|
+
}
|
|
204
|
+
if (this.drop_whitespace && cur_line.length > 0 && cur_line[cur_line.length - 1].trim() === "") {
|
|
205
|
+
cur_len -= cur_line[cur_line.length - 1].length;
|
|
206
|
+
cur_line.pop();
|
|
207
|
+
}
|
|
208
|
+
if (cur_line) {
|
|
209
|
+
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) {
|
|
210
|
+
lines.push(indent2 + cur_line.join(""));
|
|
211
|
+
} else {
|
|
212
|
+
let had_break = false;
|
|
213
|
+
while (cur_line) {
|
|
214
|
+
if (cur_line[cur_line.length - 1].trim() && cur_len + this.placeholder.length <= width) {
|
|
215
|
+
cur_line.push(this.placeholder);
|
|
216
|
+
lines.push(indent2 + cur_line.join(""));
|
|
217
|
+
had_break = true;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
cur_len -= cur_line[-1].length;
|
|
221
|
+
cur_line.pop();
|
|
222
|
+
}
|
|
223
|
+
if (!had_break) {
|
|
224
|
+
if (lines) {
|
|
225
|
+
let prev_line = lines[lines.length - 1].trimEnd();
|
|
226
|
+
if (prev_line.length + this.placeholder.length <= this.width) {
|
|
227
|
+
lines[lines.length - 1] = prev_line + this.placeholder;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
lines.push(indent2 + this.placeholder.lstrip());
|
|
232
|
+
}
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return lines;
|
|
238
|
+
}
|
|
239
|
+
_split_chunks(text) {
|
|
240
|
+
text = this._munge_whitespace(text);
|
|
241
|
+
return this._split(text);
|
|
242
|
+
}
|
|
243
|
+
wrap(text) {
|
|
244
|
+
let chunks = this._split_chunks(text);
|
|
245
|
+
return this._wrap_chunks(chunks);
|
|
246
|
+
}
|
|
247
|
+
fill(text) {
|
|
248
|
+
return this.wrap(text).join("\n");
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
function wrap(text, options = {}) {
|
|
252
|
+
let _a = options, { width = 70 } = _a, kwargs = __objRest(_a, ["width"]);
|
|
253
|
+
let w = new TextWrapper(Object.assign({ width }, kwargs));
|
|
254
|
+
return w.wrap(text);
|
|
255
|
+
}
|
|
256
|
+
function fill(text, options = {}) {
|
|
257
|
+
let _a = options, { width = 70 } = _a, kwargs = __objRest(_a, ["width"]);
|
|
258
|
+
let w = new TextWrapper(Object.assign({ width }, kwargs));
|
|
259
|
+
return w.fill(text);
|
|
260
|
+
}
|
|
261
|
+
var _whitespace_only_re = /^[ \t]+$/mg;
|
|
262
|
+
var _leading_whitespace_re = /(^[ \t]*)(?:[^ \t\n])/mg;
|
|
263
|
+
function dedent(text) {
|
|
264
|
+
let margin = void 0;
|
|
265
|
+
text = text.replace(_whitespace_only_re, "");
|
|
266
|
+
let indents = text.match(_leading_whitespace_re) || [];
|
|
267
|
+
for (let indent of indents) {
|
|
268
|
+
indent = indent.slice(0, -1);
|
|
269
|
+
if (margin === void 0) {
|
|
270
|
+
margin = indent;
|
|
271
|
+
} else if (indent.startsWith(margin)) {
|
|
272
|
+
} else if (margin.startsWith(indent)) {
|
|
273
|
+
margin = indent;
|
|
274
|
+
} else {
|
|
275
|
+
for (let i = 0; i < margin.length && i < indent.length; i++) {
|
|
276
|
+
if (margin[i] !== indent[i]) {
|
|
277
|
+
margin = margin.slice(0, i);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (margin) {
|
|
284
|
+
text = text.replace(new RegExp("^" + margin, "mg"), "");
|
|
285
|
+
}
|
|
286
|
+
return text;
|
|
287
|
+
}
|
|
288
|
+
module2.exports = { wrap, fill, dedent };
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// node_modules/argparse/argparse.js
|
|
293
|
+
var require_argparse = __commonJS({
|
|
294
|
+
"node_modules/argparse/argparse.js"(exports, module2) {
|
|
295
|
+
"use strict";
|
|
296
|
+
var SUPPRESS = "==SUPPRESS==";
|
|
297
|
+
var OPTIONAL = "?";
|
|
298
|
+
var ZERO_OR_MORE = "*";
|
|
299
|
+
var ONE_OR_MORE = "+";
|
|
300
|
+
var PARSER = "A...";
|
|
301
|
+
var REMAINDER = "...";
|
|
302
|
+
var _UNRECOGNIZED_ARGS_ATTR = "_unrecognized_args";
|
|
303
|
+
var assert = require("assert");
|
|
304
|
+
var util = require("util");
|
|
305
|
+
var fs2 = require("fs");
|
|
306
|
+
var sub = require_sub();
|
|
307
|
+
var path2 = require("path");
|
|
308
|
+
var repr = util.inspect;
|
|
309
|
+
function get_argv() {
|
|
310
|
+
return process.argv.slice(1);
|
|
311
|
+
}
|
|
312
|
+
function get_terminal_size() {
|
|
313
|
+
return {
|
|
314
|
+
columns: +process.env.COLUMNS || process.stdout.columns || 80
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function hasattr(object, name) {
|
|
318
|
+
return Object.prototype.hasOwnProperty.call(object, name);
|
|
319
|
+
}
|
|
320
|
+
function getattr(object, name, value) {
|
|
321
|
+
return hasattr(object, name) ? object[name] : value;
|
|
322
|
+
}
|
|
323
|
+
function setattr(object, name, value) {
|
|
324
|
+
object[name] = value;
|
|
325
|
+
}
|
|
326
|
+
function setdefault(object, name, value) {
|
|
327
|
+
if (!hasattr(object, name))
|
|
328
|
+
object[name] = value;
|
|
329
|
+
return object[name];
|
|
330
|
+
}
|
|
331
|
+
function delattr(object, name) {
|
|
332
|
+
delete object[name];
|
|
333
|
+
}
|
|
334
|
+
function range(from, to, step = 1) {
|
|
335
|
+
if (arguments.length === 1)
|
|
336
|
+
[to, from] = [from, 0];
|
|
337
|
+
if (typeof from !== "number" || typeof to !== "number" || typeof step !== "number") {
|
|
338
|
+
throw new TypeError("argument cannot be interpreted as an integer");
|
|
339
|
+
}
|
|
340
|
+
if (step === 0)
|
|
341
|
+
throw new TypeError("range() arg 3 must not be zero");
|
|
342
|
+
let result = [];
|
|
343
|
+
if (step > 0) {
|
|
344
|
+
for (let i = from; i < to; i += step)
|
|
345
|
+
result.push(i);
|
|
346
|
+
} else {
|
|
347
|
+
for (let i = from; i > to; i += step)
|
|
348
|
+
result.push(i);
|
|
349
|
+
}
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
function splitlines(str, keepends = false) {
|
|
353
|
+
let result;
|
|
354
|
+
if (!keepends) {
|
|
355
|
+
result = str.split(/\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029]/);
|
|
356
|
+
} else {
|
|
357
|
+
result = [];
|
|
358
|
+
let parts = str.split(/(\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029])/);
|
|
359
|
+
for (let i = 0; i < parts.length; i += 2) {
|
|
360
|
+
result.push(parts[i] + (i + 1 < parts.length ? parts[i + 1] : ""));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (!result[result.length - 1])
|
|
364
|
+
result.pop();
|
|
365
|
+
return result;
|
|
366
|
+
}
|
|
367
|
+
function _string_lstrip(string, prefix_chars) {
|
|
368
|
+
let idx = 0;
|
|
369
|
+
while (idx < string.length && prefix_chars.includes(string[idx]))
|
|
370
|
+
idx++;
|
|
371
|
+
return idx ? string.slice(idx) : string;
|
|
372
|
+
}
|
|
373
|
+
function _string_split(string, sep, maxsplit) {
|
|
374
|
+
let result = string.split(sep);
|
|
375
|
+
if (result.length > maxsplit) {
|
|
376
|
+
result = result.slice(0, maxsplit).concat([result.slice(maxsplit).join(sep)]);
|
|
377
|
+
}
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
function _array_equal(array1, array2) {
|
|
381
|
+
if (array1.length !== array2.length)
|
|
382
|
+
return false;
|
|
383
|
+
for (let i = 0; i < array1.length; i++) {
|
|
384
|
+
if (array1[i] !== array2[i])
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
function _array_remove(array, item) {
|
|
390
|
+
let idx = array.indexOf(item);
|
|
391
|
+
if (idx === -1)
|
|
392
|
+
throw new TypeError(sub("%r not in list", item));
|
|
393
|
+
array.splice(idx, 1);
|
|
394
|
+
}
|
|
395
|
+
function _choices_to_array(choices) {
|
|
396
|
+
if (choices === void 0) {
|
|
397
|
+
return [];
|
|
398
|
+
} else if (Array.isArray(choices)) {
|
|
399
|
+
return choices;
|
|
400
|
+
} else if (choices !== null && typeof choices[Symbol.iterator] === "function") {
|
|
401
|
+
return Array.from(choices);
|
|
402
|
+
} else if (typeof choices === "object" && choices !== null) {
|
|
403
|
+
return Object.keys(choices);
|
|
404
|
+
} else {
|
|
405
|
+
throw new Error(sub("invalid choices value: %r", choices));
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function _callable(cls) {
|
|
409
|
+
let result = {
|
|
410
|
+
[cls.name]: function(...args) {
|
|
411
|
+
let this_class = new.target === result || !new.target;
|
|
412
|
+
return Reflect.construct(cls, args, this_class ? cls : new.target);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
result[cls.name].prototype = cls.prototype;
|
|
416
|
+
cls.prototype[Symbol.toStringTag] = cls.name;
|
|
417
|
+
return result[cls.name];
|
|
418
|
+
}
|
|
419
|
+
function _alias(object, from, to) {
|
|
420
|
+
try {
|
|
421
|
+
let name = object.constructor.name;
|
|
422
|
+
Object.defineProperty(object, from, {
|
|
423
|
+
value: util.deprecate(object[to], sub("%s.%s() is renamed to %s.%s()", name, from, name, to)),
|
|
424
|
+
enumerable: false
|
|
425
|
+
});
|
|
426
|
+
} catch {
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function _camelcase_alias(_class) {
|
|
430
|
+
for (let name of Object.getOwnPropertyNames(_class.prototype)) {
|
|
431
|
+
let camelcase = name.replace(/\w_[a-z]/g, (s) => s[0] + s[2].toUpperCase());
|
|
432
|
+
if (camelcase !== name)
|
|
433
|
+
_alias(_class.prototype, camelcase, name);
|
|
434
|
+
}
|
|
435
|
+
return _class;
|
|
436
|
+
}
|
|
437
|
+
function _to_legacy_name(key) {
|
|
438
|
+
key = key.replace(/\w_[a-z]/g, (s) => s[0] + s[2].toUpperCase());
|
|
439
|
+
if (key === "default")
|
|
440
|
+
key = "defaultValue";
|
|
441
|
+
if (key === "const")
|
|
442
|
+
key = "constant";
|
|
443
|
+
return key;
|
|
444
|
+
}
|
|
445
|
+
function _to_new_name(key) {
|
|
446
|
+
if (key === "defaultValue")
|
|
447
|
+
key = "default";
|
|
448
|
+
if (key === "constant")
|
|
449
|
+
key = "const";
|
|
450
|
+
key = key.replace(/[A-Z]/g, (c) => "_" + c.toLowerCase());
|
|
451
|
+
return key;
|
|
452
|
+
}
|
|
453
|
+
var no_default = Symbol("no_default_value");
|
|
454
|
+
function _parse_opts(args, descriptor) {
|
|
455
|
+
function get_name() {
|
|
456
|
+
let stack = new Error().stack.split("\n").map((x) => x.match(/^ at (.*) \(.*\)$/)).filter(Boolean).map((m) => m[1]).map((fn) => fn.match(/[^ .]*$/)[0]);
|
|
457
|
+
if (stack.length && stack[0] === get_name.name)
|
|
458
|
+
stack.shift();
|
|
459
|
+
if (stack.length && stack[0] === _parse_opts.name)
|
|
460
|
+
stack.shift();
|
|
461
|
+
return stack.length ? stack[0] : "";
|
|
462
|
+
}
|
|
463
|
+
args = Array.from(args);
|
|
464
|
+
let kwargs = {};
|
|
465
|
+
let result = [];
|
|
466
|
+
let last_opt = args.length && args[args.length - 1];
|
|
467
|
+
if (typeof last_opt === "object" && last_opt !== null && !Array.isArray(last_opt) && (!last_opt.constructor || last_opt.constructor.name === "Object")) {
|
|
468
|
+
kwargs = Object.assign({}, args.pop());
|
|
469
|
+
}
|
|
470
|
+
let renames = [];
|
|
471
|
+
for (let key of Object.keys(descriptor)) {
|
|
472
|
+
let old_name = _to_legacy_name(key);
|
|
473
|
+
if (old_name !== key && old_name in kwargs) {
|
|
474
|
+
if (key in kwargs) {
|
|
475
|
+
} else {
|
|
476
|
+
kwargs[key] = kwargs[old_name];
|
|
477
|
+
}
|
|
478
|
+
renames.push([old_name, key]);
|
|
479
|
+
delete kwargs[old_name];
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (renames.length) {
|
|
483
|
+
let name = get_name();
|
|
484
|
+
deprecate("camelcase_" + name, sub("%s(): following options are renamed: %s", name, renames.map(([a, b]) => sub("%r -> %r", a, b))));
|
|
485
|
+
}
|
|
486
|
+
let missing_positionals = [];
|
|
487
|
+
let positional_count = args.length;
|
|
488
|
+
for (let [key, def] of Object.entries(descriptor)) {
|
|
489
|
+
if (key[0] === "*") {
|
|
490
|
+
if (key.length > 0 && key[1] === "*") {
|
|
491
|
+
let renames2 = [];
|
|
492
|
+
for (let key2 of Object.keys(kwargs)) {
|
|
493
|
+
let new_name = _to_new_name(key2);
|
|
494
|
+
if (new_name !== key2 && key2 in kwargs) {
|
|
495
|
+
if (new_name in kwargs) {
|
|
496
|
+
} else {
|
|
497
|
+
kwargs[new_name] = kwargs[key2];
|
|
498
|
+
}
|
|
499
|
+
renames2.push([key2, new_name]);
|
|
500
|
+
delete kwargs[key2];
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (renames2.length) {
|
|
504
|
+
let name = get_name();
|
|
505
|
+
deprecate("camelcase_" + name, sub("%s(): following options are renamed: %s", name, renames2.map(([a, b]) => sub("%r -> %r", a, b))));
|
|
506
|
+
}
|
|
507
|
+
result.push(kwargs);
|
|
508
|
+
kwargs = {};
|
|
509
|
+
} else {
|
|
510
|
+
result.push(args);
|
|
511
|
+
args = [];
|
|
512
|
+
}
|
|
513
|
+
} else if (key in kwargs && args.length > 0) {
|
|
514
|
+
throw new TypeError(sub("%s() got multiple values for argument %r", get_name(), key));
|
|
515
|
+
} else if (key in kwargs) {
|
|
516
|
+
result.push(kwargs[key]);
|
|
517
|
+
delete kwargs[key];
|
|
518
|
+
} else if (args.length > 0) {
|
|
519
|
+
result.push(args.shift());
|
|
520
|
+
} else if (def !== no_default) {
|
|
521
|
+
result.push(def);
|
|
522
|
+
} else {
|
|
523
|
+
missing_positionals.push(key);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
if (Object.keys(kwargs).length) {
|
|
527
|
+
throw new TypeError(sub("%s() got an unexpected keyword argument %r", get_name(), Object.keys(kwargs)[0]));
|
|
528
|
+
}
|
|
529
|
+
if (args.length) {
|
|
530
|
+
let from = Object.entries(descriptor).filter(([k, v]) => k[0] !== "*" && v !== no_default).length;
|
|
531
|
+
let to = Object.entries(descriptor).filter(([k]) => k[0] !== "*").length;
|
|
532
|
+
throw new TypeError(sub("%s() takes %s positional argument%s but %s %s given", get_name(), from === to ? sub("from %s to %s", from, to) : to, from === to && to === 1 ? "" : "s", positional_count, positional_count === 1 ? "was" : "were"));
|
|
533
|
+
}
|
|
534
|
+
if (missing_positionals.length) {
|
|
535
|
+
let strs = missing_positionals.map(repr);
|
|
536
|
+
if (strs.length > 1)
|
|
537
|
+
strs[strs.length - 1] = "and " + strs[strs.length - 1];
|
|
538
|
+
let str_joined = strs.join(strs.length === 2 ? "" : ", ");
|
|
539
|
+
throw new TypeError(sub("%s() missing %i required positional argument%s: %s", get_name(), strs.length, strs.length === 1 ? "" : "s", str_joined));
|
|
540
|
+
}
|
|
541
|
+
return result;
|
|
542
|
+
}
|
|
543
|
+
var _deprecations = {};
|
|
544
|
+
function deprecate(id, string) {
|
|
545
|
+
_deprecations[id] = _deprecations[id] || util.deprecate(() => {
|
|
546
|
+
}, string);
|
|
547
|
+
_deprecations[id]();
|
|
548
|
+
}
|
|
549
|
+
function _AttributeHolder(cls = Object) {
|
|
550
|
+
return class _AttributeHolder extends cls {
|
|
551
|
+
[util.inspect.custom]() {
|
|
552
|
+
let type_name = this.constructor.name;
|
|
553
|
+
let arg_strings = [];
|
|
554
|
+
let star_args = {};
|
|
555
|
+
for (let arg of this._get_args()) {
|
|
556
|
+
arg_strings.push(repr(arg));
|
|
557
|
+
}
|
|
558
|
+
for (let [name, value] of this._get_kwargs()) {
|
|
559
|
+
if (/^[a-z_][a-z0-9_$]*$/i.test(name)) {
|
|
560
|
+
arg_strings.push(sub("%s=%r", name, value));
|
|
561
|
+
} else {
|
|
562
|
+
star_args[name] = value;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (Object.keys(star_args).length) {
|
|
566
|
+
arg_strings.push(sub("**%s", repr(star_args)));
|
|
567
|
+
}
|
|
568
|
+
return sub("%s(%s)", type_name, arg_strings.join(", "));
|
|
569
|
+
}
|
|
570
|
+
toString() {
|
|
571
|
+
return this[util.inspect.custom]();
|
|
572
|
+
}
|
|
573
|
+
_get_kwargs() {
|
|
574
|
+
return Object.entries(this);
|
|
575
|
+
}
|
|
576
|
+
_get_args() {
|
|
577
|
+
return [];
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function _copy_items(items) {
|
|
582
|
+
if (items === void 0) {
|
|
583
|
+
return [];
|
|
584
|
+
}
|
|
585
|
+
return items.slice(0);
|
|
586
|
+
}
|
|
587
|
+
var HelpFormatter = _camelcase_alias(_callable(class HelpFormatter {
|
|
588
|
+
constructor() {
|
|
589
|
+
let [
|
|
590
|
+
prog,
|
|
591
|
+
indent_increment,
|
|
592
|
+
max_help_position,
|
|
593
|
+
width
|
|
594
|
+
] = _parse_opts(arguments, {
|
|
595
|
+
prog: no_default,
|
|
596
|
+
indent_increment: 2,
|
|
597
|
+
max_help_position: 24,
|
|
598
|
+
width: void 0
|
|
599
|
+
});
|
|
600
|
+
if (width === void 0) {
|
|
601
|
+
width = get_terminal_size().columns;
|
|
602
|
+
width -= 2;
|
|
603
|
+
}
|
|
604
|
+
this._prog = prog;
|
|
605
|
+
this._indent_increment = indent_increment;
|
|
606
|
+
this._max_help_position = Math.min(max_help_position, Math.max(width - 20, indent_increment * 2));
|
|
607
|
+
this._width = width;
|
|
608
|
+
this._current_indent = 0;
|
|
609
|
+
this._level = 0;
|
|
610
|
+
this._action_max_length = 0;
|
|
611
|
+
this._root_section = this._Section(this, void 0);
|
|
612
|
+
this._current_section = this._root_section;
|
|
613
|
+
this._whitespace_matcher = /[ \t\n\r\f\v]+/g;
|
|
614
|
+
this._long_break_matcher = /\n\n\n+/g;
|
|
615
|
+
}
|
|
616
|
+
_indent() {
|
|
617
|
+
this._current_indent += this._indent_increment;
|
|
618
|
+
this._level += 1;
|
|
619
|
+
}
|
|
620
|
+
_dedent() {
|
|
621
|
+
this._current_indent -= this._indent_increment;
|
|
622
|
+
assert(this._current_indent >= 0, "Indent decreased below 0.");
|
|
623
|
+
this._level -= 1;
|
|
624
|
+
}
|
|
625
|
+
_add_item(func, args) {
|
|
626
|
+
this._current_section.items.push([func, args]);
|
|
627
|
+
}
|
|
628
|
+
start_section(heading) {
|
|
629
|
+
this._indent();
|
|
630
|
+
let section = this._Section(this, this._current_section, heading);
|
|
631
|
+
this._add_item(section.format_help.bind(section), []);
|
|
632
|
+
this._current_section = section;
|
|
633
|
+
}
|
|
634
|
+
end_section() {
|
|
635
|
+
this._current_section = this._current_section.parent;
|
|
636
|
+
this._dedent();
|
|
637
|
+
}
|
|
638
|
+
add_text(text) {
|
|
639
|
+
if (text !== SUPPRESS && text !== void 0) {
|
|
640
|
+
this._add_item(this._format_text.bind(this), [text]);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
add_usage(usage, actions, groups, prefix = void 0) {
|
|
644
|
+
if (usage !== SUPPRESS) {
|
|
645
|
+
let args = [usage, actions, groups, prefix];
|
|
646
|
+
this._add_item(this._format_usage.bind(this), args);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
add_argument(action) {
|
|
650
|
+
if (action.help !== SUPPRESS) {
|
|
651
|
+
let invocations = [this._format_action_invocation(action)];
|
|
652
|
+
for (let subaction of this._iter_indented_subactions(action)) {
|
|
653
|
+
invocations.push(this._format_action_invocation(subaction));
|
|
654
|
+
}
|
|
655
|
+
let invocation_length = Math.max(...invocations.map((invocation) => invocation.length));
|
|
656
|
+
let action_length = invocation_length + this._current_indent;
|
|
657
|
+
this._action_max_length = Math.max(this._action_max_length, action_length);
|
|
658
|
+
this._add_item(this._format_action.bind(this), [action]);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
add_arguments(actions) {
|
|
662
|
+
for (let action of actions) {
|
|
663
|
+
this.add_argument(action);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
format_help() {
|
|
667
|
+
let help = this._root_section.format_help();
|
|
668
|
+
if (help) {
|
|
669
|
+
help = help.replace(this._long_break_matcher, "\n\n");
|
|
670
|
+
help = help.replace(/^\n+|\n+$/g, "") + "\n";
|
|
671
|
+
}
|
|
672
|
+
return help;
|
|
673
|
+
}
|
|
674
|
+
_join_parts(part_strings) {
|
|
675
|
+
return part_strings.filter((part) => part && part !== SUPPRESS).join("");
|
|
676
|
+
}
|
|
677
|
+
_format_usage(usage, actions, groups, prefix) {
|
|
678
|
+
if (prefix === void 0) {
|
|
679
|
+
prefix = "usage: ";
|
|
680
|
+
}
|
|
681
|
+
if (usage !== void 0) {
|
|
682
|
+
usage = sub(usage, { prog: this._prog });
|
|
683
|
+
} else if (usage === void 0 && !actions.length) {
|
|
684
|
+
usage = sub("%(prog)s", { prog: this._prog });
|
|
685
|
+
} else if (usage === void 0) {
|
|
686
|
+
let prog = sub("%(prog)s", { prog: this._prog });
|
|
687
|
+
let optionals = [];
|
|
688
|
+
let positionals = [];
|
|
689
|
+
for (let action of actions) {
|
|
690
|
+
if (action.option_strings.length) {
|
|
691
|
+
optionals.push(action);
|
|
692
|
+
} else {
|
|
693
|
+
positionals.push(action);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
let action_usage = this._format_actions_usage([].concat(optionals).concat(positionals), groups);
|
|
697
|
+
usage = [prog, action_usage].map(String).join(" ");
|
|
698
|
+
let text_width = this._width - this._current_indent;
|
|
699
|
+
if (prefix.length + usage.length > text_width) {
|
|
700
|
+
let part_regexp = /\(.*?\)+(?=\s|$)|\[.*?\]+(?=\s|$)|\S+/g;
|
|
701
|
+
let opt_usage = this._format_actions_usage(optionals, groups);
|
|
702
|
+
let pos_usage = this._format_actions_usage(positionals, groups);
|
|
703
|
+
let opt_parts = opt_usage.match(part_regexp) || [];
|
|
704
|
+
let pos_parts = pos_usage.match(part_regexp) || [];
|
|
705
|
+
assert(opt_parts.join(" ") === opt_usage);
|
|
706
|
+
assert(pos_parts.join(" ") === pos_usage);
|
|
707
|
+
let get_lines = (parts, indent, prefix2 = void 0) => {
|
|
708
|
+
let lines2 = [];
|
|
709
|
+
let line = [];
|
|
710
|
+
let line_len;
|
|
711
|
+
if (prefix2 !== void 0) {
|
|
712
|
+
line_len = prefix2.length - 1;
|
|
713
|
+
} else {
|
|
714
|
+
line_len = indent.length - 1;
|
|
715
|
+
}
|
|
716
|
+
for (let part of parts) {
|
|
717
|
+
if (line_len + 1 + part.length > text_width && line) {
|
|
718
|
+
lines2.push(indent + line.join(" "));
|
|
719
|
+
line = [];
|
|
720
|
+
line_len = indent.length - 1;
|
|
721
|
+
}
|
|
722
|
+
line.push(part);
|
|
723
|
+
line_len += part.length + 1;
|
|
724
|
+
}
|
|
725
|
+
if (line.length) {
|
|
726
|
+
lines2.push(indent + line.join(" "));
|
|
727
|
+
}
|
|
728
|
+
if (prefix2 !== void 0) {
|
|
729
|
+
lines2[0] = lines2[0].slice(indent.length);
|
|
730
|
+
}
|
|
731
|
+
return lines2;
|
|
732
|
+
};
|
|
733
|
+
let lines;
|
|
734
|
+
if (prefix.length + prog.length <= 0.75 * text_width) {
|
|
735
|
+
let indent = " ".repeat(prefix.length + prog.length + 1);
|
|
736
|
+
if (opt_parts.length) {
|
|
737
|
+
lines = get_lines([prog].concat(opt_parts), indent, prefix);
|
|
738
|
+
lines = lines.concat(get_lines(pos_parts, indent));
|
|
739
|
+
} else if (pos_parts.length) {
|
|
740
|
+
lines = get_lines([prog].concat(pos_parts), indent, prefix);
|
|
741
|
+
} else {
|
|
742
|
+
lines = [prog];
|
|
743
|
+
}
|
|
744
|
+
} else {
|
|
745
|
+
let indent = " ".repeat(prefix.length);
|
|
746
|
+
let parts = [].concat(opt_parts).concat(pos_parts);
|
|
747
|
+
lines = get_lines(parts, indent);
|
|
748
|
+
if (lines.length > 1) {
|
|
749
|
+
lines = [];
|
|
750
|
+
lines = lines.concat(get_lines(opt_parts, indent));
|
|
751
|
+
lines = lines.concat(get_lines(pos_parts, indent));
|
|
752
|
+
}
|
|
753
|
+
lines = [prog].concat(lines);
|
|
754
|
+
}
|
|
755
|
+
usage = lines.join("\n");
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
return sub("%s%s\n\n", prefix, usage);
|
|
759
|
+
}
|
|
760
|
+
_format_actions_usage(actions, groups) {
|
|
761
|
+
let group_actions = /* @__PURE__ */ new Set();
|
|
762
|
+
let inserts = {};
|
|
763
|
+
for (let group of groups) {
|
|
764
|
+
let start = actions.indexOf(group._group_actions[0]);
|
|
765
|
+
if (start === -1) {
|
|
766
|
+
continue;
|
|
767
|
+
} else {
|
|
768
|
+
let end = start + group._group_actions.length;
|
|
769
|
+
if (_array_equal(actions.slice(start, end), group._group_actions)) {
|
|
770
|
+
for (let action of group._group_actions) {
|
|
771
|
+
group_actions.add(action);
|
|
772
|
+
}
|
|
773
|
+
if (!group.required) {
|
|
774
|
+
if (start in inserts) {
|
|
775
|
+
inserts[start] += " [";
|
|
776
|
+
} else {
|
|
777
|
+
inserts[start] = "[";
|
|
778
|
+
}
|
|
779
|
+
if (end in inserts) {
|
|
780
|
+
inserts[end] += "]";
|
|
781
|
+
} else {
|
|
782
|
+
inserts[end] = "]";
|
|
783
|
+
}
|
|
784
|
+
} else {
|
|
785
|
+
if (start in inserts) {
|
|
786
|
+
inserts[start] += " (";
|
|
787
|
+
} else {
|
|
788
|
+
inserts[start] = "(";
|
|
789
|
+
}
|
|
790
|
+
if (end in inserts) {
|
|
791
|
+
inserts[end] += ")";
|
|
792
|
+
} else {
|
|
793
|
+
inserts[end] = ")";
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
for (let i of range(start + 1, end)) {
|
|
797
|
+
inserts[i] = "|";
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
let parts = [];
|
|
803
|
+
for (let [i, action] of Object.entries(actions)) {
|
|
804
|
+
if (action.help === SUPPRESS) {
|
|
805
|
+
parts.push(void 0);
|
|
806
|
+
if (inserts[+i] === "|") {
|
|
807
|
+
delete inserts[+i];
|
|
808
|
+
} else if (inserts[+i + 1] === "|") {
|
|
809
|
+
delete inserts[+i + 1];
|
|
810
|
+
}
|
|
811
|
+
} else if (!action.option_strings.length) {
|
|
812
|
+
let default_value = this._get_default_metavar_for_positional(action);
|
|
813
|
+
let part = this._format_args(action, default_value);
|
|
814
|
+
if (group_actions.has(action)) {
|
|
815
|
+
if (part[0] === "[" && part[part.length - 1] === "]") {
|
|
816
|
+
part = part.slice(1, -1);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
parts.push(part);
|
|
820
|
+
} else {
|
|
821
|
+
let option_string = action.option_strings[0];
|
|
822
|
+
let part;
|
|
823
|
+
if (action.nargs === 0) {
|
|
824
|
+
part = action.format_usage();
|
|
825
|
+
} else {
|
|
826
|
+
let default_value = this._get_default_metavar_for_optional(action);
|
|
827
|
+
let args_string = this._format_args(action, default_value);
|
|
828
|
+
part = sub("%s %s", option_string, args_string);
|
|
829
|
+
}
|
|
830
|
+
if (!action.required && !group_actions.has(action)) {
|
|
831
|
+
part = sub("[%s]", part);
|
|
832
|
+
}
|
|
833
|
+
parts.push(part);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
for (let i of Object.keys(inserts).map(Number).sort((a, b) => b - a)) {
|
|
837
|
+
parts.splice(+i, 0, inserts[+i]);
|
|
838
|
+
}
|
|
839
|
+
let text = parts.filter(Boolean).join(" ");
|
|
840
|
+
text = text.replace(/([\[(]) /g, "$1");
|
|
841
|
+
text = text.replace(/ ([\])])/g, "$1");
|
|
842
|
+
text = text.replace(/[\[(] *[\])]/g, "");
|
|
843
|
+
text = text.replace(/\(([^|]*)\)/g, "$1", text);
|
|
844
|
+
text = text.trim();
|
|
845
|
+
return text;
|
|
846
|
+
}
|
|
847
|
+
_format_text(text) {
|
|
848
|
+
if (text.includes("%(prog)")) {
|
|
849
|
+
text = sub(text, { prog: this._prog });
|
|
850
|
+
}
|
|
851
|
+
let text_width = Math.max(this._width - this._current_indent, 11);
|
|
852
|
+
let indent = " ".repeat(this._current_indent);
|
|
853
|
+
return this._fill_text(text, text_width, indent) + "\n\n";
|
|
854
|
+
}
|
|
855
|
+
_format_action(action) {
|
|
856
|
+
let help_position = Math.min(this._action_max_length + 2, this._max_help_position);
|
|
857
|
+
let help_width = Math.max(this._width - help_position, 11);
|
|
858
|
+
let action_width = help_position - this._current_indent - 2;
|
|
859
|
+
let action_header = this._format_action_invocation(action);
|
|
860
|
+
let indent_first;
|
|
861
|
+
if (!action.help) {
|
|
862
|
+
let tup = [this._current_indent, "", action_header];
|
|
863
|
+
action_header = sub("%*s%s\n", ...tup);
|
|
864
|
+
} else if (action_header.length <= action_width) {
|
|
865
|
+
let tup = [this._current_indent, "", action_width, action_header];
|
|
866
|
+
action_header = sub("%*s%-*s ", ...tup);
|
|
867
|
+
indent_first = 0;
|
|
868
|
+
} else {
|
|
869
|
+
let tup = [this._current_indent, "", action_header];
|
|
870
|
+
action_header = sub("%*s%s\n", ...tup);
|
|
871
|
+
indent_first = help_position;
|
|
872
|
+
}
|
|
873
|
+
let parts = [action_header];
|
|
874
|
+
if (action.help) {
|
|
875
|
+
let help_text = this._expand_help(action);
|
|
876
|
+
let help_lines = this._split_lines(help_text, help_width);
|
|
877
|
+
parts.push(sub("%*s%s\n", indent_first, "", help_lines[0]));
|
|
878
|
+
for (let line of help_lines.slice(1)) {
|
|
879
|
+
parts.push(sub("%*s%s\n", help_position, "", line));
|
|
880
|
+
}
|
|
881
|
+
} else if (!action_header.endsWith("\n")) {
|
|
882
|
+
parts.push("\n");
|
|
883
|
+
}
|
|
884
|
+
for (let subaction of this._iter_indented_subactions(action)) {
|
|
885
|
+
parts.push(this._format_action(subaction));
|
|
886
|
+
}
|
|
887
|
+
return this._join_parts(parts);
|
|
888
|
+
}
|
|
889
|
+
_format_action_invocation(action) {
|
|
890
|
+
if (!action.option_strings.length) {
|
|
891
|
+
let default_value = this._get_default_metavar_for_positional(action);
|
|
892
|
+
let metavar = this._metavar_formatter(action, default_value)(1)[0];
|
|
893
|
+
return metavar;
|
|
894
|
+
} else {
|
|
895
|
+
let parts = [];
|
|
896
|
+
if (action.nargs === 0) {
|
|
897
|
+
parts = parts.concat(action.option_strings);
|
|
898
|
+
} else {
|
|
899
|
+
let default_value = this._get_default_metavar_for_optional(action);
|
|
900
|
+
let args_string = this._format_args(action, default_value);
|
|
901
|
+
for (let option_string of action.option_strings) {
|
|
902
|
+
parts.push(sub("%s %s", option_string, args_string));
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
return parts.join(", ");
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
_metavar_formatter(action, default_metavar) {
|
|
909
|
+
let result;
|
|
910
|
+
if (action.metavar !== void 0) {
|
|
911
|
+
result = action.metavar;
|
|
912
|
+
} else if (action.choices !== void 0) {
|
|
913
|
+
let choice_strs = _choices_to_array(action.choices).map(String);
|
|
914
|
+
result = sub("{%s}", choice_strs.join(","));
|
|
915
|
+
} else {
|
|
916
|
+
result = default_metavar;
|
|
917
|
+
}
|
|
918
|
+
function format(tuple_size) {
|
|
919
|
+
if (Array.isArray(result)) {
|
|
920
|
+
return result;
|
|
921
|
+
} else {
|
|
922
|
+
return Array(tuple_size).fill(result);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return format;
|
|
926
|
+
}
|
|
927
|
+
_format_args(action, default_metavar) {
|
|
928
|
+
let get_metavar = this._metavar_formatter(action, default_metavar);
|
|
929
|
+
let result;
|
|
930
|
+
if (action.nargs === void 0) {
|
|
931
|
+
result = sub("%s", ...get_metavar(1));
|
|
932
|
+
} else if (action.nargs === OPTIONAL) {
|
|
933
|
+
result = sub("[%s]", ...get_metavar(1));
|
|
934
|
+
} else if (action.nargs === ZERO_OR_MORE) {
|
|
935
|
+
let metavar = get_metavar(1);
|
|
936
|
+
if (metavar.length === 2) {
|
|
937
|
+
result = sub("[%s [%s ...]]", ...metavar);
|
|
938
|
+
} else {
|
|
939
|
+
result = sub("[%s ...]", ...metavar);
|
|
940
|
+
}
|
|
941
|
+
} else if (action.nargs === ONE_OR_MORE) {
|
|
942
|
+
result = sub("%s [%s ...]", ...get_metavar(2));
|
|
943
|
+
} else if (action.nargs === REMAINDER) {
|
|
944
|
+
result = "...";
|
|
945
|
+
} else if (action.nargs === PARSER) {
|
|
946
|
+
result = sub("%s ...", ...get_metavar(1));
|
|
947
|
+
} else if (action.nargs === SUPPRESS) {
|
|
948
|
+
result = "";
|
|
949
|
+
} else {
|
|
950
|
+
let formats;
|
|
951
|
+
try {
|
|
952
|
+
formats = range(action.nargs).map(() => "%s");
|
|
953
|
+
} catch (err) {
|
|
954
|
+
throw new TypeError("invalid nargs value");
|
|
955
|
+
}
|
|
956
|
+
result = sub(formats.join(" "), ...get_metavar(action.nargs));
|
|
957
|
+
}
|
|
958
|
+
return result;
|
|
959
|
+
}
|
|
960
|
+
_expand_help(action) {
|
|
961
|
+
let params = Object.assign({ prog: this._prog }, action);
|
|
962
|
+
for (let name of Object.keys(params)) {
|
|
963
|
+
if (params[name] === SUPPRESS) {
|
|
964
|
+
delete params[name];
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
for (let name of Object.keys(params)) {
|
|
968
|
+
if (params[name] && params[name].name) {
|
|
969
|
+
params[name] = params[name].name;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
if (params.choices !== void 0) {
|
|
973
|
+
let choices_str = _choices_to_array(params.choices).map(String).join(", ");
|
|
974
|
+
params.choices = choices_str;
|
|
975
|
+
}
|
|
976
|
+
for (let key of Object.keys(params)) {
|
|
977
|
+
let old_name = _to_legacy_name(key);
|
|
978
|
+
if (old_name !== key) {
|
|
979
|
+
params[old_name] = params[key];
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return sub(this._get_help_string(action), params);
|
|
983
|
+
}
|
|
984
|
+
*_iter_indented_subactions(action) {
|
|
985
|
+
if (typeof action._get_subactions === "function") {
|
|
986
|
+
this._indent();
|
|
987
|
+
yield* action._get_subactions();
|
|
988
|
+
this._dedent();
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
_split_lines(text, width) {
|
|
992
|
+
text = text.replace(this._whitespace_matcher, " ").trim();
|
|
993
|
+
let textwrap = require_textwrap();
|
|
994
|
+
return textwrap.wrap(text, { width });
|
|
995
|
+
}
|
|
996
|
+
_fill_text(text, width, indent) {
|
|
997
|
+
text = text.replace(this._whitespace_matcher, " ").trim();
|
|
998
|
+
let textwrap = require_textwrap();
|
|
999
|
+
return textwrap.fill(text, {
|
|
1000
|
+
width,
|
|
1001
|
+
initial_indent: indent,
|
|
1002
|
+
subsequent_indent: indent
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
_get_help_string(action) {
|
|
1006
|
+
return action.help;
|
|
1007
|
+
}
|
|
1008
|
+
_get_default_metavar_for_optional(action) {
|
|
1009
|
+
return action.dest.toUpperCase();
|
|
1010
|
+
}
|
|
1011
|
+
_get_default_metavar_for_positional(action) {
|
|
1012
|
+
return action.dest;
|
|
1013
|
+
}
|
|
1014
|
+
}));
|
|
1015
|
+
HelpFormatter.prototype._Section = _callable(class _Section {
|
|
1016
|
+
constructor(formatter, parent, heading = void 0) {
|
|
1017
|
+
this.formatter = formatter;
|
|
1018
|
+
this.parent = parent;
|
|
1019
|
+
this.heading = heading;
|
|
1020
|
+
this.items = [];
|
|
1021
|
+
}
|
|
1022
|
+
format_help() {
|
|
1023
|
+
if (this.parent !== void 0) {
|
|
1024
|
+
this.formatter._indent();
|
|
1025
|
+
}
|
|
1026
|
+
let item_help = this.formatter._join_parts(this.items.map(([func, args]) => func.apply(null, args)));
|
|
1027
|
+
if (this.parent !== void 0) {
|
|
1028
|
+
this.formatter._dedent();
|
|
1029
|
+
}
|
|
1030
|
+
if (!item_help) {
|
|
1031
|
+
return "";
|
|
1032
|
+
}
|
|
1033
|
+
let heading;
|
|
1034
|
+
if (this.heading !== SUPPRESS && this.heading !== void 0) {
|
|
1035
|
+
let current_indent = this.formatter._current_indent;
|
|
1036
|
+
heading = sub("%*s%s:\n", current_indent, "", this.heading);
|
|
1037
|
+
} else {
|
|
1038
|
+
heading = "";
|
|
1039
|
+
}
|
|
1040
|
+
return this.formatter._join_parts(["\n", heading, item_help, "\n"]);
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
var RawDescriptionHelpFormatter = _camelcase_alias(_callable(class RawDescriptionHelpFormatter extends HelpFormatter {
|
|
1044
|
+
_fill_text(text, width, indent) {
|
|
1045
|
+
return splitlines(text, true).map((line) => indent + line).join("");
|
|
1046
|
+
}
|
|
1047
|
+
}));
|
|
1048
|
+
var RawTextHelpFormatter = _camelcase_alias(_callable(class RawTextHelpFormatter extends RawDescriptionHelpFormatter {
|
|
1049
|
+
_split_lines(text) {
|
|
1050
|
+
return splitlines(text);
|
|
1051
|
+
}
|
|
1052
|
+
}));
|
|
1053
|
+
var ArgumentDefaultsHelpFormatter = _camelcase_alias(_callable(class ArgumentDefaultsHelpFormatter extends HelpFormatter {
|
|
1054
|
+
_get_help_string(action) {
|
|
1055
|
+
let help = action.help;
|
|
1056
|
+
if (!action.help.includes("%(default)") && !action.help.includes("%(defaultValue)")) {
|
|
1057
|
+
if (action.default !== SUPPRESS) {
|
|
1058
|
+
let defaulting_nargs = [OPTIONAL, ZERO_OR_MORE];
|
|
1059
|
+
if (action.option_strings.length || defaulting_nargs.includes(action.nargs)) {
|
|
1060
|
+
help += " (default: %(default)s)";
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return help;
|
|
1065
|
+
}
|
|
1066
|
+
}));
|
|
1067
|
+
var MetavarTypeHelpFormatter = _camelcase_alias(_callable(class MetavarTypeHelpFormatter extends HelpFormatter {
|
|
1068
|
+
_get_default_metavar_for_optional(action) {
|
|
1069
|
+
return typeof action.type === "function" ? action.type.name : action.type;
|
|
1070
|
+
}
|
|
1071
|
+
_get_default_metavar_for_positional(action) {
|
|
1072
|
+
return typeof action.type === "function" ? action.type.name : action.type;
|
|
1073
|
+
}
|
|
1074
|
+
}));
|
|
1075
|
+
function _get_action_name(argument) {
|
|
1076
|
+
if (argument === void 0) {
|
|
1077
|
+
return void 0;
|
|
1078
|
+
} else if (argument.option_strings.length) {
|
|
1079
|
+
return argument.option_strings.join("/");
|
|
1080
|
+
} else if (![void 0, SUPPRESS].includes(argument.metavar)) {
|
|
1081
|
+
return argument.metavar;
|
|
1082
|
+
} else if (![void 0, SUPPRESS].includes(argument.dest)) {
|
|
1083
|
+
return argument.dest;
|
|
1084
|
+
} else {
|
|
1085
|
+
return void 0;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
var ArgumentError = _callable(class ArgumentError extends Error {
|
|
1089
|
+
constructor(argument, message) {
|
|
1090
|
+
super();
|
|
1091
|
+
this.name = "ArgumentError";
|
|
1092
|
+
this._argument_name = _get_action_name(argument);
|
|
1093
|
+
this._message = message;
|
|
1094
|
+
this.message = this.str();
|
|
1095
|
+
}
|
|
1096
|
+
str() {
|
|
1097
|
+
let format;
|
|
1098
|
+
if (this._argument_name === void 0) {
|
|
1099
|
+
format = "%(message)s";
|
|
1100
|
+
} else {
|
|
1101
|
+
format = "argument %(argument_name)s: %(message)s";
|
|
1102
|
+
}
|
|
1103
|
+
return sub(format, {
|
|
1104
|
+
message: this._message,
|
|
1105
|
+
argument_name: this._argument_name
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
var ArgumentTypeError = _callable(class ArgumentTypeError extends Error {
|
|
1110
|
+
constructor(message) {
|
|
1111
|
+
super(message);
|
|
1112
|
+
this.name = "ArgumentTypeError";
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
var Action = _camelcase_alias(_callable(class Action extends _AttributeHolder(Function) {
|
|
1116
|
+
constructor() {
|
|
1117
|
+
let [
|
|
1118
|
+
option_strings,
|
|
1119
|
+
dest,
|
|
1120
|
+
nargs,
|
|
1121
|
+
const_value,
|
|
1122
|
+
default_value,
|
|
1123
|
+
type,
|
|
1124
|
+
choices,
|
|
1125
|
+
required,
|
|
1126
|
+
help,
|
|
1127
|
+
metavar
|
|
1128
|
+
] = _parse_opts(arguments, {
|
|
1129
|
+
option_strings: no_default,
|
|
1130
|
+
dest: no_default,
|
|
1131
|
+
nargs: void 0,
|
|
1132
|
+
const: void 0,
|
|
1133
|
+
default: void 0,
|
|
1134
|
+
type: void 0,
|
|
1135
|
+
choices: void 0,
|
|
1136
|
+
required: false,
|
|
1137
|
+
help: void 0,
|
|
1138
|
+
metavar: void 0
|
|
1139
|
+
});
|
|
1140
|
+
super("return arguments.callee.call.apply(arguments.callee, arguments)");
|
|
1141
|
+
this.option_strings = option_strings;
|
|
1142
|
+
this.dest = dest;
|
|
1143
|
+
this.nargs = nargs;
|
|
1144
|
+
this.const = const_value;
|
|
1145
|
+
this.default = default_value;
|
|
1146
|
+
this.type = type;
|
|
1147
|
+
this.choices = choices;
|
|
1148
|
+
this.required = required;
|
|
1149
|
+
this.help = help;
|
|
1150
|
+
this.metavar = metavar;
|
|
1151
|
+
}
|
|
1152
|
+
_get_kwargs() {
|
|
1153
|
+
let names = [
|
|
1154
|
+
"option_strings",
|
|
1155
|
+
"dest",
|
|
1156
|
+
"nargs",
|
|
1157
|
+
"const",
|
|
1158
|
+
"default",
|
|
1159
|
+
"type",
|
|
1160
|
+
"choices",
|
|
1161
|
+
"help",
|
|
1162
|
+
"metavar"
|
|
1163
|
+
];
|
|
1164
|
+
return names.map((name) => [name, getattr(this, name)]);
|
|
1165
|
+
}
|
|
1166
|
+
format_usage() {
|
|
1167
|
+
return this.option_strings[0];
|
|
1168
|
+
}
|
|
1169
|
+
call() {
|
|
1170
|
+
throw new Error(".call() not defined");
|
|
1171
|
+
}
|
|
1172
|
+
}));
|
|
1173
|
+
var BooleanOptionalAction = _camelcase_alias(_callable(class BooleanOptionalAction extends Action {
|
|
1174
|
+
constructor() {
|
|
1175
|
+
let [
|
|
1176
|
+
option_strings,
|
|
1177
|
+
dest,
|
|
1178
|
+
default_value,
|
|
1179
|
+
type,
|
|
1180
|
+
choices,
|
|
1181
|
+
required,
|
|
1182
|
+
help,
|
|
1183
|
+
metavar
|
|
1184
|
+
] = _parse_opts(arguments, {
|
|
1185
|
+
option_strings: no_default,
|
|
1186
|
+
dest: no_default,
|
|
1187
|
+
default: void 0,
|
|
1188
|
+
type: void 0,
|
|
1189
|
+
choices: void 0,
|
|
1190
|
+
required: false,
|
|
1191
|
+
help: void 0,
|
|
1192
|
+
metavar: void 0
|
|
1193
|
+
});
|
|
1194
|
+
let _option_strings = [];
|
|
1195
|
+
for (let option_string of option_strings) {
|
|
1196
|
+
_option_strings.push(option_string);
|
|
1197
|
+
if (option_string.startsWith("--")) {
|
|
1198
|
+
option_string = "--no-" + option_string.slice(2);
|
|
1199
|
+
_option_strings.push(option_string);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
if (help !== void 0 && default_value !== void 0) {
|
|
1203
|
+
help += ` (default: ${default_value})`;
|
|
1204
|
+
}
|
|
1205
|
+
super({
|
|
1206
|
+
option_strings: _option_strings,
|
|
1207
|
+
dest,
|
|
1208
|
+
nargs: 0,
|
|
1209
|
+
default: default_value,
|
|
1210
|
+
type,
|
|
1211
|
+
choices,
|
|
1212
|
+
required,
|
|
1213
|
+
help,
|
|
1214
|
+
metavar
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
call(parser, namespace, values, option_string = void 0) {
|
|
1218
|
+
if (this.option_strings.includes(option_string)) {
|
|
1219
|
+
setattr(namespace, this.dest, !option_string.startsWith("--no-"));
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
format_usage() {
|
|
1223
|
+
return this.option_strings.join(" | ");
|
|
1224
|
+
}
|
|
1225
|
+
}));
|
|
1226
|
+
var _StoreAction = _callable(class _StoreAction extends Action {
|
|
1227
|
+
constructor() {
|
|
1228
|
+
let [
|
|
1229
|
+
option_strings,
|
|
1230
|
+
dest,
|
|
1231
|
+
nargs,
|
|
1232
|
+
const_value,
|
|
1233
|
+
default_value,
|
|
1234
|
+
type,
|
|
1235
|
+
choices,
|
|
1236
|
+
required,
|
|
1237
|
+
help,
|
|
1238
|
+
metavar
|
|
1239
|
+
] = _parse_opts(arguments, {
|
|
1240
|
+
option_strings: no_default,
|
|
1241
|
+
dest: no_default,
|
|
1242
|
+
nargs: void 0,
|
|
1243
|
+
const: void 0,
|
|
1244
|
+
default: void 0,
|
|
1245
|
+
type: void 0,
|
|
1246
|
+
choices: void 0,
|
|
1247
|
+
required: false,
|
|
1248
|
+
help: void 0,
|
|
1249
|
+
metavar: void 0
|
|
1250
|
+
});
|
|
1251
|
+
if (nargs === 0) {
|
|
1252
|
+
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");
|
|
1253
|
+
}
|
|
1254
|
+
if (const_value !== void 0 && nargs !== OPTIONAL) {
|
|
1255
|
+
throw new TypeError(sub("nargs must be %r to supply const", OPTIONAL));
|
|
1256
|
+
}
|
|
1257
|
+
super({
|
|
1258
|
+
option_strings,
|
|
1259
|
+
dest,
|
|
1260
|
+
nargs,
|
|
1261
|
+
const: const_value,
|
|
1262
|
+
default: default_value,
|
|
1263
|
+
type,
|
|
1264
|
+
choices,
|
|
1265
|
+
required,
|
|
1266
|
+
help,
|
|
1267
|
+
metavar
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
call(parser, namespace, values) {
|
|
1271
|
+
setattr(namespace, this.dest, values);
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
var _StoreConstAction = _callable(class _StoreConstAction extends Action {
|
|
1275
|
+
constructor() {
|
|
1276
|
+
let [
|
|
1277
|
+
option_strings,
|
|
1278
|
+
dest,
|
|
1279
|
+
const_value,
|
|
1280
|
+
default_value,
|
|
1281
|
+
required,
|
|
1282
|
+
help
|
|
1283
|
+
] = _parse_opts(arguments, {
|
|
1284
|
+
option_strings: no_default,
|
|
1285
|
+
dest: no_default,
|
|
1286
|
+
const: no_default,
|
|
1287
|
+
default: void 0,
|
|
1288
|
+
required: false,
|
|
1289
|
+
help: void 0,
|
|
1290
|
+
metavar: void 0
|
|
1291
|
+
});
|
|
1292
|
+
super({
|
|
1293
|
+
option_strings,
|
|
1294
|
+
dest,
|
|
1295
|
+
nargs: 0,
|
|
1296
|
+
const: const_value,
|
|
1297
|
+
default: default_value,
|
|
1298
|
+
required,
|
|
1299
|
+
help
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
call(parser, namespace) {
|
|
1303
|
+
setattr(namespace, this.dest, this.const);
|
|
1304
|
+
}
|
|
1305
|
+
});
|
|
1306
|
+
var _StoreTrueAction = _callable(class _StoreTrueAction extends _StoreConstAction {
|
|
1307
|
+
constructor() {
|
|
1308
|
+
let [
|
|
1309
|
+
option_strings,
|
|
1310
|
+
dest,
|
|
1311
|
+
default_value,
|
|
1312
|
+
required,
|
|
1313
|
+
help
|
|
1314
|
+
] = _parse_opts(arguments, {
|
|
1315
|
+
option_strings: no_default,
|
|
1316
|
+
dest: no_default,
|
|
1317
|
+
default: false,
|
|
1318
|
+
required: false,
|
|
1319
|
+
help: void 0
|
|
1320
|
+
});
|
|
1321
|
+
super({
|
|
1322
|
+
option_strings,
|
|
1323
|
+
dest,
|
|
1324
|
+
const: true,
|
|
1325
|
+
default: default_value,
|
|
1326
|
+
required,
|
|
1327
|
+
help
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
var _StoreFalseAction = _callable(class _StoreFalseAction extends _StoreConstAction {
|
|
1332
|
+
constructor() {
|
|
1333
|
+
let [
|
|
1334
|
+
option_strings,
|
|
1335
|
+
dest,
|
|
1336
|
+
default_value,
|
|
1337
|
+
required,
|
|
1338
|
+
help
|
|
1339
|
+
] = _parse_opts(arguments, {
|
|
1340
|
+
option_strings: no_default,
|
|
1341
|
+
dest: no_default,
|
|
1342
|
+
default: true,
|
|
1343
|
+
required: false,
|
|
1344
|
+
help: void 0
|
|
1345
|
+
});
|
|
1346
|
+
super({
|
|
1347
|
+
option_strings,
|
|
1348
|
+
dest,
|
|
1349
|
+
const: false,
|
|
1350
|
+
default: default_value,
|
|
1351
|
+
required,
|
|
1352
|
+
help
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1356
|
+
var _AppendAction = _callable(class _AppendAction extends Action {
|
|
1357
|
+
constructor() {
|
|
1358
|
+
let [
|
|
1359
|
+
option_strings,
|
|
1360
|
+
dest,
|
|
1361
|
+
nargs,
|
|
1362
|
+
const_value,
|
|
1363
|
+
default_value,
|
|
1364
|
+
type,
|
|
1365
|
+
choices,
|
|
1366
|
+
required,
|
|
1367
|
+
help,
|
|
1368
|
+
metavar
|
|
1369
|
+
] = _parse_opts(arguments, {
|
|
1370
|
+
option_strings: no_default,
|
|
1371
|
+
dest: no_default,
|
|
1372
|
+
nargs: void 0,
|
|
1373
|
+
const: void 0,
|
|
1374
|
+
default: void 0,
|
|
1375
|
+
type: void 0,
|
|
1376
|
+
choices: void 0,
|
|
1377
|
+
required: false,
|
|
1378
|
+
help: void 0,
|
|
1379
|
+
metavar: void 0
|
|
1380
|
+
});
|
|
1381
|
+
if (nargs === 0) {
|
|
1382
|
+
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");
|
|
1383
|
+
}
|
|
1384
|
+
if (const_value !== void 0 && nargs !== OPTIONAL) {
|
|
1385
|
+
throw new TypeError(sub("nargs must be %r to supply const", OPTIONAL));
|
|
1386
|
+
}
|
|
1387
|
+
super({
|
|
1388
|
+
option_strings,
|
|
1389
|
+
dest,
|
|
1390
|
+
nargs,
|
|
1391
|
+
const: const_value,
|
|
1392
|
+
default: default_value,
|
|
1393
|
+
type,
|
|
1394
|
+
choices,
|
|
1395
|
+
required,
|
|
1396
|
+
help,
|
|
1397
|
+
metavar
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
call(parser, namespace, values) {
|
|
1401
|
+
let items = getattr(namespace, this.dest, void 0);
|
|
1402
|
+
items = _copy_items(items);
|
|
1403
|
+
items.push(values);
|
|
1404
|
+
setattr(namespace, this.dest, items);
|
|
1405
|
+
}
|
|
1406
|
+
});
|
|
1407
|
+
var _AppendConstAction = _callable(class _AppendConstAction extends Action {
|
|
1408
|
+
constructor() {
|
|
1409
|
+
let [
|
|
1410
|
+
option_strings,
|
|
1411
|
+
dest,
|
|
1412
|
+
const_value,
|
|
1413
|
+
default_value,
|
|
1414
|
+
required,
|
|
1415
|
+
help,
|
|
1416
|
+
metavar
|
|
1417
|
+
] = _parse_opts(arguments, {
|
|
1418
|
+
option_strings: no_default,
|
|
1419
|
+
dest: no_default,
|
|
1420
|
+
const: no_default,
|
|
1421
|
+
default: void 0,
|
|
1422
|
+
required: false,
|
|
1423
|
+
help: void 0,
|
|
1424
|
+
metavar: void 0
|
|
1425
|
+
});
|
|
1426
|
+
super({
|
|
1427
|
+
option_strings,
|
|
1428
|
+
dest,
|
|
1429
|
+
nargs: 0,
|
|
1430
|
+
const: const_value,
|
|
1431
|
+
default: default_value,
|
|
1432
|
+
required,
|
|
1433
|
+
help,
|
|
1434
|
+
metavar
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
call(parser, namespace) {
|
|
1438
|
+
let items = getattr(namespace, this.dest, void 0);
|
|
1439
|
+
items = _copy_items(items);
|
|
1440
|
+
items.push(this.const);
|
|
1441
|
+
setattr(namespace, this.dest, items);
|
|
1442
|
+
}
|
|
1443
|
+
});
|
|
1444
|
+
var _CountAction = _callable(class _CountAction extends Action {
|
|
1445
|
+
constructor() {
|
|
1446
|
+
let [
|
|
1447
|
+
option_strings,
|
|
1448
|
+
dest,
|
|
1449
|
+
default_value,
|
|
1450
|
+
required,
|
|
1451
|
+
help
|
|
1452
|
+
] = _parse_opts(arguments, {
|
|
1453
|
+
option_strings: no_default,
|
|
1454
|
+
dest: no_default,
|
|
1455
|
+
default: void 0,
|
|
1456
|
+
required: false,
|
|
1457
|
+
help: void 0
|
|
1458
|
+
});
|
|
1459
|
+
super({
|
|
1460
|
+
option_strings,
|
|
1461
|
+
dest,
|
|
1462
|
+
nargs: 0,
|
|
1463
|
+
default: default_value,
|
|
1464
|
+
required,
|
|
1465
|
+
help
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
call(parser, namespace) {
|
|
1469
|
+
let count = getattr(namespace, this.dest, void 0);
|
|
1470
|
+
if (count === void 0) {
|
|
1471
|
+
count = 0;
|
|
1472
|
+
}
|
|
1473
|
+
setattr(namespace, this.dest, count + 1);
|
|
1474
|
+
}
|
|
1475
|
+
});
|
|
1476
|
+
var _HelpAction = _callable(class _HelpAction extends Action {
|
|
1477
|
+
constructor() {
|
|
1478
|
+
let [
|
|
1479
|
+
option_strings,
|
|
1480
|
+
dest,
|
|
1481
|
+
default_value,
|
|
1482
|
+
help
|
|
1483
|
+
] = _parse_opts(arguments, {
|
|
1484
|
+
option_strings: no_default,
|
|
1485
|
+
dest: SUPPRESS,
|
|
1486
|
+
default: SUPPRESS,
|
|
1487
|
+
help: void 0
|
|
1488
|
+
});
|
|
1489
|
+
super({
|
|
1490
|
+
option_strings,
|
|
1491
|
+
dest,
|
|
1492
|
+
default: default_value,
|
|
1493
|
+
nargs: 0,
|
|
1494
|
+
help
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
call(parser) {
|
|
1498
|
+
parser.print_help();
|
|
1499
|
+
parser.exit();
|
|
1500
|
+
}
|
|
1501
|
+
});
|
|
1502
|
+
var _VersionAction = _callable(class _VersionAction extends Action {
|
|
1503
|
+
constructor() {
|
|
1504
|
+
let [
|
|
1505
|
+
option_strings,
|
|
1506
|
+
version,
|
|
1507
|
+
dest,
|
|
1508
|
+
default_value,
|
|
1509
|
+
help
|
|
1510
|
+
] = _parse_opts(arguments, {
|
|
1511
|
+
option_strings: no_default,
|
|
1512
|
+
version: void 0,
|
|
1513
|
+
dest: SUPPRESS,
|
|
1514
|
+
default: SUPPRESS,
|
|
1515
|
+
help: "show program's version number and exit"
|
|
1516
|
+
});
|
|
1517
|
+
super({
|
|
1518
|
+
option_strings,
|
|
1519
|
+
dest,
|
|
1520
|
+
default: default_value,
|
|
1521
|
+
nargs: 0,
|
|
1522
|
+
help
|
|
1523
|
+
});
|
|
1524
|
+
this.version = version;
|
|
1525
|
+
}
|
|
1526
|
+
call(parser) {
|
|
1527
|
+
let version = this.version;
|
|
1528
|
+
if (version === void 0) {
|
|
1529
|
+
version = parser.version;
|
|
1530
|
+
}
|
|
1531
|
+
let formatter = parser._get_formatter();
|
|
1532
|
+
formatter.add_text(version);
|
|
1533
|
+
parser._print_message(formatter.format_help(), process.stdout);
|
|
1534
|
+
parser.exit();
|
|
1535
|
+
}
|
|
1536
|
+
});
|
|
1537
|
+
var _SubParsersAction = _camelcase_alias(_callable(class _SubParsersAction extends Action {
|
|
1538
|
+
constructor() {
|
|
1539
|
+
let [
|
|
1540
|
+
option_strings,
|
|
1541
|
+
prog,
|
|
1542
|
+
parser_class,
|
|
1543
|
+
dest,
|
|
1544
|
+
required,
|
|
1545
|
+
help,
|
|
1546
|
+
metavar
|
|
1547
|
+
] = _parse_opts(arguments, {
|
|
1548
|
+
option_strings: no_default,
|
|
1549
|
+
prog: no_default,
|
|
1550
|
+
parser_class: no_default,
|
|
1551
|
+
dest: SUPPRESS,
|
|
1552
|
+
required: false,
|
|
1553
|
+
help: void 0,
|
|
1554
|
+
metavar: void 0
|
|
1555
|
+
});
|
|
1556
|
+
let name_parser_map = {};
|
|
1557
|
+
super({
|
|
1558
|
+
option_strings,
|
|
1559
|
+
dest,
|
|
1560
|
+
nargs: PARSER,
|
|
1561
|
+
choices: name_parser_map,
|
|
1562
|
+
required,
|
|
1563
|
+
help,
|
|
1564
|
+
metavar
|
|
1565
|
+
});
|
|
1566
|
+
this._prog_prefix = prog;
|
|
1567
|
+
this._parser_class = parser_class;
|
|
1568
|
+
this._name_parser_map = name_parser_map;
|
|
1569
|
+
this._choices_actions = [];
|
|
1570
|
+
}
|
|
1571
|
+
add_parser() {
|
|
1572
|
+
let [
|
|
1573
|
+
name,
|
|
1574
|
+
kwargs
|
|
1575
|
+
] = _parse_opts(arguments, {
|
|
1576
|
+
name: no_default,
|
|
1577
|
+
"**kwargs": no_default
|
|
1578
|
+
});
|
|
1579
|
+
if (kwargs.prog === void 0) {
|
|
1580
|
+
kwargs.prog = sub("%s %s", this._prog_prefix, name);
|
|
1581
|
+
}
|
|
1582
|
+
let aliases = getattr(kwargs, "aliases", []);
|
|
1583
|
+
delete kwargs.aliases;
|
|
1584
|
+
if ("help" in kwargs) {
|
|
1585
|
+
let help = kwargs.help;
|
|
1586
|
+
delete kwargs.help;
|
|
1587
|
+
let choice_action = this._ChoicesPseudoAction(name, aliases, help);
|
|
1588
|
+
this._choices_actions.push(choice_action);
|
|
1589
|
+
}
|
|
1590
|
+
let parser = new this._parser_class(kwargs);
|
|
1591
|
+
this._name_parser_map[name] = parser;
|
|
1592
|
+
for (let alias of aliases) {
|
|
1593
|
+
this._name_parser_map[alias] = parser;
|
|
1594
|
+
}
|
|
1595
|
+
return parser;
|
|
1596
|
+
}
|
|
1597
|
+
_get_subactions() {
|
|
1598
|
+
return this._choices_actions;
|
|
1599
|
+
}
|
|
1600
|
+
call(parser, namespace, values) {
|
|
1601
|
+
let parser_name = values[0];
|
|
1602
|
+
let arg_strings = values.slice(1);
|
|
1603
|
+
if (this.dest !== SUPPRESS) {
|
|
1604
|
+
setattr(namespace, this.dest, parser_name);
|
|
1605
|
+
}
|
|
1606
|
+
if (hasattr(this._name_parser_map, parser_name)) {
|
|
1607
|
+
parser = this._name_parser_map[parser_name];
|
|
1608
|
+
} else {
|
|
1609
|
+
let args = {
|
|
1610
|
+
parser_name,
|
|
1611
|
+
choices: this._name_parser_map.join(", ")
|
|
1612
|
+
};
|
|
1613
|
+
let msg = sub("unknown parser %(parser_name)r (choices: %(choices)s)", args);
|
|
1614
|
+
throw new ArgumentError(this, msg);
|
|
1615
|
+
}
|
|
1616
|
+
let subnamespace;
|
|
1617
|
+
[subnamespace, arg_strings] = parser.parse_known_args(arg_strings, void 0);
|
|
1618
|
+
for (let [key, value] of Object.entries(subnamespace)) {
|
|
1619
|
+
setattr(namespace, key, value);
|
|
1620
|
+
}
|
|
1621
|
+
if (arg_strings.length) {
|
|
1622
|
+
setdefault(namespace, _UNRECOGNIZED_ARGS_ATTR, []);
|
|
1623
|
+
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).push(...arg_strings);
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
}));
|
|
1627
|
+
_SubParsersAction.prototype._ChoicesPseudoAction = _callable(class _ChoicesPseudoAction extends Action {
|
|
1628
|
+
constructor(name, aliases, help) {
|
|
1629
|
+
let metavar = name, dest = name;
|
|
1630
|
+
if (aliases.length) {
|
|
1631
|
+
metavar += sub(" (%s)", aliases.join(", "));
|
|
1632
|
+
}
|
|
1633
|
+
super({ option_strings: [], dest, help, metavar });
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
var _ExtendAction = _callable(class _ExtendAction extends _AppendAction {
|
|
1637
|
+
call(parser, namespace, values) {
|
|
1638
|
+
let items = getattr(namespace, this.dest, void 0);
|
|
1639
|
+
items = _copy_items(items);
|
|
1640
|
+
items = items.concat(values);
|
|
1641
|
+
setattr(namespace, this.dest, items);
|
|
1642
|
+
}
|
|
1643
|
+
});
|
|
1644
|
+
var FileType = _callable(class FileType extends Function {
|
|
1645
|
+
constructor() {
|
|
1646
|
+
let [
|
|
1647
|
+
flags,
|
|
1648
|
+
encoding,
|
|
1649
|
+
mode,
|
|
1650
|
+
autoClose,
|
|
1651
|
+
emitClose,
|
|
1652
|
+
start,
|
|
1653
|
+
end,
|
|
1654
|
+
highWaterMark,
|
|
1655
|
+
fs3
|
|
1656
|
+
] = _parse_opts(arguments, {
|
|
1657
|
+
flags: "r",
|
|
1658
|
+
encoding: void 0,
|
|
1659
|
+
mode: void 0,
|
|
1660
|
+
autoClose: void 0,
|
|
1661
|
+
emitClose: void 0,
|
|
1662
|
+
start: void 0,
|
|
1663
|
+
end: void 0,
|
|
1664
|
+
highWaterMark: void 0,
|
|
1665
|
+
fs: void 0
|
|
1666
|
+
});
|
|
1667
|
+
super("return arguments.callee.call.apply(arguments.callee, arguments)");
|
|
1668
|
+
Object.defineProperty(this, "name", {
|
|
1669
|
+
get() {
|
|
1670
|
+
return sub("FileType(%r)", flags);
|
|
1671
|
+
}
|
|
1672
|
+
});
|
|
1673
|
+
this._flags = flags;
|
|
1674
|
+
this._options = {};
|
|
1675
|
+
if (encoding !== void 0)
|
|
1676
|
+
this._options.encoding = encoding;
|
|
1677
|
+
if (mode !== void 0)
|
|
1678
|
+
this._options.mode = mode;
|
|
1679
|
+
if (autoClose !== void 0)
|
|
1680
|
+
this._options.autoClose = autoClose;
|
|
1681
|
+
if (emitClose !== void 0)
|
|
1682
|
+
this._options.emitClose = emitClose;
|
|
1683
|
+
if (start !== void 0)
|
|
1684
|
+
this._options.start = start;
|
|
1685
|
+
if (end !== void 0)
|
|
1686
|
+
this._options.end = end;
|
|
1687
|
+
if (highWaterMark !== void 0)
|
|
1688
|
+
this._options.highWaterMark = highWaterMark;
|
|
1689
|
+
if (fs3 !== void 0)
|
|
1690
|
+
this._options.fs = fs3;
|
|
1691
|
+
}
|
|
1692
|
+
call(string) {
|
|
1693
|
+
if (string === "-") {
|
|
1694
|
+
if (this._flags.includes("r")) {
|
|
1695
|
+
return process.stdin;
|
|
1696
|
+
} else if (this._flags.includes("w")) {
|
|
1697
|
+
return process.stdout;
|
|
1698
|
+
} else {
|
|
1699
|
+
let msg = sub('argument "-" with mode %r', this._flags);
|
|
1700
|
+
throw new TypeError(msg);
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
let fd;
|
|
1704
|
+
try {
|
|
1705
|
+
fd = fs2.openSync(string, this._flags, this._options.mode);
|
|
1706
|
+
} catch (e) {
|
|
1707
|
+
let args = { filename: string, error: e.message };
|
|
1708
|
+
let message = "can't open '%(filename)s': %(error)s";
|
|
1709
|
+
throw new ArgumentTypeError(sub(message, args));
|
|
1710
|
+
}
|
|
1711
|
+
let options = Object.assign({ fd, flags: this._flags }, this._options);
|
|
1712
|
+
if (this._flags.includes("r")) {
|
|
1713
|
+
return fs2.createReadStream(void 0, options);
|
|
1714
|
+
} else if (this._flags.includes("w")) {
|
|
1715
|
+
return fs2.createWriteStream(void 0, options);
|
|
1716
|
+
} else {
|
|
1717
|
+
let msg = sub('argument "%s" with mode %r', string, this._flags);
|
|
1718
|
+
throw new TypeError(msg);
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
[util.inspect.custom]() {
|
|
1722
|
+
let args = [this._flags];
|
|
1723
|
+
let kwargs = Object.entries(this._options).map(([k, v]) => {
|
|
1724
|
+
if (k === "mode")
|
|
1725
|
+
v = { value: v, [util.inspect.custom]() {
|
|
1726
|
+
return "0o" + this.value.toString(8);
|
|
1727
|
+
} };
|
|
1728
|
+
return [k, v];
|
|
1729
|
+
});
|
|
1730
|
+
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(", ");
|
|
1731
|
+
return sub("%s(%s)", this.constructor.name, args_str);
|
|
1732
|
+
}
|
|
1733
|
+
toString() {
|
|
1734
|
+
return this[util.inspect.custom]();
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
var Namespace = _callable(class Namespace extends _AttributeHolder() {
|
|
1738
|
+
constructor(options = {}) {
|
|
1739
|
+
super();
|
|
1740
|
+
Object.assign(this, options);
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
Namespace.prototype[Symbol.toStringTag] = void 0;
|
|
1744
|
+
var _ActionsContainer = _camelcase_alias(_callable(class _ActionsContainer {
|
|
1745
|
+
constructor() {
|
|
1746
|
+
let [
|
|
1747
|
+
description,
|
|
1748
|
+
prefix_chars,
|
|
1749
|
+
argument_default,
|
|
1750
|
+
conflict_handler
|
|
1751
|
+
] = _parse_opts(arguments, {
|
|
1752
|
+
description: no_default,
|
|
1753
|
+
prefix_chars: no_default,
|
|
1754
|
+
argument_default: no_default,
|
|
1755
|
+
conflict_handler: no_default
|
|
1756
|
+
});
|
|
1757
|
+
this.description = description;
|
|
1758
|
+
this.argument_default = argument_default;
|
|
1759
|
+
this.prefix_chars = prefix_chars;
|
|
1760
|
+
this.conflict_handler = conflict_handler;
|
|
1761
|
+
this._registries = {};
|
|
1762
|
+
this.register("action", void 0, _StoreAction);
|
|
1763
|
+
this.register("action", "store", _StoreAction);
|
|
1764
|
+
this.register("action", "store_const", _StoreConstAction);
|
|
1765
|
+
this.register("action", "store_true", _StoreTrueAction);
|
|
1766
|
+
this.register("action", "store_false", _StoreFalseAction);
|
|
1767
|
+
this.register("action", "append", _AppendAction);
|
|
1768
|
+
this.register("action", "append_const", _AppendConstAction);
|
|
1769
|
+
this.register("action", "count", _CountAction);
|
|
1770
|
+
this.register("action", "help", _HelpAction);
|
|
1771
|
+
this.register("action", "version", _VersionAction);
|
|
1772
|
+
this.register("action", "parsers", _SubParsersAction);
|
|
1773
|
+
this.register("action", "extend", _ExtendAction);
|
|
1774
|
+
["storeConst", "storeTrue", "storeFalse", "appendConst"].forEach((old_name) => {
|
|
1775
|
+
let new_name = _to_new_name(old_name);
|
|
1776
|
+
this.register("action", old_name, util.deprecate(this._registry_get("action", new_name), sub('{action: "%s"} is renamed to {action: "%s"}', old_name, new_name)));
|
|
1777
|
+
});
|
|
1778
|
+
this._get_handler();
|
|
1779
|
+
this._actions = [];
|
|
1780
|
+
this._option_string_actions = {};
|
|
1781
|
+
this._action_groups = [];
|
|
1782
|
+
this._mutually_exclusive_groups = [];
|
|
1783
|
+
this._defaults = {};
|
|
1784
|
+
this._negative_number_matcher = /^-\d+$|^-\d*\.\d+$/;
|
|
1785
|
+
this._has_negative_number_optionals = [];
|
|
1786
|
+
}
|
|
1787
|
+
register(registry_name, value, object) {
|
|
1788
|
+
let registry = setdefault(this._registries, registry_name, {});
|
|
1789
|
+
registry[value] = object;
|
|
1790
|
+
}
|
|
1791
|
+
_registry_get(registry_name, value, default_value = void 0) {
|
|
1792
|
+
return getattr(this._registries[registry_name], value, default_value);
|
|
1793
|
+
}
|
|
1794
|
+
set_defaults(kwargs) {
|
|
1795
|
+
Object.assign(this._defaults, kwargs);
|
|
1796
|
+
for (let action of this._actions) {
|
|
1797
|
+
if (action.dest in kwargs) {
|
|
1798
|
+
action.default = kwargs[action.dest];
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
get_default(dest) {
|
|
1803
|
+
for (let action of this._actions) {
|
|
1804
|
+
if (action.dest === dest && action.default !== void 0) {
|
|
1805
|
+
return action.default;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
return this._defaults[dest];
|
|
1809
|
+
}
|
|
1810
|
+
add_argument() {
|
|
1811
|
+
let [
|
|
1812
|
+
args,
|
|
1813
|
+
kwargs
|
|
1814
|
+
] = _parse_opts(arguments, {
|
|
1815
|
+
"*args": no_default,
|
|
1816
|
+
"**kwargs": no_default
|
|
1817
|
+
});
|
|
1818
|
+
if (args.length === 1 && Array.isArray(args[0])) {
|
|
1819
|
+
args = args[0];
|
|
1820
|
+
deprecate("argument-array", sub("use add_argument(%(args)s, {...}) instead of add_argument([ %(args)s ], { ... })", {
|
|
1821
|
+
args: args.map(repr).join(", ")
|
|
1822
|
+
}));
|
|
1823
|
+
}
|
|
1824
|
+
let chars = this.prefix_chars;
|
|
1825
|
+
if (!args.length || args.length === 1 && !chars.includes(args[0][0])) {
|
|
1826
|
+
if (args.length && "dest" in kwargs) {
|
|
1827
|
+
throw new TypeError("dest supplied twice for positional argument");
|
|
1828
|
+
}
|
|
1829
|
+
kwargs = this._get_positional_kwargs(...args, kwargs);
|
|
1830
|
+
} else {
|
|
1831
|
+
kwargs = this._get_optional_kwargs(...args, kwargs);
|
|
1832
|
+
}
|
|
1833
|
+
if (!("default" in kwargs)) {
|
|
1834
|
+
let dest = kwargs.dest;
|
|
1835
|
+
if (dest in this._defaults) {
|
|
1836
|
+
kwargs.default = this._defaults[dest];
|
|
1837
|
+
} else if (this.argument_default !== void 0) {
|
|
1838
|
+
kwargs.default = this.argument_default;
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
let action_class = this._pop_action_class(kwargs);
|
|
1842
|
+
if (typeof action_class !== "function") {
|
|
1843
|
+
throw new TypeError(sub('unknown action "%s"', action_class));
|
|
1844
|
+
}
|
|
1845
|
+
let action = new action_class(kwargs);
|
|
1846
|
+
let type_func = this._registry_get("type", action.type, action.type);
|
|
1847
|
+
if (typeof type_func !== "function") {
|
|
1848
|
+
throw new TypeError(sub("%r is not callable", type_func));
|
|
1849
|
+
}
|
|
1850
|
+
if (type_func === FileType) {
|
|
1851
|
+
throw new TypeError(sub("%r is a FileType class object, instance of it must be passed", type_func));
|
|
1852
|
+
}
|
|
1853
|
+
if ("_get_formatter" in this) {
|
|
1854
|
+
try {
|
|
1855
|
+
this._get_formatter()._format_args(action, void 0);
|
|
1856
|
+
} catch (err) {
|
|
1857
|
+
if (err instanceof TypeError && err.message !== "invalid nargs value") {
|
|
1858
|
+
throw new TypeError("length of metavar tuple does not match nargs");
|
|
1859
|
+
} else {
|
|
1860
|
+
throw err;
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
return this._add_action(action);
|
|
1865
|
+
}
|
|
1866
|
+
add_argument_group() {
|
|
1867
|
+
let group = _ArgumentGroup(this, ...arguments);
|
|
1868
|
+
this._action_groups.push(group);
|
|
1869
|
+
return group;
|
|
1870
|
+
}
|
|
1871
|
+
add_mutually_exclusive_group() {
|
|
1872
|
+
let group = _MutuallyExclusiveGroup(this, ...arguments);
|
|
1873
|
+
this._mutually_exclusive_groups.push(group);
|
|
1874
|
+
return group;
|
|
1875
|
+
}
|
|
1876
|
+
_add_action(action) {
|
|
1877
|
+
this._check_conflict(action);
|
|
1878
|
+
this._actions.push(action);
|
|
1879
|
+
action.container = this;
|
|
1880
|
+
for (let option_string of action.option_strings) {
|
|
1881
|
+
this._option_string_actions[option_string] = action;
|
|
1882
|
+
}
|
|
1883
|
+
for (let option_string of action.option_strings) {
|
|
1884
|
+
if (this._negative_number_matcher.test(option_string)) {
|
|
1885
|
+
if (!this._has_negative_number_optionals.length) {
|
|
1886
|
+
this._has_negative_number_optionals.push(true);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
return action;
|
|
1891
|
+
}
|
|
1892
|
+
_remove_action(action) {
|
|
1893
|
+
_array_remove(this._actions, action);
|
|
1894
|
+
}
|
|
1895
|
+
_add_container_actions(container) {
|
|
1896
|
+
let title_group_map = {};
|
|
1897
|
+
for (let group of this._action_groups) {
|
|
1898
|
+
if (group.title in title_group_map) {
|
|
1899
|
+
let msg = "cannot merge actions - two groups are named %r";
|
|
1900
|
+
throw new TypeError(sub(msg, group.title));
|
|
1901
|
+
}
|
|
1902
|
+
title_group_map[group.title] = group;
|
|
1903
|
+
}
|
|
1904
|
+
let group_map = /* @__PURE__ */ new Map();
|
|
1905
|
+
for (let group of container._action_groups) {
|
|
1906
|
+
if (!(group.title in title_group_map)) {
|
|
1907
|
+
title_group_map[group.title] = this.add_argument_group({
|
|
1908
|
+
title: group.title,
|
|
1909
|
+
description: group.description,
|
|
1910
|
+
conflict_handler: group.conflict_handler
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
for (let action of group._group_actions) {
|
|
1914
|
+
group_map.set(action, title_group_map[group.title]);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
for (let group of container._mutually_exclusive_groups) {
|
|
1918
|
+
let mutex_group = this.add_mutually_exclusive_group({
|
|
1919
|
+
required: group.required
|
|
1920
|
+
});
|
|
1921
|
+
for (let action of group._group_actions) {
|
|
1922
|
+
group_map.set(action, mutex_group);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
for (let action of container._actions) {
|
|
1926
|
+
group_map.get(action)._add_action(action);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
_get_positional_kwargs() {
|
|
1930
|
+
let [
|
|
1931
|
+
dest,
|
|
1932
|
+
kwargs
|
|
1933
|
+
] = _parse_opts(arguments, {
|
|
1934
|
+
dest: no_default,
|
|
1935
|
+
"**kwargs": no_default
|
|
1936
|
+
});
|
|
1937
|
+
if ("required" in kwargs) {
|
|
1938
|
+
let msg = "'required' is an invalid argument for positionals";
|
|
1939
|
+
throw new TypeError(msg);
|
|
1940
|
+
}
|
|
1941
|
+
if (![OPTIONAL, ZERO_OR_MORE].includes(kwargs.nargs)) {
|
|
1942
|
+
kwargs.required = true;
|
|
1943
|
+
}
|
|
1944
|
+
if (kwargs.nargs === ZERO_OR_MORE && !("default" in kwargs)) {
|
|
1945
|
+
kwargs.required = true;
|
|
1946
|
+
}
|
|
1947
|
+
return Object.assign(kwargs, { dest, option_strings: [] });
|
|
1948
|
+
}
|
|
1949
|
+
_get_optional_kwargs() {
|
|
1950
|
+
let [
|
|
1951
|
+
args,
|
|
1952
|
+
kwargs
|
|
1953
|
+
] = _parse_opts(arguments, {
|
|
1954
|
+
"*args": no_default,
|
|
1955
|
+
"**kwargs": no_default
|
|
1956
|
+
});
|
|
1957
|
+
let option_strings = [];
|
|
1958
|
+
let long_option_strings = [];
|
|
1959
|
+
let option_string;
|
|
1960
|
+
for (option_string of args) {
|
|
1961
|
+
if (!this.prefix_chars.includes(option_string[0])) {
|
|
1962
|
+
let args2 = {
|
|
1963
|
+
option: option_string,
|
|
1964
|
+
prefix_chars: this.prefix_chars
|
|
1965
|
+
};
|
|
1966
|
+
let msg = "invalid option string %(option)r: must start with a character %(prefix_chars)r";
|
|
1967
|
+
throw new TypeError(sub(msg, args2));
|
|
1968
|
+
}
|
|
1969
|
+
option_strings.push(option_string);
|
|
1970
|
+
if (option_string.length > 1 && this.prefix_chars.includes(option_string[1])) {
|
|
1971
|
+
long_option_strings.push(option_string);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
let dest = kwargs.dest;
|
|
1975
|
+
delete kwargs.dest;
|
|
1976
|
+
if (dest === void 0) {
|
|
1977
|
+
let dest_option_string;
|
|
1978
|
+
if (long_option_strings.length) {
|
|
1979
|
+
dest_option_string = long_option_strings[0];
|
|
1980
|
+
} else {
|
|
1981
|
+
dest_option_string = option_strings[0];
|
|
1982
|
+
}
|
|
1983
|
+
dest = _string_lstrip(dest_option_string, this.prefix_chars);
|
|
1984
|
+
if (!dest) {
|
|
1985
|
+
let msg = "dest= is required for options like %r";
|
|
1986
|
+
throw new TypeError(sub(msg, option_string));
|
|
1987
|
+
}
|
|
1988
|
+
dest = dest.replace(/-/g, "_");
|
|
1989
|
+
}
|
|
1990
|
+
return Object.assign(kwargs, { dest, option_strings });
|
|
1991
|
+
}
|
|
1992
|
+
_pop_action_class(kwargs, default_value = void 0) {
|
|
1993
|
+
let action = getattr(kwargs, "action", default_value);
|
|
1994
|
+
delete kwargs.action;
|
|
1995
|
+
return this._registry_get("action", action, action);
|
|
1996
|
+
}
|
|
1997
|
+
_get_handler() {
|
|
1998
|
+
let handler_func_name = sub("_handle_conflict_%s", this.conflict_handler);
|
|
1999
|
+
if (typeof this[handler_func_name] === "function") {
|
|
2000
|
+
return this[handler_func_name];
|
|
2001
|
+
} else {
|
|
2002
|
+
let msg = "invalid conflict_resolution value: %r";
|
|
2003
|
+
throw new TypeError(sub(msg, this.conflict_handler));
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
_check_conflict(action) {
|
|
2007
|
+
let confl_optionals = [];
|
|
2008
|
+
for (let option_string of action.option_strings) {
|
|
2009
|
+
if (hasattr(this._option_string_actions, option_string)) {
|
|
2010
|
+
let confl_optional = this._option_string_actions[option_string];
|
|
2011
|
+
confl_optionals.push([option_string, confl_optional]);
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
if (confl_optionals.length) {
|
|
2015
|
+
let conflict_handler = this._get_handler();
|
|
2016
|
+
conflict_handler.call(this, action, confl_optionals);
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
_handle_conflict_error(action, conflicting_actions) {
|
|
2020
|
+
let message = conflicting_actions.length === 1 ? "conflicting option string: %s" : "conflicting option strings: %s";
|
|
2021
|
+
let conflict_string = conflicting_actions.map(([option_string]) => option_string).join(", ");
|
|
2022
|
+
throw new ArgumentError(action, sub(message, conflict_string));
|
|
2023
|
+
}
|
|
2024
|
+
_handle_conflict_resolve(action, conflicting_actions) {
|
|
2025
|
+
for (let [option_string, action2] of conflicting_actions) {
|
|
2026
|
+
_array_remove(action2.option_strings, option_string);
|
|
2027
|
+
delete this._option_string_actions[option_string];
|
|
2028
|
+
if (!action2.option_strings.length) {
|
|
2029
|
+
action2.container._remove_action(action2);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
}));
|
|
2034
|
+
var _ArgumentGroup = _callable(class _ArgumentGroup extends _ActionsContainer {
|
|
2035
|
+
constructor() {
|
|
2036
|
+
let [
|
|
2037
|
+
container,
|
|
2038
|
+
title,
|
|
2039
|
+
description,
|
|
2040
|
+
kwargs
|
|
2041
|
+
] = _parse_opts(arguments, {
|
|
2042
|
+
container: no_default,
|
|
2043
|
+
title: void 0,
|
|
2044
|
+
description: void 0,
|
|
2045
|
+
"**kwargs": no_default
|
|
2046
|
+
});
|
|
2047
|
+
setdefault(kwargs, "conflict_handler", container.conflict_handler);
|
|
2048
|
+
setdefault(kwargs, "prefix_chars", container.prefix_chars);
|
|
2049
|
+
setdefault(kwargs, "argument_default", container.argument_default);
|
|
2050
|
+
super(Object.assign({ description }, kwargs));
|
|
2051
|
+
this.title = title;
|
|
2052
|
+
this._group_actions = [];
|
|
2053
|
+
this._registries = container._registries;
|
|
2054
|
+
this._actions = container._actions;
|
|
2055
|
+
this._option_string_actions = container._option_string_actions;
|
|
2056
|
+
this._defaults = container._defaults;
|
|
2057
|
+
this._has_negative_number_optionals = container._has_negative_number_optionals;
|
|
2058
|
+
this._mutually_exclusive_groups = container._mutually_exclusive_groups;
|
|
2059
|
+
}
|
|
2060
|
+
_add_action(action) {
|
|
2061
|
+
action = super._add_action(action);
|
|
2062
|
+
this._group_actions.push(action);
|
|
2063
|
+
return action;
|
|
2064
|
+
}
|
|
2065
|
+
_remove_action(action) {
|
|
2066
|
+
super._remove_action(action);
|
|
2067
|
+
_array_remove(this._group_actions, action);
|
|
2068
|
+
}
|
|
2069
|
+
});
|
|
2070
|
+
var _MutuallyExclusiveGroup = _callable(class _MutuallyExclusiveGroup extends _ArgumentGroup {
|
|
2071
|
+
constructor() {
|
|
2072
|
+
let [
|
|
2073
|
+
container,
|
|
2074
|
+
required
|
|
2075
|
+
] = _parse_opts(arguments, {
|
|
2076
|
+
container: no_default,
|
|
2077
|
+
required: false
|
|
2078
|
+
});
|
|
2079
|
+
super(container);
|
|
2080
|
+
this.required = required;
|
|
2081
|
+
this._container = container;
|
|
2082
|
+
}
|
|
2083
|
+
_add_action(action) {
|
|
2084
|
+
if (action.required) {
|
|
2085
|
+
let msg = "mutually exclusive arguments must be optional";
|
|
2086
|
+
throw new TypeError(msg);
|
|
2087
|
+
}
|
|
2088
|
+
action = this._container._add_action(action);
|
|
2089
|
+
this._group_actions.push(action);
|
|
2090
|
+
return action;
|
|
2091
|
+
}
|
|
2092
|
+
_remove_action(action) {
|
|
2093
|
+
this._container._remove_action(action);
|
|
2094
|
+
_array_remove(this._group_actions, action);
|
|
2095
|
+
}
|
|
2096
|
+
});
|
|
2097
|
+
var ArgumentParser2 = _camelcase_alias(_callable(class ArgumentParser extends _AttributeHolder(_ActionsContainer) {
|
|
2098
|
+
constructor() {
|
|
2099
|
+
let [
|
|
2100
|
+
prog,
|
|
2101
|
+
usage,
|
|
2102
|
+
description,
|
|
2103
|
+
epilog,
|
|
2104
|
+
parents,
|
|
2105
|
+
formatter_class,
|
|
2106
|
+
prefix_chars,
|
|
2107
|
+
fromfile_prefix_chars,
|
|
2108
|
+
argument_default,
|
|
2109
|
+
conflict_handler,
|
|
2110
|
+
add_help,
|
|
2111
|
+
allow_abbrev,
|
|
2112
|
+
exit_on_error,
|
|
2113
|
+
debug,
|
|
2114
|
+
version
|
|
2115
|
+
] = _parse_opts(arguments, {
|
|
2116
|
+
prog: void 0,
|
|
2117
|
+
usage: void 0,
|
|
2118
|
+
description: void 0,
|
|
2119
|
+
epilog: void 0,
|
|
2120
|
+
parents: [],
|
|
2121
|
+
formatter_class: HelpFormatter,
|
|
2122
|
+
prefix_chars: "-",
|
|
2123
|
+
fromfile_prefix_chars: void 0,
|
|
2124
|
+
argument_default: void 0,
|
|
2125
|
+
conflict_handler: "error",
|
|
2126
|
+
add_help: true,
|
|
2127
|
+
allow_abbrev: true,
|
|
2128
|
+
exit_on_error: true,
|
|
2129
|
+
debug: void 0,
|
|
2130
|
+
version: void 0
|
|
2131
|
+
});
|
|
2132
|
+
if (debug !== void 0) {
|
|
2133
|
+
deprecate("debug", 'The "debug" argument to ArgumentParser is deprecated. Please override ArgumentParser.exit function instead.');
|
|
2134
|
+
}
|
|
2135
|
+
if (version !== void 0) {
|
|
2136
|
+
deprecate("version", `The "version" argument to ArgumentParser is deprecated. Please use add_argument(..., { action: 'version', version: 'N', ... }) instead.`);
|
|
2137
|
+
}
|
|
2138
|
+
super({
|
|
2139
|
+
description,
|
|
2140
|
+
prefix_chars,
|
|
2141
|
+
argument_default,
|
|
2142
|
+
conflict_handler
|
|
2143
|
+
});
|
|
2144
|
+
if (prog === void 0) {
|
|
2145
|
+
prog = path2.basename(get_argv()[0] || "");
|
|
2146
|
+
}
|
|
2147
|
+
this.prog = prog;
|
|
2148
|
+
this.usage = usage;
|
|
2149
|
+
this.epilog = epilog;
|
|
2150
|
+
this.formatter_class = formatter_class;
|
|
2151
|
+
this.fromfile_prefix_chars = fromfile_prefix_chars;
|
|
2152
|
+
this.add_help = add_help;
|
|
2153
|
+
this.allow_abbrev = allow_abbrev;
|
|
2154
|
+
this.exit_on_error = exit_on_error;
|
|
2155
|
+
this.debug = debug;
|
|
2156
|
+
this._positionals = this.add_argument_group("positional arguments");
|
|
2157
|
+
this._optionals = this.add_argument_group("optional arguments");
|
|
2158
|
+
this._subparsers = void 0;
|
|
2159
|
+
function identity(string) {
|
|
2160
|
+
return string;
|
|
2161
|
+
}
|
|
2162
|
+
this.register("type", void 0, identity);
|
|
2163
|
+
this.register("type", null, identity);
|
|
2164
|
+
this.register("type", "auto", identity);
|
|
2165
|
+
this.register("type", "int", function(x) {
|
|
2166
|
+
let result = Number(x);
|
|
2167
|
+
if (!Number.isInteger(result)) {
|
|
2168
|
+
throw new TypeError(sub("could not convert string to int: %r", x));
|
|
2169
|
+
}
|
|
2170
|
+
return result;
|
|
2171
|
+
});
|
|
2172
|
+
this.register("type", "float", function(x) {
|
|
2173
|
+
let result = Number(x);
|
|
2174
|
+
if (isNaN(result)) {
|
|
2175
|
+
throw new TypeError(sub("could not convert string to float: %r", x));
|
|
2176
|
+
}
|
|
2177
|
+
return result;
|
|
2178
|
+
});
|
|
2179
|
+
this.register("type", "str", String);
|
|
2180
|
+
this.register("type", "string", util.deprecate(String, 'use {type:"str"} or {type:String} instead of {type:"string"}'));
|
|
2181
|
+
let default_prefix = prefix_chars.includes("-") ? "-" : prefix_chars[0];
|
|
2182
|
+
if (this.add_help) {
|
|
2183
|
+
this.add_argument(default_prefix + "h", default_prefix.repeat(2) + "help", {
|
|
2184
|
+
action: "help",
|
|
2185
|
+
default: SUPPRESS,
|
|
2186
|
+
help: "show this help message and exit"
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
if (version) {
|
|
2190
|
+
this.add_argument(default_prefix + "v", default_prefix.repeat(2) + "version", {
|
|
2191
|
+
action: "version",
|
|
2192
|
+
default: SUPPRESS,
|
|
2193
|
+
version: this.version,
|
|
2194
|
+
help: "show program's version number and exit"
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
for (let parent of parents) {
|
|
2198
|
+
this._add_container_actions(parent);
|
|
2199
|
+
Object.assign(this._defaults, parent._defaults);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
_get_kwargs() {
|
|
2203
|
+
let names = [
|
|
2204
|
+
"prog",
|
|
2205
|
+
"usage",
|
|
2206
|
+
"description",
|
|
2207
|
+
"formatter_class",
|
|
2208
|
+
"conflict_handler",
|
|
2209
|
+
"add_help"
|
|
2210
|
+
];
|
|
2211
|
+
return names.map((name) => [name, getattr(this, name)]);
|
|
2212
|
+
}
|
|
2213
|
+
add_subparsers() {
|
|
2214
|
+
let [
|
|
2215
|
+
kwargs
|
|
2216
|
+
] = _parse_opts(arguments, {
|
|
2217
|
+
"**kwargs": no_default
|
|
2218
|
+
});
|
|
2219
|
+
if (this._subparsers !== void 0) {
|
|
2220
|
+
this.error("cannot have multiple subparser arguments");
|
|
2221
|
+
}
|
|
2222
|
+
setdefault(kwargs, "parser_class", this.constructor);
|
|
2223
|
+
if ("title" in kwargs || "description" in kwargs) {
|
|
2224
|
+
let title = getattr(kwargs, "title", "subcommands");
|
|
2225
|
+
let description = getattr(kwargs, "description", void 0);
|
|
2226
|
+
delete kwargs.title;
|
|
2227
|
+
delete kwargs.description;
|
|
2228
|
+
this._subparsers = this.add_argument_group(title, description);
|
|
2229
|
+
} else {
|
|
2230
|
+
this._subparsers = this._positionals;
|
|
2231
|
+
}
|
|
2232
|
+
if (kwargs.prog === void 0) {
|
|
2233
|
+
let formatter = this._get_formatter();
|
|
2234
|
+
let positionals = this._get_positional_actions();
|
|
2235
|
+
let groups = this._mutually_exclusive_groups;
|
|
2236
|
+
formatter.add_usage(this.usage, positionals, groups, "");
|
|
2237
|
+
kwargs.prog = formatter.format_help().trim();
|
|
2238
|
+
}
|
|
2239
|
+
let parsers_class = this._pop_action_class(kwargs, "parsers");
|
|
2240
|
+
let action = new parsers_class(Object.assign({ option_strings: [] }, kwargs));
|
|
2241
|
+
this._subparsers._add_action(action);
|
|
2242
|
+
return action;
|
|
2243
|
+
}
|
|
2244
|
+
_add_action(action) {
|
|
2245
|
+
if (action.option_strings.length) {
|
|
2246
|
+
this._optionals._add_action(action);
|
|
2247
|
+
} else {
|
|
2248
|
+
this._positionals._add_action(action);
|
|
2249
|
+
}
|
|
2250
|
+
return action;
|
|
2251
|
+
}
|
|
2252
|
+
_get_optional_actions() {
|
|
2253
|
+
return this._actions.filter((action) => action.option_strings.length);
|
|
2254
|
+
}
|
|
2255
|
+
_get_positional_actions() {
|
|
2256
|
+
return this._actions.filter((action) => !action.option_strings.length);
|
|
2257
|
+
}
|
|
2258
|
+
parse_args(args = void 0, namespace = void 0) {
|
|
2259
|
+
let argv;
|
|
2260
|
+
[args, argv] = this.parse_known_args(args, namespace);
|
|
2261
|
+
if (argv && argv.length > 0) {
|
|
2262
|
+
let msg = "unrecognized arguments: %s";
|
|
2263
|
+
this.error(sub(msg, argv.join(" ")));
|
|
2264
|
+
}
|
|
2265
|
+
return args;
|
|
2266
|
+
}
|
|
2267
|
+
parse_known_args(args = void 0, namespace = void 0) {
|
|
2268
|
+
if (args === void 0) {
|
|
2269
|
+
args = get_argv().slice(1);
|
|
2270
|
+
}
|
|
2271
|
+
if (namespace === void 0) {
|
|
2272
|
+
namespace = new Namespace();
|
|
2273
|
+
}
|
|
2274
|
+
for (let action of this._actions) {
|
|
2275
|
+
if (action.dest !== SUPPRESS) {
|
|
2276
|
+
if (!hasattr(namespace, action.dest)) {
|
|
2277
|
+
if (action.default !== SUPPRESS) {
|
|
2278
|
+
setattr(namespace, action.dest, action.default);
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
for (let dest of Object.keys(this._defaults)) {
|
|
2284
|
+
if (!hasattr(namespace, dest)) {
|
|
2285
|
+
setattr(namespace, dest, this._defaults[dest]);
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
if (this.exit_on_error) {
|
|
2289
|
+
try {
|
|
2290
|
+
[namespace, args] = this._parse_known_args(args, namespace);
|
|
2291
|
+
} catch (err) {
|
|
2292
|
+
if (err instanceof ArgumentError) {
|
|
2293
|
+
this.error(err.message);
|
|
2294
|
+
} else {
|
|
2295
|
+
throw err;
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
} else {
|
|
2299
|
+
[namespace, args] = this._parse_known_args(args, namespace);
|
|
2300
|
+
}
|
|
2301
|
+
if (hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR)) {
|
|
2302
|
+
args = args.concat(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR));
|
|
2303
|
+
delattr(namespace, _UNRECOGNIZED_ARGS_ATTR);
|
|
2304
|
+
}
|
|
2305
|
+
return [namespace, args];
|
|
2306
|
+
}
|
|
2307
|
+
_parse_known_args(arg_strings, namespace) {
|
|
2308
|
+
if (this.fromfile_prefix_chars !== void 0) {
|
|
2309
|
+
arg_strings = this._read_args_from_files(arg_strings);
|
|
2310
|
+
}
|
|
2311
|
+
let action_conflicts = /* @__PURE__ */ new Map();
|
|
2312
|
+
for (let mutex_group of this._mutually_exclusive_groups) {
|
|
2313
|
+
let group_actions = mutex_group._group_actions;
|
|
2314
|
+
for (let [i, mutex_action] of Object.entries(mutex_group._group_actions)) {
|
|
2315
|
+
let conflicts = action_conflicts.get(mutex_action) || [];
|
|
2316
|
+
conflicts = conflicts.concat(group_actions.slice(0, +i));
|
|
2317
|
+
conflicts = conflicts.concat(group_actions.slice(+i + 1));
|
|
2318
|
+
action_conflicts.set(mutex_action, conflicts);
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
let option_string_indices = {};
|
|
2322
|
+
let arg_string_pattern_parts = [];
|
|
2323
|
+
let arg_strings_iter = Object.entries(arg_strings)[Symbol.iterator]();
|
|
2324
|
+
for (let [i, arg_string] of arg_strings_iter) {
|
|
2325
|
+
if (arg_string === "--") {
|
|
2326
|
+
arg_string_pattern_parts.push("-");
|
|
2327
|
+
for ([i, arg_string] of arg_strings_iter) {
|
|
2328
|
+
arg_string_pattern_parts.push("A");
|
|
2329
|
+
}
|
|
2330
|
+
} else {
|
|
2331
|
+
let option_tuple = this._parse_optional(arg_string);
|
|
2332
|
+
let pattern;
|
|
2333
|
+
if (option_tuple === void 0) {
|
|
2334
|
+
pattern = "A";
|
|
2335
|
+
} else {
|
|
2336
|
+
option_string_indices[i] = option_tuple;
|
|
2337
|
+
pattern = "O";
|
|
2338
|
+
}
|
|
2339
|
+
arg_string_pattern_parts.push(pattern);
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
let arg_strings_pattern = arg_string_pattern_parts.join("");
|
|
2343
|
+
let seen_actions = /* @__PURE__ */ new Set();
|
|
2344
|
+
let seen_non_default_actions = /* @__PURE__ */ new Set();
|
|
2345
|
+
let extras;
|
|
2346
|
+
let take_action = (action, argument_strings, option_string = void 0) => {
|
|
2347
|
+
seen_actions.add(action);
|
|
2348
|
+
let argument_values = this._get_values(action, argument_strings);
|
|
2349
|
+
if (argument_values !== action.default) {
|
|
2350
|
+
seen_non_default_actions.add(action);
|
|
2351
|
+
for (let conflict_action of action_conflicts.get(action) || []) {
|
|
2352
|
+
if (seen_non_default_actions.has(conflict_action)) {
|
|
2353
|
+
let msg = "not allowed with argument %s";
|
|
2354
|
+
let action_name = _get_action_name(conflict_action);
|
|
2355
|
+
throw new ArgumentError(action, sub(msg, action_name));
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
if (argument_values !== SUPPRESS) {
|
|
2360
|
+
action(this, namespace, argument_values, option_string);
|
|
2361
|
+
}
|
|
2362
|
+
};
|
|
2363
|
+
let consume_optional = (start_index2) => {
|
|
2364
|
+
let option_tuple = option_string_indices[start_index2];
|
|
2365
|
+
let [action, option_string, explicit_arg] = option_tuple;
|
|
2366
|
+
let action_tuples = [];
|
|
2367
|
+
let stop;
|
|
2368
|
+
for (; ; ) {
|
|
2369
|
+
if (action === void 0) {
|
|
2370
|
+
extras.push(arg_strings[start_index2]);
|
|
2371
|
+
return start_index2 + 1;
|
|
2372
|
+
}
|
|
2373
|
+
if (explicit_arg !== void 0) {
|
|
2374
|
+
let arg_count = this._match_argument(action, "A");
|
|
2375
|
+
let chars = this.prefix_chars;
|
|
2376
|
+
if (arg_count === 0 && !chars.includes(option_string[1])) {
|
|
2377
|
+
action_tuples.push([action, [], option_string]);
|
|
2378
|
+
let char = option_string[0];
|
|
2379
|
+
option_string = char + explicit_arg[0];
|
|
2380
|
+
let new_explicit_arg = explicit_arg.slice(1) || void 0;
|
|
2381
|
+
let optionals_map = this._option_string_actions;
|
|
2382
|
+
if (hasattr(optionals_map, option_string)) {
|
|
2383
|
+
action = optionals_map[option_string];
|
|
2384
|
+
explicit_arg = new_explicit_arg;
|
|
2385
|
+
} else {
|
|
2386
|
+
let msg = "ignored explicit argument %r";
|
|
2387
|
+
throw new ArgumentError(action, sub(msg, explicit_arg));
|
|
2388
|
+
}
|
|
2389
|
+
} else if (arg_count === 1) {
|
|
2390
|
+
stop = start_index2 + 1;
|
|
2391
|
+
let args = [explicit_arg];
|
|
2392
|
+
action_tuples.push([action, args, option_string]);
|
|
2393
|
+
break;
|
|
2394
|
+
} else {
|
|
2395
|
+
let msg = "ignored explicit argument %r";
|
|
2396
|
+
throw new ArgumentError(action, sub(msg, explicit_arg));
|
|
2397
|
+
}
|
|
2398
|
+
} else {
|
|
2399
|
+
let start = start_index2 + 1;
|
|
2400
|
+
let selected_patterns = arg_strings_pattern.slice(start);
|
|
2401
|
+
let arg_count = this._match_argument(action, selected_patterns);
|
|
2402
|
+
stop = start + arg_count;
|
|
2403
|
+
let args = arg_strings.slice(start, stop);
|
|
2404
|
+
action_tuples.push([action, args, option_string]);
|
|
2405
|
+
break;
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
assert(action_tuples.length);
|
|
2409
|
+
for (let [action2, args, option_string2] of action_tuples) {
|
|
2410
|
+
take_action(action2, args, option_string2);
|
|
2411
|
+
}
|
|
2412
|
+
return stop;
|
|
2413
|
+
};
|
|
2414
|
+
let positionals = this._get_positional_actions();
|
|
2415
|
+
let consume_positionals = (start_index2) => {
|
|
2416
|
+
let selected_pattern = arg_strings_pattern.slice(start_index2);
|
|
2417
|
+
let arg_counts = this._match_arguments_partial(positionals, selected_pattern);
|
|
2418
|
+
for (let i = 0; i < positionals.length && i < arg_counts.length; i++) {
|
|
2419
|
+
let action = positionals[i];
|
|
2420
|
+
let arg_count = arg_counts[i];
|
|
2421
|
+
let args = arg_strings.slice(start_index2, start_index2 + arg_count);
|
|
2422
|
+
start_index2 += arg_count;
|
|
2423
|
+
take_action(action, args);
|
|
2424
|
+
}
|
|
2425
|
+
positionals = positionals.slice(arg_counts.length);
|
|
2426
|
+
return start_index2;
|
|
2427
|
+
};
|
|
2428
|
+
extras = [];
|
|
2429
|
+
let start_index = 0;
|
|
2430
|
+
let max_option_string_index = Math.max(-1, ...Object.keys(option_string_indices).map(Number));
|
|
2431
|
+
while (start_index <= max_option_string_index) {
|
|
2432
|
+
let next_option_string_index = Math.min(...Object.keys(option_string_indices).map(Number).filter((index) => index >= start_index));
|
|
2433
|
+
if (start_index !== next_option_string_index) {
|
|
2434
|
+
let positionals_end_index = consume_positionals(start_index);
|
|
2435
|
+
if (positionals_end_index > start_index) {
|
|
2436
|
+
start_index = positionals_end_index;
|
|
2437
|
+
continue;
|
|
2438
|
+
} else {
|
|
2439
|
+
start_index = positionals_end_index;
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
if (!(start_index in option_string_indices)) {
|
|
2443
|
+
let strings = arg_strings.slice(start_index, next_option_string_index);
|
|
2444
|
+
extras = extras.concat(strings);
|
|
2445
|
+
start_index = next_option_string_index;
|
|
2446
|
+
}
|
|
2447
|
+
start_index = consume_optional(start_index);
|
|
2448
|
+
}
|
|
2449
|
+
let stop_index = consume_positionals(start_index);
|
|
2450
|
+
extras = extras.concat(arg_strings.slice(stop_index));
|
|
2451
|
+
let required_actions = [];
|
|
2452
|
+
for (let action of this._actions) {
|
|
2453
|
+
if (!seen_actions.has(action)) {
|
|
2454
|
+
if (action.required) {
|
|
2455
|
+
required_actions.push(_get_action_name(action));
|
|
2456
|
+
} else {
|
|
2457
|
+
if (action.default !== void 0 && typeof action.default === "string" && hasattr(namespace, action.dest) && action.default === getattr(namespace, action.dest)) {
|
|
2458
|
+
setattr(namespace, action.dest, this._get_value(action, action.default));
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
if (required_actions.length) {
|
|
2464
|
+
this.error(sub("the following arguments are required: %s", required_actions.join(", ")));
|
|
2465
|
+
}
|
|
2466
|
+
for (let group of this._mutually_exclusive_groups) {
|
|
2467
|
+
if (group.required) {
|
|
2468
|
+
let no_actions_used = true;
|
|
2469
|
+
for (let action of group._group_actions) {
|
|
2470
|
+
if (seen_non_default_actions.has(action)) {
|
|
2471
|
+
no_actions_used = false;
|
|
2472
|
+
break;
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
if (no_actions_used) {
|
|
2476
|
+
let names = group._group_actions.filter((action) => action.help !== SUPPRESS).map((action) => _get_action_name(action));
|
|
2477
|
+
let msg = "one of the arguments %s is required";
|
|
2478
|
+
this.error(sub(msg, names.join(" ")));
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
return [namespace, extras];
|
|
2483
|
+
}
|
|
2484
|
+
_read_args_from_files(arg_strings) {
|
|
2485
|
+
let new_arg_strings = [];
|
|
2486
|
+
for (let arg_string of arg_strings) {
|
|
2487
|
+
if (!arg_string || !this.fromfile_prefix_chars.includes(arg_string[0])) {
|
|
2488
|
+
new_arg_strings.push(arg_string);
|
|
2489
|
+
} else {
|
|
2490
|
+
try {
|
|
2491
|
+
let args_file = fs2.readFileSync(arg_string.slice(1), "utf8");
|
|
2492
|
+
let arg_strings2 = [];
|
|
2493
|
+
for (let arg_line of splitlines(args_file)) {
|
|
2494
|
+
for (let arg of this.convert_arg_line_to_args(arg_line)) {
|
|
2495
|
+
arg_strings2.push(arg);
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
arg_strings2 = this._read_args_from_files(arg_strings2);
|
|
2499
|
+
new_arg_strings = new_arg_strings.concat(arg_strings2);
|
|
2500
|
+
} catch (err) {
|
|
2501
|
+
this.error(err.message);
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
return new_arg_strings;
|
|
2506
|
+
}
|
|
2507
|
+
convert_arg_line_to_args(arg_line) {
|
|
2508
|
+
return [arg_line];
|
|
2509
|
+
}
|
|
2510
|
+
_match_argument(action, arg_strings_pattern) {
|
|
2511
|
+
let nargs_pattern = this._get_nargs_pattern(action);
|
|
2512
|
+
let match = arg_strings_pattern.match(new RegExp("^" + nargs_pattern));
|
|
2513
|
+
if (match === null) {
|
|
2514
|
+
let nargs_errors = {
|
|
2515
|
+
undefined: "expected one argument",
|
|
2516
|
+
[OPTIONAL]: "expected at most one argument",
|
|
2517
|
+
[ONE_OR_MORE]: "expected at least one argument"
|
|
2518
|
+
};
|
|
2519
|
+
let msg = nargs_errors[action.nargs];
|
|
2520
|
+
if (msg === void 0) {
|
|
2521
|
+
msg = sub(action.nargs === 1 ? "expected %s argument" : "expected %s arguments", action.nargs);
|
|
2522
|
+
}
|
|
2523
|
+
throw new ArgumentError(action, msg);
|
|
2524
|
+
}
|
|
2525
|
+
return match[1].length;
|
|
2526
|
+
}
|
|
2527
|
+
_match_arguments_partial(actions, arg_strings_pattern) {
|
|
2528
|
+
let result = [];
|
|
2529
|
+
for (let i of range(actions.length, 0, -1)) {
|
|
2530
|
+
let actions_slice = actions.slice(0, i);
|
|
2531
|
+
let pattern = actions_slice.map((action) => this._get_nargs_pattern(action)).join("");
|
|
2532
|
+
let match = arg_strings_pattern.match(new RegExp("^" + pattern));
|
|
2533
|
+
if (match !== null) {
|
|
2534
|
+
result = result.concat(match.slice(1).map((string) => string.length));
|
|
2535
|
+
break;
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
return result;
|
|
2539
|
+
}
|
|
2540
|
+
_parse_optional(arg_string) {
|
|
2541
|
+
if (!arg_string) {
|
|
2542
|
+
return void 0;
|
|
2543
|
+
}
|
|
2544
|
+
if (!this.prefix_chars.includes(arg_string[0])) {
|
|
2545
|
+
return void 0;
|
|
2546
|
+
}
|
|
2547
|
+
if (arg_string in this._option_string_actions) {
|
|
2548
|
+
let action = this._option_string_actions[arg_string];
|
|
2549
|
+
return [action, arg_string, void 0];
|
|
2550
|
+
}
|
|
2551
|
+
if (arg_string.length === 1) {
|
|
2552
|
+
return void 0;
|
|
2553
|
+
}
|
|
2554
|
+
if (arg_string.includes("=")) {
|
|
2555
|
+
let [option_string, explicit_arg] = _string_split(arg_string, "=", 1);
|
|
2556
|
+
if (option_string in this._option_string_actions) {
|
|
2557
|
+
let action = this._option_string_actions[option_string];
|
|
2558
|
+
return [action, option_string, explicit_arg];
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
let option_tuples = this._get_option_tuples(arg_string);
|
|
2562
|
+
if (option_tuples.length > 1) {
|
|
2563
|
+
let options = option_tuples.map(([, option_string]) => option_string).join(", ");
|
|
2564
|
+
let args = { option: arg_string, matches: options };
|
|
2565
|
+
let msg = "ambiguous option: %(option)s could match %(matches)s";
|
|
2566
|
+
this.error(sub(msg, args));
|
|
2567
|
+
} else if (option_tuples.length === 1) {
|
|
2568
|
+
let [option_tuple] = option_tuples;
|
|
2569
|
+
return option_tuple;
|
|
2570
|
+
}
|
|
2571
|
+
if (this._negative_number_matcher.test(arg_string)) {
|
|
2572
|
+
if (!this._has_negative_number_optionals.length) {
|
|
2573
|
+
return void 0;
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
if (arg_string.includes(" ")) {
|
|
2577
|
+
return void 0;
|
|
2578
|
+
}
|
|
2579
|
+
return [void 0, arg_string, void 0];
|
|
2580
|
+
}
|
|
2581
|
+
_get_option_tuples(option_string) {
|
|
2582
|
+
let result = [];
|
|
2583
|
+
let chars = this.prefix_chars;
|
|
2584
|
+
if (chars.includes(option_string[0]) && chars.includes(option_string[1])) {
|
|
2585
|
+
if (this.allow_abbrev) {
|
|
2586
|
+
let option_prefix, explicit_arg;
|
|
2587
|
+
if (option_string.includes("=")) {
|
|
2588
|
+
[option_prefix, explicit_arg] = _string_split(option_string, "=", 1);
|
|
2589
|
+
} else {
|
|
2590
|
+
option_prefix = option_string;
|
|
2591
|
+
explicit_arg = void 0;
|
|
2592
|
+
}
|
|
2593
|
+
for (let option_string2 of Object.keys(this._option_string_actions)) {
|
|
2594
|
+
if (option_string2.startsWith(option_prefix)) {
|
|
2595
|
+
let action = this._option_string_actions[option_string2];
|
|
2596
|
+
let tup = [action, option_string2, explicit_arg];
|
|
2597
|
+
result.push(tup);
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
} else if (chars.includes(option_string[0]) && !chars.includes(option_string[1])) {
|
|
2602
|
+
let option_prefix = option_string;
|
|
2603
|
+
let explicit_arg = void 0;
|
|
2604
|
+
let short_option_prefix = option_string.slice(0, 2);
|
|
2605
|
+
let short_explicit_arg = option_string.slice(2);
|
|
2606
|
+
for (let option_string2 of Object.keys(this._option_string_actions)) {
|
|
2607
|
+
if (option_string2 === short_option_prefix) {
|
|
2608
|
+
let action = this._option_string_actions[option_string2];
|
|
2609
|
+
let tup = [action, option_string2, short_explicit_arg];
|
|
2610
|
+
result.push(tup);
|
|
2611
|
+
} else if (option_string2.startsWith(option_prefix)) {
|
|
2612
|
+
let action = this._option_string_actions[option_string2];
|
|
2613
|
+
let tup = [action, option_string2, explicit_arg];
|
|
2614
|
+
result.push(tup);
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
} else {
|
|
2618
|
+
this.error(sub("unexpected option string: %s", option_string));
|
|
2619
|
+
}
|
|
2620
|
+
return result;
|
|
2621
|
+
}
|
|
2622
|
+
_get_nargs_pattern(action) {
|
|
2623
|
+
let nargs = action.nargs;
|
|
2624
|
+
let nargs_pattern;
|
|
2625
|
+
if (nargs === void 0) {
|
|
2626
|
+
nargs_pattern = "(-*A-*)";
|
|
2627
|
+
} else if (nargs === OPTIONAL) {
|
|
2628
|
+
nargs_pattern = "(-*A?-*)";
|
|
2629
|
+
} else if (nargs === ZERO_OR_MORE) {
|
|
2630
|
+
nargs_pattern = "(-*[A-]*)";
|
|
2631
|
+
} else if (nargs === ONE_OR_MORE) {
|
|
2632
|
+
nargs_pattern = "(-*A[A-]*)";
|
|
2633
|
+
} else if (nargs === REMAINDER) {
|
|
2634
|
+
nargs_pattern = "([-AO]*)";
|
|
2635
|
+
} else if (nargs === PARSER) {
|
|
2636
|
+
nargs_pattern = "(-*A[-AO]*)";
|
|
2637
|
+
} else if (nargs === SUPPRESS) {
|
|
2638
|
+
nargs_pattern = "(-*-*)";
|
|
2639
|
+
} else {
|
|
2640
|
+
nargs_pattern = sub("(-*%s-*)", "A".repeat(nargs).split("").join("-*"));
|
|
2641
|
+
}
|
|
2642
|
+
if (action.option_strings.length) {
|
|
2643
|
+
nargs_pattern = nargs_pattern.replace(/-\*/g, "");
|
|
2644
|
+
nargs_pattern = nargs_pattern.replace(/-/g, "");
|
|
2645
|
+
}
|
|
2646
|
+
return nargs_pattern;
|
|
2647
|
+
}
|
|
2648
|
+
parse_intermixed_args(args = void 0, namespace = void 0) {
|
|
2649
|
+
let argv;
|
|
2650
|
+
[args, argv] = this.parse_known_intermixed_args(args, namespace);
|
|
2651
|
+
if (argv.length) {
|
|
2652
|
+
let msg = "unrecognized arguments: %s";
|
|
2653
|
+
this.error(sub(msg, argv.join(" ")));
|
|
2654
|
+
}
|
|
2655
|
+
return args;
|
|
2656
|
+
}
|
|
2657
|
+
parse_known_intermixed_args(args = void 0, namespace = void 0) {
|
|
2658
|
+
let extras;
|
|
2659
|
+
let positionals = this._get_positional_actions();
|
|
2660
|
+
let a = positionals.filter((action) => [PARSER, REMAINDER].includes(action.nargs));
|
|
2661
|
+
if (a.length) {
|
|
2662
|
+
throw new TypeError(sub("parse_intermixed_args: positional arg with nargs=%s", a[0].nargs));
|
|
2663
|
+
}
|
|
2664
|
+
for (let group of this._mutually_exclusive_groups) {
|
|
2665
|
+
for (let action of group._group_actions) {
|
|
2666
|
+
if (positionals.includes(action)) {
|
|
2667
|
+
throw new TypeError("parse_intermixed_args: positional in mutuallyExclusiveGroup");
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
let save_usage;
|
|
2672
|
+
try {
|
|
2673
|
+
save_usage = this.usage;
|
|
2674
|
+
let remaining_args;
|
|
2675
|
+
try {
|
|
2676
|
+
if (this.usage === void 0) {
|
|
2677
|
+
this.usage = this.format_usage().slice(7);
|
|
2678
|
+
}
|
|
2679
|
+
for (let action of positionals) {
|
|
2680
|
+
action.save_nargs = action.nargs;
|
|
2681
|
+
action.nargs = SUPPRESS;
|
|
2682
|
+
action.save_default = action.default;
|
|
2683
|
+
action.default = SUPPRESS;
|
|
2684
|
+
}
|
|
2685
|
+
[namespace, remaining_args] = this.parse_known_args(args, namespace);
|
|
2686
|
+
for (let action of positionals) {
|
|
2687
|
+
let attr = getattr(namespace, action.dest);
|
|
2688
|
+
if (Array.isArray(attr) && attr.length === 0) {
|
|
2689
|
+
console.warn(sub("Do not expect %s in %s", action.dest, namespace));
|
|
2690
|
+
delattr(namespace, action.dest);
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
} finally {
|
|
2694
|
+
for (let action of positionals) {
|
|
2695
|
+
action.nargs = action.save_nargs;
|
|
2696
|
+
action.default = action.save_default;
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
let optionals = this._get_optional_actions();
|
|
2700
|
+
try {
|
|
2701
|
+
for (let action of optionals) {
|
|
2702
|
+
action.save_required = action.required;
|
|
2703
|
+
action.required = false;
|
|
2704
|
+
}
|
|
2705
|
+
for (let group of this._mutually_exclusive_groups) {
|
|
2706
|
+
group.save_required = group.required;
|
|
2707
|
+
group.required = false;
|
|
2708
|
+
}
|
|
2709
|
+
[namespace, extras] = this.parse_known_args(remaining_args, namespace);
|
|
2710
|
+
} finally {
|
|
2711
|
+
for (let action of optionals) {
|
|
2712
|
+
action.required = action.save_required;
|
|
2713
|
+
}
|
|
2714
|
+
for (let group of this._mutually_exclusive_groups) {
|
|
2715
|
+
group.required = group.save_required;
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
} finally {
|
|
2719
|
+
this.usage = save_usage;
|
|
2720
|
+
}
|
|
2721
|
+
return [namespace, extras];
|
|
2722
|
+
}
|
|
2723
|
+
_get_values(action, arg_strings) {
|
|
2724
|
+
if (![PARSER, REMAINDER].includes(action.nargs)) {
|
|
2725
|
+
try {
|
|
2726
|
+
_array_remove(arg_strings, "--");
|
|
2727
|
+
} catch (err) {
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
let value;
|
|
2731
|
+
if (!arg_strings.length && action.nargs === OPTIONAL) {
|
|
2732
|
+
if (action.option_strings.length) {
|
|
2733
|
+
value = action.const;
|
|
2734
|
+
} else {
|
|
2735
|
+
value = action.default;
|
|
2736
|
+
}
|
|
2737
|
+
if (typeof value === "string") {
|
|
2738
|
+
value = this._get_value(action, value);
|
|
2739
|
+
this._check_value(action, value);
|
|
2740
|
+
}
|
|
2741
|
+
} else if (!arg_strings.length && action.nargs === ZERO_OR_MORE && !action.option_strings.length) {
|
|
2742
|
+
if (action.default !== void 0) {
|
|
2743
|
+
value = action.default;
|
|
2744
|
+
} else {
|
|
2745
|
+
value = arg_strings;
|
|
2746
|
+
}
|
|
2747
|
+
this._check_value(action, value);
|
|
2748
|
+
} else if (arg_strings.length === 1 && [void 0, OPTIONAL].includes(action.nargs)) {
|
|
2749
|
+
let arg_string = arg_strings[0];
|
|
2750
|
+
value = this._get_value(action, arg_string);
|
|
2751
|
+
this._check_value(action, value);
|
|
2752
|
+
} else if (action.nargs === REMAINDER) {
|
|
2753
|
+
value = arg_strings.map((v) => this._get_value(action, v));
|
|
2754
|
+
} else if (action.nargs === PARSER) {
|
|
2755
|
+
value = arg_strings.map((v) => this._get_value(action, v));
|
|
2756
|
+
this._check_value(action, value[0]);
|
|
2757
|
+
} else if (action.nargs === SUPPRESS) {
|
|
2758
|
+
value = SUPPRESS;
|
|
2759
|
+
} else {
|
|
2760
|
+
value = arg_strings.map((v) => this._get_value(action, v));
|
|
2761
|
+
for (let v of value) {
|
|
2762
|
+
this._check_value(action, v);
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
return value;
|
|
2766
|
+
}
|
|
2767
|
+
_get_value(action, arg_string) {
|
|
2768
|
+
let type_func = this._registry_get("type", action.type, action.type);
|
|
2769
|
+
if (typeof type_func !== "function") {
|
|
2770
|
+
let msg = "%r is not callable";
|
|
2771
|
+
throw new ArgumentError(action, sub(msg, type_func));
|
|
2772
|
+
}
|
|
2773
|
+
let result;
|
|
2774
|
+
try {
|
|
2775
|
+
try {
|
|
2776
|
+
result = type_func(arg_string);
|
|
2777
|
+
} catch (err) {
|
|
2778
|
+
if (err instanceof TypeError && /Class constructor .* cannot be invoked without 'new'/.test(err.message)) {
|
|
2779
|
+
result = new type_func(arg_string);
|
|
2780
|
+
} else {
|
|
2781
|
+
throw err;
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
} catch (err) {
|
|
2785
|
+
if (err instanceof ArgumentTypeError) {
|
|
2786
|
+
let msg = err.message;
|
|
2787
|
+
throw new ArgumentError(action, msg);
|
|
2788
|
+
} else if (err instanceof TypeError) {
|
|
2789
|
+
let name = getattr(action.type, "name", repr(action.type));
|
|
2790
|
+
let args = { type: name, value: arg_string };
|
|
2791
|
+
let msg = "invalid %(type)s value: %(value)r";
|
|
2792
|
+
throw new ArgumentError(action, sub(msg, args));
|
|
2793
|
+
} else {
|
|
2794
|
+
throw err;
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
return result;
|
|
2798
|
+
}
|
|
2799
|
+
_check_value(action, value) {
|
|
2800
|
+
if (action.choices !== void 0 && !_choices_to_array(action.choices).includes(value)) {
|
|
2801
|
+
let args = {
|
|
2802
|
+
value,
|
|
2803
|
+
choices: _choices_to_array(action.choices).map(repr).join(", ")
|
|
2804
|
+
};
|
|
2805
|
+
let msg = "invalid choice: %(value)r (choose from %(choices)s)";
|
|
2806
|
+
throw new ArgumentError(action, sub(msg, args));
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
format_usage() {
|
|
2810
|
+
let formatter = this._get_formatter();
|
|
2811
|
+
formatter.add_usage(this.usage, this._actions, this._mutually_exclusive_groups);
|
|
2812
|
+
return formatter.format_help();
|
|
2813
|
+
}
|
|
2814
|
+
format_help() {
|
|
2815
|
+
let formatter = this._get_formatter();
|
|
2816
|
+
formatter.add_usage(this.usage, this._actions, this._mutually_exclusive_groups);
|
|
2817
|
+
formatter.add_text(this.description);
|
|
2818
|
+
for (let action_group of this._action_groups) {
|
|
2819
|
+
formatter.start_section(action_group.title);
|
|
2820
|
+
formatter.add_text(action_group.description);
|
|
2821
|
+
formatter.add_arguments(action_group._group_actions);
|
|
2822
|
+
formatter.end_section();
|
|
2823
|
+
}
|
|
2824
|
+
formatter.add_text(this.epilog);
|
|
2825
|
+
return formatter.format_help();
|
|
2826
|
+
}
|
|
2827
|
+
_get_formatter() {
|
|
2828
|
+
return new this.formatter_class({ prog: this.prog });
|
|
2829
|
+
}
|
|
2830
|
+
print_usage(file = void 0) {
|
|
2831
|
+
if (file === void 0)
|
|
2832
|
+
file = process.stdout;
|
|
2833
|
+
this._print_message(this.format_usage(), file);
|
|
2834
|
+
}
|
|
2835
|
+
print_help(file = void 0) {
|
|
2836
|
+
if (file === void 0)
|
|
2837
|
+
file = process.stdout;
|
|
2838
|
+
this._print_message(this.format_help(), file);
|
|
2839
|
+
}
|
|
2840
|
+
_print_message(message, file = void 0) {
|
|
2841
|
+
if (message) {
|
|
2842
|
+
if (file === void 0)
|
|
2843
|
+
file = process.stderr;
|
|
2844
|
+
file.write(message);
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
exit(status = 0, message = void 0) {
|
|
2848
|
+
if (message) {
|
|
2849
|
+
this._print_message(message, process.stderr);
|
|
2850
|
+
}
|
|
2851
|
+
process.exit(status);
|
|
2852
|
+
}
|
|
2853
|
+
error(message) {
|
|
2854
|
+
if (this.debug === true)
|
|
2855
|
+
throw new Error(message);
|
|
2856
|
+
this.print_usage(process.stderr);
|
|
2857
|
+
let args = { prog: this.prog, message };
|
|
2858
|
+
this.exit(2, sub("%(prog)s: error: %(message)s\n", args));
|
|
2859
|
+
}
|
|
2860
|
+
}));
|
|
2861
|
+
module2.exports = {
|
|
2862
|
+
ArgumentParser: ArgumentParser2,
|
|
2863
|
+
ArgumentError,
|
|
2864
|
+
ArgumentTypeError,
|
|
2865
|
+
BooleanOptionalAction,
|
|
2866
|
+
FileType,
|
|
2867
|
+
HelpFormatter,
|
|
2868
|
+
ArgumentDefaultsHelpFormatter,
|
|
2869
|
+
RawDescriptionHelpFormatter,
|
|
2870
|
+
RawTextHelpFormatter,
|
|
2871
|
+
MetavarTypeHelpFormatter,
|
|
2872
|
+
Namespace,
|
|
2873
|
+
Action,
|
|
2874
|
+
ONE_OR_MORE,
|
|
2875
|
+
OPTIONAL,
|
|
2876
|
+
PARSER,
|
|
2877
|
+
REMAINDER,
|
|
2878
|
+
SUPPRESS,
|
|
2879
|
+
ZERO_OR_MORE
|
|
2880
|
+
};
|
|
2881
|
+
Object.defineProperty(module2.exports, "Const", {
|
|
2882
|
+
get() {
|
|
2883
|
+
let result = {};
|
|
2884
|
+
Object.entries({ ONE_OR_MORE, OPTIONAL, PARSER, REMAINDER, SUPPRESS, ZERO_OR_MORE }).forEach(([n, v]) => {
|
|
2885
|
+
Object.defineProperty(result, n, {
|
|
2886
|
+
get() {
|
|
2887
|
+
deprecate(n, sub("use argparse.%s instead of argparse.Const.%s", n, n));
|
|
2888
|
+
return v;
|
|
2889
|
+
}
|
|
2890
|
+
});
|
|
2891
|
+
});
|
|
2892
|
+
Object.entries({ _UNRECOGNIZED_ARGS_ATTR }).forEach(([n, v]) => {
|
|
2893
|
+
Object.defineProperty(result, n, {
|
|
2894
|
+
get() {
|
|
2895
|
+
deprecate(n, sub("argparse.Const.%s is an internal symbol and will no longer be available", n));
|
|
2896
|
+
return v;
|
|
2897
|
+
}
|
|
2898
|
+
});
|
|
2899
|
+
});
|
|
2900
|
+
return result;
|
|
2901
|
+
},
|
|
2902
|
+
enumerable: false
|
|
2903
|
+
});
|
|
2904
|
+
}
|
|
2905
|
+
});
|
|
2906
|
+
|
|
2907
|
+
// src/index.ts
|
|
2908
|
+
var import_fs = require("fs");
|
|
2909
|
+
var import_path = __toESM(require("path"));
|
|
2910
|
+
var import_puppeteer = __toESM(require("puppeteer"));
|
|
2911
|
+
var import_argparse = __toESM(require_argparse());
|
|
2912
|
+
function normalizeUrl(url) {
|
|
2913
|
+
if (url.match(/:\/\//)) {
|
|
2914
|
+
return url;
|
|
2915
|
+
} else {
|
|
2916
|
+
return `https://${url}`;
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
(async () => {
|
|
2920
|
+
const pkg = JSON.parse(await import_fs.promises.readFile(import_path.default.join(__dirname, "../package.json"), "utf-8"));
|
|
2921
|
+
const parser = new import_argparse.ArgumentParser({
|
|
2922
|
+
description: pkg.description
|
|
2923
|
+
});
|
|
2924
|
+
parser.add_argument("-v", "--version", { action: "version", version: pkg.version });
|
|
2925
|
+
parser.add_argument("-f", "--foo", { help: "foo bar" });
|
|
2926
|
+
parser.add_argument("-b", "--bar", { help: "bar foo" });
|
|
2927
|
+
parser.add_argument("url", { help: "URL to fetch", metavar: "URL" });
|
|
2928
|
+
const args = parser.parse_args();
|
|
2929
|
+
const url = normalizeUrl(args.url);
|
|
2930
|
+
const browser = await import_puppeteer.default.launch({ headless: false });
|
|
2931
|
+
const page = await browser.newPage();
|
|
2932
|
+
await page.goto(url);
|
|
2933
|
+
const source = await page.content();
|
|
2934
|
+
await browser.close();
|
|
2935
|
+
console.log(source);
|
|
2936
|
+
})();
|