UNPKG

@modern-js/utils

Version:

A Progressive React Framework for modern web development.

1,054 lines • 71.3 kB
(()=>{ var t = { 81: (t)=>{ "use strict"; t.exports = require("child_process"); }, 361: (t)=>{ "use strict"; t.exports = require("events"); }, 147: (t)=>{ "use strict"; t.exports = require("fs"); }, 17: (t)=>{ "use strict"; t.exports = require("path"); }, 282: (t)=>{ "use strict"; t.exports = require("process"); }, 632: (t, e, i)=>{ const { Argument: n } = i(535); const { Command: s } = i(302); const { CommanderError: r, InvalidArgumentError: o } = i(796); const { Help: a } = i(519); const { Option: l } = i(437); e = t.exports = new s; e.program = e; e.Argument = n; e.Command = s; e.CommanderError = r; e.Help = a; e.InvalidArgumentError = o; e.InvalidOptionArgumentError = o; e.Option = l; }, 535: (t, e, i)=>{ const { InvalidArgumentError: n } = i(796); class Argument { constructor(t, e){ this.description = e || ""; this.variadic = false; this.parseArg = void 0; this.defaultValue = void 0; this.defaultValueDescription = void 0; this.argChoices = void 0; switch(t[0]){ case "<": this.required = true; this._name = t.slice(1, -1); break; case "[": this.required = false; this._name = t.slice(1, -1); break; default: this.required = true; this._name = t; break; } if (this._name.length > 3 && "..." === this._name.slice(-3)) { this.variadic = true; this._name = this._name.slice(0, -3); } } name() { return this._name; } _concatValue(t, e) { if (e === this.defaultValue || !Array.isArray(e)) return [ t ]; return e.concat(t); } default(t, e) { this.defaultValue = t; this.defaultValueDescription = e; return this; } argParser(t) { this.parseArg = t; return this; } choices(t) { this.argChoices = t.slice(); this.parseArg = (t, e)=>{ if (!this.argChoices.includes(t)) throw new n(`Allowed choices are ${this.argChoices.join(", ")}.`); if (this.variadic) return this._concatValue(t, e); return t; }; return this; } argRequired() { this.required = true; return this; } argOptional() { this.required = false; return this; } } function humanReadableArgName(t) { const e = t.name() + (true === t.variadic ? "..." : ""); return t.required ? "<" + e + ">" : "[" + e + "]"; } e.Argument = Argument; e.humanReadableArgName = humanReadableArgName; }, 302: (t, e, i)=>{ const n = i(361).EventEmitter; const s = i(81); const r = i(17); const o = i(147); const a = i(282); const { Argument: l, humanReadableArgName: h } = i(535); const { CommanderError: u } = i(796); const { Help: c } = i(519); const { Option: p, splitOptionFlags: m, DualOptions: d } = i(437); const { suggestSimilar: f } = i(860); class Command extends n { constructor(t){ super(); this.commands = []; this.options = []; this.parent = null; this._allowUnknownOption = false; this._allowExcessArguments = true; this._args = []; this.args = []; this.rawArgs = []; this.processedArgs = []; this._scriptPath = null; this._name = t || ""; this._optionValues = {}; this._optionValueSources = {}; this._storeOptionsAsProperties = false; this._actionHandler = null; this._executableHandler = false; this._executableFile = null; this._executableDir = null; this._defaultCommandName = null; this._exitCallback = null; this._aliases = []; this._combineFlagAndOptionalValue = true; this._description = ""; this._summary = ""; this._argsDescription = void 0; this._enablePositionalOptions = false; this._passThroughOptions = false; this._lifeCycleHooks = {}; this._showHelpAfterError = false; this._showSuggestionAfterError = true; this._outputConfiguration = { writeOut: (t)=>a.stdout.write(t), writeErr: (t)=>a.stderr.write(t), getOutHelpWidth: ()=>a.stdout.isTTY ? a.stdout.columns : void 0, getErrHelpWidth: ()=>a.stderr.isTTY ? a.stderr.columns : void 0, outputError: (t, e)=>e(t) }; this._hidden = false; this._hasHelpOption = true; this._helpFlags = "-h, --help"; this._helpDescription = "display help for command"; this._helpShortFlag = "-h"; this._helpLongFlag = "--help"; this._addImplicitHelpCommand = void 0; this._helpCommandName = "help"; this._helpCommandnameAndArgs = "help [command]"; this._helpCommandDescription = "display help for command"; this._helpConfiguration = {}; } copyInheritedSettings(t) { this._outputConfiguration = t._outputConfiguration; this._hasHelpOption = t._hasHelpOption; this._helpFlags = t._helpFlags; this._helpDescription = t._helpDescription; this._helpShortFlag = t._helpShortFlag; this._helpLongFlag = t._helpLongFlag; this._helpCommandName = t._helpCommandName; this._helpCommandnameAndArgs = t._helpCommandnameAndArgs; this._helpCommandDescription = t._helpCommandDescription; this._helpConfiguration = t._helpConfiguration; this._exitCallback = t._exitCallback; this._storeOptionsAsProperties = t._storeOptionsAsProperties; this._combineFlagAndOptionalValue = t._combineFlagAndOptionalValue; this._allowExcessArguments = t._allowExcessArguments; this._enablePositionalOptions = t._enablePositionalOptions; this._showHelpAfterError = t._showHelpAfterError; this._showSuggestionAfterError = t._showSuggestionAfterError; return this; } command(t, e, i) { let n = e; let s = i; if ("object" == typeof n && null !== n) { s = n; n = null; } s = s || {}; const [, r, o] = t.match(/([^ ]+) *(.*)/); const a = this.createCommand(r); if (n) { a.description(n); a._executableHandler = true; } if (s.isDefault) this._defaultCommandName = a._name; a._hidden = !!(s.noHelp || s.hidden); a._executableFile = s.executableFile || null; if (o) a.arguments(o); this.commands.push(a); a.parent = this; a.copyInheritedSettings(this); if (n) return this; return a; } createCommand(t) { return new Command(t); } createHelp() { return Object.assign(new c, this.configureHelp()); } configureHelp(t) { if (void 0 === t) return this._helpConfiguration; this._helpConfiguration = t; return this; } configureOutput(t) { if (void 0 === t) return this._outputConfiguration; Object.assign(this._outputConfiguration, t); return this; } showHelpAfterError(t = true) { if ("string" != typeof t) t = !!t; this._showHelpAfterError = t; return this; } showSuggestionAfterError(t = true) { this._showSuggestionAfterError = !!t; return this; } addCommand(t, e) { if (!t._name) throw new Error(`Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()`); e = e || {}; if (e.isDefault) this._defaultCommandName = t._name; if (e.noHelp || e.hidden) t._hidden = true; this.commands.push(t); t.parent = this; return this; } createArgument(t, e) { return new l(t, e); } argument(t, e, i, n) { const s = this.createArgument(t, e); if ("function" == typeof i) s.default(n).argParser(i); else s.default(i); this.addArgument(s); return this; } arguments(t) { t.split(/ +/).forEach((t)=>{ this.argument(t); }); return this; } addArgument(t) { const e = this._args.slice(-1)[0]; if (e && e.variadic) throw new Error(`only the last argument can be variadic '${e.name()}'`); if (t.required && void 0 !== t.defaultValue && void 0 === t.parseArg) throw new Error(`a default value for a required argument is never used: '${t.name()}'`); this._args.push(t); return this; } addHelpCommand(t, e) { if (false === t) this._addImplicitHelpCommand = false; else { this._addImplicitHelpCommand = true; if ("string" == typeof t) { this._helpCommandName = t.split(" ")[0]; this._helpCommandnameAndArgs = t; } this._helpCommandDescription = e || this._helpCommandDescription; } return this; } _hasImplicitHelpCommand() { if (void 0 === this._addImplicitHelpCommand) return this.commands.length && !this._actionHandler && !this._findCommand("help"); return this._addImplicitHelpCommand; } hook(t, e) { const i = [ "preSubcommand", "preAction", "postAction" ]; if (!i.includes(t)) throw new Error(`Unexpected value for event passed to hook : '${t}'.\nExpecting one of '${i.join("', '")}'`); if (this._lifeCycleHooks[t]) this._lifeCycleHooks[t].push(e); else this._lifeCycleHooks[t] = [ e ]; return this; } exitOverride(t) { if (t) this._exitCallback = t; else this._exitCallback = (t)=>{ if ("commander.executeSubCommandAsync" !== t.code) throw t; }; return this; } _exit(t, e, i) { if (this._exitCallback) this._exitCallback(new u(t, e, i)); a.exit(t); } action(t) { const listener = (e)=>{ const i = this._args.length; const n = e.slice(0, i); if (this._storeOptionsAsProperties) n[i] = this; else n[i] = this.opts(); n.push(this); return t.apply(this, n); }; this._actionHandler = listener; return this; } createOption(t, e) { return new p(t, e); } addOption(t) { const e = t.name(); const i = t.attributeName(); if (t.negate) { const e = t.long.replace(/^--no-/, "--"); if (!this._findOption(e)) this.setOptionValueWithSource(i, void 0 === t.defaultValue ? true : t.defaultValue, "default"); } else if (void 0 !== t.defaultValue) this.setOptionValueWithSource(i, t.defaultValue, "default"); this.options.push(t); const handleOptionValue = (e, n, s)=>{ if (null == e && void 0 !== t.presetArg) e = t.presetArg; const r = this.getOptionValue(i); if (null !== e && t.parseArg) try { e = t.parseArg(e, r); } catch (t) { if ("commander.invalidArgument" === t.code) { const e = `${n} ${t.message}`; this.error(e, { exitCode: t.exitCode, code: t.code }); } throw t; } else if (null !== e && t.variadic) e = t._concatValue(e, r); if (null == e) e = t.negate ? false : t.isBoolean() || t.optional ? true : ""; this.setOptionValueWithSource(i, e, s); }; this.on("option:" + e, (e)=>{ const i = `error: option '${t.flags}' argument '${e}' is invalid.`; handleOptionValue(e, i, "cli"); }); if (t.envVar) this.on("optionEnv:" + e, (e)=>{ const i = `error: option '${t.flags}' value '${e}' from env '${t.envVar}' is invalid.`; handleOptionValue(e, i, "env"); }); return this; } _optionEx(t, e, i, n, s) { if ("object" == typeof e && e instanceof p) throw new Error("To add an Option object use addOption() instead of option() or requiredOption()"); const r = this.createOption(e, i); r.makeOptionMandatory(!!t.mandatory); if ("function" == typeof n) r.default(s).argParser(n); else if (n instanceof RegExp) { const t = n; n = (e, i)=>{ const n = t.exec(e); return n ? n[0] : i; }; r.default(s).argParser(n); } else r.default(n); return this.addOption(r); } option(t, e, i, n) { return this._optionEx({}, t, e, i, n); } requiredOption(t, e, i, n) { return this._optionEx({ mandatory: true }, t, e, i, n); } combineFlagAndOptionalValue(t = true) { this._combineFlagAndOptionalValue = !!t; return this; } allowUnknownOption(t = true) { this._allowUnknownOption = !!t; return this; } allowExcessArguments(t = true) { this._allowExcessArguments = !!t; return this; } enablePositionalOptions(t = true) { this._enablePositionalOptions = !!t; return this; } passThroughOptions(t = true) { this._passThroughOptions = !!t; if (!!this.parent && t && !this.parent._enablePositionalOptions) throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)"); return this; } storeOptionsAsProperties(t = true) { this._storeOptionsAsProperties = !!t; if (this.options.length) throw new Error("call .storeOptionsAsProperties() before adding options"); return this; } getOptionValue(t) { if (this._storeOptionsAsProperties) return this[t]; return this._optionValues[t]; } setOptionValue(t, e) { return this.setOptionValueWithSource(t, e, void 0); } setOptionValueWithSource(t, e, i) { if (this._storeOptionsAsProperties) this[t] = e; else this._optionValues[t] = e; this._optionValueSources[t] = i; return this; } getOptionValueSource(t) { return this._optionValueSources[t]; } getOptionValueSourceWithGlobals(t) { let e; getCommandAndParents(this).forEach((i)=>{ if (void 0 !== i.getOptionValueSource(t)) e = i.getOptionValueSource(t); }); return e; } _prepareUserArgs(t, e) { if (void 0 !== t && !Array.isArray(t)) throw new Error("first parameter to parse must be array or undefined"); e = e || {}; if (void 0 === t) { t = a.argv; if (a.versions && a.versions.electron) e.from = "electron"; } this.rawArgs = t.slice(); let i; switch(e.from){ case void 0: case "node": this._scriptPath = t[1]; i = t.slice(2); break; case "electron": if (a.defaultApp) { this._scriptPath = t[1]; i = t.slice(2); } else i = t.slice(1); break; case "user": i = t.slice(0); break; default: throw new Error(`unexpected parse option { from: '${e.from}' }`); } if (!this._name && this._scriptPath) this.nameFromFilename(this._scriptPath); this._name = this._name || "program"; return i; } parse(t, e) { const i = this._prepareUserArgs(t, e); this._parseCommand([], i); return this; } async parseAsync(t, e) { const i = this._prepareUserArgs(t, e); await this._parseCommand([], i); return this; } _executeSubCommand(t, e) { e = e.slice(); let i = false; const n = [ ".js", ".ts", ".tsx", ".mjs", ".cjs" ]; function findFile(t, e) { const i = r.resolve(t, e); if (o.existsSync(i)) return i; if (n.includes(r.extname(e))) return; const s = n.find((t)=>o.existsSync(`${i}${t}`)); if (s) return `${i}${s}`; } this._checkForMissingMandatoryOptions(); this._checkForConflictingOptions(); let l = t._executableFile || `${this._name}-${t._name}`; let h = this._executableDir || ""; if (this._scriptPath) { let t; try { t = o.realpathSync(this._scriptPath); } catch (e) { t = this._scriptPath; } h = r.resolve(r.dirname(t), h); } if (h) { let e = findFile(h, l); if (!e && !t._executableFile && this._scriptPath) { const i = r.basename(this._scriptPath, r.extname(this._scriptPath)); if (i !== this._name) e = findFile(h, `${i}-${t._name}`); } l = e || l; } i = n.includes(r.extname(l)); let c; if ("win32" !== a.platform) if (i) { e.unshift(l); e = incrementNodeInspectorPort(a.execArgv).concat(e); c = s.spawn(a.argv[0], e, { stdio: "inherit" }); } else c = s.spawn(l, e, { stdio: "inherit" }); else { e.unshift(l); e = incrementNodeInspectorPort(a.execArgv).concat(e); c = s.spawn(a.execPath, e, { stdio: "inherit" }); } if (!c.killed) { const t = [ "SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP" ]; t.forEach((t)=>{ a.on(t, ()=>{ if (false === c.killed && null === c.exitCode) c.kill(t); }); }); } const p = this._exitCallback; if (p) c.on("close", ()=>{ p(new u(a.exitCode || 0, "commander.executeSubCommandAsync", "(close)")); }); else c.on("close", a.exit.bind(a)); c.on("error", (e)=>{ if ("ENOENT" === e.code) { const e = h ? `searched for local subcommand relative to directory '${h}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory"; const i = `'${l}' does not exist\n - if '${t._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${e}`; throw new Error(i); } if ("EACCES" === e.code) throw new Error(`'${l}' not executable`); if (p) { const t = new u(1, "commander.executeSubCommandAsync", "(error)"); t.nestedError = e; p(t); } else a.exit(1); }); this.runningCommand = c; } _dispatchSubcommand(t, e, i) { const n = this._findCommand(t); if (!n) this.help({ error: true }); let s; s = this._chainOrCallSubCommandHook(s, n, "preSubcommand"); s = this._chainOrCall(s, ()=>{ if (!n._executableHandler) return n._parseCommand(e, i); this._executeSubCommand(n, e.concat(i)); }); return s; } _checkNumberOfArguments() { this._args.forEach((t, e)=>{ if (t.required && null == this.args[e]) this.missingArgument(t.name()); }); if (this._args.length > 0 && this._args[this._args.length - 1].variadic) return; if (this.args.length > this._args.length) this._excessArguments(this.args); } _processArguments() { const myParseArg = (t, e, i)=>{ let n = e; if (null !== e && t.parseArg) try { n = t.parseArg(e, i); } catch (i) { if ("commander.invalidArgument" === i.code) { const n = `error: command-argument value '${e}' is invalid for argument '${t.name()}'. ${i.message}`; this.error(n, { exitCode: i.exitCode, code: i.code }); } throw i; } return n; }; this._checkNumberOfArguments(); const t = []; this._args.forEach((e, i)=>{ let n = e.defaultValue; if (e.variadic) { if (i < this.args.length) { n = this.args.slice(i); if (e.parseArg) n = n.reduce((t, i)=>myParseArg(e, i, t), e.defaultValue); } else if (void 0 === n) n = []; } else if (i < this.args.length) { n = this.args[i]; if (e.parseArg) n = myParseArg(e, n, e.defaultValue); } t[i] = n; }); this.processedArgs = t; } _chainOrCall(t, e) { if (t && t.then && "function" == typeof t.then) return t.then(()=>e()); return e(); } _chainOrCallHooks(t, e) { let i = t; const n = []; getCommandAndParents(this).reverse().filter((t)=>void 0 !== t._lifeCycleHooks[e]).forEach((t)=>{ t._lifeCycleHooks[e].forEach((e)=>{ n.push({ hookedCommand: t, callback: e }); }); }); if ("postAction" === e) n.reverse(); n.forEach((t)=>{ i = this._chainOrCall(i, ()=>t.callback(t.hookedCommand, this)); }); return i; } _chainOrCallSubCommandHook(t, e, i) { let n = t; if (void 0 !== this._lifeCycleHooks[i]) this._lifeCycleHooks[i].forEach((t)=>{ n = this._chainOrCall(n, ()=>t(this, e)); }); return n; } _parseCommand(t, e) { const i = this.parseOptions(e); this._parseOptionsEnv(); this._parseOptionsImplied(); t = t.concat(i.operands); e = i.unknown; this.args = t.concat(e); if (t && this._findCommand(t[0])) return this._dispatchSubcommand(t[0], t.slice(1), e); if (this._hasImplicitHelpCommand() && t[0] === this._helpCommandName) { if (1 === t.length) this.help(); return this._dispatchSubcommand(t[1], [], [ this._helpLongFlag ]); } if (this._defaultCommandName) { outputHelpIfRequested(this, e); return this._dispatchSubcommand(this._defaultCommandName, t, e); } if (this.commands.length && 0 === this.args.length && !this._actionHandler && !this._defaultCommandName) this.help({ error: true }); outputHelpIfRequested(this, i.unknown); this._checkForMissingMandatoryOptions(); this._checkForConflictingOptions(); const checkForUnknownOptions = ()=>{ if (i.unknown.length > 0) this.unknownOption(i.unknown[0]); }; const n = `command:${this.name()}`; if (this._actionHandler) { checkForUnknownOptions(); this._processArguments(); let i; i = this._chainOrCallHooks(i, "preAction"); i = this._chainOrCall(i, ()=>this._actionHandler(this.processedArgs)); if (this.parent) i = this._chainOrCall(i, ()=>{ this.parent.emit(n, t, e); }); i = this._chainOrCallHooks(i, "postAction"); return i; } if (this.parent && this.parent.listenerCount(n)) { checkForUnknownOptions(); this._processArguments(); this.parent.emit(n, t, e); } else if (t.length) { if (this._findCommand("*")) return this._dispatchSubcommand("*", t, e); if (this.listenerCount("command:*")) this.emit("command:*", t, e); else if (this.commands.length) this.unknownCommand(); else { checkForUnknownOptions(); this._processArguments(); } } else if (this.commands.length) { checkForUnknownOptions(); this.help({ error: true }); } else { checkForUnknownOptions(); this._processArguments(); } } _findCommand(t) { if (!t) return; return this.commands.find((e)=>e._name === t || e._aliases.includes(t)); } _findOption(t) { return this.options.find((e)=>e.is(t)); } _checkForMissingMandatoryOptions() { for(let t = this; t; t = t.parent)t.options.forEach((e)=>{ if (e.mandatory && void 0 === t.getOptionValue(e.attributeName())) t.missingMandatoryOptionValue(e); }); } _checkForConflictingLocalOptions() { const t = this.options.filter((t)=>{ const e = t.attributeName(); if (void 0 === this.getOptionValue(e)) return false; return "default" !== this.getOptionValueSource(e); }); const e = t.filter((t)=>t.conflictsWith.length > 0); e.forEach((e)=>{ const i = t.find((t)=>e.conflictsWith.includes(t.attributeName())); if (i) this._conflictingOption(e, i); }); } _checkForConflictingOptions() { for(let t = this; t; t = t.parent)t._checkForConflictingLocalOptions(); } parseOptions(t) { const e = []; const i = []; let n = e; const s = t.slice(); function maybeOption(t) { return t.length > 1 && "-" === t[0]; } let r = null; while(s.length){ const t = s.shift(); if ("--" === t) { if (n === i) n.push(t); n.push(...s); break; } if (r && !maybeOption(t)) { this.emit(`option:${r.name()}`, t); continue; } r = null; if (maybeOption(t)) { const e = this._findOption(t); if (e) { if (e.required) { const t = s.shift(); if (void 0 === t) this.optionMissingArgument(e); this.emit(`option:${e.name()}`, t); } else if (e.optional) { let t = null; if (s.length > 0 && !maybeOption(s[0])) t = s.shift(); this.emit(`option:${e.name()}`, t); } else this.emit(`option:${e.name()}`); r = e.variadic ? e : null; continue; } } if (t.length > 2 && "-" === t[0] && "-" !== t[1]) { const e = this._findOption(`-${t[1]}`); if (e) { if (e.required || e.optional && this._combineFlagAndOptionalValue) this.emit(`option:${e.name()}`, t.slice(2)); else { this.emit(`option:${e.name()}`); s.unshift(`-${t.slice(2)}`); } continue; } } if (/^--[^=]+=/.test(t)) { const e = t.indexOf("="); const i = this._findOption(t.slice(0, e)); if (i && (i.required || i.optional)) { this.emit(`option:${i.name()}`, t.slice(e + 1)); continue; } } if (maybeOption(t)) n = i; if ((this._enablePositionalOptions || this._passThroughOptions) && 0 === e.length && 0 === i.length) { if (this._findCommand(t)) { e.push(t); if (s.length > 0) i.push(...s); break; } else if (t === this._helpCommandName && this._hasImplicitHelpCommand()) { e.push(t); if (s.length > 0) e.push(...s); break; } else if (this._defaultCommandName) { i.push(t); if (s.length > 0) i.push(...s); break; } } if (this._passThroughOptions) { n.push(t); if (s.length > 0) n.push(...s); break; } n.push(t); } return { operands: e, unknown: i }; } opts() { if (this._storeOptionsAsProperties) { const t = {}; const e = this.options.length; for(let i = 0; i < e; i++){ const e = this.options[i].attributeName(); t[e] = e === this._versionOptionName ? this._version : this[e]; } return t; } return this._optionValues; } optsWithGlobals() { return getCommandAndParents(this).reduce((t, e)=>Object.assign(t, e.opts()), {}); } error(t, e) { this._outputConfiguration.outputError(`${t}\n`, this._outputConfiguration.writeErr); if ("string" == typeof this._showHelpAfterError) this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`); else if (this._showHelpAfterError) { this._outputConfiguration.writeErr("\n"); this.outputHelp({ error: true }); } const i = e || {}; const n = i.exitCode || 1; const s = i.code || "commander.error"; this._exit(n, s, t); } _parseOptionsEnv() { this.options.forEach((t)=>{ if (t.envVar && t.envVar in a.env) { const e = t.attributeName(); if (void 0 === this.getOptionValue(e) || [ "default", "config", "env" ].includes(this.getOptionValueSource(e))) if (t.required || t.optional) this.emit(`optionEnv:${t.name()}`, a.env[t.envVar]); else this.emit(`optionEnv:${t.name()}`); } }); } _parseOptionsImplied() { const t = new d(this.options); const hasCustomOptionValue = (t)=>void 0 !== this.getOptionValue(t) && ![ "default", "implied" ].includes(this.getOptionValueSource(t)); this.options.filter((e)=>void 0 !== e.implied && hasCustomOptionValue(e.attributeName()) && t.valueFromOption(this.getOptionValue(e.attributeName()), e)).forEach((t)=>{ Object.keys(t.implied).filter((t)=>!hasCustomOptionValue(t)).forEach((e)=>{ this.setOptionValueWithSource(e, t.implied[e], "implied"); }); }); } missingArgument(t) { const e = `error: missing required argument '${t}'`; this.error(e, { code: "commander.missingArgument" }); } optionMissingArgument(t) { const e = `error: option '${t.flags}' argument missing`; this.error(e, { code: "commander.optionMissingArgument" }); } missingMandatoryOptionValue(t) { const e = `error: required option '${t.flags}' not specified`; this.error(e, { code: "commander.missingMandatoryOptionValue" }); } _conflictingOption(t, e) { const findBestOptionFromValue = (t)=>{ const e = t.attributeName(); const i = this.getOptionValue(e); const n = this.options.find((t)=>t.negate && e === t.attributeName()); const s = this.options.find((t)=>!t.negate && e === t.attributeName()); if (n && (void 0 === n.presetArg && false === i || void 0 !== n.presetArg && i === n.presetArg)) return n; return s || t; }; const getErrorMessage = (t)=>{ const e = findBestOptionFromValue(t); const i = e.attributeName(); const n = this.getOptionValueSource(i); if ("env" === n) return `environment variable '${e.envVar}'`; return `option '${e.flags}'`; }; const i = `error: ${getErrorMessage(t)} cannot be used with ${getErrorMessage(e)}`; this.error(i, { code: "commander.conflictingOption" }); } unknownOption(t) { if (this._allowUnknownOption) return; let e = ""; if (t.startsWith("--") && this._showSuggestionAfterError) { let i = []; let n = this; do { const t = n.createHelp().visibleOptions(n).filter((t)=>t.long).map((t)=>t.long); i = i.concat(t); n = n.parent; }while (n && !n._enablePositionalOptions); e = f(t, i); } const i = `error: unknown option '${t}'${e}`; this.error(i, { code: "commander.unknownOption" }); } _excessArguments(t) { if (this._allowExcessArguments) return; const e = this._args.length; const i = 1 === e ? "" : "s"; const n = this.parent ? ` for '${this.name()}'` : ""; const s = `error: too many arguments${n}. Expected ${e} argument${i} but got ${t.length}.`; this.error(s, { code: "commander.excessArguments" }); } unknownCommand() { const t = this.args[0]; let e = ""; if (this._showSuggestionAfterError) { const i = []; this.createHelp().visibleCommands(this).forEach((t)=>{ i.push(t.name()); if (t.alias()) i.push(t.alias()); }); e = f(t, i); } const i = `error: unknown command '${t}'${e}`; this.error(i, { code: "commander.unknownCommand" }); } version(t, e, i) { if (void 0 === t) return this._version; this._version = t; e = e || "-V, --version"; i = i || "output the version number"; const n = this.createOption(e, i); this._versionOptionName = n.attributeName(); this.options.push(n); this.on("option:" + n.name(), ()=>{ this._outputConfiguration.writeOut(`${t}\n`); this._exit(0, "commander.version", t); }); return this; } description(t, e) { if (void 0 === t && void 0 === e) return this._description; this._description = t; if (e) this._argsDescription = e; return this; } summary(t) { if (void 0 === t) return this._summary; this._summary = t; return this; } alias(t) { if (void 0 === t) return this._aliases[0]; let e = this; if (0 !== this.commands.length && this.commands[this.commands.length - 1]._executableHandler) e = this.commands[this.commands.length - 1]; if (t === e._name) throw new Error("Command alias can't be the same as its name"); e._aliases.push(t); return this; } aliases(t) { if (void 0 === t) return this._aliases; t.forEach((t)=>this.alias(t)); return this; } usage(t) { if (void 0 === t) { if (this._usage) return this._usage; const t = this._args.map((t)=>h(t)); return [].concat(this.options.length || this._hasHelpOption ? "[options]" : [], this.commands.length ? "[command]" : [], this._args.length ? t : []).join(" "); } this._usage = t; return this; } name(t) { if (void 0 === t) return this._name; this._name = t; return this; } nameFromFilename(t) { this._name = r.basename(t, r.extname(t)); return this; } executableDir(t) { if (void 0 === t) return this._executableDir; this._executableDir = t; return this; } helpInformation(t) { const e = this.createHelp(); if (void 0 === e.helpWidth) e.helpWidth = t && t.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth(); return e.formatHelp(this, e); } _getHelpContext(t) { t = t || {}; const e = { error: !!t.error }; let i; i = e.error ? (t)=>this._outputConfiguration.writeErr(t) : (t)=>this._outputConfiguration.writeOut(t); e.write = t.write || i; e.command = this; return e; } outputHelp(t) { let e; if ("function" == typeof t) { e = t; t = void 0; } const i = this._getHelpContext(t); getCommandAndParents(this).reverse().forEach((t)=>t.emit("beforeAllHelp", i)); this.emit("beforeHelp", i); let n = this.helpInformation(i); if (e) { n = e(n); if ("string" != typeof n && !Buffer.isBuffer(n)) throw new Error("outputHelp callback must return a string or a Buffer"); } i.write(n); this.emit(th