UNPKG

node-command-line-starter-1

Version:
1 lines 33.3 kB
!function(t){var e={};function i(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)i.d(n,s,function(e){return t[e]}.bind(null,s));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=844)}({138:function(t,e,i){const{InvalidArgumentError:n}=i(92);e.Argument=class{constructor(t,e){switch(this.description=e||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t}this._name.length>3&&"..."===this._name.slice(-3)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?e.concat(t):[t]}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}argParser(t){return this.parseArg=t,this}choices(t){return this.argChoices=t,this.parseArg=(e,i)=>{if(!t.includes(e))throw new n(`Allowed choices are ${t.join(", ")}.`);return this.variadic?this._concatValue(e,i):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}},e.humanReadableArgName=function(t){const e=t.name()+(!0===t.variadic?"...":"");return t.required?"<"+e+">":"["+e+"]"}},209:function(t,e,i){const{humanReadableArgName:n}=i(138);e.Help=class{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1}visibleCommands(t){const e=t.commands.filter(t=>!t._hidden);if(t._hasImplicitHelpCommand()){const[,i,n]=t._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/),s=t.createCommand(i).helpOption(!1);s.description(t._helpCommandDescription),n&&s.arguments(n),e.push(s)}return this.sortSubcommands&&e.sort((t,e)=>t.name().localeCompare(e.name())),e}visibleOptions(t){const e=t.options.filter(t=>!t.hidden),i=t._hasHelpOption&&t._helpShortFlag&&!t._findOption(t._helpShortFlag),n=t._hasHelpOption&&!t._findOption(t._helpLongFlag);if(i||n){let s;s=i?n?t.createOption(t._helpFlags,t._helpDescription):t.createOption(t._helpShortFlag,t._helpDescription):t.createOption(t._helpLongFlag,t._helpDescription),e.push(s)}if(this.sortOptions){const t=t=>t.short?t.short.replace(/^-/,""):t.long.replace(/^--/,"");e.sort((e,i)=>t(e).localeCompare(t(i)))}return e}visibleArguments(t){return t._argsDescription&&t._args.forEach(e=>{e.description=e.description||t._argsDescription[e.name()]||""}),t._args.find(t=>t.description)?t._args:[]}subcommandTerm(t){const e=t._args.map(t=>n(t)).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(e?" "+e:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce((t,i)=>Math.max(t,e.subcommandTerm(i).length),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce((t,i)=>Math.max(t,e.optionTerm(i).length),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce((t,i)=>Math.max(t,e.argumentTerm(i).length),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let i="";for(let e=t.parent;e;e=e.parent)i=e.name()+" "+i;return i+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.description()}optionDescription(t){const e=[];return t.argChoices&&!t.negate&&e.push("choices: "+t.argChoices.map(t=>JSON.stringify(t)).join(", ")),void 0===t.defaultValue||t.negate||e.push("default: "+(t.defaultValueDescription||JSON.stringify(t.defaultValue))),void 0!==t.envVar&&e.push("env: "+t.envVar),e.length>0?`${t.description} (${e.join(", ")})`:t.description}argumentDescription(t){const e=[];if(t.argChoices&&e.push("choices: "+t.argChoices.map(t=>JSON.stringify(t)).join(", ")),void 0!==t.defaultValue&&e.push("default: "+(t.defaultValueDescription||JSON.stringify(t.defaultValue))),e.length>0){const i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}formatHelp(t,e){const i=e.padWidth(t,e),n=e.helpWidth||80;function s(t,s){if(s){const r=`${t.padEnd(i+2)}${s}`;return e.wrap(r,n-2,i+2)}return t}function r(t){return t.join("\n").replace(/^/gm," ".repeat(2))}let o=["Usage: "+e.commandUsage(t),""];const a=e.commandDescription(t);a.length>0&&(o=o.concat([a,""]));const h=e.visibleArguments(t).map(t=>s(e.argumentTerm(t),e.argumentDescription(t)));h.length>0&&(o=o.concat(["Arguments:",r(h),""]));const l=e.visibleOptions(t).map(t=>s(e.optionTerm(t),e.optionDescription(t)));l.length>0&&(o=o.concat(["Options:",r(l),""]));const c=e.visibleCommands(t).map(t=>s(e.subcommandTerm(t),e.subcommandDescription(t)));return c.length>0&&(o=o.concat(["Commands:",r(c),""])),o.join("\n")}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}wrap(t,e,i,n=40){if(t.match(/[\n]\s+/))return t;const s=e-i;if(s<n)return t;const r=t.substr(0,i),o=t.substr(i),a=" ".repeat(i),h=new RegExp(".{1,"+(s-1)+"}([\\s​]|$)|[^\\s​]+?([\\s​]|$)","g");return r+(o.match(h)||[]).map((t,e)=>("\n"===t.slice(-1)&&(t=t.slice(0,t.length-1)),(e>0?a:"")+t.trimRight())).join("\n")}}},210:function(t,e,i){const{InvalidArgumentError:n}=i(92);function s(t){let e,i;const n=t.split(/[ |,]+/);return n.length>1&&!/^[[<]/.test(n[1])&&(e=n.shift()),i=n.shift(),!e&&/^-[^-]$/.test(i)&&(e=i,i=void 0),{shortFlag:e,longFlag:i}}e.Option=class{constructor(t,e){this.flags=t,this.description=e||"",this.required=t.includes("<"),this.optional=t.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(t),this.mandatory=!1;const i=s(t);this.short=i.shortFlag,this.long=i.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}env(t){return this.envVar=t,this}argParser(t){return this.parseArg=t,this}makeOptionMandatory(t=!0){return this.mandatory=!!t,this}hideHelp(t=!0){return this.hidden=!!t,this}_concatValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?e.concat(t):[t]}choices(t){return this.argChoices=t,this.parseArg=(e,i)=>{if(!t.includes(e))throw new n(`Allowed choices are ${t.join(", ")}.`);return this.variadic?this._concatValue(e,i):e},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.name().replace(/^no-/,"").split("-").reduce((t,e)=>t+e[0].toUpperCase()+e.slice(1))}is(t){return this.short===t||this.long===t}},e.splitOptionFlags=s},254:function(t,e,i){const{Argument:n}=i(138),{Command:s}=i(497),{CommanderError:r,InvalidArgumentError:o}=i(92),{Help:a}=i(209),{Option:h}=i(210);(e=t.exports=new s).program=e,e.Argument=n,e.Command=s,e.CommanderError=r,e.Help=a,e.InvalidArgumentError=o,e.InvalidOptionArgumentError=o,e.Option=h},255:function(t){t.exports=JSON.parse('{"name":"node-command-line-starter-1","version":"2.1.6","author":"Himanshu @himanshu-dixit","repository":"crusherdev/CLI","main":"index.js","husky":{"hooks":{"pre-commit":"lint-staged","commit-msg":"commitlint -E HUSKY_GIT_PARAMS"}},"lint-staged":{"{src,__mocks__,bin}/**/*.ts":["prettier --write","git add"]},"commitlint":{"extends":["@commitlint/config-conventional"]},"config":{"commitizen":{"path":"@commitlint/prompt"}},"scripts":{"build":"tsc","commit":"git-cz","format:check":"prettier --list-different \'{src,__mocks__,bin}/**/*.ts\'","format:write":"prettier --write \'{src,__mocks__,bin}/**/*.ts\'","start:help":"ts-node ./src/bin/order.ts -h","start:example":"ts-node ./src/bin/order.ts","test":"jest","bump-version":"rjp package.json version $VERSION","test:coverage":"jest --coverage","report:coverage":"npm run test:coverage && codecov","semantic-release":"semantic-release","webpack":"webpack && cp package.json dist"},"bin":{"node-command-line-starter-1":"./src/bin/base.js","login":"./src/bin/login.js","logout":"./src/bin/logout.js","test":"./src/bin/test.js","whoami":"./src/bin/whoami.js","invite":"./src/bin/invite.js"},"keywords":["CLI","Replace","JSON","Buildtool","Starter"],"license":"MIT","dependencies":{},"devDependencies":{"@commitlint/cli":"^13.1.0","@commitlint/config-conventional":"^13.1.0","@commitlint/prompt":"^13.1.0","@semantic-release/changelog":"^5.0.1","@semantic-release/exec":"^5.0.0","@semantic-release/git":"^9.0.1","@types/jest":"^27.0.1","@types/node":"^16.9.4","axios":"^0.25.0","boxen":"^5.1.2","chalk":"^5.0.0","cli-ux":"^6.0.9","codecov":"^3.1.0","command-exists":"^1.2.9","commander":"^8.2.0","commitizen":"^4.2.4","copy-webpack-plugin":"^10.2.4","fastify":"^3.27.1","glob":"^7.2.0","husky":"^7.0.2","jest":"^27.2.0","jsonfile":"^6.1.0","lint-staged":"^11.1.2","localtunnel":"^2.0.2","prettier":"^2.4.1","replace-json-property":"^1.4.1","semantic-release":"^18.0.0","ts-jest":"^27.0.5","ts-loader":"^8.2.6","ts-node":"^10.2.1","typescript":"^4.4.3","webpack":"^4.2.0","webpack-cli":"^4.9.2"}}')},33:function(t,e){t.exports=require("events")},4:function(t,e){t.exports=require("path")},46:function(t,e){t.exports=require("child_process")},497:function(t,e,i){const n=i(33).EventEmitter,s=i(46),r=i(4),o=i(6),{Argument:a,humanReadableArgName:h}=i(138),{CommanderError:l}=i(92),{Help:c}=i(209),{Option:p,splitOptionFlags:u}=i(210),{suggestSimilar:m}=i(498);class d extends n{constructor(t){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!0,this._args=[],this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=t||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!1,this._outputConfiguration={writeOut:t=>process.stdout.write(t),writeErr:t=>process.stderr.write(t),getOutHelpWidth:()=>process.stdout.isTTY?process.stdout.columns:void 0,getErrHelpWidth:()=>process.stderr.isTTY?process.stderr.columns:void 0,outputError:(t,e)=>e(t)},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(t){return 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,this}command(t,e,i){let n=e,s=i;"object"==typeof n&&null!==n&&(s=n,n=null),s=s||{};const[,r,o]=t.match(/([^ ]+) *(.*)/),a=this.createCommand(r);return n&&(a.description(n),a._executableHandler=!0),s.isDefault&&(this._defaultCommandName=a._name),a._hidden=!(!s.noHelp&&!s.hidden),a._executableFile=s.executableFile||null,o&&a.arguments(o),this.commands.push(a),a.parent=this,a.copyInheritedSettings(this),n?this:a}createCommand(t){return new d(t)}createHelp(){return Object.assign(new c,this.configureHelp())}configureHelp(t){return void 0===t?this._helpConfiguration:(this._helpConfiguration=t,this)}configureOutput(t){return void 0===t?this._outputConfiguration:(Object.assign(this._outputConfiguration,t),this)}showHelpAfterError(t=!0){return"string"!=typeof t&&(t=!!t),this._showHelpAfterError=t,this}showSuggestionAfterError(t=!0){return this._showSuggestionAfterError=!!t,this}addCommand(t,e){if(!t._name)throw new Error("Command passed to .addCommand() must have a name");return function t(e){e.forEach(e=>{if(e._executableHandler&&!e._executableFile)throw new Error("Must specify executableFile for deeply nested executable: "+e.name());t(e.commands)})}(t.commands),(e=e||{}).isDefault&&(this._defaultCommandName=t._name),(e.noHelp||e.hidden)&&(t._hidden=!0),this.commands.push(t),t.parent=this,this}createArgument(t,e){return new a(t,e)}argument(t,e,i,n){const s=this.createArgument(t,e);return"function"==typeof i?s.default(n).argParser(i):s.default(i),this.addArgument(s),this}arguments(t){return t.split(/ +/).forEach(t=>{this.argument(t)}),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()}'`);return this._args.push(t),this}addHelpCommand(t,e){return!1===t?this._addImplicitHelpCommand=!1:(this._addImplicitHelpCommand=!0,"string"==typeof t&&(this._helpCommandName=t.split(" ")[0],this._helpCommandnameAndArgs=t),this._helpCommandDescription=e||this._helpCommandDescription),this}_hasImplicitHelpCommand(){return void 0===this._addImplicitHelpCommand?this.commands.length&&!this._actionHandler&&!this._findCommand("help"):this._addImplicitHelpCommand}hook(t,e){const i=["preAction","postAction"];if(!i.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.\nExpecting one of '${i.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(e):this._lifeCycleHooks[t]=[e],this}exitOverride(t){return this._exitCallback=t||(t=>{if("commander.executeSubCommandAsync"!==t.code)throw t}),this}_exit(t,e,i){this._exitCallback&&this._exitCallback(new l(t,e,i)),process.exit(t)}action(t){return this._actionHandler=e=>{const i=this._args.length,n=e.slice(0,i);return this._storeOptionsAsProperties?n[i]=this:n[i]=this.opts(),n.push(this),t.apply(this,n)},this}createOption(t,e){return new p(t,e)}addOption(t){const e=t.name(),i=t.attributeName();let n=t.defaultValue;if(t.negate||t.optional||t.required||"boolean"==typeof n){if(t.negate){const e=t.long.replace(/^--no-/,"--");n=!this._findOption(e)||this.getOptionValue(i)}void 0!==n&&this.setOptionValueWithSource(i,n,"default")}this.options.push(t);const s=(e,s,r)=>{const o=this.getOptionValue(i);if(null!==e&&t.parseArg)try{e=t.parseArg(e,void 0===o?n:o)}catch(t){if("commander.invalidArgument"===t.code){const e=`${s} ${t.message}`;this._displayError(t.exitCode,t.code,e)}throw t}else null!==e&&t.variadic&&(e=t._concatValue(e,o));"boolean"==typeof o||void 0===o?null==e?this.setOptionValueWithSource(i,!t.negate&&(n||!0),r):this.setOptionValueWithSource(i,e,r):null!==e&&this.setOptionValueWithSource(i,!t.negate&&e,r)};return this.on("option:"+e,e=>{const i=`error: option '${t.flags}' argument '${e}' is invalid.`;s(e,i,"cli")}),t.envVar&&this.on("optionEnv:"+e,e=>{const i=`error: option '${t.flags}' value '${e}' from env '${t.envVar}' is invalid.`;s(e,i,"env")}),this}_optionEx(t,e,i,n,s){const r=this.createOption(e,i);if(r.makeOptionMandatory(!!t.mandatory),"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:!0},t,e,i,n)}combineFlagAndOptionalValue(t=!0){return this._combineFlagAndOptionalValue=!!t,this}allowUnknownOption(t=!0){return this._allowUnknownOption=!!t,this}allowExcessArguments(t=!0){return this._allowExcessArguments=!!t,this}enablePositionalOptions(t=!0){return this._enablePositionalOptions=!!t,this}passThroughOptions(t=!0){if(this._passThroughOptions=!!t,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=!0){if(this._storeOptionsAsProperties=!!t,this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");return this}getOptionValue(t){return this._storeOptionsAsProperties?this[t]:this._optionValues[t]}setOptionValue(t,e){return this._storeOptionsAsProperties?this[t]=e:this._optionValues[t]=e,this}setOptionValueWithSource(t,e,i){return this.setOptionValue(t,e),this._optionValueSources[t]=i,this}getOptionValueSource(t){return this._optionValueSources[t]}_prepareUserArgs(t,e){if(void 0!==t&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");let n;switch(e=e||{},void 0===t&&(t=process.argv,process.versions&&process.versions.electron&&(e.from="electron")),this.rawArgs=t.slice(),e.from){case void 0:case"node":this._scriptPath=t[1],n=t.slice(2);break;case"electron":process.defaultApp?(this._scriptPath=t[1],n=t.slice(2)):n=t.slice(1);break;case"user":n=t.slice(0);break;default:throw new Error(`unexpected parse option { from: '${e.from}' }`)}return!this._scriptPath&&i.c[i.s]&&(this._scriptPath=i.c[i.s].filename),this._name=this._name||this._scriptPath&&r.basename(this._scriptPath,r.extname(this._scriptPath)),n}parse(t,e){const i=this._prepareUserArgs(t,e);return this._parseCommand([],i),this}async parseAsync(t,e){const i=this._prepareUserArgs(t,e);return await this._parseCommand([],i),this}_executeSubCommand(t,e){e=e.slice();let n=!1;const a=[".js",".ts",".tsx",".mjs",".cjs"];this._checkForMissingMandatoryOptions();let h,c=this._scriptPath;!c&&i.c[i.s]&&(c=i.c[i.s].filename);try{const t=o.realpathSync(c);h=r.dirname(t)}catch(t){h="."}let p=r.basename(c,r.extname(c))+"-"+t._name;t._executableFile&&(p=t._executableFile);const u=r.join(h,p);let m;o.existsSync(u)?p=u:a.forEach(t=>{o.existsSync(`${u}${t}`)&&(p=`${u}${t}`)}),n=a.includes(r.extname(p)),"win32"!==process.platform?n?(e.unshift(p),e=f(process.execArgv).concat(e),m=s.spawn(process.argv[0],e,{stdio:"inherit"})):m=s.spawn(p,e,{stdio:"inherit"}):(e.unshift(p),e=f(process.execArgv).concat(e),m=s.spawn(process.execPath,e,{stdio:"inherit"}));["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(t=>{process.on(t,()=>{!1===m.killed&&null===m.exitCode&&m.kill(t)})});const d=this._exitCallback;d?m.on("close",()=>{d(new l(process.exitCode||0,"commander.executeSubCommandAsync","(close)"))}):m.on("close",process.exit.bind(process)),m.on("error",e=>{if("ENOENT"===e.code){const e=`'${p}' 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`;throw new Error(e)}if("EACCES"===e.code)throw new Error(`'${p}' not executable`);if(d){const t=new l(1,"commander.executeSubCommandAsync","(error)");t.nestedError=e,d(t)}else process.exit(1)}),this.runningCommand=m}_dispatchSubcommand(t,e,i){const n=this._findCommand(t);if(n||this.help({error:!0}),!n._executableHandler)return n._parseCommand(e,i);this._executeSubCommand(n,e.concat(i))}_checkNumberOfArguments(){this._args.forEach((t,e)=>{t.required&&null==this.args[e]&&this.missingArgument(t.name())}),this._args.length>0&&this._args[this._args.length-1].variadic||this.args.length>this._args.length&&this._excessArguments(this.args)}_processArguments(){const t=(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._displayError(i.exitCode,i.code,n)}throw i}return n};this._checkNumberOfArguments();const e=[];this._args.forEach((i,n)=>{let s=i.defaultValue;i.variadic?n<this.args.length?(s=this.args.slice(n),i.parseArg&&(s=s.reduce((e,n)=>t(i,n,e),i.defaultValue))):void 0===s&&(s=[]):n<this.args.length&&(s=this.args[n],i.parseArg&&(s=t(i,s,i.defaultValue))),e[n]=s}),this.processedArgs=e}_chainOrCall(t,e){return t&&t.then&&"function"==typeof t.then?t.then(()=>e()):e()}_chainOrCallHooks(t,e){let i=t;const n=[];return _(this).reverse().filter(t=>void 0!==t._lifeCycleHooks[e]).forEach(t=>{t._lifeCycleHooks[e].forEach(e=>{n.push({hookedCommand:t,callback:e})})}),"postAction"===e&&n.reverse(),n.forEach(t=>{i=this._chainOrCall(i,()=>t.callback(t.hookedCommand,this))}),i}_parseCommand(t,e){const i=this.parseOptions(e);if(this._parseOptionsEnv(),t=t.concat(i.operands),e=i.unknown,this.args=t.concat(e),t&&this._findCommand(t[0]))return this._dispatchSubcommand(t[0],t.slice(1),e);if(this._hasImplicitHelpCommand()&&t[0]===this._helpCommandName)return 1===t.length&&this.help(),this._dispatchSubcommand(t[1],[],[this._helpLongFlag]);if(this._defaultCommandName)return g(this,e),this._dispatchSubcommand(this._defaultCommandName,t,e);!this.commands.length||0!==this.args.length||this._actionHandler||this._defaultCommandName||this.help({error:!0}),g(this,i.unknown),this._checkForMissingMandatoryOptions();const n=()=>{i.unknown.length>0&&this.unknownOption(i.unknown[0])},s="command:"+this.name();if(this._actionHandler){let i;return n(),this._processArguments(),i=this._chainOrCallHooks(i,"preAction"),i=this._chainOrCall(i,()=>this._actionHandler(this.processedArgs)),this.parent&&this.parent.emit(s,t,e),i=this._chainOrCallHooks(i,"postAction"),i}if(this.parent&&this.parent.listenerCount(s))n(),this._processArguments(),this.parent.emit(s,t,e);else if(t.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",t,e);this.listenerCount("command:*")?this.emit("command:*",t,e):this.commands.length?this.unknownCommand():(n(),this._processArguments())}else this.commands.length?(n(),this.help({error:!0})):(n(),this._processArguments())}_findCommand(t){if(t)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=>{e.mandatory&&void 0===t.getOptionValue(e.attributeName())&&t.missingMandatoryOptionValue(e)})}parseOptions(t){const e=[],i=[];let n=e;const s=t.slice();function r(t){return t.length>1&&"-"===t[0]}let o=null;for(;s.length;){const t=s.shift();if("--"===t){n===i&&n.push(t),n.push(...s);break}if(!o||r(t)){if(o=null,r(t)){const e=this._findOption(t);if(e){if(e.required){const t=s.shift();void 0===t&&this.optionMissingArgument(e),this.emit("option:"+e.name(),t)}else if(e.optional){let t=null;s.length>0&&!r(s[0])&&(t=s.shift()),this.emit("option:"+e.name(),t)}else this.emit("option:"+e.name());o=e.variadic?e:null;continue}}if(t.length>2&&"-"===t[0]&&"-"!==t[1]){const e=this._findOption("-"+t[1]);if(e){e.required||e.optional&&this._combineFlagAndOptionalValue?this.emit("option:"+e.name(),t.slice(2)):(this.emit("option:"+e.name()),s.unshift("-"+t.slice(2)));continue}}if(/^--[^=]+=/.test(t)){const e=t.indexOf("="),i=this._findOption(t.slice(0,e));if(i&&(i.required||i.optional)){this.emit("option:"+i.name(),t.slice(e+1));continue}}if(r(t)&&(n=i),(this._enablePositionalOptions||this._passThroughOptions)&&0===e.length&&0===i.length){if(this._findCommand(t)){e.push(t),s.length>0&&i.push(...s);break}if(t===this._helpCommandName&&this._hasImplicitHelpCommand()){e.push(t),s.length>0&&e.push(...s);break}if(this._defaultCommandName){i.push(t),s.length>0&&i.push(...s);break}}if(this._passThroughOptions){n.push(t),s.length>0&&n.push(...s);break}n.push(t)}else this.emit("option:"+o.name(),t)}return{operands:e,unknown:i}}opts(){if(this._storeOptionsAsProperties){const t={},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}_displayError(t,e,i){this._outputConfiguration.outputError(i+"\n",this._outputConfiguration.writeErr),"string"==typeof this._showHelpAfterError?this._outputConfiguration.writeErr(this._showHelpAfterError+"\n"):this._showHelpAfterError&&(this._outputConfiguration.writeErr("\n"),this.outputHelp({error:!0})),this._exit(t,e,i)}_parseOptionsEnv(){this.options.forEach(t=>{if(t.envVar&&t.envVar in process.env){const e=t.attributeName();(void 0===this.getOptionValue(e)||["default","config","env"].includes(this.getOptionValueSource(e)))&&(t.required||t.optional?this.emit("optionEnv:"+t.name(),process.env[t.envVar]):this.emit("optionEnv:"+t.name()))}})}missingArgument(t){const e=`error: missing required argument '${t}'`;this._displayError(1,"commander.missingArgument",e)}optionMissingArgument(t){const e=`error: option '${t.flags}' argument missing`;this._displayError(1,"commander.optionMissingArgument",e)}missingMandatoryOptionValue(t){const e=`error: required option '${t.flags}' not specified`;this._displayError(1,"commander.missingMandatoryOptionValue",e)}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let i=[],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=m(t,i)}const i=`error: unknown option '${t}'${e}`;this._displayError(1,"commander.unknownOption",i)}_excessArguments(t){if(this._allowExcessArguments)return;const e=this._args.length,i=1===e?"":"s",n=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${e} argument${i} but got ${t.length}.`;this._displayError(1,"commander.excessArguments",n)}unknownCommand(){const t=this.args[0];let e="";if(this._showSuggestionAfterError){const i=[];this.createHelp().visibleCommands(this).forEach(t=>{i.push(t.name()),t.alias()&&i.push(t.alias())}),e=m(t,i)}const i=`error: unknown command '${t}'${e}`;this._displayError(1,"commander.unknownCommand",i)}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);return this._versionOptionName=n.attributeName(),this.options.push(n),this.on("option:"+n.name(),()=>{this._outputConfiguration.writeOut(t+"\n"),this._exit(0,"commander.version",t)}),this}description(t,e){return void 0===t&&void 0===e?this._description:(this._description=t,e&&(this._argsDescription=e),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]),t===e._name)throw new Error("Command alias can't be the same as its name");return e._aliases.push(t),this}aliases(t){return void 0===t?this._aliases:(t.forEach(t=>this.alias(t)),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(" ")}return this._usage=t,this}name(t){return void 0===t?this._name:(this._name=t,this)}helpInformation(t){const e=this.createHelp();return void 0===e.helpWidth&&(e.helpWidth=t&&t.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth()),e.formatHelp(this,e)}_getHelpContext(t){const e={error:!!(t=t||{}).error};let i;return i=e.error?t=>this._outputConfiguration.writeErr(t):t=>this._outputConfiguration.writeOut(t),e.write=t.write||i,e.command=this,e}outputHelp(t){let e;"function"==typeof t&&(e=t,t=void 0);const i=this._getHelpContext(t);_(this).reverse().forEach(t=>t.emit("beforeAllHelp",i)),this.emit("beforeHelp",i);let n=this.helpInformation(i);if(e&&(n=e(n),"string"!=typeof n&&!Buffer.isBuffer(n)))throw new Error("outputHelp callback must return a string or a Buffer");i.write(n),this.emit(this._helpLongFlag),this.emit("afterHelp",i),_(this).forEach(t=>t.emit("afterAllHelp",i))}helpOption(t,e){if("boolean"==typeof t)return this._hasHelpOption=t,this;this._helpFlags=t||this._helpFlags,this._helpDescription=e||this._helpDescription;const i=u(this._helpFlags);return this._helpShortFlag=i.shortFlag,this._helpLongFlag=i.longFlag,this}help(t){this.outputHelp(t);let e=process.exitCode||0;0===e&&t&&"function"!=typeof t&&t.error&&(e=1),this._exit(e,"commander.help","(outputHelp)")}addHelpText(t,e){const i=["beforeAll","before","after","afterAll"];if(!i.includes(t))throw new Error(`Unexpected value for position to addHelpText.\nExpecting one of '${i.join("', '")}'`);const n=t+"Help";return this.on(n,t=>{let i;i="function"==typeof e?e({error:t.error,command:t.command}):e,i&&t.write(i+"\n")}),this}}function g(t,e){t._hasHelpOption&&e.find(e=>e===t._helpLongFlag||e===t._helpShortFlag)&&(t.outputHelp(),t._exit(0,"commander.helpDisplayed","(outputHelp)"))}function f(t){return t.map(t=>{if(!t.startsWith("--inspect"))return t;let e,i,n="127.0.0.1",s="9229";return null!==(i=t.match(/^(--inspect(-brk)?)$/))?e=i[1]:null!==(i=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))?(e=i[1],/^\d+$/.test(i[3])?s=i[3]:n=i[3]):null!==(i=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))&&(e=i[1],n=i[3],s=i[4]),e&&"0"!==s?`${e}=${n}:${parseInt(s)+1}`:t})}function _(t){const e=[];for(let i=t;i;i=i.parent)e.push(i);return e}e.Command=d},498:function(t,e){e.suggestSimilar=function(t,e){if(!e||0===e.length)return"";e=Array.from(new Set(e));const i=t.startsWith("--");i&&(t=t.slice(2),e=e.map(t=>t.slice(2)));let n=[],s=3;return e.forEach(e=>{if(e.length<=1)return;const i=function(t,e){if(Math.abs(t.length-e.length)>3)return Math.max(t.length,e.length);const i=[];for(let e=0;e<=t.length;e++)i[e]=[e];for(let t=0;t<=e.length;t++)i[0][t]=t;for(let n=1;n<=e.length;n++)for(let s=1;s<=t.length;s++){let r=1;r=t[s-1]===e[n-1]?0:1,i[s][n]=Math.min(i[s-1][n]+1,i[s][n-1]+1,i[s-1][n-1]+r),s>1&&n>1&&t[s-1]===e[n-2]&&t[s-2]===e[n-1]&&(i[s][n]=Math.min(i[s][n],i[s-2][n-2]+1))}return i[t.length][e.length]}(t,e),r=Math.max(t.length,e.length);(r-i)/r>.4&&(i<s?(s=i,n=[e]):i===s&&n.push(e))}),n.sort((t,e)=>t.localeCompare(e)),i&&(n=n.map(t=>"--"+t)),n.length>1?`\n(Did you mean one of ${n.join(", ")}?)`:1===n.length?`\n(Did you mean ${n[0]}?)`:""}},6:function(t,e){t.exports=require("fs")},844:function(t,e,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,i,n){void 0===n&&(n=i),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[i]}})}:function(t,e,i,n){void 0===n&&(n=i),t[n]=e[i]}),s=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),r=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var i in t)"default"!==i&&Object.prototype.hasOwnProperty.call(t,i)&&n(e,t,i);return s(e,t),e};Object.defineProperty(e,"__esModule",{value:!0});const o=i(254),a=r(i(255)),h=new o.Command;h.addHelpText("after","\n Example call:\n $ custom-help --help"),h.version(a.version).option("-h, --help","Show commands list").option("-v, --version","Version of CLI").parse(process.argv);new class{constructor(){const t=h.opts(),{help:e,version:i}=t;!0!==e?!0!==i?this.run():this.printVersion():this.help()}printVersion(){console.log(a.version)}help(){console.log("\n Commands\n Basic\n test create Create a test for your project\n test run Run all the test for your project\n\n Advanced\n login Create a test for your project\n init\n info\n whoami Run all the test for your project\n logout Create a test for your project\n\n ")}run(){console.log("\n\n ls Show all of your credit cards\n add Add a new credit card\n rm [id] Remove a credit card\n set-default [id] Make a credit card your default one\n\n ")}}},92:function(t,e){class i extends Error{constructor(t,e,i){super(i),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0}}e.CommanderError=i,e.InvalidArgumentError=class extends i{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}}}});