()
| 7943 | - ${H}`;throw Error(J)}else if(j.code==="EACCES")throw Error(`'${$}' not executable`);if(!w)pJ.exit(1);else{let H=new i_7(1,"commander.executeSubCommandAsync","(error)");H.nestedError=j,w(H)}}),this.runningCommand=O}_dispatchSubcommand(q,K,_){let z=this._findCommand(q);if(!z)this.help({error:!0});let Y;return Y=this._chainOrCallSubCommandHook(Y,z,"preSubcommand"),Y=this._chainOrCall(Y,()=>{if(z._executableHandler)this._executeSubCommand(z,K.concat(_));else return z._parseCommand(K,_)}),Y}_dispatchHelpCommand(q){if(!q)this.help();let K=this._findCommand(q);if(K&&!K._executableHandler)K.help();return this._dispatchSubcommand(q,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){if(this.registeredArguments.forEach((q,K)=>{if(q.required&&this.args[K]==null)this.missingArgument(q.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)return;if(this.args.length>this.registeredArguments.length)this._excessArguments(this.args)}_processArguments(){let q=(_,z,Y)=>{let $=z;if(z!==null&&_.parseArg){let A=`error: command-argument value '${z}' is invalid for argument '${_.name()}'.`;$=this._callParseArg(_,z,Y,A)}return $};this._checkNumberOfArguments();let K=[];this.registeredArguments.forEach((_,z)=>{let Y=_.defaultValue;if(_.variadic){if(z<this.args.length){if(Y=this.args.slice(z),_.parseArg)Y=Y.reduce(($,A)=>{return q(_,A,$)},_.defaultValue)}else if(Y===void 0)Y=[]}else if(z<this.args.length){if(Y=this.args[z],_.parseArg)Y=q(_,Y,_.defaultValue)}K[z]=Y}),this.processedArgs=K}_chainOrCall(q,K){if(q&&q.then&&typeof q.then==="function")return q.then(()=>K());return K()}_chainOrCallHooks(q,K){let _=q,z=[];if(this._getCommandAndAncestors().reverse().filter((Y)=>Y._lifeCycleHooks[K]!==void 0).forEach((Y)=>{Y._lifeCycleHooks[K].forEach(($)=>{z.push({hookedCommand:Y,callback:$})})}),K==="postAction")z.reverse();return z.forEach((Y)=>{_=this._chainOrCall(_,()=>{return Y.callback(Y.hookedCommand,this)})}),_}_chainOrCallSubCommandHook(q,K,_){let z=q;if(this._lifeCycleHooks[_]!==void 0)this._lifeCycleHooks[_].forEach((Y)=>{z=this._chainOrCall(z,()=>{return Y(this,K)})});return z}_parseCommand(q,K){let _=this.parseOptions(K);if(this._parseOptionsEnv(),this._parseOptionsImplied(),q=q.concat(_.operands),K=_.unknown,this.args=q.concat(K),q&&this._findCommand(q[0]))return this._dispatchSubcommand(q[0],q.slice(1),K);if(this._getHelpCommand()&&q[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(q[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(K),this._dispatchSubcommand(this._defaultCommandName,q,K);if(this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName)this.help({error:!0});this._outputHelpIfRequested(_.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let z=()=>{if(_.unknown.length>0)this.unknownOption(_.unknown[0])},Y=`command:${this.name()}`;if(this._actionHandler){z(),this._processArguments();let $;if($=this._chainOrCallHooks($,"preAction"),$=this._chainOrCall($,()=>this._actionHandler(this.processedArgs)),this.parent)$=this._chainOrCall($,()=>{this.parent.emit(Y,q,K)});return $=this._chainOrCallHooks($,"postAction"),$}if(this.parent&&this.parent.listenerCount(Y))z(),this._processArguments(),this.parent.emit(Y,q,K);else if(q.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",q,K);if(this.listenerCount("command:*"))this.emit("command:*",q,K);else if(this.commands.length)this.unknownCommand();else z(),this._processArguments()}else if(this.commands.length)z(),this.help({error:!0});else z(),this._processArguments()}_findCommand(q){if(!q)return;return this.commands.find((K)=>K._name===q||K._aliases.includes(q))}_findOption(q){return this.options.find((K)=>K.is(q))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach((q)=>{q.options.forEach((K)=>{if(K.mandatory&&q.getOptionValue(K.attributeName())===void 0)q.missingMandatoryOptionValue(K)})})}_checkForConflictingLocalOptions(){let q=this.options.filter((_)=>{let z=_.attributeName();if(this.getOptionValue(z)===void 0)return!1;return this.getOptionValueSource(z)!=="default"});q.filter((_)=>_.conflictsWith.length>0).forEach((_)=>{let z=q.find((Y)=>_.conflictsWith.includes(Y.attributeName()));if(z)this._conflictingOption(_,z)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach((q)=>{q._checkForConflictingLocalOptions()})}parseOptions(q){let K=[],_=[],z=K,Y=q.slice();function $(O){return O.length>1&&O[0]==="-"}let A=null;while(Y.length){let O=Y.shift();if(O==="--"){if(z===_)z.push(O);z.push(...Y);break}if(A&&!$(O)){this.emit(`option:${A.name()}`,O);continue}if(A=null,$(O)){let w=this._findOption(O);if(w){if(w.required){let j=Y.shift();if(j===void 0)this.optionMissingArgument(w);this.emit(`option:${w.name()}`,j)}else if(w.optional){let j=null;if(Y.length>0&&!$(Y[0]))j=Y.shift();this.emit(`option:${w.name()}`,j)}else this.emit(`option:${w.name()}`);A=w.variadic?w:null;continue}}if(O.length>2&&O[0]==="-"&&O[1]!=="-"){let w=this._findOption(`-${O[1]}`);if(w){if(w.required||w.optional&&this._combineFlagAndOptionalValue)this.emit(`option:${w.name()}`,O.slice(2));else this.emit(`option:${w.name()}`),Y.unshift(`-${O.slice(2)}`);continue}}if(/^--[^=]+=/.test(O)){let w=O.indexOf("="),j=this._findOption(O.slice(0,w));if(j&&(j.required||j.optional)){this.emit(`option:${j.name()}`,O.slice(w+1));continue}}if($(O))z=_;if((this._enablePositionalOptions||this._passThroughOptions)&&K.length===0&&_.length===0){if(this._findCommand(O)){if(K.push(O),Y.length>0)_.push(...Y);break}else if(this._getHelpCommand()&&O===this._getHelpCommand().name()){if(K.push(O),Y.length>0)K.push(...Y);break}else if(this._defaultCommandName){if(_.push(O),Y.length>0)_.push(...Y);break}}if(this._passThroughOptions){if(z.push(O),Y.length>0)z.push(...Y);break}z.push(O)}return{operands:K,unknown:_}}opts(){if(this._storeOptionsAsProperties){let q={},K=this.options.length;for(let _=0;_<K;_++){let z=this.options[_].attributeName();q[z]=z===this._versionOptionName?this._version:this[z]}return q}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((q,K)=>Object.assign(q,K.opts()),{})}error(q,K){if(this._outputConfiguration.outputError(`${q} |
| 7944 | `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==="string")this._outputConfiguration.writeErr(`${this._showHelpAfterError} |
| 7945 | `);else if(this._showHelpAfterError)this._outputConfiguration.writeErr(` |
| 7946 | `),this.outputHelp({error:!0});let _=K||{},z=_.exitCode||1,Y=_.code||"commander.error";this._exit(z,Y,q)}_parseOptionsEnv(){this.options.forEach((q)=>{if(q.envVar&&q.envVar in pJ.env){let K=q.attributeName();if(this.getOptionValue(K)===void 0||["default","config","env"].includes(this.getOptionValueSource(K)))if(q.required||q.optional)this.emit(`optionEnv:${q.name()}`,pJ.env[q.envVar]);else this.emit(`optionEnv:${q.name()}`)}})}_parseOptionsImplied(){let q=new lbY(this.options),K=(_)=>{return this.getOptionValue(_)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(_))};this.options.filter((_)=>_.implied!==void 0&&K(_.attributeName())&&q.valueFromOption(this.getOptionValue(_.attributeName()),_)).forEach((_)=>{Object.keys(_.implied).filter((z)=>!K(z)).forEach((z)=>{this.setOptionValueWithSource(z,_.implied[z],"implied")})})}missingArgument(q){let K=`error: missing required argument '${q}'`;this.error(K,{code:"commander.missingArgument"})}optionMissingArgument(q){let K=`error: option '${q.flags}' argument missing`;this.error(K,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(q){let K=`error: required option '${q.flags}' not specified`;this.error(K,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(q,K){let _=($)=>{let A=$.attributeName(),O=this.getOptionValue(A),w=this.options.find((H)=>H.negate&&A===H.attributeName()),j=this.options.find((H)=>!H.negate&&A===H.attributeName());if(w&&(w.presetArg===void 0&&O===!1||w.presetArg!==void 0&&O===w.presetArg))return w;return j||$},z=($)=>{let A=_($),O=A.attributeName();if(this.getOptionValueSource(O)==="env")return`environment variable '${A.envVar}'`;return`option '${A.flags}'`},Y=`error: ${z(q)} cannot be used with ${z(K)}`;this.error(Y,{code:"commander.conflictingOption"})}unknownOption(q){if(this._allowUnknownOption)return;let K="";if(q.startsWith("--")&&this._showSuggestionAfterError){let z=[],Y=this;do{let $=Y.createHelp().visibleOptions(Y).filter((A)=>A.long).map((A)=>A.long);z=z.concat($),Y=Y.parent}while(Y&&!Y._enablePositionalOptions);K=nFK(q,z)}let _=`error: unknown option '${q}'${K}`;this.error(_,{code:"commander.unknownOption"})}_excessArguments(q){if(this._allowExcessArguments)return;let K=this.registeredArguments.length,_=K===1?"":"s",Y=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${K} argument${_} but got ${q.length}.`;this.error(Y,{code:"commander.excessArguments"})}unknownCommand(){let q=this.args[0],K="";if(this._showSuggestionAfterError){let z=[];this.createHelp().visibleCommands(this).forEach((Y)=>{if(z.push(Y.name()),Y.alias())z.push(Y.alias())}),K=nFK(q,z)}let _=`error: unknown command '${q}'${K}`;this.error(_,{code:"commander.unknownCommand"})}version(q,K,_){if(q===void 0)return this._version;this._version=q,K=K||"-V, --version",_=_||"output the version number";let z=this.createOption(K,_);return this._versionOptionName=z.attributeName(),this._registerOption(z),this.on("option:"+z.name(),()=>{this._outputConfiguration.writeOut(`${q} |
| 7947 | `),this._exit(0,"commander.version",q)}),this}description(q,K){if(q===void 0&&K===void 0)return this._description;if(this._description=q,K)this._argsDescription=K;return this}summary(q){if(q===void 0)return this._summary;return this._summary=q,this}alias(q){if(q===void 0)return this._aliases[0];let K=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler)K=this.commands[this.commands.length-1];if(q===K._name)throw Error("Command alias can't be the same as its name");let _=this.parent?._findCommand(q);if(_){let z=[_.name()].concat(_.aliases()).join("|");throw Error(`cannot add alias '${q}' to command '${this.name()}' as already have command '${z}'`)}return K._aliases.push(q),this}aliases(q){if(q===void 0)return this._aliases;return q.forEach((K)=>this.alias(K)),this}usage(q){if(q===void 0){if(this._usage)return this._usage;let K=this.registeredArguments.map((_)=>{return dbY(_)});return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?K:[]).join(" ")}return this._usage=q,this}name(q){if(q===void 0)return this._name;return this._name=q,this}nameFromFilename(q){return this._name=hs.basename(q,hs.extname(q)),this}executableDir(q){if(q===void 0)return this._executableDir;return this._executableDir=q,this}helpInformation(q){let K=this.createHelp();if(K.helpWidth===void 0)K.helpWidth=q&&q.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth();return K.formatHelp(this,K)}_getHelpContext(q){q=q||{};let K={error:!!q.error},_;if(K.error)_=(z)=>this._outputConfiguration.writeErr(z);else _=(z)=>this._outputConfiguration.writeOut(z);return K.write=q.write||_,K.command=this,K}outputHelp(q){let K;if(typeof q==="function")K=q,q=void 0;let _=this._getHelpContext(q);this._getCommandAndAncestors().reverse().forEach((Y)=>Y.emit("beforeAllHelp",_)),this.emit("beforeHelp",_);let z=this.helpInformation(_);if(K){if(z=K(z),typeof z!=="string"&&!Buffer.isBuffer(z))throw Error("outputHelp callback must return a string or a Buffer")}if(_.write(z),this._getHelpOption()?.long)this.emit(this._getHelpOption().long);this.emit("afterHelp",_),this._getCommandAndAncestors().forEach((Y)=>Y.emit("afterAllHelp",_))}helpOption(q,K){if(typeof q==="boolean"){if(q)this._helpOption=this._helpOption??void 0;else this._helpOption=null;return this}return q=q??"-h, --help",K=K??"display help for command",this._helpOption=this.createOption(q,K),this}_getHelpOption(){if(this._helpOption===void 0)this.helpOption(void 0,void 0);return this._helpOption}addHelpOption(q){return this._helpOption=q,this}help(q){this.outputHelp(q);let K=pJ.exitCode||0;if(K===0&&q&&typeof q!=="function"&&q.error)K=1;this._exit(K,"commander.help","(outputHelp)")}addHelpText(q,K){let _=["beforeAll","before","after","afterAll"];if(!_.includes(q))throw Error(`Unexpected value for position to addHelpText. |
| 7948 | Expecting one of '${_.join("', '")}'`);let z=`${q}Help`;return this.on(z,(Y)=>{let $;if(typeof K==="function")$=K({error:Y.error,command:Y.command});else $=K;if($)Y.write(`${$} |
no test coverage detected