UNPKG

npm-min-peer

Version:

Get minimum version required by a peerDependency

1,307 lines (1,303 loc) 165 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // node_modules/argparse/lib/sub.js var require_sub = __commonJS({ "node_modules/argparse/lib/sub.js"(exports2, module2) { "use strict"; var { inspect } = require("util"); module2.exports = function sub(pattern, ...values) { let regex = /%(?:(%)|(-)?(\*)?(?:\((\w+)\))?([A-Za-z]))/g; let result = pattern.replace(regex, function(_, is_literal, is_left_align, is_padded, name, format) { if (is_literal) return "%"; let padded_count = 0; if (is_padded) { if (values.length === 0) throw new TypeError("not enough arguments for format string"); padded_count = values.shift(); if (!Number.isInteger(padded_count)) throw new TypeError("* wants int"); } let str; if (name !== void 0) { let dict = values[0]; if (typeof dict !== "object" || dict === null) throw new TypeError("format requires a mapping"); if (!(name in dict)) throw new TypeError(`no such key: '${name}'`); str = dict[name]; } else { if (values.length === 0) throw new TypeError("not enough arguments for format string"); str = values.shift(); } switch (format) { case "s": str = String(str); break; case "r": str = inspect(str); break; case "d": case "i": if (typeof str !== "number") { throw new TypeError(`%${format} format: a number is required, not ${typeof str}`); } str = String(str.toFixed(0)); break; default: throw new TypeError(`unsupported format character '${format}'`); } if (padded_count > 0) { return is_left_align ? str.padEnd(padded_count) : str.padStart(padded_count); } else { return str; } }); if (values.length) { if (values.length === 1 && typeof values[0] === "object" && values[0] !== null) { } else { throw new TypeError("not all arguments converted during string formatting"); } } return result; }; } }); // node_modules/argparse/lib/textwrap.js var require_textwrap = __commonJS({ "node_modules/argparse/lib/textwrap.js"(exports2, module2) { "use strict"; var wordsep_simple_re = /([\t\n\x0b\x0c\r ]+)/; var TextWrapper = class { /* * Object for wrapping/filling text. The public interface consists of * the wrap() and fill() methods; the other methods are just there for * subclasses to override in order to tweak the default behaviour. * If you want to completely replace the main wrapping algorithm, * you'll probably have to override _wrap_chunks(). * * Several instance attributes control various aspects of wrapping: * width (default: 70) * the maximum width of wrapped lines (unless break_long_words * is false) * initial_indent (default: "") * string that will be prepended to the first line of wrapped * output. Counts towards the line's width. * subsequent_indent (default: "") * string that will be prepended to all lines save the first * of wrapped output; also counts towards each line's width. * expand_tabs (default: true) * Expand tabs in input text to spaces before further processing. * Each tab will become 0 .. 'tabsize' spaces, depending on its position * in its line. If false, each tab is treated as a single character. * tabsize (default: 8) * Expand tabs in input text to 0 .. 'tabsize' spaces, unless * 'expand_tabs' is false. * replace_whitespace (default: true) * Replace all whitespace characters in the input text by spaces * after tab expansion. Note that if expand_tabs is false and * replace_whitespace is true, every tab will be converted to a * single space! * fix_sentence_endings (default: false) * Ensure that sentence-ending punctuation is always followed * by two spaces. Off by default because the algorithm is * (unavoidably) imperfect. * break_long_words (default: true) * Break words longer than 'width'. If false, those words will not * be broken, and some lines might be longer than 'width'. * break_on_hyphens (default: true) * Allow breaking hyphenated words. If true, wrapping will occur * preferably on whitespaces and right after hyphens part of * compound words. * drop_whitespace (default: true) * Drop leading and trailing whitespace from lines. * max_lines (default: None) * Truncate wrapped lines. * placeholder (default: ' [...]') * Append to the last line of truncated text. */ constructor(options = {}) { let { width = 70, initial_indent = "", subsequent_indent = "", expand_tabs = true, replace_whitespace = true, fix_sentence_endings = false, break_long_words = true, drop_whitespace = true, break_on_hyphens = true, tabsize = 8, max_lines = void 0, placeholder = " [...]" } = options; this.width = width; this.initial_indent = initial_indent; this.subsequent_indent = subsequent_indent; this.expand_tabs = expand_tabs; this.replace_whitespace = replace_whitespace; this.fix_sentence_endings = fix_sentence_endings; this.break_long_words = break_long_words; this.drop_whitespace = drop_whitespace; this.break_on_hyphens = break_on_hyphens; this.tabsize = tabsize; this.max_lines = max_lines; this.placeholder = placeholder; } // -- Private methods ----------------------------------------------- // (possibly useful for subclasses to override) _munge_whitespace(text) { if (this.expand_tabs) { text = text.replace(/\t/g, " ".repeat(this.tabsize)); } if (this.replace_whitespace) { text = text.replace(/[\t\n\x0b\x0c\r]/g, " "); } return text; } _split(text) { let chunks = text.split(wordsep_simple_re); chunks = chunks.filter(Boolean); return chunks; } _handle_long_word(reversed_chunks, cur_line, cur_len, width) { let space_left; if (width < 1) { space_left = 1; } else { space_left = width - cur_len; } if (this.break_long_words) { cur_line.push(reversed_chunks[reversed_chunks.length - 1].slice(0, space_left)); reversed_chunks[reversed_chunks.length - 1] = reversed_chunks[reversed_chunks.length - 1].slice(space_left); } else if (!cur_line) { cur_line.push(...reversed_chunks.pop()); } } _wrap_chunks(chunks) { let lines = []; let indent; if (this.width <= 0) { throw Error(`invalid width ${this.width} (must be > 0)`); } if (this.max_lines !== void 0) { if (this.max_lines > 1) { indent = this.subsequent_indent; } else { indent = this.initial_indent; } if (indent.length + this.placeholder.trimStart().length > this.width) { throw Error("placeholder too large for max width"); } } chunks = chunks.reverse(); while (chunks.length > 0) { let cur_line = []; let cur_len = 0; let indent2; if (lines) { indent2 = this.subsequent_indent; } else { indent2 = this.initial_indent; } let width = this.width - indent2.length; if (this.drop_whitespace && chunks[chunks.length - 1].trim() === "" && lines.length > 0) { chunks.pop(); } while (chunks.length > 0) { let l = chunks[chunks.length - 1].length; if (cur_len + l <= width) { cur_line.push(chunks.pop()); cur_len += l; } else { break; } } if (chunks.length && chunks[chunks.length - 1].length > width) { this._handle_long_word(chunks, cur_line, cur_len, width); cur_len = cur_line.map((l) => l.length).reduce((a, b) => a + b, 0); } if (this.drop_whitespace && cur_line.length > 0 && cur_line[cur_line.length - 1].trim() === "") { cur_len -= cur_line[cur_line.length - 1].length; cur_line.pop(); } if (cur_line) { 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) { lines.push(indent2 + cur_line.join("")); } else { let had_break = false; while (cur_line) { if (cur_line[cur_line.length - 1].trim() && cur_len + this.placeholder.length <= width) { cur_line.push(this.placeholder); lines.push(indent2 + cur_line.join("")); had_break = true; break; } cur_len -= cur_line[-1].length; cur_line.pop(); } if (!had_break) { if (lines) { let prev_line = lines[lines.length - 1].trimEnd(); if (prev_line.length + this.placeholder.length <= this.width) { lines[lines.length - 1] = prev_line + this.placeholder; break; } } lines.push(indent2 + this.placeholder.lstrip()); } break; } } } return lines; } _split_chunks(text) { text = this._munge_whitespace(text); return this._split(text); } // -- Public interface ---------------------------------------------- wrap(text) { let chunks = this._split_chunks(text); return this._wrap_chunks(chunks); } fill(text) { return this.wrap(text).join("\n"); } }; function wrap(text, options = {}) { let { width = 70, ...kwargs } = options; let w = new TextWrapper(Object.assign({ width }, kwargs)); return w.wrap(text); } function fill(text, options = {}) { let { width = 70, ...kwargs } = options; let w = new TextWrapper(Object.assign({ width }, kwargs)); return w.fill(text); } var _whitespace_only_re = /^[ \t]+$/mg; var _leading_whitespace_re = /(^[ \t]*)(?:[^ \t\n])/mg; function dedent(text) { let margin = void 0; text = text.replace(_whitespace_only_re, ""); let indents = text.match(_leading_whitespace_re) || []; for (let indent of indents) { indent = indent.slice(0, -1); if (margin === void 0) { margin = indent; } else if (indent.startsWith(margin)) { } else if (margin.startsWith(indent)) { margin = indent; } else { for (let i = 0; i < margin.length && i < indent.length; i++) { if (margin[i] !== indent[i]) { margin = margin.slice(0, i); break; } } } } if (margin) { text = text.replace(new RegExp("^" + margin, "mg"), ""); } return text; } module2.exports = { wrap, fill, dedent }; } }); // node_modules/argparse/argparse.js var require_argparse = __commonJS({ "node_modules/argparse/argparse.js"(exports2, module2) { "use strict"; var SUPPRESS = "==SUPPRESS=="; var OPTIONAL = "?"; var ZERO_OR_MORE = "*"; var ONE_OR_MORE = "+"; var PARSER = "A..."; var REMAINDER = "..."; var _UNRECOGNIZED_ARGS_ATTR = "_unrecognized_args"; var assert = require("assert"); var util = require("util"); var fs3 = require("fs"); var sub = require_sub(); var path3 = require("path"); var repr = util.inspect; function get_argv() { return process.argv.slice(1); } function get_terminal_size() { return { columns: +process.env.COLUMNS || process.stdout.columns || 80 }; } function hasattr(object, name) { return Object.prototype.hasOwnProperty.call(object, name); } function getattr(object, name, value) { return hasattr(object, name) ? object[name] : value; } function setattr(object, name, value) { object[name] = value; } function setdefault(object, name, value) { if (!hasattr(object, name)) object[name] = value; return object[name]; } function delattr(object, name) { delete object[name]; } function range(from, to, step = 1) { if (arguments.length === 1) [to, from] = [from, 0]; if (typeof from !== "number" || typeof to !== "number" || typeof step !== "number") { throw new TypeError("argument cannot be interpreted as an integer"); } if (step === 0) throw new TypeError("range() arg 3 must not be zero"); let result = []; if (step > 0) { for (let i = from; i < to; i += step) result.push(i); } else { for (let i = from; i > to; i += step) result.push(i); } return result; } function splitlines(str, keepends = false) { let result; if (!keepends) { result = str.split(/\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029]/); } else { result = []; let parts = str.split(/(\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029])/); for (let i = 0; i < parts.length; i += 2) { result.push(parts[i] + (i + 1 < parts.length ? parts[i + 1] : "")); } } if (!result[result.length - 1]) result.pop(); return result; } function _string_lstrip(string, prefix_chars) { let idx = 0; while (idx < string.length && prefix_chars.includes(string[idx])) idx++; return idx ? string.slice(idx) : string; } function _string_split(string, sep, maxsplit) { let result = string.split(sep); if (result.length > maxsplit) { result = result.slice(0, maxsplit).concat([result.slice(maxsplit).join(sep)]); } return result; } function _array_equal(array1, array2) { if (array1.length !== array2.length) return false; for (let i = 0; i < array1.length; i++) { if (array1[i] !== array2[i]) return false; } return true; } function _array_remove(array, item) { let idx = array.indexOf(item); if (idx === -1) throw new TypeError(sub("%r not in list", item)); array.splice(idx, 1); } function _choices_to_array(choices) { if (choices === void 0) { return []; } else if (Array.isArray(choices)) { return choices; } else if (choices !== null && typeof choices[Symbol.iterator] === "function") { return Array.from(choices); } else if (typeof choices === "object" && choices !== null) { return Object.keys(choices); } else { throw new Error(sub("invalid choices value: %r", choices)); } } function _callable(cls) { let result = { // object is needed for inferred class name [cls.name]: function(...args) { let this_class = new.target === result || !new.target; return Reflect.construct(cls, args, this_class ? cls : new.target); } }; result[cls.name].prototype = cls.prototype; cls.prototype[Symbol.toStringTag] = cls.name; return result[cls.name]; } function _alias(object, from, to) { try { let name = object.constructor.name; Object.defineProperty(object, from, { value: util.deprecate(object[to], sub( "%s.%s() is renamed to %s.%s()", name, from, name, to )), enumerable: false }); } catch { } } function _camelcase_alias(_class) { for (let name of Object.getOwnPropertyNames(_class.prototype)) { let camelcase = name.replace(/\w_[a-z]/g, (s) => s[0] + s[2].toUpperCase()); if (camelcase !== name) _alias(_class.prototype, camelcase, name); } return _class; } function _to_legacy_name(key) { key = key.replace(/\w_[a-z]/g, (s) => s[0] + s[2].toUpperCase()); if (key === "default") key = "defaultValue"; if (key === "const") key = "constant"; return key; } function _to_new_name(key) { if (key === "defaultValue") key = "default"; if (key === "constant") key = "const"; key = key.replace(/[A-Z]/g, (c) => "_" + c.toLowerCase()); return key; } var no_default = Symbol("no_default_value"); function _parse_opts(args, descriptor) { function get_name() { let stack = new Error().stack.split("\n").map((x) => x.match(/^ at (.*) \(.*\)$/)).filter(Boolean).map((m) => m[1]).map((fn) => fn.match(/[^ .]*$/)[0]); if (stack.length && stack[0] === get_name.name) stack.shift(); if (stack.length && stack[0] === _parse_opts.name) stack.shift(); return stack.length ? stack[0] : ""; } args = Array.from(args); let kwargs = {}; let result = []; let last_opt = args.length && args[args.length - 1]; if (typeof last_opt === "object" && last_opt !== null && !Array.isArray(last_opt) && (!last_opt.constructor || last_opt.constructor.name === "Object")) { kwargs = Object.assign({}, args.pop()); } let renames = []; for (let key of Object.keys(descriptor)) { let old_name = _to_legacy_name(key); if (old_name !== key && old_name in kwargs) { if (key in kwargs) { } else { kwargs[key] = kwargs[old_name]; } renames.push([old_name, key]); delete kwargs[old_name]; } } if (renames.length) { let name = get_name(); deprecate("camelcase_" + name, sub( "%s(): following options are renamed: %s", name, renames.map(([a, b]) => sub("%r -> %r", a, b)) )); } let missing_positionals = []; let positional_count = args.length; for (let [key, def] of Object.entries(descriptor)) { if (key[0] === "*") { if (key.length > 0 && key[1] === "*") { let renames2 = []; for (let key2 of Object.keys(kwargs)) { let new_name = _to_new_name(key2); if (new_name !== key2 && key2 in kwargs) { if (new_name in kwargs) { } else { kwargs[new_name] = kwargs[key2]; } renames2.push([key2, new_name]); delete kwargs[key2]; } } if (renames2.length) { let name = get_name(); deprecate("camelcase_" + name, sub( "%s(): following options are renamed: %s", name, renames2.map(([a, b]) => sub("%r -> %r", a, b)) )); } result.push(kwargs); kwargs = {}; } else { result.push(args); args = []; } } else if (key in kwargs && args.length > 0) { throw new TypeError(sub("%s() got multiple values for argument %r", get_name(), key)); } else if (key in kwargs) { result.push(kwargs[key]); delete kwargs[key]; } else if (args.length > 0) { result.push(args.shift()); } else if (def !== no_default) { result.push(def); } else { missing_positionals.push(key); } } if (Object.keys(kwargs).length) { throw new TypeError(sub( "%s() got an unexpected keyword argument %r", get_name(), Object.keys(kwargs)[0] )); } if (args.length) { let from = Object.entries(descriptor).filter(([k, v]) => k[0] !== "*" && v !== no_default).length; let to = Object.entries(descriptor).filter(([k]) => k[0] !== "*").length; 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" )); } if (missing_positionals.length) { let strs = missing_positionals.map(repr); if (strs.length > 1) strs[strs.length - 1] = "and " + strs[strs.length - 1]; let str_joined = strs.join(strs.length === 2 ? "" : ", "); throw new TypeError(sub( "%s() missing %i required positional argument%s: %s", get_name(), strs.length, strs.length === 1 ? "" : "s", str_joined )); } return result; } var _deprecations = {}; function deprecate(id, string) { _deprecations[id] = _deprecations[id] || util.deprecate(() => { }, string); _deprecations[id](); } function _AttributeHolder(cls = Object) { return class _AttributeHolder extends cls { [util.inspect.custom]() { let type_name = this.constructor.name; let arg_strings = []; let star_args = {}; for (let arg of this._get_args()) { arg_strings.push(repr(arg)); } for (let [name, value] of this._get_kwargs()) { if (/^[a-z_][a-z0-9_$]*$/i.test(name)) { arg_strings.push(sub("%s=%r", name, value)); } else { star_args[name] = value; } } if (Object.keys(star_args).length) { arg_strings.push(sub("**%s", repr(star_args))); } return sub("%s(%s)", type_name, arg_strings.join(", ")); } toString() { return this[util.inspect.custom](); } _get_kwargs() { return Object.entries(this); } _get_args() { return []; } }; } function _copy_items(items) { if (items === void 0) { return []; } return items.slice(0); } var HelpFormatter = _camelcase_alias(_callable(class HelpFormatter { /* * Formatter for generating usage messages and argument help strings. * * Only the name of this class is considered a public API. All the methods * provided by the class are considered an implementation detail. */ constructor() { let [ prog, indent_increment, max_help_position, width ] = _parse_opts(arguments, { prog: no_default, indent_increment: 2, max_help_position: 24, width: void 0 }); if (width === void 0) { width = get_terminal_size().columns; width -= 2; } this._prog = prog; this._indent_increment = indent_increment; this._max_help_position = Math.min( max_help_position, Math.max(width - 20, indent_increment * 2) ); this._width = width; this._current_indent = 0; this._level = 0; this._action_max_length = 0; this._root_section = this._Section(this, void 0); this._current_section = this._root_section; this._whitespace_matcher = /[ \t\n\r\f\v]+/g; this._long_break_matcher = /\n\n\n+/g; } // =============================== // Section and indentation methods // =============================== _indent() { this._current_indent += this._indent_increment; this._level += 1; } _dedent() { this._current_indent -= this._indent_increment; assert(this._current_indent >= 0, "Indent decreased below 0."); this._level -= 1; } _add_item(func, args) { this._current_section.items.push([func, args]); } // ======================== // Message building methods // ======================== start_section(heading) { this._indent(); let section = this._Section(this, this._current_section, heading); this._add_item(section.format_help.bind(section), []); this._current_section = section; } end_section() { this._current_section = this._current_section.parent; this._dedent(); } add_text(text) { if (text !== SUPPRESS && text !== void 0) { this._add_item(this._format_text.bind(this), [text]); } } add_usage(usage, actions, groups, prefix = void 0) { if (usage !== SUPPRESS) { let args = [usage, actions, groups, prefix]; this._add_item(this._format_usage.bind(this), args); } } add_argument(action) { if (action.help !== SUPPRESS) { let invocations = [this._format_action_invocation(action)]; for (let subaction of this._iter_indented_subactions(action)) { invocations.push(this._format_action_invocation(subaction)); } let invocation_length = Math.max(...invocations.map((invocation) => invocation.length)); let action_length = invocation_length + this._current_indent; this._action_max_length = Math.max( this._action_max_length, action_length ); this._add_item(this._format_action.bind(this), [action]); } } add_arguments(actions) { for (let action of actions) { this.add_argument(action); } } // ======================= // Help-formatting methods // ======================= format_help() { let help = this._root_section.format_help(); if (help) { help = help.replace(this._long_break_matcher, "\n\n"); help = help.replace(/^\n+|\n+$/g, "") + "\n"; } return help; } _join_parts(part_strings) { return part_strings.filter((part) => part && part !== SUPPRESS).join(""); } _format_usage(usage, actions, groups, prefix) { if (prefix === void 0) { prefix = "usage: "; } if (usage !== void 0) { usage = sub(usage, { prog: this._prog }); } else if (usage === void 0 && !actions.length) { usage = sub("%(prog)s", { prog: this._prog }); } else if (usage === void 0) { let prog = sub("%(prog)s", { prog: this._prog }); let optionals = []; let positionals = []; for (let action of actions) { if (action.option_strings.length) { optionals.push(action); } else { positionals.push(action); } } let action_usage = this._format_actions_usage([].concat(optionals).concat(positionals), groups); usage = [prog, action_usage].map(String).join(" "); let text_width = this._width - this._current_indent; if (prefix.length + usage.length > text_width) { let part_regexp = /\(.*?\)+(?=\s|$)|\[.*?\]+(?=\s|$)|\S+/g; let opt_usage = this._format_actions_usage(optionals, groups); let pos_usage = this._format_actions_usage(positionals, groups); let opt_parts = opt_usage.match(part_regexp) || []; let pos_parts = pos_usage.match(part_regexp) || []; assert(opt_parts.join(" ") === opt_usage); assert(pos_parts.join(" ") === pos_usage); let get_lines = (parts, indent, prefix2 = void 0) => { let lines2 = []; let line = []; let line_len; if (prefix2 !== void 0) { line_len = prefix2.length - 1; } else { line_len = indent.length - 1; } for (let part of parts) { if (line_len + 1 + part.length > text_width && line) { lines2.push(indent + line.join(" ")); line = []; line_len = indent.length - 1; } line.push(part); line_len += part.length + 1; } if (line.length) { lines2.push(indent + line.join(" ")); } if (prefix2 !== void 0) { lines2[0] = lines2[0].slice(indent.length); } return lines2; }; let lines; if (prefix.length + prog.length <= 0.75 * text_width) { let indent = " ".repeat(prefix.length + prog.length + 1); if (opt_parts.length) { lines = get_lines([prog].concat(opt_parts), indent, prefix); lines = lines.concat(get_lines(pos_parts, indent)); } else if (pos_parts.length) { lines = get_lines([prog].concat(pos_parts), indent, prefix); } else { lines = [prog]; } } else { let indent = " ".repeat(prefix.length); let parts = [].concat(opt_parts).concat(pos_parts); lines = get_lines(parts, indent); if (lines.length > 1) { lines = []; lines = lines.concat(get_lines(opt_parts, indent)); lines = lines.concat(get_lines(pos_parts, indent)); } lines = [prog].concat(lines); } usage = lines.join("\n"); } } return sub("%s%s\n\n", prefix, usage); } _format_actions_usage(actions, groups) { let group_actions = /* @__PURE__ */ new Set(); let inserts = {}; for (let group of groups) { let start = actions.indexOf(group._group_actions[0]); if (start === -1) { continue; } else { let end = start + group._group_actions.length; if (_array_equal(actions.slice(start, end), group._group_actions)) { for (let action of group._group_actions) { group_actions.add(action); } if (!group.required) { if (start in inserts) { inserts[start] += " ["; } else { inserts[start] = "["; } if (end in inserts) { inserts[end] += "]"; } else { inserts[end] = "]"; } } else { if (start in inserts) { inserts[start] += " ("; } else { inserts[start] = "("; } if (end in inserts) { inserts[end] += ")"; } else { inserts[end] = ")"; } } for (let i of range(start + 1, end)) { inserts[i] = "|"; } } } } let parts = []; for (let [i, action] of Object.entries(actions)) { if (action.help === SUPPRESS) { parts.push(void 0); if (inserts[+i] === "|") { delete inserts[+i]; } else if (inserts[+i + 1] === "|") { delete inserts[+i + 1]; } } else if (!action.option_strings.length) { let default_value = this._get_default_metavar_for_positional(action); let part = this._format_args(action, default_value); if (group_actions.has(action)) { if (part[0] === "[" && part[part.length - 1] === "]") { part = part.slice(1, -1); } } parts.push(part); } else { let option_string = action.option_strings[0]; let part; if (action.nargs === 0) { part = action.format_usage(); } else { let default_value = this._get_default_metavar_for_optional(action); let args_string = this._format_args(action, default_value); part = sub("%s %s", option_string, args_string); } if (!action.required && !group_actions.has(action)) { part = sub("[%s]", part); } parts.push(part); } } for (let i of Object.keys(inserts).map(Number).sort((a, b) => b - a)) { parts.splice(+i, 0, inserts[+i]); } let text = parts.filter(Boolean).join(" "); text = text.replace(/([\[(]) /g, "$1"); text = text.replace(/ ([\])])/g, "$1"); text = text.replace(/[\[(] *[\])]/g, ""); text = text.replace(/\(([^|]*)\)/g, "$1", text); text = text.trim(); return text; } _format_text(text) { if (text.includes("%(prog)")) { text = sub(text, { prog: this._prog }); } let text_width = Math.max(this._width - this._current_indent, 11); let indent = " ".repeat(this._current_indent); return this._fill_text(text, text_width, indent) + "\n\n"; } _format_action(action) { let help_position = Math.min( this._action_max_length + 2, this._max_help_position ); let help_width = Math.max(this._width - help_position, 11); let action_width = help_position - this._current_indent - 2; let action_header = this._format_action_invocation(action); let indent_first; if (!action.help) { let tup = [this._current_indent, "", action_header]; action_header = sub("%*s%s\n", ...tup); } else if (action_header.length <= action_width) { let tup = [this._current_indent, "", action_width, action_header]; action_header = sub("%*s%-*s ", ...tup); indent_first = 0; } else { let tup = [this._current_indent, "", action_header]; action_header = sub("%*s%s\n", ...tup); indent_first = help_position; } let parts = [action_header]; if (action.help) { let help_text = this._expand_help(action); let help_lines = this._split_lines(help_text, help_width); parts.push(sub("%*s%s\n", indent_first, "", help_lines[0])); for (let line of help_lines.slice(1)) { parts.push(sub("%*s%s\n", help_position, "", line)); } } else if (!action_header.endsWith("\n")) { parts.push("\n"); } for (let subaction of this._iter_indented_subactions(action)) { parts.push(this._format_action(subaction)); } return this._join_parts(parts); } _format_action_invocation(action) { if (!action.option_strings.length) { let default_value = this._get_default_metavar_for_positional(action); let metavar = this._metavar_formatter(action, default_value)(1)[0]; return metavar; } else { let parts = []; if (action.nargs === 0) { parts = parts.concat(action.option_strings); } else { let default_value = this._get_default_metavar_for_optional(action); let args_string = this._format_args(action, default_value); for (let option_string of action.option_strings) { parts.push(sub("%s %s", option_string, args_string)); } } return parts.join(", "); } } _metavar_formatter(action, default_metavar) { let result; if (action.metavar !== void 0) { result = action.metavar; } else if (action.choices !== void 0) { let choice_strs = _choices_to_array(action.choices).map(String); result = sub("{%s}", choice_strs.join(",")); } else { result = default_metavar; } function format(tuple_size) { if (Array.isArray(result)) { return result; } else { return Array(tuple_size).fill(result); } } return format; } _format_args(action, default_metavar) { let get_metavar = this._metavar_formatter(action, default_metavar); let result; if (action.nargs === void 0) { result = sub("%s", ...get_metavar(1)); } else if (action.nargs === OPTIONAL) { result = sub("[%s]", ...get_metavar(1)); } else if (action.nargs === ZERO_OR_MORE) { let metavar = get_metavar(1); if (metavar.length === 2) { result = sub("[%s [%s ...]]", ...metavar); } else { result = sub("[%s ...]", ...metavar); } } else if (action.nargs === ONE_OR_MORE) { result = sub("%s [%s ...]", ...get_metavar(2)); } else if (action.nargs === REMAINDER) { result = "..."; } else if (action.nargs === PARSER) { result = sub("%s ...", ...get_metavar(1)); } else if (action.nargs === SUPPRESS) { result = ""; } else { let formats; try { formats = range(action.nargs).map(() => "%s"); } catch (err) { throw new TypeError("invalid nargs value"); } result = sub(formats.join(" "), ...get_metavar(action.nargs)); } return result; } _expand_help(action) { let params = Object.assign({ prog: this._prog }, action); for (let name of Object.keys(params)) { if (params[name] === SUPPRESS) { delete params[name]; } } for (let name of Object.keys(params)) { if (params[name] && params[name].name) { params[name] = params[name].name; } } if (params.choices !== void 0) { let choices_str = _choices_to_array(params.choices).map(String).join(", "); params.choices = choices_str; } for (let key of Object.keys(params)) { let old_name = _to_legacy_name(key); if (old_name !== key) { params[old_name] = params[key]; } } return sub(this._get_help_string(action), params); } *_iter_indented_subactions(action) { if (typeof action._get_subactions === "function") { this._indent(); yield* action._get_subactions(); this._dedent(); } } _split_lines(text, width) { text = text.replace(this._whitespace_matcher, " ").trim(); let textwrap = require_textwrap(); return textwrap.wrap(text, { width }); } _fill_text(text, width, indent) { text = text.replace(this._whitespace_matcher, " ").trim(); let textwrap = require_textwrap(); return textwrap.fill(text, { width, initial_indent: indent, subsequent_indent: indent }); } _get_help_string(action) { return action.help; } _get_default_metavar_for_optional(action) { return action.dest.toUpperCase(); } _get_default_metavar_for_positional(action) { return action.dest; } })); HelpFormatter.prototype._Section = _callable(class _Section { constructor(formatter, parent, heading = void 0) { this.formatter = formatter; this.parent = parent; this.heading = heading; this.items = []; } format_help() { if (this.parent !== void 0) { this.formatter._indent(); } let item_help = this.formatter._join_parts(this.items.map(([func, args]) => func.apply(null, args))); if (this.parent !== void 0) { this.formatter._dedent(); } if (!item_help) { return ""; } let heading; if (this.heading !== SUPPRESS && this.heading !== void 0) { let current_indent = this.formatter._current_indent; heading = sub("%*s%s:\n", current_indent, "", this.heading); } else { heading = ""; } return this.formatter._join_parts(["\n", heading, item_help, "\n"]); } }); var RawDescriptionHelpFormatter = _camelcase_alias(_callable(class RawDescriptionHelpFormatter extends HelpFormatter { /* * Help message formatter which retains any formatting in descriptions. * * Only the name of this class is considered a public API. All the methods * provided by the class are considered an implementation detail. */ _fill_text(text, width, indent) { return splitlines(text, true).map((line) => indent + line).join(""); } })); var RawTextHelpFormatter = _camelcase_alias(_callable(class RawTextHelpFormatter extends RawDescriptionHelpFormatter { /* * Help message formatter which retains formatting of all help text. * * Only the name of this class is considered a public API. All the methods * provided by the class are considered an implementation detail. */ _split_lines(text) { return splitlines(text); } })); var ArgumentDefaultsHelpFormatter = _camelcase_alias(_callable(class ArgumentDefaultsHelpFormatter extends HelpFormatter { /* * Help message formatter which adds default values to argument help. * * Only the name of this class is considered a public API. All the methods * provided by the class are considered an implementation detail. */ _get_help_string(action) { let help = action.help; if (!action.help.includes("%(default)") && !action.help.includes("%(defaultValue)")) { if (action.default !== SUPPRESS) { let defaulting_nargs = [OPTIONAL, ZERO_OR_MORE]; if (action.option_strings.length || defaulting_nargs.includes(action.nargs)) { help += " (default: %(default)s)"; } } } return help; } })); var MetavarTypeHelpFormatter = _camelcase_alias(_callable(class MetavarTypeHelpFormatter extends HelpFormatter { /* * Help message formatter which uses the argument 'type' as the default * metavar value (instead of the argument 'dest') * * Only the name of this class is considered a public API. All the methods * provided by the class are considered an implementation detail. */ _get_default_metavar_for_optional(action) { return typeof action.type === "function" ? action.type.name : action.type; } _get_default_metavar_for_positional(action) { return typeof action.type === "function" ? action.type.name : action.type; } })); function _get_action_name(argument) { if (argument === void 0) { return void 0; } else if (argument.option_strings.length) { return argument.option_strings.join("/"); } else if (![void 0, SUPPRESS].includes(argument.metavar)) { return argument.metavar; } else if (![void 0, SUPPRESS].includes(argument.dest)) { return argument.dest; } else { return void 0; } } var ArgumentError = _callable(class ArgumentError extends Error { /* * An error from creating or using an argument (optional or positional). * * The string value of this exception is the message, augmented with * information about the argument that caused it. */ constructor(argument, message) { super(); this.name = "ArgumentError"; this._argument_name = _get_action_name(argument); this._message = message; this.message = this.str(); } str() { let format; if (this._argument_name === void 0) { format = "%(message)s"; } else { format = "argument %(argument_name)s: %(message)s"; } return sub(format, { message: this._message, argument_name: this._argument_name }); } }); var ArgumentTypeError = _callable(class ArgumentTypeError extends Error { /* * An error from trying to convert a command line string to a type. */ constructor(message) { super(message); this.name = "ArgumentTypeError"; } }); var Action = _camelcase_alias(_callable(class Action extends _AttributeHolder(Function) { /* * Information about how to convert command line strings to Python objects. * * Action objects are used by an ArgumentParser to represent the information * needed to parse a single argument from one or more strings from the * command line. The keyword arguments to the Action constructor are also * all attributes of Action instances. * * Keyword Arguments: * * - option_strings -- A list of command-line option strings which * should be associated with this action. * * - dest -- The name of the attribute to hold the created object(s) * * - nargs -- The number of command-line arguments that should be * consumed. By default, one argument will be consumed and a single * value will be produced. Other values include: * - N (an integer) consumes N arguments (and produces a list) * - '?' consumes zero or one arguments * - '*' consumes zero or more arguments (and produces a list) * - '+' consumes one or more arguments (and produces a list) * Note that the difference between the default and nargs=1 is that * with the default, a single value will be produced, while with * nargs=1, a list containing a single value will be produced. * * - const -- The value to be produced if the option is specified and the * option uses an action that takes no values. * * - default -- The value to be produced if the option is not specified. * * - type -- A callable that accepts a single string argument, and * returns the converted value. The standard Python types str, int, * float, and complex are useful examples of such callables. If None, * str is used. * * - choices -- A container of values that should be allowed. If not None, * after a command-line argument has been converted to the appropriate * type, an exception will be raised if it is not a member of this * collection. * * - required -- True if the action must always be specified at the * command line. This is only meaningful for optional command-line * arguments. * * - help -- The help string describing the argument. * * - metavar -- The name to be used for the option's argument with the * help string. If None, the 'dest' value will be used as the name. */ constructor() { let [ option_strings, dest, nargs, const_value, default_value, type, choices, required, help, metavar ] = _parse_opts(arguments, { option_strings: no_default, dest: no_default, nargs: void 0, const: void 0, default: void 0, type: void 0, choices: void 0, required: false, help: void 0, metavar: void 0 }); super("return arguments.callee.call.apply(arguments.callee, arguments)"); this.option_strings = option_strings;