buildx-cli
Version:
CLI tool for BuildX API with authentication and schema synchronization
2 lines • 1.51 MB
JavaScript
#!/usr/bin/env node
var require$$0$4=require("events"),require$$1$3=require("child_process"),require$$1$2=require("path"),require$$0$5=require("fs"),require$$4$2=require("process"),process$1=require("node:process"),os=require("node:os"),tty=require("node:tty"),assert=require("node:assert"),require$$0$6=require("tty"),require$$0$b=require("readline"),require$$0$7=require("os"),require$$0$8=require("assert"),stream$1=require("stream"),require$$0$9=require("buffer"),require$$0$a=require("util"),require$$1$4=require("string_decoder"),require$$2$2=require("crypto"),node_stream=require("node:stream"),readline=require("node:readline"),node_util=require("node:util"),fs$2=require("node:fs"),path=require("node:path"),crypto=require("node:crypto"),require$$3$3=require("http"),require$$4$3=require("https"),require$$0$c=require("url"),zlib=require("zlib"),require$$0$d=require("constants"),commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs(x){return x&&x.__esModule&&Object.prototype.hasOwnProperty.call(x,"default")?x.default:x}var hasRequiredError,hasRequiredArgument,commander$1={exports:{}},argument={},error={};function requireError(){if(hasRequiredError)return error;hasRequiredError=1;class CommanderError extends Error{constructor(exitCode,code,message){super(message),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=code,this.exitCode=exitCode,this.nestedError=void 0}}return error.CommanderError=CommanderError,error.InvalidArgumentError=class InvalidArgumentError extends CommanderError{constructor(message){super(1,"commander.invalidArgument",message),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},error}function requireArgument(){if(hasRequiredArgument)return argument;hasRequiredArgument=1;const{InvalidArgumentError:InvalidArgumentError}=requireError();return argument.Argument=class Argument{constructor(name,description){switch(this.description=description||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,name[0]){case"<":this.required=!0,this._name=name.slice(1,-1);break;case"[":this.required=!1,this._name=name.slice(1,-1);break;default:this.required=!0,this._name=name}this._name.length>3&&"..."===this._name.slice(-3)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(value,previous){return previous!==this.defaultValue&&Array.isArray(previous)?previous.concat(value):[value]}default(value,description){return this.defaultValue=value,this.defaultValueDescription=description,this}argParser(fn){return this.parseArg=fn,this}choices(values){return this.argChoices=values.slice(),this.parseArg=(arg,previous)=>{if(!this.argChoices.includes(arg))throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(arg,previous):arg},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}},argument.humanReadableArgName=function humanReadableArgName(arg){const nameOutput=arg.name()+(!0===arg.variadic?"...":"");return arg.required?"<"+nameOutput+">":"["+nameOutput+"]"},argument}var hasRequiredHelp,command={},help={};function requireHelp(){if(hasRequiredHelp)return help;hasRequiredHelp=1;const{humanReadableArgName:humanReadableArgName}=requireArgument();return help.Help=class Help{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(cmd){const visibleCommands=cmd.commands.filter(cmd=>!cmd._hidden);if(cmd._hasImplicitHelpCommand()){const[,helpName,helpArgs]=cmd._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/),helpCommand=cmd.createCommand(helpName).helpOption(!1);helpCommand.description(cmd._helpCommandDescription),helpArgs&&helpCommand.arguments(helpArgs),visibleCommands.push(helpCommand)}return this.sortSubcommands&&visibleCommands.sort((a,b)=>a.name().localeCompare(b.name())),visibleCommands}compareOptions(a,b){const getSortKey=option=>option.short?option.short.replace(/^-/,""):option.long.replace(/^--/,"");return getSortKey(a).localeCompare(getSortKey(b))}visibleOptions(cmd){const visibleOptions=cmd.options.filter(option=>!option.hidden),showShortHelpFlag=cmd._hasHelpOption&&cmd._helpShortFlag&&!cmd._findOption(cmd._helpShortFlag),showLongHelpFlag=cmd._hasHelpOption&&!cmd._findOption(cmd._helpLongFlag);if(showShortHelpFlag||showLongHelpFlag){let helpOption;helpOption=showShortHelpFlag?showLongHelpFlag?cmd.createOption(cmd._helpFlags,cmd._helpDescription):cmd.createOption(cmd._helpShortFlag,cmd._helpDescription):cmd.createOption(cmd._helpLongFlag,cmd._helpDescription),visibleOptions.push(helpOption)}return this.sortOptions&&visibleOptions.sort(this.compareOptions),visibleOptions}visibleGlobalOptions(cmd){if(!this.showGlobalOptions)return[];const globalOptions=[];for(let ancestorCmd=cmd.parent;ancestorCmd;ancestorCmd=ancestorCmd.parent){const visibleOptions=ancestorCmd.options.filter(option=>!option.hidden);globalOptions.push(...visibleOptions)}return this.sortOptions&&globalOptions.sort(this.compareOptions),globalOptions}visibleArguments(cmd){return cmd._argsDescription&&cmd.registeredArguments.forEach(argument=>{argument.description=argument.description||cmd._argsDescription[argument.name()]||""}),cmd.registeredArguments.find(argument=>argument.description)?cmd.registeredArguments:[]}subcommandTerm(cmd){const args=cmd.registeredArguments.map(arg=>humanReadableArgName(arg)).join(" ");return cmd._name+(cmd._aliases[0]?"|"+cmd._aliases[0]:"")+(cmd.options.length?" [options]":"")+(args?" "+args:"")}optionTerm(option){return option.flags}argumentTerm(argument){return argument.name()}longestSubcommandTermLength(cmd,helper){return helper.visibleCommands(cmd).reduce((max,command)=>Math.max(max,helper.subcommandTerm(command).length),0)}longestOptionTermLength(cmd,helper){return helper.visibleOptions(cmd).reduce((max,option)=>Math.max(max,helper.optionTerm(option).length),0)}longestGlobalOptionTermLength(cmd,helper){return helper.visibleGlobalOptions(cmd).reduce((max,option)=>Math.max(max,helper.optionTerm(option).length),0)}longestArgumentTermLength(cmd,helper){return helper.visibleArguments(cmd).reduce((max,argument)=>Math.max(max,helper.argumentTerm(argument).length),0)}commandUsage(cmd){let cmdName=cmd._name;cmd._aliases[0]&&(cmdName=cmdName+"|"+cmd._aliases[0]);let ancestorCmdNames="";for(let ancestorCmd=cmd.parent;ancestorCmd;ancestorCmd=ancestorCmd.parent)ancestorCmdNames=ancestorCmd.name()+" "+ancestorCmdNames;return ancestorCmdNames+cmdName+" "+cmd.usage()}commandDescription(cmd){return cmd.description()}subcommandDescription(cmd){return cmd.summary()||cmd.description()}optionDescription(option){const extraInfo=[];if(option.argChoices&&extraInfo.push(`choices: ${option.argChoices.map(choice=>JSON.stringify(choice)).join(", ")}`),void 0!==option.defaultValue){(option.required||option.optional||option.isBoolean()&&"boolean"==typeof option.defaultValue)&&extraInfo.push(`default: ${option.defaultValueDescription||JSON.stringify(option.defaultValue)}`)}return void 0!==option.presetArg&&option.optional&&extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`),void 0!==option.envVar&&extraInfo.push(`env: ${option.envVar}`),extraInfo.length>0?`${option.description} (${extraInfo.join(", ")})`:option.description}argumentDescription(argument){const extraInfo=[];if(argument.argChoices&&extraInfo.push(`choices: ${argument.argChoices.map(choice=>JSON.stringify(choice)).join(", ")}`),void 0!==argument.defaultValue&&extraInfo.push(`default: ${argument.defaultValueDescription||JSON.stringify(argument.defaultValue)}`),extraInfo.length>0){const extraDescripton=`(${extraInfo.join(", ")})`;return argument.description?`${argument.description} ${extraDescripton}`:extraDescripton}return argument.description}formatHelp(cmd,helper){const termWidth=helper.padWidth(cmd,helper),helpWidth=helper.helpWidth||80;function formatItem(term,description){if(description){const fullText=`${term.padEnd(termWidth+2)}${description}`;return helper.wrap(fullText,helpWidth-2,termWidth+2)}return term}function formatList(textArray){return textArray.join("\n").replace(/^/gm," ".repeat(2))}let output=[`Usage: ${helper.commandUsage(cmd)}`,""];const commandDescription=helper.commandDescription(cmd);commandDescription.length>0&&(output=output.concat([helper.wrap(commandDescription,helpWidth,0),""]));const argumentList=helper.visibleArguments(cmd).map(argument=>formatItem(helper.argumentTerm(argument),helper.argumentDescription(argument)));argumentList.length>0&&(output=output.concat(["Arguments:",formatList(argumentList),""]));const optionList=helper.visibleOptions(cmd).map(option=>formatItem(helper.optionTerm(option),helper.optionDescription(option)));if(optionList.length>0&&(output=output.concat(["Options:",formatList(optionList),""])),this.showGlobalOptions){const globalOptionList=helper.visibleGlobalOptions(cmd).map(option=>formatItem(helper.optionTerm(option),helper.optionDescription(option)));globalOptionList.length>0&&(output=output.concat(["Global Options:",formatList(globalOptionList),""]))}const commandList=helper.visibleCommands(cmd).map(cmd=>formatItem(helper.subcommandTerm(cmd),helper.subcommandDescription(cmd)));return commandList.length>0&&(output=output.concat(["Commands:",formatList(commandList),""])),output.join("\n")}padWidth(cmd,helper){return Math.max(helper.longestOptionTermLength(cmd,helper),helper.longestGlobalOptionTermLength(cmd,helper),helper.longestSubcommandTermLength(cmd,helper),helper.longestArgumentTermLength(cmd,helper))}wrap(str,width,indent,minColumnWidth=40){const manualIndent=new RegExp("[\\n][ \\f\\t\\v - \ufeff]+");if(str.match(manualIndent))return str;const columnWidth=width-indent;if(columnWidth<minColumnWidth)return str;const leadingStr=str.slice(0,indent),columnText=str.slice(indent).replace("\r\n","\n"),indentString=" ".repeat(indent),regex=new RegExp(`\n|.{1,${columnWidth-1}}([\\s]|$)|[^\\s]+?([\\s]|$)`,"g");return leadingStr+(columnText.match(regex)||[]).map((line,i)=>"\n"===line?"":(i>0?indentString:"")+line.trimEnd()).join("\n")}},help}var hasRequiredOption,option={};function requireOption(){if(hasRequiredOption)return option;hasRequiredOption=1;const{InvalidArgumentError:InvalidArgumentError}=requireError();function splitOptionFlags(flags){let shortFlag,longFlag;const flagParts=flags.split(/[ |,]+/);return flagParts.length>1&&!/^[[<]/.test(flagParts[1])&&(shortFlag=flagParts.shift()),longFlag=flagParts.shift(),!shortFlag&&/^-[^-]$/.test(longFlag)&&(shortFlag=longFlag,longFlag=void 0),{shortFlag:shortFlag,longFlag:longFlag}}return option.Option=class Option{constructor(flags,description){this.flags=flags,this.description=description||"",this.required=flags.includes("<"),this.optional=flags.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(flags),this.mandatory=!1;const optionFlags=splitOptionFlags(flags);this.short=optionFlags.shortFlag,this.long=optionFlags.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0}default(value,description){return this.defaultValue=value,this.defaultValueDescription=description,this}preset(arg){return this.presetArg=arg,this}conflicts(names){return this.conflictsWith=this.conflictsWith.concat(names),this}implies(impliedOptionValues){let newImplied=impliedOptionValues;return"string"==typeof impliedOptionValues&&(newImplied={[impliedOptionValues]:!0}),this.implied=Object.assign(this.implied||{},newImplied),this}env(name){return this.envVar=name,this}argParser(fn){return this.parseArg=fn,this}makeOptionMandatory(mandatory=!0){return this.mandatory=!!mandatory,this}hideHelp(hide=!0){return this.hidden=!!hide,this}_concatValue(value,previous){return previous!==this.defaultValue&&Array.isArray(previous)?previous.concat(value):[value]}choices(values){return this.argChoices=values.slice(),this.parseArg=(arg,previous)=>{if(!this.argChoices.includes(arg))throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(arg,previous):arg},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return function camelcase(str){return str.split("-").reduce((str,word)=>str+word[0].toUpperCase()+word.slice(1))}(this.name().replace(/^no-/,""))}is(arg){return this.short===arg||this.long===arg}isBoolean(){return!this.required&&!this.optional&&!this.negate}},option.splitOptionFlags=splitOptionFlags,option.DualOptions=class DualOptions{constructor(options){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,options.forEach(option=>{option.negate?this.negativeOptions.set(option.attributeName(),option):this.positiveOptions.set(option.attributeName(),option)}),this.negativeOptions.forEach((value,key)=>{this.positiveOptions.has(key)&&this.dualOptions.add(key)})}valueFromOption(value,option){const optionKey=option.attributeName();if(!this.dualOptions.has(optionKey))return!0;const preset=this.negativeOptions.get(optionKey).presetArg,negativeValue=void 0!==preset&&preset;return option.negate===(negativeValue===value)}},option}var hasRequiredSuggestSimilar,hasRequiredCommand,hasRequiredCommander,suggestSimilar={};function requireSuggestSimilar(){if(hasRequiredSuggestSimilar)return suggestSimilar;hasRequiredSuggestSimilar=1;return suggestSimilar.suggestSimilar=function suggestSimilar$1(word,candidates){if(!candidates||0===candidates.length)return"";candidates=Array.from(new Set(candidates));const searchingOptions=word.startsWith("--");searchingOptions&&(word=word.slice(2),candidates=candidates.map(candidate=>candidate.slice(2)));let similar=[],bestDistance=3;return candidates.forEach(candidate=>{if(candidate.length<=1)return;const distance=function editDistance(a,b){if(Math.abs(a.length-b.length)>3)return Math.max(a.length,b.length);const d=[];for(let i=0;i<=a.length;i++)d[i]=[i];for(let j=0;j<=b.length;j++)d[0][j]=j;for(let j=1;j<=b.length;j++)for(let i=1;i<=a.length;i++){let cost=1;cost=a[i-1]===b[j-1]?0:1,d[i][j]=Math.min(d[i-1][j]+1,d[i][j-1]+1,d[i-1][j-1]+cost),i>1&&j>1&&a[i-1]===b[j-2]&&a[i-2]===b[j-1]&&(d[i][j]=Math.min(d[i][j],d[i-2][j-2]+1))}return d[a.length][b.length]}(word,candidate),length=Math.max(word.length,candidate.length);(length-distance)/length>.4&&(distance<bestDistance?(bestDistance=distance,similar=[candidate]):distance===bestDistance&&similar.push(candidate))}),similar.sort((a,b)=>a.localeCompare(b)),searchingOptions&&(similar=similar.map(candidate=>`--${candidate}`)),similar.length>1?`\n(Did you mean one of ${similar.join(", ")}?)`:1===similar.length?`\n(Did you mean ${similar[0]}?)`:""},suggestSimilar}var commanderExports=function requireCommander(){return hasRequiredCommander||(hasRequiredCommander=1,function(module,exports){const{Argument:Argument}=requireArgument(),{Command:Command}=function requireCommand(){if(hasRequiredCommand)return command;hasRequiredCommand=1;const EventEmitter=require$$0$4.EventEmitter,childProcess=require$$1$3,path=require$$1$2,fs=require$$0$5,process=require$$4$2,{Argument:Argument,humanReadableArgName:humanReadableArgName}=requireArgument(),{CommanderError:CommanderError}=requireError(),{Help:Help}=requireHelp(),{Option:Option,splitOptionFlags:splitOptionFlags,DualOptions:DualOptions}=requireOption(),{suggestSimilar:suggestSimilar}=requireSuggestSimilar();class Command extends EventEmitter{constructor(name){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!0,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=name||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._outputConfiguration={writeOut:str=>process.stdout.write(str),writeErr:str=>process.stderr.write(str),getOutHelpWidth:()=>process.stdout.isTTY?process.stdout.columns:void 0,getErrHelpWidth:()=>process.stderr.isTTY?process.stderr.columns:void 0,outputError:(str,write)=>write(str)},this._hidden=!1,this._hasHelpOption=!0,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(sourceCommand){return this._outputConfiguration=sourceCommand._outputConfiguration,this._hasHelpOption=sourceCommand._hasHelpOption,this._helpFlags=sourceCommand._helpFlags,this._helpDescription=sourceCommand._helpDescription,this._helpShortFlag=sourceCommand._helpShortFlag,this._helpLongFlag=sourceCommand._helpLongFlag,this._helpCommandName=sourceCommand._helpCommandName,this._helpCommandnameAndArgs=sourceCommand._helpCommandnameAndArgs,this._helpCommandDescription=sourceCommand._helpCommandDescription,this._helpConfiguration=sourceCommand._helpConfiguration,this._exitCallback=sourceCommand._exitCallback,this._storeOptionsAsProperties=sourceCommand._storeOptionsAsProperties,this._combineFlagAndOptionalValue=sourceCommand._combineFlagAndOptionalValue,this._allowExcessArguments=sourceCommand._allowExcessArguments,this._enablePositionalOptions=sourceCommand._enablePositionalOptions,this._showHelpAfterError=sourceCommand._showHelpAfterError,this._showSuggestionAfterError=sourceCommand._showSuggestionAfterError,this}_getCommandAndAncestors(){const result=[];for(let command=this;command;command=command.parent)result.push(command);return result}command(nameAndArgs,actionOptsOrExecDesc,execOpts){let desc=actionOptsOrExecDesc,opts=execOpts;"object"==typeof desc&&null!==desc&&(opts=desc,desc=null),opts=opts||{};const[,name,args]=nameAndArgs.match(/([^ ]+) *(.*)/),cmd=this.createCommand(name);return desc&&(cmd.description(desc),cmd._executableHandler=!0),opts.isDefault&&(this._defaultCommandName=cmd._name),cmd._hidden=!(!opts.noHelp&&!opts.hidden),cmd._executableFile=opts.executableFile||null,args&&cmd.arguments(args),this.commands.push(cmd),cmd.parent=this,cmd.copyInheritedSettings(this),desc?this:cmd}createCommand(name){return new Command(name)}createHelp(){return Object.assign(new Help,this.configureHelp())}configureHelp(configuration){return void 0===configuration?this._helpConfiguration:(this._helpConfiguration=configuration,this)}configureOutput(configuration){return void 0===configuration?this._outputConfiguration:(Object.assign(this._outputConfiguration,configuration),this)}showHelpAfterError(displayHelp=!0){return"string"!=typeof displayHelp&&(displayHelp=!!displayHelp),this._showHelpAfterError=displayHelp,this}showSuggestionAfterError(displaySuggestion=!0){return this._showSuggestionAfterError=!!displaySuggestion,this}addCommand(cmd,opts){if(!cmd._name)throw new Error("Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()");return(opts=opts||{}).isDefault&&(this._defaultCommandName=cmd._name),(opts.noHelp||opts.hidden)&&(cmd._hidden=!0),this.commands.push(cmd),cmd.parent=this,this}createArgument(name,description){return new Argument(name,description)}argument(name,description,fn,defaultValue){const argument=this.createArgument(name,description);return"function"==typeof fn?argument.default(defaultValue).argParser(fn):argument.default(fn),this.addArgument(argument),this}arguments(names){return names.trim().split(/ +/).forEach(detail=>{this.argument(detail)}),this}addArgument(argument){const previousArgument=this.registeredArguments.slice(-1)[0];if(previousArgument&&previousArgument.variadic)throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);if(argument.required&&void 0!==argument.defaultValue&&void 0===argument.parseArg)throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);return this.registeredArguments.push(argument),this}addHelpCommand(enableOrNameAndArgs,description){return!1===enableOrNameAndArgs?this._addImplicitHelpCommand=!1:(this._addImplicitHelpCommand=!0,"string"==typeof enableOrNameAndArgs&&(this._helpCommandName=enableOrNameAndArgs.split(" ")[0],this._helpCommandnameAndArgs=enableOrNameAndArgs),this._helpCommandDescription=description||this._helpCommandDescription),this}_hasImplicitHelpCommand(){return void 0===this._addImplicitHelpCommand?this.commands.length&&!this._actionHandler&&!this._findCommand("help"):this._addImplicitHelpCommand}hook(event,listener){const allowedValues=["preSubcommand","preAction","postAction"];if(!allowedValues.includes(event))throw new Error(`Unexpected value for event passed to hook : '${event}'.\nExpecting one of '${allowedValues.join("', '")}'`);return this._lifeCycleHooks[event]?this._lifeCycleHooks[event].push(listener):this._lifeCycleHooks[event]=[listener],this}exitOverride(fn){return this._exitCallback=fn||(err=>{if("commander.executeSubCommandAsync"!==err.code)throw err}),this}_exit(exitCode,code,message){this._exitCallback&&this._exitCallback(new CommanderError(exitCode,code,message)),process.exit(exitCode)}action(fn){return this._actionHandler=args=>{const expectedArgsCount=this.registeredArguments.length,actionArgs=args.slice(0,expectedArgsCount);return this._storeOptionsAsProperties?actionArgs[expectedArgsCount]=this:actionArgs[expectedArgsCount]=this.opts(),actionArgs.push(this),fn.apply(this,actionArgs)},this}createOption(flags,description){return new Option(flags,description)}_callParseArg(target,value,previous,invalidArgumentMessage){try{return target.parseArg(value,previous)}catch(err){if("commander.invalidArgument"===err.code){const message=`${invalidArgumentMessage} ${err.message}`;this.error(message,{exitCode:err.exitCode,code:err.code})}throw err}}addOption(option){const oname=option.name(),name=option.attributeName();if(option.negate){const positiveLongFlag=option.long.replace(/^--no-/,"--");this._findOption(positiveLongFlag)||this.setOptionValueWithSource(name,void 0===option.defaultValue||option.defaultValue,"default")}else void 0!==option.defaultValue&&this.setOptionValueWithSource(name,option.defaultValue,"default");this.options.push(option);const handleOptionValue=(val,invalidValueMessage,valueSource)=>{null==val&&void 0!==option.presetArg&&(val=option.presetArg);const oldValue=this.getOptionValue(name);null!==val&&option.parseArg?val=this._callParseArg(option,val,oldValue,invalidValueMessage):null!==val&&option.variadic&&(val=option._concatValue(val,oldValue)),null==val&&(val=!option.negate&&(!(!option.isBoolean()&&!option.optional)||"")),this.setOptionValueWithSource(name,val,valueSource)};return this.on("option:"+oname,val=>{const invalidValueMessage=`error: option '${option.flags}' argument '${val}' is invalid.`;handleOptionValue(val,invalidValueMessage,"cli")}),option.envVar&&this.on("optionEnv:"+oname,val=>{const invalidValueMessage=`error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;handleOptionValue(val,invalidValueMessage,"env")}),this}_optionEx(config,flags,description,fn,defaultValue){if("object"==typeof flags&&flags instanceof Option)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const option=this.createOption(flags,description);if(option.makeOptionMandatory(!!config.mandatory),"function"==typeof fn)option.default(defaultValue).argParser(fn);else if(fn instanceof RegExp){const regex=fn;fn=(val,def)=>{const m=regex.exec(val);return m?m[0]:def},option.default(defaultValue).argParser(fn)}else option.default(fn);return this.addOption(option)}option(flags,description,parseArg,defaultValue){return this._optionEx({},flags,description,parseArg,defaultValue)}requiredOption(flags,description,parseArg,defaultValue){return this._optionEx({mandatory:!0},flags,description,parseArg,defaultValue)}combineFlagAndOptionalValue(combine=!0){return this._combineFlagAndOptionalValue=!!combine,this}allowUnknownOption(allowUnknown=!0){return this._allowUnknownOption=!!allowUnknown,this}allowExcessArguments(allowExcess=!0){return this._allowExcessArguments=!!allowExcess,this}enablePositionalOptions(positional=!0){return this._enablePositionalOptions=!!positional,this}passThroughOptions(passThrough=!0){if(this._passThroughOptions=!!passThrough,this.parent&&passThrough&&!this.parent._enablePositionalOptions)throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)");return this}storeOptionsAsProperties(storeAsProperties=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");return this._storeOptionsAsProperties=!!storeAsProperties,this}getOptionValue(key){return this._storeOptionsAsProperties?this[key]:this._optionValues[key]}setOptionValue(key,value){return this.setOptionValueWithSource(key,value,void 0)}setOptionValueWithSource(key,value,source){return this._storeOptionsAsProperties?this[key]=value:this._optionValues[key]=value,this._optionValueSources[key]=source,this}getOptionValueSource(key){return this._optionValueSources[key]}getOptionValueSourceWithGlobals(key){let source;return this._getCommandAndAncestors().forEach(cmd=>{void 0!==cmd.getOptionValueSource(key)&&(source=cmd.getOptionValueSource(key))}),source}_prepareUserArgs(argv,parseOptions){if(void 0!==argv&&!Array.isArray(argv))throw new Error("first parameter to parse must be array or undefined");let userArgs;switch(parseOptions=parseOptions||{},void 0===argv&&(argv=process.argv,process.versions&&process.versions.electron&&(parseOptions.from="electron")),this.rawArgs=argv.slice(),parseOptions.from){case void 0:case"node":this._scriptPath=argv[1],userArgs=argv.slice(2);break;case"electron":process.defaultApp?(this._scriptPath=argv[1],userArgs=argv.slice(2)):userArgs=argv.slice(1);break;case"user":userArgs=argv.slice(0);break;default:throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",userArgs}parse(argv,parseOptions){const userArgs=this._prepareUserArgs(argv,parseOptions);return this._parseCommand([],userArgs),this}async parseAsync(argv,parseOptions){const userArgs=this._prepareUserArgs(argv,parseOptions);return await this._parseCommand([],userArgs),this}_executeSubCommand(subcommand,args){args=args.slice();let launchWithNode=!1;const sourceExt=[".js",".ts",".tsx",".mjs",".cjs"];function findFile(baseDir,baseName){const localBin=path.resolve(baseDir,baseName);if(fs.existsSync(localBin))return localBin;if(sourceExt.includes(path.extname(baseName)))return;const foundExt=sourceExt.find(ext=>fs.existsSync(`${localBin}${ext}`));return foundExt?`${localBin}${foundExt}`:void 0}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let proc,executableFile=subcommand._executableFile||`${this._name}-${subcommand._name}`,executableDir=this._executableDir||"";if(this._scriptPath){let resolvedScriptPath;try{resolvedScriptPath=fs.realpathSync(this._scriptPath)}catch(err){resolvedScriptPath=this._scriptPath}executableDir=path.resolve(path.dirname(resolvedScriptPath),executableDir)}if(executableDir){let localFile=findFile(executableDir,executableFile);if(!localFile&&!subcommand._executableFile&&this._scriptPath){const legacyName=path.basename(this._scriptPath,path.extname(this._scriptPath));legacyName!==this._name&&(localFile=findFile(executableDir,`${legacyName}-${subcommand._name}`))}executableFile=localFile||executableFile}launchWithNode=sourceExt.includes(path.extname(executableFile)),"win32"!==process.platform?launchWithNode?(args.unshift(executableFile),args=incrementNodeInspectorPort(process.execArgv).concat(args),proc=childProcess.spawn(process.argv[0],args,{stdio:"inherit"})):proc=childProcess.spawn(executableFile,args,{stdio:"inherit"}):(args.unshift(executableFile),args=incrementNodeInspectorPort(process.execArgv).concat(args),proc=childProcess.spawn(process.execPath,args,{stdio:"inherit"})),proc.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(signal=>{process.on(signal,()=>{!1===proc.killed&&null===proc.exitCode&&proc.kill(signal)})});const exitCallback=this._exitCallback;exitCallback?proc.on("close",()=>{exitCallback(new CommanderError(process.exitCode||0,"commander.executeSubCommandAsync","(close)"))}):proc.on("close",process.exit.bind(process)),proc.on("error",err=>{if("ENOENT"===err.code){const executableDirMessage=executableDir?`searched for local subcommand relative to directory '${executableDir}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",executableMissing=`'${executableFile}' does not exist\n - if '${subcommand._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 - ${executableDirMessage}`;throw new Error(executableMissing)}if("EACCES"===err.code)throw new Error(`'${executableFile}' not executable`);if(exitCallback){const wrappedError=new CommanderError(1,"commander.executeSubCommandAsync","(error)");wrappedError.nestedError=err,exitCallback(wrappedError)}else process.exit(1)}),this.runningCommand=proc}_dispatchSubcommand(commandName,operands,unknown){const subCommand=this._findCommand(commandName);let promiseChain;return subCommand||this.help({error:!0}),promiseChain=this._chainOrCallSubCommandHook(promiseChain,subCommand,"preSubcommand"),promiseChain=this._chainOrCall(promiseChain,()=>{if(!subCommand._executableHandler)return subCommand._parseCommand(operands,unknown);this._executeSubCommand(subCommand,operands.concat(unknown))}),promiseChain}_dispatchHelpCommand(subcommandName){subcommandName||this.help();const subCommand=this._findCommand(subcommandName);return subCommand&&!subCommand._executableHandler&&subCommand.help(),this._dispatchSubcommand(subcommandName,[],[this._helpLongFlag||this._helpShortFlag])}_checkNumberOfArguments(){this.registeredArguments.forEach((arg,i)=>{arg.required&&null==this.args[i]&&this.missingArgument(arg.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic||this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){const myParseArg=(argument,value,previous)=>{let parsedValue=value;if(null!==value&&argument.parseArg){const invalidValueMessage=`error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;parsedValue=this._callParseArg(argument,value,previous,invalidValueMessage)}return parsedValue};this._checkNumberOfArguments();const processedArgs=[];this.registeredArguments.forEach((declaredArg,index)=>{let value=declaredArg.defaultValue;declaredArg.variadic?index<this.args.length?(value=this.args.slice(index),declaredArg.parseArg&&(value=value.reduce((processed,v)=>myParseArg(declaredArg,v,processed),declaredArg.defaultValue))):void 0===value&&(value=[]):index<this.args.length&&(value=this.args[index],declaredArg.parseArg&&(value=myParseArg(declaredArg,value,declaredArg.defaultValue))),processedArgs[index]=value}),this.processedArgs=processedArgs}_chainOrCall(promise,fn){return promise&&promise.then&&"function"==typeof promise.then?promise.then(()=>fn()):fn()}_chainOrCallHooks(promise,event){let result=promise;const hooks=[];return this._getCommandAndAncestors().reverse().filter(cmd=>void 0!==cmd._lifeCycleHooks[event]).forEach(hookedCommand=>{hookedCommand._lifeCycleHooks[event].forEach(callback=>{hooks.push({hookedCommand:hookedCommand,callback:callback})})}),"postAction"===event&&hooks.reverse(),hooks.forEach(hookDetail=>{result=this._chainOrCall(result,()=>hookDetail.callback(hookDetail.hookedCommand,this))}),result}_chainOrCallSubCommandHook(promise,subCommand,event){let result=promise;return void 0!==this._lifeCycleHooks[event]&&this._lifeCycleHooks[event].forEach(hook=>{result=this._chainOrCall(result,()=>hook(this,subCommand))}),result}_parseCommand(operands,unknown){const parsed=this.parseOptions(unknown);if(this._parseOptionsEnv(),this._parseOptionsImplied(),operands=operands.concat(parsed.operands),unknown=parsed.unknown,this.args=operands.concat(unknown),operands&&this._findCommand(operands[0]))return this._dispatchSubcommand(operands[0],operands.slice(1),unknown);if(this._hasImplicitHelpCommand()&&operands[0]===this._helpCommandName)return this._dispatchHelpCommand(operands[1]);if(this._defaultCommandName)return outputHelpIfRequested(this,unknown),this._dispatchSubcommand(this._defaultCommandName,operands,unknown);!this.commands.length||0!==this.args.length||this._actionHandler||this._defaultCommandName||this.help({error:!0}),outputHelpIfRequested(this,parsed.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const checkForUnknownOptions=()=>{parsed.unknown.length>0&&this.unknownOption(parsed.unknown[0])},commandEvent=`command:${this.name()}`;if(this._actionHandler){let promiseChain;return checkForUnknownOptions(),this._processArguments(),promiseChain=this._chainOrCallHooks(promiseChain,"preAction"),promiseChain=this._chainOrCall(promiseChain,()=>this._actionHandler(this.processedArgs)),this.parent&&(promiseChain=this._chainOrCall(promiseChain,()=>{this.parent.emit(commandEvent,operands,unknown)})),promiseChain=this._chainOrCallHooks(promiseChain,"postAction"),promiseChain}if(this.parent&&this.parent.listenerCount(commandEvent))checkForUnknownOptions(),this._processArguments(),this.parent.emit(commandEvent,operands,unknown);else if(operands.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",operands,unknown);this.listenerCount("command:*")?this.emit("command:*",operands,unknown):this.commands.length?this.unknownCommand():(checkForUnknownOptions(),this._processArguments())}else this.commands.length?(checkForUnknownOptions(),this.help({error:!0})):(checkForUnknownOptions(),this._processArguments())}_findCommand(name){if(name)return this.commands.find(cmd=>cmd._name===name||cmd._aliases.includes(name))}_findOption(arg){return this.options.find(option=>option.is(arg))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(cmd=>{cmd.options.forEach(anOption=>{anOption.mandatory&&void 0===cmd.getOptionValue(anOption.attributeName())&&cmd.missingMandatoryOptionValue(anOption)})})}_checkForConflictingLocalOptions(){const definedNonDefaultOptions=this.options.filter(option=>{const optionKey=option.attributeName();return void 0!==this.getOptionValue(optionKey)&&"default"!==this.getOptionValueSource(optionKey)}),optionsWithConflicting=definedNonDefaultOptions.filter(option=>option.conflictsWith.length>0);optionsWithConflicting.forEach(option=>{const conflictingAndDefined=definedNonDefaultOptions.find(defined=>option.conflictsWith.includes(defined.attributeName()));conflictingAndDefined&&this._conflictingOption(option,conflictingAndDefined)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(cmd=>{cmd._checkForConflictingLocalOptions()})}parseOptions(argv){const operands=[],unknown=[];let dest=operands;const args=argv.slice();function maybeOption(arg){return arg.length>1&&"-"===arg[0]}let activeVariadicOption=null;for(;args.length;){const arg=args.shift();if("--"===arg){dest===unknown&&dest.push(arg),dest.push(...args);break}if(!activeVariadicOption||maybeOption(arg)){if(activeVariadicOption=null,maybeOption(arg)){const option=this._findOption(arg);if(option){if(option.required){const value=args.shift();void 0===value&&this.optionMissingArgument(option),this.emit(`option:${option.name()}`,value)}else if(option.optional){let value=null;args.length>0&&!maybeOption(args[0])&&(value=args.shift()),this.emit(`option:${option.name()}`,value)}else this.emit(`option:${option.name()}`);activeVariadicOption=option.variadic?option:null;continue}}if(arg.length>2&&"-"===arg[0]&&"-"!==arg[1]){const option=this._findOption(`-${arg[1]}`);if(option){option.required||option.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${option.name()}`,arg.slice(2)):(this.emit(`option:${option.name()}`),args.unshift(`-${arg.slice(2)}`));continue}}if(/^--[^=]+=/.test(arg)){const index=arg.indexOf("="),option=this._findOption(arg.slice(0,index));if(option&&(option.required||option.optional)){this.emit(`option:${option.name()}`,arg.slice(index+1));continue}}if(maybeOption(arg)&&(dest=unknown),(this._enablePositionalOptions||this._passThroughOptions)&&0===operands.length&&0===unknown.length){if(this._findCommand(arg)){operands.push(arg),args.length>0&&unknown.push(...args);break}if(arg===this._helpCommandName&&this._hasImplicitHelpCommand()){operands.push(arg),args.length>0&&operands.push(...args);break}if(this._defaultCommandName){unknown.push(arg),args.length>0&&unknown.push(...args);break}}if(this._passThroughOptions){dest.push(arg),args.length>0&&dest.push(...args);break}dest.push(arg)}else this.emit(`option:${activeVariadicOption.name()}`,arg)}return{operands:operands,unknown:unknown}}opts(){if(this._storeOptionsAsProperties){const result={},len=this.options.length;for(let i=0;i<len;i++){const key=this.options[i].attributeName();result[key]=key===this._versionOptionName?this._version:this[key]}return result}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((combinedOptions,cmd)=>Object.assign(combinedOptions,cmd.opts()),{})}error(message,errorOptions){this._outputConfiguration.outputError(`${message}\n`,this._outputConfiguration.writeErr),"string"==typeof this._showHelpAfterError?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr("\n"),this.outputHelp({error:!0}));const config=errorOptions||{},exitCode=config.exitCode||1,code=config.code||"commander.error";this._exit(exitCode,code,message)}_parseOptionsEnv(){this.options.forEach(option=>{if(option.envVar&&option.envVar in process.env){const optionKey=option.attributeName();(void 0===this.getOptionValue(optionKey)||["default","config","env"].includes(this.getOptionValueSource(optionKey)))&&(option.required||option.optional?this.emit(`optionEnv:${option.name()}`,process.env[option.envVar]):this.emit(`optionEnv:${option.name()}`))}})}_parseOptionsImplied(){const dualHelper=new DualOptions(this.options),hasCustomOptionValue=optionKey=>void 0!==this.getOptionValue(optionKey)&&!["default","implied"].includes(this.getOptionValueSource(optionKey));this.options.filter(option=>void 0!==option.implied&&hasCustomOptionValue(option.attributeName())&&dualHelper.valueFromOption(this.getOptionValue(option.attributeName()),option)).forEach(option=>{Object.keys(option.implied).filter(impliedKey=>!hasCustomOptionValue(impliedKey)).forEach(impliedKey=>{this.setOptionValueWithSource(impliedKey,option.implied[impliedKey],"implied")})})}missingArgument(name){const message=`error: missing required argument '${name}'`;this.error(message,{code:"commander.missingArgument"})}optionMissingArgument(option){const message=`error: option '${option.flags}' argument missing`;this.error(message,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(option){const message=`error: required option '${option.flags}' not specified`;this.error(message,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(option,conflictingOption){const findBestOptionFromValue=option=>{const optionKey=option.attributeName(),optionValue=this.getOptionValue(optionKey),negativeOption=this.options.find(target=>target.negate&&optionKey===target.attributeName()),positiveOption=this.options.find(target=>!target.negate&&optionKey===target.attributeName());return negativeOption&&(void 0===negativeOption.presetArg&&!1===optionValue||void 0!==negativeOption.presetArg&&optionValue===negativeOption.presetArg)?negativeOption:positiveOption||option},getErrorMessage=option=>{const bestOption=findBestOptionFromValue(option),optionKey=bestOption.attributeName();return"env"===this.getOptionValueSource(optionKey)?`environment variable '${bestOption.envVar}'`:`option '${bestOption.flags}'`},message=`error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;this.error(message,{code:"commander.conflictingOption"})}unknownOption(flag){if(this._allowUnknownOption)return;let suggestion="";if(flag.startsWith("--")&&this._showSuggestionAfterError){let candidateFlags=[],command=this;do{const moreFlags=command.createHelp().visibleOptions(command).filter(option=>option.long).map(option=>option.long);candidateFlags=candidateFlags.concat(moreFlags),command=command.parent}while(command&&!command._enablePositionalOptions);suggestion=suggestSimilar(flag,candidateFlags)}const message=`error: unknown option '${flag}'${suggestion}`;this.error(message,{code:"commander.unknownOption"})}_excessArguments(receivedArgs){if(this._allowExcessArguments)return;const expected=this.registeredArguments.length,s=1===expected?"":"s",message=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;this.error(message,{code:"commander.excessArguments"})}unknownCommand(){const unknownName=this.args[0];let suggestion="";if(this._showSuggestionAfterError){const candidateNames=[];this.createHelp().visibleCommands(this).forEach(command=>{candidateNames.push(command.name()),command.alias()&&candidateNames.push(command.alias())}),suggestion=suggestSimilar(unknownName,candidateNames)}const message=`error: unknown command '${unknownName}'${suggestion}`;this.error(message,{code:"commander.unknownCommand"})}version(str,flags,description){if(void 0===str)return this._version;this._version=str,flags=flags||"-V, --version",description=description||"output the version number";const versionOption=this.createOption(flags,description);return this._versionOptionName=versionOption.attributeName(),this.options.push(versionOption),this.on("option:"+versionOption.name(),()=>{this._outputConfiguration.writeOut(`${str}\n`),this._exit(0,"commander.version",str)}),this}description(str,argsDescription){return void 0===str&&void 0===argsDescription?this._description:(this._description=str,argsDescription&&(this._argsDescription=argsDescription),this)}summary(str){return void 0===str?this._summary:(this._summary=str,this)}alias(alias){if(void 0===alias)return this._aliases[0];let command=this;if(0!==this.commands.length&&this.commands[this.commands.length-1]._executableHandler&&(command=this.commands[this.commands.length-1]),alias===command._name)throw new Error("Command alias can't be the same as its name");return command._aliases.push(alias),this}aliases(aliases){return void 0===aliases?this._aliases:(aliases.forEach(alias=>this.alias(alias)),this)}usage(str){if(void 0===str){if(this._usage)return this._usage;const args=this.registeredArguments.map(arg=>humanReadableArgName(arg));return[].concat(this.options.length||this._hasHelpOption?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?args:[]).join(" ")}return this._usage=str,this}name(str){return void 0===str?this._name:(this._name=str,this)}nameFromFilename(filename){return this._name=path.basename(filename,path.extname(filename)),this}executableDir(path){return void 0===path?this._executableDir:(this._executableDir=path,this)}helpInformation(contextOptions){const helper=this.createHelp();return void 0===helper.helpWidth&&(helper.helpWidth=contextOptions&&contextOptions.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth()),helper.formatHelp(this,helper)}_getHelpContext(contextOptions){const context={error:!!(contextOptions=contextOptions||{}).error};let write;return write=context.error?arg=>this._outputConfiguration.writeErr(arg):arg=>this._outputConfiguration.writeOut(arg),context.write=contextOptions.write||write,context.command=this,context}outputHelp(contextOptions){let deprecatedCallback;"function"==typeof contextOptions&&(deprecatedCallback=contextOptions,contextOptions=void 0);const context=this._getHelpContext(contextOptions);this._getCommandAndAncestors().reverse().forEach(command=>command.emit("beforeAllHelp",context)),this.emit("beforeHelp",context);let helpInformation=this.helpInformation(context);if(deprecatedCallback&&(helpInformation=deprecatedCallback(helpInformation),"string"!=typeof helpInformation&&!Buffer.isBuffer(helpInformation)))throw new Error("outputHelp callback must return a string or a Buffer");context.write(helpInformation),this._helpLongFlag&&this.emit(this._helpLongFlag),this.emit("afterHelp",context),this._getCommandAndAncestors().forEach(command=>command.emit("afterAllHelp",context))}helpOption(flags,description){if("boolean"==typeof flags)return this._hasHelpOption=flags,this;this._helpFlags=flags||this._helpFlags,this._helpDescription=description||this._helpDescription;const helpFlags=splitOptionFlags(this._helpFlags);return this._helpShortFlag=helpFlags.shortFlag,this._helpLongFlag=helpFlags.longFlag,this}help(contextOptions){this.outputHelp(contextOptions);let exitCode=process.exitCode||0;0===exitCode&&contextOptions&&"function"!=typeof contextOptions&&contextOptions.error&&(exitCode=1),this._exit(exitCode,"commander.help","(outputHelp)")}addHelpText(position,text){const allowedValues=["beforeAll","before","after","afterAll"];if(!allowedValues.includes(position))throw new Error(`Unexpected value for position to addHelpText.\nExpecting one of '${allowedValues.join("', '")}'`);const helpEvent=`${position}Help`;return this.on(helpEvent,context=>{let helpStr;helpStr="function"==typeof text?text({error:context.error,command:context.command}):text,helpStr&&context.write(`${helpStr}\n`)}),this}}function outputHelpIfRequested(cmd,args){cmd._hasHelpOption&&args.find(arg=>arg===cmd._helpLongFlag||arg===cmd._helpShortFlag)&&(cmd.outputHelp(),cmd._exit(0,"commander.helpDisplayed","(outputHelp)"))}function incrementNodeInspectorPort(args){return args.map(arg=>{if(!arg.startsWith("--inspect"))return arg;let debugOption,match,debugHost="127.0.0.1",debugPort="9229";return null!==(match=arg.match(/^(--inspect(-brk)?)$/))?debugOption=match[1]:null!==(match=arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))?(debugOption=match[1],/^\d+$/.test(match[3])?debugPort=match[3]:debugHost=match[3]):null!==(match=arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))&&(debugOption=match[1],debugHost=match[3],debugPort=match[4]),debugOption&&"0"!==debugPort?`${debugOption}=${debugHost}:${parseInt(debugPort)+1}`:arg})}return command.Command=Command,command}(),{CommanderError:CommanderError,InvalidArgumentError:InvalidArgumentError}=requireError(),{Help:Help}=requireHelp(),{Option:Option}=requireOption();(exports=module.exports=new Command).program=exports,exports.Command=Command,exports.Option=Option,exports.Argument=Argument,exports.Help=Help,exports.CommanderError=CommanderError,exports.InvalidArgumentError=InvalidArgumentError,exports.InvalidOptionArgumentError=InvalidArgumentError}(commander$1,commander$1.exports)),commander$1.exports}(),commander=getDefaultExportFromCjs(commanderExports);const{program:program$1,createCommand:createCommand,createArgument:createArgument,createOption:createOption,CommanderError:CommanderError,InvalidArgumentError:InvalidArgumentError,InvalidOptionArgumentError:InvalidOptionArgumentError,Command:Command,Argument:Argument,Option:Option,Help:Help}=commander,wrapAnsi16=(offset=0)=>code=>`[${code+offset}m`,wrapAnsi256=(offset=0)=>code=>`[${38+offset};5;${code}m`,wrapAnsi16m=(offset=0)=>(red,green,blue)=>`[${38+offset};2;${red};${green};${blue}m`,styles$1={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(styles$1.modifier);Object.keys(styles$1.color),Object.keys(styles$1.bgColor);const ansiStyles$1=function assembleStyles(){const codes=new Map;for(const[groupName,group]of Object.entries(styles$1)){for(const[styleName,style]of Object.entries(group))styles$1[styleName]={open:`[${style[0]}m`,close:`[${style[1]}m`},group[styleName]=styles$1[styleName],codes.set(style[0],style[1]);Object.defineProperty(styles$1,groupName,{value:group,enumerable:!1})}return Object.defineProperty(styles$1,"codes",{value:codes,enumerable:!1}),styles$1.color.close="[39m",styles$1.bgColor.close="[49m",styles$1.color.ansi=wrapAnsi16(),styles$1.color.ansi256=wrapAnsi256(),styles$1.color.ansi16m