@flapcode/cli 1.8.4 → 1.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/flapcode.cjs +55 -55
- package/package.json +1 -1
package/dist/flapcode.cjs
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`).replace(/^/gm," ".repeat(n))}let u=[`Usage: ${t.commandUsage(e)}`,""],d=t.commandDescription(e);d.length>0&&(u=u.concat([t.wrap(d,r,0),""]));let p=t.visibleArguments(e).map(
|
|
2
|
+
var rl=Object.create;var ps=Object.defineProperty;var nl=Object.getOwnPropertyDescriptor;var ol=Object.getOwnPropertyNames;var al=Object.getPrototypeOf,ll=Object.prototype.hasOwnProperty;var c=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var ul=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ol(e))!ll.call(i,r)&&r!==t&&ps(i,r,{get:()=>e[r],enumerable:!(s=nl(e,r))||s.enumerable});return i};var $=(i,e,t)=>(t=i!=null?rl(al(i)):{},ul(e||!i||!i.__esModule?ps(t,"default",{value:i,enumerable:!0}):t,i));var Ae=c(yt=>{var Ye=class extends Error{constructor(e,t,s){super(s),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},wt=class extends Ye{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};yt.CommanderError=Ye;yt.InvalidArgumentError=wt});var We=c(vt=>{var{InvalidArgumentError:hl}=Ae(),_t=class{constructor(e,t){switch(this.description=t||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.length>3&&this._name.slice(-3)==="..."&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_concatValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:t.concat(e)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,s)=>{if(!this.argChoices.includes(t))throw new hl(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,s):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function cl(i){let e=i.name()+(i.variadic===!0?"...":"");return i.required?"<"+e+">":"["+e+"]"}vt.Argument=_t;vt.humanReadableArgName=cl});var Ct=c(ms=>{var{humanReadableArgName:dl}=We(),xt=class{constructor(){this.helpWidth=void 0,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}visibleCommands(e){let t=e.commands.filter(r=>!r._hidden),s=e._getHelpCommand();return s&&!s._hidden&&t.push(s),this.sortSubcommands&&t.sort((r,n)=>r.name().localeCompare(n.name())),t}compareOptions(e,t){let s=r=>r.short?r.short.replace(/^-/,""):r.long.replace(/^--/,"");return s(e).localeCompare(s(t))}visibleOptions(e){let t=e.options.filter(r=>!r.hidden),s=e._getHelpOption();if(s&&!s.hidden){let r=s.short&&e._findOption(s.short),n=s.long&&e._findOption(s.long);!r&&!n?t.push(s):s.long&&!n?t.push(e.createOption(s.long,s.description)):s.short&&!r&&t.push(e.createOption(s.short,s.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let s=e.parent;s;s=s.parent){let r=s.options.filter(n=>!n.hidden);t.push(...r)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e.registeredArguments.find(t=>t.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(s=>dl(s)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(t?" "+t:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((s,r)=>Math.max(s,t.subcommandTerm(r).length),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((s,r)=>Math.max(s,t.optionTerm(r).length),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((s,r)=>Math.max(s,t.optionTerm(r).length),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((s,r)=>Math.max(s,t.argumentTerm(r).length),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let s="";for(let r=e.parent;r;r=r.parent)s=r.name()+" "+s;return s+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];return e.argChoices&&t.push(`choices: ${e.argChoices.map(s=>JSON.stringify(s)).join(", ")}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue=="boolean")&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0?`${e.description} (${t.join(", ")})`:e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(s=>JSON.stringify(s)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let s=`(${t.join(", ")})`;return e.description?`${e.description} ${s}`:s}return e.description}formatHelp(e,t){let s=t.padWidth(e,t),r=t.helpWidth||80,n=2,o=2;function a(g,q){if(q){let P=`${g.padEnd(s+o)}${q}`;return t.wrap(P,r-n,s+o)}return g}function l(g){return g.join(`
|
|
3
|
+
`).replace(/^/gm," ".repeat(n))}let u=[`Usage: ${t.commandUsage(e)}`,""],d=t.commandDescription(e);d.length>0&&(u=u.concat([t.wrap(d,r,0),""]));let p=t.visibleArguments(e).map(g=>a(t.argumentTerm(g),t.argumentDescription(g)));p.length>0&&(u=u.concat(["Arguments:",l(p),""]));let m=t.visibleOptions(e).map(g=>a(t.optionTerm(g),t.optionDescription(g)));if(m.length>0&&(u=u.concat(["Options:",l(m),""])),this.showGlobalOptions){let g=t.visibleGlobalOptions(e).map(q=>a(t.optionTerm(q),t.optionDescription(q)));g.length>0&&(u=u.concat(["Global Options:",l(g),""]))}let v=t.visibleCommands(e).map(g=>a(t.subcommandTerm(g),t.subcommandDescription(g)));return v.length>0&&(u=u.concat(["Commands:",l(v),""])),u.join(`
|
|
4
4
|
`)}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}wrap(e,t,s,r=40){let n=" \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF",o=new RegExp(`[\\n][${n}]+`);if(e.match(o))return e;let a=t-s;if(a<r)return e;let l=e.slice(0,s),u=e.slice(s).replace(`\r
|
|
5
5
|
`,`
|
|
6
6
|
`),d=" ".repeat(s),m="\\s\u200B",v=new RegExp(`
|
|
7
|
-
|.{1,${a-1}}([${m}]|$)|[^${m}]+?([${m}]|$)`,"g"),
|
|
7
|
+
|.{1,${a-1}}([${m}]|$)|[^${m}]+?([${m}]|$)`,"g"),g=u.match(v)||[];return l+g.map((q,P)=>q===`
|
|
8
8
|
`?"":(P>0?d:"")+q.trimEnd()).join(`
|
|
9
|
-
`)}};ms.Help=xt});var $t=c(At=>{var{InvalidArgumentError:
|
|
9
|
+
`)}};ms.Help=xt});var $t=c(At=>{var{InvalidArgumentError:fl}=Ae(),Ot=class{constructor(e,t){this.flags=e,this.description=t||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let s=ml(e);this.short=s.shortFlag,this.long=s.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(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e=="string"&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_concatValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:t.concat(e)}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,s)=>{if(!this.argChoices.includes(t))throw new fl(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._concatValue(t,s):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return pl(this.name().replace(/^no-/,""))}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},St=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,s)=>{this.positiveOptions.has(s)&&this.dualOptions.add(s)})}valueFromOption(e,t){let s=t.attributeName();if(!this.dualOptions.has(s))return!0;let r=this.negativeOptions.get(s).presetArg,n=r!==void 0?r:!1;return t.negate===(n===e)}};function pl(i){return i.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function ml(i){let e,t,s=i.split(/[ |,]+/);return s.length>1&&!/^[[<]/.test(s[1])&&(e=s.shift()),t=s.shift(),!e&&/^-[^-]$/.test(t)&&(e=t,t=void 0),{shortFlag:e,longFlag:t}}At.Option=Ot;At.DualOptions=St});var bs=c(gs=>{function gl(i,e){if(Math.abs(i.length-e.length)>3)return Math.max(i.length,e.length);let t=[];for(let s=0;s<=i.length;s++)t[s]=[s];for(let s=0;s<=e.length;s++)t[0][s]=s;for(let s=1;s<=e.length;s++)for(let r=1;r<=i.length;r++){let n=1;i[r-1]===e[s-1]?n=0:n=1,t[r][s]=Math.min(t[r-1][s]+1,t[r][s-1]+1,t[r-1][s-1]+n),r>1&&s>1&&i[r-1]===e[s-2]&&i[r-2]===e[s-1]&&(t[r][s]=Math.min(t[r][s],t[r-2][s-2]+1))}return t[i.length][e.length]}function bl(i,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));let t=i.startsWith("--");t&&(i=i.slice(2),e=e.map(o=>o.slice(2)));let s=[],r=3,n=.4;return e.forEach(o=>{if(o.length<=1)return;let a=gl(i,o),l=Math.max(i.length,o.length);(l-a)/l>n&&(a<r?(r=a,s=[o]):a===r&&s.push(o))}),s.sort((o,a)=>o.localeCompare(a)),t&&(s=s.map(o=>`--${o}`)),s.length>1?`
|
|
10
10
|
(Did you mean one of ${s.join(", ")}?)`:s.length===1?`
|
|
11
|
-
(Did you mean ${s[0]}?)`:""}gs.suggestSimilar=
|
|
12
|
-
- specify the name in Command constructor or using .name()`);return t=t||{},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new
|
|
11
|
+
(Did you mean ${s[0]}?)`:""}gs.suggestSimilar=bl});var xs=c(vs=>{var wl=require("node:events").EventEmitter,Et=require("node:child_process"),K=require("node:path"),Pt=require("node:fs"),S=require("node:process"),{Argument:yl,humanReadableArgName:_l}=We(),{CommanderError:kt}=Ae(),{Help:vl}=Ct(),{Option:ws,DualOptions:xl}=$t(),{suggestSimilar:ys}=bs(),Tt=class i extends wl{constructor(e){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=e||"",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:t=>S.stdout.write(t),writeErr:t=>S.stderr.write(t),getOutHelpWidth:()=>S.stdout.isTTY?S.stdout.columns:void 0,getErrHelpWidth:()=>S.stderr.isTTY?S.stderr.columns:void 0,outputError:(t,s)=>s(t)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={}}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,s){let r=t,n=s;typeof r=="object"&&r!==null&&(n=r,r=null),n=n||{};let[,o,a]=e.match(/([^ ]+) *(.*)/),l=this.createCommand(o);return r&&(l.description(r),l._executableHandler=!0),n.isDefault&&(this._defaultCommandName=l._name),l._hidden=!!(n.noHelp||n.hidden),l._executableFile=n.executableFile||null,a&&l.arguments(a),this._registerCommand(l),l.parent=this,l.copyInheritedSettings(this),r?this:l}createCommand(e){return new i(e)}createHelp(){return Object.assign(new vl,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(Object.assign(this._outputConfiguration,e),this)}showHelpAfterError(e=!0){return typeof e!="string"&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw new Error(`Command passed to .addCommand() must have a name
|
|
12
|
+
- specify the name in Command constructor or using .name()`);return t=t||{},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new yl(e,t)}argument(e,t,s,r){let n=this.createArgument(e,t);return typeof s=="function"?n.default(r).argParser(s):n.default(s),this.addArgument(n),this}arguments(e){return e.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t&&t.variadic)throw new Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e=="boolean")return this._addImplicitHelpCommand=e,this;e=e??"help [command]";let[,s,r]=e.match(/([^ ]+) *(.*)/),n=t??"display help for command",o=this.createCommand(s);return o.helpOption(!1),r&&o.arguments(r),n&&o.description(n),this._addImplicitHelpCommand=!0,this._helpCommand=o,this}addHelpCommand(e,t){return typeof e!="object"?(this.helpCommand(e,t),this):(this._addImplicitHelpCommand=!0,this._helpCommand=e,this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let s=["preSubcommand","preAction","postAction"];if(!s.includes(e))throw new Error(`Unexpected value for event passed to hook : '${e}'.
|
|
13
13
|
Expecting one of '${s.join("', '")}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync")throw t},this}_exit(e,t,s){this._exitCallback&&this._exitCallback(new kt(e,t,s)),S.exit(e)}action(e){let t=s=>{let r=this.registeredArguments.length,n=s.slice(0,r);return this._storeOptionsAsProperties?n[r]=this:n[r]=this.opts(),n.push(this),e.apply(this,n)};return this._actionHandler=t,this}createOption(e,t){return new ws(e,t)}_callParseArg(e,t,s,r){try{return e.parseArg(t,s)}catch(n){if(n.code==="commander.invalidArgument"){let o=`${r} ${n.message}`;this.error(o,{exitCode:n.exitCode,code:n.code})}throw n}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let s=e.long&&this._findOption(e.long)?e.long:e.short;throw new Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${s}'
|
|
14
|
-
- already used by option '${t.flags}'`)}this.options.push(e)}_registerCommand(e){let t=r=>[r.name()].concat(r.aliases()),s=t(e).find(r=>this._findCommand(r));if(s){let r=t(this._findCommand(s)).join("|"),n=t(e).join("|");throw new Error(`cannot add command '${n}' as already have command '${r}'`)}this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),s=e.attributeName();if(e.negate){let n=e.long.replace(/^--no-/,"--");this._findOption(n)||this.setOptionValueWithSource(s,e.defaultValue===void 0?!0:e.defaultValue,"default")}else e.defaultValue!==void 0&&this.setOptionValueWithSource(s,e.defaultValue,"default");let r=(n,o,a)=>{n==null&&e.presetArg!==void 0&&(n=e.presetArg);let l=this.getOptionValue(s);n!==null&&e.parseArg?n=this._callParseArg(e,n,l,o):n!==null&&e.variadic&&(n=e._concatValue(n,l)),n==null&&(e.negate?n=!1:e.isBoolean()||e.optional?n=!0:n=""),this.setOptionValueWithSource(s,n,a)};return this.on("option:"+t,n=>{let o=`error: option '${e.flags}' argument '${n}' is invalid.`;r(n,o,"cli")}),e.envVar&&this.on("optionEnv:"+t,n=>{let o=`error: option '${e.flags}' value '${n}' from env '${e.envVar}' is invalid.`;r(n,o,"env")}),this}_optionEx(e,t,s,r,n){if(typeof t=="object"&&t instanceof ws)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let o=this.createOption(t,s);if(o.makeOptionMandatory(!!e.mandatory),typeof r=="function")o.default(n).argParser(r);else if(r instanceof RegExp){let a=r;r=(l,u)=>{let d=a.exec(l);return d?d[0]:u},o.default(n).argParser(r)}else o.default(r);return this.addOption(o)}option(e,t,s,r){return this._optionEx({},e,t,s,r)}requiredOption(e,t,s,r){return this._optionEx({mandatory:!0},e,t,s,r)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,s){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=s,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(s=>{s.getOptionValueSource(e)!==void 0&&(t=s.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw new Error("first parameter to parse must be array or undefined");if(t=t||{},e===void 0&&t.from===void 0){S.versions?.electron&&(t.from="electron");let r=S.execArgv??[];(r.includes("-e")||r.includes("--eval")||r.includes("-p")||r.includes("--print"))&&(t.from="eval")}e===void 0&&(e=S.argv),this.rawArgs=e.slice();let s;switch(t.from){case void 0:case"node":this._scriptPath=e[1],s=e.slice(2);break;case"electron":S.defaultApp?(this._scriptPath=e[1],s=e.slice(2)):s=e.slice(1);break;case"user":s=e.slice(0);break;case"eval":s=e.slice(1);break;default:throw new Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",s}parse(e,t){let s=this._prepareUserArgs(e,t);return this._parseCommand([],s),this}async parseAsync(e,t){let s=this._prepareUserArgs(e,t);return await this._parseCommand([],s),this}_executeSubCommand(e,t){t=t.slice();let s=!1,r=[".js",".ts",".tsx",".mjs",".cjs"];function n(d,p){let m=K.resolve(d,p);if(Pt.existsSync(m))return m;if(r.includes(K.extname(p)))return;let v=r.find(
|
|
14
|
+
- already used by option '${t.flags}'`)}this.options.push(e)}_registerCommand(e){let t=r=>[r.name()].concat(r.aliases()),s=t(e).find(r=>this._findCommand(r));if(s){let r=t(this._findCommand(s)).join("|"),n=t(e).join("|");throw new Error(`cannot add command '${n}' as already have command '${r}'`)}this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),s=e.attributeName();if(e.negate){let n=e.long.replace(/^--no-/,"--");this._findOption(n)||this.setOptionValueWithSource(s,e.defaultValue===void 0?!0:e.defaultValue,"default")}else e.defaultValue!==void 0&&this.setOptionValueWithSource(s,e.defaultValue,"default");let r=(n,o,a)=>{n==null&&e.presetArg!==void 0&&(n=e.presetArg);let l=this.getOptionValue(s);n!==null&&e.parseArg?n=this._callParseArg(e,n,l,o):n!==null&&e.variadic&&(n=e._concatValue(n,l)),n==null&&(e.negate?n=!1:e.isBoolean()||e.optional?n=!0:n=""),this.setOptionValueWithSource(s,n,a)};return this.on("option:"+t,n=>{let o=`error: option '${e.flags}' argument '${n}' is invalid.`;r(n,o,"cli")}),e.envVar&&this.on("optionEnv:"+t,n=>{let o=`error: option '${e.flags}' value '${n}' from env '${e.envVar}' is invalid.`;r(n,o,"env")}),this}_optionEx(e,t,s,r,n){if(typeof t=="object"&&t instanceof ws)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let o=this.createOption(t,s);if(o.makeOptionMandatory(!!e.mandatory),typeof r=="function")o.default(n).argParser(r);else if(r instanceof RegExp){let a=r;r=(l,u)=>{let d=a.exec(l);return d?d[0]:u},o.default(n).argParser(r)}else o.default(r);return this.addOption(o)}option(e,t,s,r){return this._optionEx({},e,t,s,r)}requiredOption(e,t,s,r){return this._optionEx({mandatory:!0},e,t,s,r)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,s){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=s,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(s=>{s.getOptionValueSource(e)!==void 0&&(t=s.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw new Error("first parameter to parse must be array or undefined");if(t=t||{},e===void 0&&t.from===void 0){S.versions?.electron&&(t.from="electron");let r=S.execArgv??[];(r.includes("-e")||r.includes("--eval")||r.includes("-p")||r.includes("--print"))&&(t.from="eval")}e===void 0&&(e=S.argv),this.rawArgs=e.slice();let s;switch(t.from){case void 0:case"node":this._scriptPath=e[1],s=e.slice(2);break;case"electron":S.defaultApp?(this._scriptPath=e[1],s=e.slice(2)):s=e.slice(1);break;case"user":s=e.slice(0);break;case"eval":s=e.slice(1);break;default:throw new Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",s}parse(e,t){let s=this._prepareUserArgs(e,t);return this._parseCommand([],s),this}async parseAsync(e,t){let s=this._prepareUserArgs(e,t);return await this._parseCommand([],s),this}_executeSubCommand(e,t){t=t.slice();let s=!1,r=[".js",".ts",".tsx",".mjs",".cjs"];function n(d,p){let m=K.resolve(d,p);if(Pt.existsSync(m))return m;if(r.includes(K.extname(p)))return;let v=r.find(g=>Pt.existsSync(`${m}${g}`));if(v)return`${m}${v}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=e._executableFile||`${this._name}-${e._name}`,a=this._executableDir||"";if(this._scriptPath){let d;try{d=Pt.realpathSync(this._scriptPath)}catch{d=this._scriptPath}a=K.resolve(K.dirname(d),a)}if(a){let d=n(a,o);if(!d&&!e._executableFile&&this._scriptPath){let p=K.basename(this._scriptPath,K.extname(this._scriptPath));p!==this._name&&(d=n(a,`${p}-${e._name}`))}o=d||o}s=r.includes(K.extname(o));let l;S.platform!=="win32"?s?(t.unshift(o),t=_s(S.execArgv).concat(t),l=Et.spawn(S.argv[0],t,{stdio:"inherit"})):l=Et.spawn(o,t,{stdio:"inherit"}):(t.unshift(o),t=_s(S.execArgv).concat(t),l=Et.spawn(S.execPath,t,{stdio:"inherit"})),l.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(p=>{S.on(p,()=>{l.killed===!1&&l.exitCode===null&&l.kill(p)})});let u=this._exitCallback;l.on("close",d=>{d=d??1,u?u(new kt(d,"commander.executeSubCommandAsync","(close)")):S.exit(d)}),l.on("error",d=>{if(d.code==="ENOENT"){let p=a?`searched for local subcommand relative to directory '${a}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",m=`'${o}' does not exist
|
|
15
15
|
- if '${e._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
16
16
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
17
17
|
- ${p}`;throw new Error(m)}else if(d.code==="EACCES")throw new Error(`'${o}' not executable`);if(!u)S.exit(1);else{let p=new kt(1,"commander.executeSubCommandAsync","(error)");p.nestedError=d,u(p)}}),this.runningCommand=l}_dispatchSubcommand(e,t,s){let r=this._findCommand(e);r||this.help({error:!0});let n;return n=this._chainOrCallSubCommandHook(n,r,"preSubcommand"),n=this._chainOrCall(n,()=>{if(r._executableHandler)this._executeSubCommand(r,t.concat(s));else return r._parseCommand(t,s)}),n}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(s,r,n)=>{let o=r;if(r!==null&&s.parseArg){let a=`error: command-argument value '${r}' is invalid for argument '${s.name()}'.`;o=this._callParseArg(s,r,n,a)}return o};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((s,r)=>{let n=s.defaultValue;s.variadic?r<this.args.length?(n=this.args.slice(r),s.parseArg&&(n=n.reduce((o,a)=>e(s,a,o),s.defaultValue))):n===void 0&&(n=[]):r<this.args.length&&(n=this.args[r],s.parseArg&&(n=e(s,n,s.defaultValue))),t[r]=n}),this.processedArgs=t}_chainOrCall(e,t){return e&&e.then&&typeof e.then=="function"?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let s=e,r=[];return this._getCommandAndAncestors().reverse().filter(n=>n._lifeCycleHooks[t]!==void 0).forEach(n=>{n._lifeCycleHooks[t].forEach(o=>{r.push({hookedCommand:n,callback:o})})}),t==="postAction"&&r.reverse(),r.forEach(n=>{s=this._chainOrCall(s,()=>n.callback(n.hookedCommand,this))}),s}_chainOrCallSubCommandHook(e,t,s){let r=e;return this._lifeCycleHooks[s]!==void 0&&this._lifeCycleHooks[s].forEach(n=>{r=this._chainOrCall(r,()=>n(this,t))}),r}_parseCommand(e,t){let s=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(s.operands),t=s.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(s.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=()=>{s.unknown.length>0&&this.unknownOption(s.unknown[0])},n=`command:${this.name()}`;if(this._actionHandler){r(),this._processArguments();let o;return o=this._chainOrCallHooks(o,"preAction"),o=this._chainOrCall(o,()=>this._actionHandler(this.processedArgs)),this.parent&&(o=this._chainOrCall(o,()=>{this.parent.emit(n,e,t)})),o=this._chainOrCallHooks(o,"postAction"),o}if(this.parent&&this.parent.listenerCount(n))r(),this._processArguments(),this.parent.emit(n,e,t);else if(e.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",e,t);this.listenerCount("command:*")?this.emit("command:*",e,t):this.commands.length?this.unknownCommand():(r(),this._processArguments())}else this.commands.length?(r(),this.help({error:!0})):(r(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(s=>{let r=s.attributeName();return this.getOptionValue(r)===void 0?!1:this.getOptionValueSource(r)!=="default"});e.filter(s=>s.conflictsWith.length>0).forEach(s=>{let r=e.find(n=>s.conflictsWith.includes(n.attributeName()));r&&this._conflictingOption(s,r)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],s=[],r=t,n=e.slice();function o(l){return l.length>1&&l[0]==="-"}let a=null;for(;n.length;){let l=n.shift();if(l==="--"){r===s&&r.push(l),r.push(...n);break}if(a&&!o(l)){this.emit(`option:${a.name()}`,l);continue}if(a=null,o(l)){let u=this._findOption(l);if(u){if(u.required){let d=n.shift();d===void 0&&this.optionMissingArgument(u),this.emit(`option:${u.name()}`,d)}else if(u.optional){let d=null;n.length>0&&!o(n[0])&&(d=n.shift()),this.emit(`option:${u.name()}`,d)}else this.emit(`option:${u.name()}`);a=u.variadic?u:null;continue}}if(l.length>2&&l[0]==="-"&&l[1]!=="-"){let u=this._findOption(`-${l[1]}`);if(u){u.required||u.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${u.name()}`,l.slice(2)):(this.emit(`option:${u.name()}`),n.unshift(`-${l.slice(2)}`));continue}}if(/^--[^=]+=/.test(l)){let u=l.indexOf("="),d=this._findOption(l.slice(0,u));if(d&&(d.required||d.optional)){this.emit(`option:${d.name()}`,l.slice(u+1));continue}}if(o(l)&&(r=s),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&s.length===0){if(this._findCommand(l)){t.push(l),n.length>0&&s.push(...n);break}else if(this._getHelpCommand()&&l===this._getHelpCommand().name()){t.push(l),n.length>0&&t.push(...n);break}else if(this._defaultCommandName){s.push(l),n.length>0&&s.push(...n);break}}if(this._passThroughOptions){r.push(l),n.length>0&&r.push(...n);break}r.push(l)}return{operands:t,unknown:s}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let s=0;s<t;s++){let r=this.options[s].attributeName();e[r]=r===this._versionOptionName?this._version:this[r]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
|
|
18
18
|
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
19
19
|
`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
20
|
-
`),this.outputHelp({error:!0}));let s=t||{},r=s.exitCode||1,n=s.code||"commander.error";this._exit(r,n,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in S.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,S.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new
|
|
21
|
-
`),this._exit(0,"commander.version",e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw new Error("Command alias can't be the same as its name");let s=this.parent?._findCommand(e);if(s){let r=[s.name()].concat(s.aliases()).join("|");throw new Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${r}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(t=>this.alias(t)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let t=this.registeredArguments.map(s=>
|
|
20
|
+
`),this.outputHelp({error:!0}));let s=t||{},r=s.exitCode||1,n=s.code||"commander.error";this._exit(r,n,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in S.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,S.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new xl(this.options),t=s=>this.getOptionValue(s)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(s));this.options.filter(s=>s.implied!==void 0&&t(s.attributeName())&&e.valueFromOption(this.getOptionValue(s.attributeName()),s)).forEach(s=>{Object.keys(s.implied).filter(r=>!t(r)).forEach(r=>{this.setOptionValueWithSource(r,s.implied[r],"implied")})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){let s=o=>{let a=o.attributeName(),l=this.getOptionValue(a),u=this.options.find(p=>p.negate&&a===p.attributeName()),d=this.options.find(p=>!p.negate&&a===p.attributeName());return u&&(u.presetArg===void 0&&l===!1||u.presetArg!==void 0&&l===u.presetArg)?u:d||o},r=o=>{let a=s(o),l=a.attributeName();return this.getOptionValueSource(l)==="env"?`environment variable '${a.envVar}'`:`option '${a.flags}'`},n=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(n,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let r=[],n=this;do{let o=n.createHelp().visibleOptions(n).filter(a=>a.long).map(a=>a.long);r=r.concat(o),n=n.parent}while(n&&!n._enablePositionalOptions);t=ys(e,r)}let s=`error: unknown option '${e}'${t}`;this.error(s,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,s=t===1?"":"s",n=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${t} argument${s} but got ${e.length}.`;this.error(n,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let r=[];this.createHelp().visibleCommands(this).forEach(n=>{r.push(n.name()),n.alias()&&r.push(n.alias())}),t=ys(e,r)}let s=`error: unknown command '${e}'${t}`;this.error(s,{code:"commander.unknownCommand"})}version(e,t,s){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",s=s||"output the version number";let r=this.createOption(t,s);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on("option:"+r.name(),()=>{this._outputConfiguration.writeOut(`${e}
|
|
21
|
+
`),this._exit(0,"commander.version",e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw new Error("Command alias can't be the same as its name");let s=this.parent?._findCommand(e);if(s){let r=[s.name()].concat(s.aliases()).join("|");throw new Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${r}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(t=>this.alias(t)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let t=this.registeredArguments.map(s=>_l(s));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}nameFromFilename(e){return this._name=K.basename(e,K.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp();return t.helpWidth===void 0&&(t.helpWidth=e&&e.error?this._outputConfiguration.getErrHelpWidth():this._outputConfiguration.getOutHelpWidth()),t.formatHelp(this,t)}_getHelpContext(e){e=e||{};let t={error:!!e.error},s;return t.error?s=r=>this._outputConfiguration.writeErr(r):s=r=>this._outputConfiguration.writeOut(r),t.write=e.write||s,t.command=this,t}outputHelp(e){let t;typeof e=="function"&&(t=e,e=void 0);let s=this._getHelpContext(e);this._getCommandAndAncestors().reverse().forEach(n=>n.emit("beforeAllHelp",s)),this.emit("beforeHelp",s);let r=this.helpInformation(s);if(t&&(r=t(r),typeof r!="string"&&!Buffer.isBuffer(r)))throw new Error("outputHelp callback must return a string or a Buffer");s.write(r),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",s),this._getCommandAndAncestors().forEach(n=>n.emit("afterAllHelp",s))}helpOption(e,t){return typeof e=="boolean"?(e?this._helpOption=this._helpOption??void 0:this._helpOption=null,this):(e=e??"-h, --help",t=t??"display help for command",this._helpOption=this.createOption(e,t),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this}help(e){this.outputHelp(e);let t=S.exitCode||0;t===0&&e&&typeof e!="function"&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){let s=["beforeAll","before","after","afterAll"];if(!s.includes(e))throw new Error(`Unexpected value for position to addHelpText.
|
|
22
22
|
Expecting one of '${s.join("', '")}'`);let r=`${e}Help`;return this.on(r,n=>{let o;typeof t=="function"?o=t({error:n.error,command:n.command}):o=t,o&&n.write(`${o}
|
|
23
|
-
`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(r=>t.is(r))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function _s(i){return i.map(e=>{if(!e.startsWith("--inspect"))return e;let t,s="127.0.0.1",r="9229",n;return(n=e.match(/^(--inspect(-brk)?)$/))!==null?t=n[1]:(n=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=n[1],/^\d+$/.test(n[3])?r=n[3]:s=n[3]):(n=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=n[1],s=n[3],r=n[4]),t&&r!=="0"?`${t}=${s}:${parseInt(r)+1}`:e})}vs.Command=Tt});var As=c(M=>{var{Argument:Cs}=We(),{Command:It}=xs(),{CommanderError:
|
|
24
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var n=!0,o=!1,a;return{s:function(){t=t.call(i)},n:function(){var u=t.next();return n=u.done,u},e:function(u){o=!0,a=u},f:function(){try{!n&&t.return!=null&&t.return()}finally{if(o)throw a}}}}function
|
|
23
|
+
`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(r=>t.is(r))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function _s(i){return i.map(e=>{if(!e.startsWith("--inspect"))return e;let t,s="127.0.0.1",r="9229",n;return(n=e.match(/^(--inspect(-brk)?)$/))!==null?t=n[1]:(n=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=n[1],/^\d+$/.test(n[3])?r=n[3]:s=n[3]):(n=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=n[1],s=n[3],r=n[4]),t&&r!=="0"?`${t}=${s}:${parseInt(r)+1}`:e})}vs.Command=Tt});var As=c(M=>{var{Argument:Cs}=We(),{Command:It}=xs(),{CommanderError:Cl,InvalidArgumentError:Os}=Ae(),{Help:Ol}=Ct(),{Option:Ss}=$t();M.program=new It;M.createCommand=i=>new It(i);M.createOption=(i,e)=>new Ss(i,e);M.createArgument=(i,e)=>new Cs(i,e);M.Command=It;M.Option=Ss;M.Argument=Cs;M.Help=Ol;M.CommanderError=Cl;M.InvalidArgumentError=Os;M.InvalidOptionArgumentError=Os});var x=c((Hd,Vs)=>{"use strict";var{FORCE_COLOR:Al,NODE_DISABLE_COLORS:$l,TERM:El}=process.env,w={enabled:!$l&&El!=="dumb"&&Al!=="0",reset:_(0,0),bold:_(1,22),dim:_(2,22),italic:_(3,23),underline:_(4,24),inverse:_(7,27),hidden:_(8,28),strikethrough:_(9,29),black:_(30,39),red:_(31,39),green:_(32,39),yellow:_(33,39),blue:_(34,39),magenta:_(35,39),cyan:_(36,39),white:_(37,39),gray:_(90,39),grey:_(90,39),bgBlack:_(40,49),bgRed:_(41,49),bgGreen:_(42,49),bgYellow:_(43,49),bgBlue:_(44,49),bgMagenta:_(45,49),bgCyan:_(46,49),bgWhite:_(47,49)};function Ds(i,e){let t=0,s,r="",n="";for(;t<i.length;t++)s=i[t],r+=s.open,n+=s.close,e.includes(s.close)&&(e=e.replace(s.rgx,s.close+s.open));return r+e+n}function Pl(i,e){let t={has:i,keys:e};return t.reset=w.reset.bind(t),t.bold=w.bold.bind(t),t.dim=w.dim.bind(t),t.italic=w.italic.bind(t),t.underline=w.underline.bind(t),t.inverse=w.inverse.bind(t),t.hidden=w.hidden.bind(t),t.strikethrough=w.strikethrough.bind(t),t.black=w.black.bind(t),t.red=w.red.bind(t),t.green=w.green.bind(t),t.yellow=w.yellow.bind(t),t.blue=w.blue.bind(t),t.magenta=w.magenta.bind(t),t.cyan=w.cyan.bind(t),t.white=w.white.bind(t),t.gray=w.gray.bind(t),t.grey=w.grey.bind(t),t.bgBlack=w.bgBlack.bind(t),t.bgRed=w.bgRed.bind(t),t.bgGreen=w.bgGreen.bind(t),t.bgYellow=w.bgYellow.bind(t),t.bgBlue=w.bgBlue.bind(t),t.bgMagenta=w.bgMagenta.bind(t),t.bgCyan=w.bgCyan.bind(t),t.bgWhite=w.bgWhite.bind(t),t}function _(i,e){let t={open:`\x1B[${i}m`,close:`\x1B[${e}m`,rgx:new RegExp(`\\x1b\\[${e}m`,"g")};return function(s){return this!==void 0&&this.has!==void 0?(this.has.includes(i)||(this.has.push(i),this.keys.push(t)),s===void 0?this:w.enabled?Ds(this.keys,s+""):s+""):s===void 0?Pl([i],[t]):w.enabled?Ds([t],s+""):s+""}}Vs.exports=w});var Hs=c((Fd,js)=>{"use strict";js.exports=(i,e)=>{if(!(i.meta&&i.name!=="escape")){if(i.ctrl){if(i.name==="a")return"first";if(i.name==="c"||i.name==="d")return"abort";if(i.name==="e")return"last";if(i.name==="g")return"reset"}if(e){if(i.name==="j")return"down";if(i.name==="k")return"up"}return i.name==="return"||i.name==="enter"?"submit":i.name==="backspace"?"delete":i.name==="delete"?"deleteForward":i.name==="abort"?"abort":i.name==="escape"?"exit":i.name==="tab"?"next":i.name==="pagedown"?"nextPage":i.name==="pageup"?"prevPage":i.name==="home"?"home":i.name==="end"?"end":i.name==="up"?"up":i.name==="down"?"down":i.name==="right"?"right":i.name==="left"?"left":!1}}});var Je=c((Rd,Fs)=>{"use strict";Fs.exports=i=>{let e=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"].join("|"),t=new RegExp(e,"g");return typeof i=="string"?i.replace(t,""):i}});var O=c((Nd,Rs)=>{"use strict";var Mt="\x1B",C=`${Mt}[`,kl="\x07",Dt={to(i,e){return e?`${C}${e+1};${i+1}H`:`${C}${i+1}G`},move(i,e){let t="";return i<0?t+=`${C}${-i}D`:i>0&&(t+=`${C}${i}C`),e<0?t+=`${C}${-e}A`:e>0&&(t+=`${C}${e}B`),t},up:(i=1)=>`${C}${i}A`,down:(i=1)=>`${C}${i}B`,forward:(i=1)=>`${C}${i}C`,backward:(i=1)=>`${C}${i}D`,nextLine:(i=1)=>`${C}E`.repeat(i),prevLine:(i=1)=>`${C}F`.repeat(i),left:`${C}G`,hide:`${C}?25l`,show:`${C}?25h`,save:`${Mt}7`,restore:`${Mt}8`},Tl={up:(i=1)=>`${C}S`.repeat(i),down:(i=1)=>`${C}T`.repeat(i)},Il={screen:`${C}2J`,up:(i=1)=>`${C}1J`.repeat(i),down:(i=1)=>`${C}J`.repeat(i),line:`${C}2K`,lineEnd:`${C}K`,lineStart:`${C}1K`,lines(i){let e="";for(let t=0;t<i;t++)e+=this.line+(t<i-1?Dt.up():"");return i&&(e+=Dt.left),e}};Rs.exports={cursor:Dt,scroll:Tl,erase:Il,beep:kl}});var Bs=c((Ld,Gs)=>{"use strict";function ql(i,e){var t=typeof Symbol<"u"&&i[Symbol.iterator]||i["@@iterator"];if(!t){if(Array.isArray(i)||(t=Ml(i))||e&&i&&typeof i.length=="number"){t&&(i=t);var s=0,r=function(){};return{s:r,n:function(){return s>=i.length?{done:!0}:{done:!1,value:i[s++]}},e:function(u){throw u},f:r}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
24
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var n=!0,o=!1,a;return{s:function(){t=t.call(i)},n:function(){var u=t.next();return n=u.done,u},e:function(u){o=!0,a=u},f:function(){try{!n&&t.return!=null&&t.return()}finally{if(o)throw a}}}}function Ml(i,e){if(i){if(typeof i=="string")return Ns(i,e);var t=Object.prototype.toString.call(i).slice(8,-1);if(t==="Object"&&i.constructor&&(t=i.constructor.name),t==="Map"||t==="Set")return Array.from(i);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return Ns(i,e)}}function Ns(i,e){(e==null||e>i.length)&&(e=i.length);for(var t=0,s=new Array(e);t<e;t++)s[t]=i[t];return s}var Dl=Je(),Us=O(),Ls=Us.erase,Vl=Us.cursor,jl=i=>[...Dl(i)].length;Gs.exports=function(i,e){if(!e)return Ls.line+Vl.to(0);let t=0,s=i.split(/\r?\n/);var r=ql(s),n;try{for(r.s();!(n=r.n()).done;){let o=n.value;t+=1+Math.floor(Math.max(jl(o)-1,0)/e)}}catch(o){r.e(o)}finally{r.f()}return Ls.lines(t)}});var Vt=c((Ud,Ys)=>{"use strict";var $e={arrowUp:"\u2191",arrowDown:"\u2193",arrowLeft:"\u2190",arrowRight:"\u2192",radioOn:"\u25C9",radioOff:"\u25EF",tick:"\u2714",cross:"\u2716",ellipsis:"\u2026",pointerSmall:"\u203A",line:"\u2500",pointer:"\u276F"},Hl={arrowUp:$e.arrowUp,arrowDown:$e.arrowDown,arrowLeft:$e.arrowLeft,arrowRight:$e.arrowRight,radioOn:"(*)",radioOff:"( )",tick:"\u221A",cross:"\xD7",ellipsis:"...",pointerSmall:"\xBB",line:"\u2500",pointer:">"},Fl=process.platform==="win32"?Hl:$e;Ys.exports=Fl});var Js=c((Gd,Ws)=>{"use strict";var _e=x(),me=Vt(),jt=Object.freeze({password:{scale:1,render:i=>"*".repeat(i.length)},emoji:{scale:2,render:i=>"\u{1F603}".repeat(i.length)},invisible:{scale:0,render:i=>""},default:{scale:1,render:i=>`${i}`}}),Rl=i=>jt[i]||jt.default,Ee=Object.freeze({aborted:_e.red(me.cross),done:_e.green(me.tick),exited:_e.yellow(me.cross),default:_e.cyan("?")}),Nl=(i,e,t)=>e?Ee.aborted:t?Ee.exited:i?Ee.done:Ee.default,Ll=i=>_e.gray(i?me.ellipsis:me.pointerSmall),Ul=(i,e)=>_e.gray(i?e?me.pointerSmall:"+":me.line);Ws.exports={styles:jt,render:Rl,symbols:Ee,symbol:Nl,delimiter:Ll,item:Ul}});var zs=c((Bd,Ks)=>{"use strict";var Gl=Je();Ks.exports=function(i,e){let t=String(Gl(i)||"").split(/\r?\n/);return e?t.map(s=>Math.ceil(s.length/e)).reduce((s,r)=>s+r):t.length}});var Xs=c((Yd,Zs)=>{"use strict";Zs.exports=(i,e={})=>{let t=Number.isSafeInteger(parseInt(e.margin))?new Array(parseInt(e.margin)).fill(" ").join(""):e.margin||"",s=e.width;return(i||"").split(/\r?\n/g).map(r=>r.split(/\s+/g).reduce((n,o)=>(o.length+t.length>=s||n[n.length-1].length+o.length+1<s?n[n.length-1]+=` ${o}`:n.push(`${t}${o}`),n),[t]).join(`
|
|
25
25
|
`)).join(`
|
|
26
|
-
`)}});var er=c((
|
|
26
|
+
`)}});var er=c((Wd,Qs)=>{"use strict";Qs.exports=(i,e,t)=>{t=t||e;let s=Math.min(e-t,i-Math.floor(t/2));s<0&&(s=0);let r=Math.min(s+t,e);return{startIndex:s,endIndex:r}}});var V=c((Jd,tr)=>{"use strict";tr.exports={action:Hs(),clear:Bs(),style:Js(),strip:Je(),figures:Vt(),lines:zs(),wrap:Xs(),entriesToDisplay:er()}});var z=c((Kd,rr)=>{"use strict";var ir=require("readline"),Bl=V(),Yl=Bl.action,Wl=require("events"),sr=O(),Jl=sr.beep,Kl=sr.cursor,zl=x(),Ht=class extends Wl{constructor(e={}){super(),this.firstRender=!0,this.in=e.stdin||process.stdin,this.out=e.stdout||process.stdout,this.onRender=(e.onRender||(()=>{})).bind(this);let t=ir.createInterface({input:this.in,escapeCodeTimeout:50});ir.emitKeypressEvents(this.in,t),this.in.isTTY&&this.in.setRawMode(!0);let s=["SelectPrompt","MultiselectPrompt"].indexOf(this.constructor.name)>-1,r=(n,o)=>{let a=Yl(o,s);a===!1?this._&&this._(n,o):typeof this[a]=="function"?this[a](o):this.bell()};this.close=()=>{this.out.write(Kl.show),this.in.removeListener("keypress",r),this.in.isTTY&&this.in.setRawMode(!1),t.close(),this.emit(this.aborted?"abort":this.exited?"exit":"submit",this.value),this.closed=!0},this.in.on("keypress",r)}fire(){this.emit("state",{value:this.value,aborted:!!this.aborted,exited:!!this.exited})}bell(){this.out.write(Jl)}render(){this.onRender(zl),this.firstRender&&(this.firstRender=!1)}};rr.exports=Ht});var ur=c((zd,lr)=>{"use strict";function nr(i,e,t,s,r,n,o){try{var a=i[n](o),l=a.value}catch(u){t(u);return}a.done?e(l):Promise.resolve(l).then(s,r)}function or(i){return function(){var e=this,t=arguments;return new Promise(function(s,r){var n=i.apply(e,t);function o(l){nr(n,s,r,o,a,"next",l)}function a(l){nr(n,s,r,o,a,"throw",l)}o(void 0)})}}var Ke=x(),Zl=z(),ar=O(),Xl=ar.erase,Pe=ar.cursor,ze=V(),Ft=ze.style,Rt=ze.clear,Ql=ze.lines,eu=ze.figures,Nt=class extends Zl{constructor(e={}){super(e),this.transform=Ft.render(e.style),this.scale=this.transform.scale,this.msg=e.message,this.initial=e.initial||"",this.validator=e.validate||(()=>!0),this.value="",this.errorMsg=e.error||"Please Enter A Valid Value",this.cursor=+!!this.initial,this.cursorOffset=0,this.clear=Rt("",this.out.columns),this.render()}set value(e){!e&&this.initial?(this.placeholder=!0,this.rendered=Ke.gray(this.transform.render(this.initial))):(this.placeholder=!1,this.rendered=this.transform.render(e)),this._value=e,this.fire()}get value(){return this._value}reset(){this.value="",this.cursor=+!!this.initial,this.cursorOffset=0,this.fire(),this.render()}exit(){this.abort()}abort(){this.value=this.value||this.initial,this.done=this.aborted=!0,this.error=!1,this.red=!1,this.fire(),this.render(),this.out.write(`
|
|
27
27
|
`),this.close()}validate(){var e=this;return or(function*(){let t=yield e.validator(e.value);typeof t=="string"&&(e.errorMsg=t,t=!1),e.error=!t})()}submit(){var e=this;return or(function*(){if(e.value=e.value||e.initial,e.cursorOffset=0,e.cursor=e.rendered.length,yield e.validate(),e.error){e.red=!0,e.fire(),e.render();return}e.done=!0,e.aborted=!1,e.fire(),e.render(),e.out.write(`
|
|
28
|
-
`),e.close()})()}next(){if(!this.placeholder)return this.bell();this.value=this.initial,this.cursor=this.rendered.length,this.fire(),this.render()}moveCursor(e){this.placeholder||(this.cursor=this.cursor+e,this.cursorOffset+=e)}_(e,t){let s=this.value.slice(0,this.cursor),r=this.value.slice(this.cursor);this.value=`${s}${e}${r}`,this.red=!1,this.cursor=this.placeholder?0:s.length+1,this.render()}delete(){if(this.isCursorAtStart())return this.bell();let e=this.value.slice(0,this.cursor-1),t=this.value.slice(this.cursor);this.value=`${e}${t}`,this.red=!1,this.isCursorAtStart()?this.cursorOffset=0:(this.cursorOffset++,this.moveCursor(-1)),this.render()}deleteForward(){if(this.cursor*this.scale>=this.rendered.length||this.placeholder)return this.bell();let e=this.value.slice(0,this.cursor),t=this.value.slice(this.cursor+1);this.value=`${e}${t}`,this.red=!1,this.isCursorAtEnd()?this.cursorOffset=0:this.cursorOffset++,this.render()}first(){this.cursor=0,this.render()}last(){this.cursor=this.value.length,this.render()}left(){if(this.cursor<=0||this.placeholder)return this.bell();this.moveCursor(-1),this.render()}right(){if(this.cursor*this.scale>=this.rendered.length||this.placeholder)return this.bell();this.moveCursor(1),this.render()}isCursorAtStart(){return this.cursor===0||this.placeholder&&this.cursor===1}isCursorAtEnd(){return this.cursor===this.rendered.length||this.placeholder&&this.cursor===this.rendered.length+1}render(){this.closed||(this.firstRender||(this.outputError&&this.out.write(Pe.down(
|
|
28
|
+
`),e.close()})()}next(){if(!this.placeholder)return this.bell();this.value=this.initial,this.cursor=this.rendered.length,this.fire(),this.render()}moveCursor(e){this.placeholder||(this.cursor=this.cursor+e,this.cursorOffset+=e)}_(e,t){let s=this.value.slice(0,this.cursor),r=this.value.slice(this.cursor);this.value=`${s}${e}${r}`,this.red=!1,this.cursor=this.placeholder?0:s.length+1,this.render()}delete(){if(this.isCursorAtStart())return this.bell();let e=this.value.slice(0,this.cursor-1),t=this.value.slice(this.cursor);this.value=`${e}${t}`,this.red=!1,this.isCursorAtStart()?this.cursorOffset=0:(this.cursorOffset++,this.moveCursor(-1)),this.render()}deleteForward(){if(this.cursor*this.scale>=this.rendered.length||this.placeholder)return this.bell();let e=this.value.slice(0,this.cursor),t=this.value.slice(this.cursor+1);this.value=`${e}${t}`,this.red=!1,this.isCursorAtEnd()?this.cursorOffset=0:this.cursorOffset++,this.render()}first(){this.cursor=0,this.render()}last(){this.cursor=this.value.length,this.render()}left(){if(this.cursor<=0||this.placeholder)return this.bell();this.moveCursor(-1),this.render()}right(){if(this.cursor*this.scale>=this.rendered.length||this.placeholder)return this.bell();this.moveCursor(1),this.render()}isCursorAtStart(){return this.cursor===0||this.placeholder&&this.cursor===1}isCursorAtEnd(){return this.cursor===this.rendered.length||this.placeholder&&this.cursor===this.rendered.length+1}render(){this.closed||(this.firstRender||(this.outputError&&this.out.write(Pe.down(Ql(this.outputError,this.out.columns)-1)+Rt(this.outputError,this.out.columns)),this.out.write(Rt(this.outputText,this.out.columns))),super.render(),this.outputError="",this.outputText=[Ft.symbol(this.done,this.aborted),Ke.bold(this.msg),Ft.delimiter(this.done),this.red?Ke.red(this.rendered):this.rendered].join(" "),this.error&&(this.outputError+=this.errorMsg.split(`
|
|
29
29
|
`).reduce((e,t,s)=>e+`
|
|
30
|
-
${s?" ":
|
|
30
|
+
${s?" ":eu.pointerSmall} ${Ke.red().italic(t)}`,"")),this.out.write(Xl.line+Pe.to(0)+this.outputText+Pe.save+this.outputError+Pe.restore+Pe.move(this.cursorOffset,0)))}};lr.exports=Nt});var fr=c((Zd,dr)=>{"use strict";var Z=x(),tu=z(),ke=V(),hr=ke.style,cr=ke.clear,Ze=ke.figures,iu=ke.wrap,su=ke.entriesToDisplay,ru=O(),nu=ru.cursor,Lt=class extends tu{constructor(e={}){super(e),this.msg=e.message,this.hint=e.hint||"- Use arrow-keys. Return to submit.",this.warn=e.warn||"- This option is disabled",this.cursor=e.initial||0,this.choices=e.choices.map((t,s)=>(typeof t=="string"&&(t={title:t,value:s}),{title:t&&(t.title||t.value||t),value:t&&(t.value===void 0?s:t.value),description:t&&t.description,selected:t&&t.selected,disabled:t&&t.disabled})),this.optionsPerPage=e.optionsPerPage||10,this.value=(this.choices[this.cursor]||{}).value,this.clear=cr("",this.out.columns),this.render()}moveCursor(e){this.cursor=e,this.value=this.choices[e].value,this.fire()}reset(){this.moveCursor(0),this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
|
|
31
31
|
`),this.close()}submit(){this.selection.disabled?this.bell():(this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
32
|
-
`),this.close())}first(){this.moveCursor(0),this.render()}last(){this.moveCursor(this.choices.length-1),this.render()}up(){this.cursor===0?this.moveCursor(this.choices.length-1):this.moveCursor(this.cursor-1),this.render()}down(){this.cursor===this.choices.length-1?this.moveCursor(0):this.moveCursor(this.cursor+1),this.render()}next(){this.moveCursor((this.cursor+1)%this.choices.length),this.render()}_(e,t){if(e===" ")return this.submit()}get selection(){return this.choices[this.cursor]}render(){if(this.closed)return;this.firstRender?this.out.write(
|
|
32
|
+
`),this.close())}first(){this.moveCursor(0),this.render()}last(){this.moveCursor(this.choices.length-1),this.render()}up(){this.cursor===0?this.moveCursor(this.choices.length-1):this.moveCursor(this.cursor-1),this.render()}down(){this.cursor===this.choices.length-1?this.moveCursor(0):this.moveCursor(this.cursor+1),this.render()}next(){this.moveCursor((this.cursor+1)%this.choices.length),this.render()}_(e,t){if(e===" ")return this.submit()}get selection(){return this.choices[this.cursor]}render(){if(this.closed)return;this.firstRender?this.out.write(nu.hide):this.out.write(cr(this.outputText,this.out.columns)),super.render();let e=su(this.cursor,this.choices.length,this.optionsPerPage),t=e.startIndex,s=e.endIndex;if(this.outputText=[hr.symbol(this.done,this.aborted),Z.bold(this.msg),hr.delimiter(!1),this.done?this.selection.title:this.selection.disabled?Z.yellow(this.warn):Z.gray(this.hint)].join(" "),!this.done){this.outputText+=`
|
|
33
33
|
`;for(let r=t;r<s;r++){let n,o,a="",l=this.choices[r];r===t&&t>0?o=Ze.arrowUp:r===s-1&&s<this.choices.length?o=Ze.arrowDown:o=" ",l.disabled?(n=this.cursor===r?Z.gray().underline(l.title):Z.strikethrough().gray(l.title),o=(this.cursor===r?Z.bold().gray(Ze.pointer)+" ":" ")+o):(n=this.cursor===r?Z.cyan().underline(l.title):l.title,o=(this.cursor===r?Z.cyan(Ze.pointer)+" ":" ")+o,l.description&&this.cursor===r&&(a=` - ${l.description}`,(o.length+n.length+a.length>=this.out.columns||l.description.split(/\r?\n/).length>1)&&(a=`
|
|
34
|
-
`+
|
|
35
|
-
`}}this.out.write(this.outputText)}};dr.exports=Lt});var yr=c((
|
|
34
|
+
`+iu(l.description,{margin:3,width:this.out.columns})))),this.outputText+=`${o} ${n}${Z.gray(a)}
|
|
35
|
+
`}}this.out.write(this.outputText)}};dr.exports=Lt});var yr=c((Xd,wr)=>{"use strict";var Xe=x(),ou=z(),gr=V(),pr=gr.style,au=gr.clear,br=O(),mr=br.cursor,lu=br.erase,Ut=class extends ou{constructor(e={}){super(e),this.msg=e.message,this.value=!!e.initial,this.active=e.active||"on",this.inactive=e.inactive||"off",this.initialValue=this.value,this.render()}reset(){this.value=this.initialValue,this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
|
|
36
36
|
`),this.close()}submit(){this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
37
|
-
`),this.close()}deactivate(){if(this.value===!1)return this.bell();this.value=!1,this.render()}activate(){if(this.value===!0)return this.bell();this.value=!0,this.render()}delete(){this.deactivate()}left(){this.deactivate()}right(){this.activate()}down(){this.deactivate()}up(){this.activate()}next(){this.value=!this.value,this.fire(),this.render()}_(e,t){if(e===" ")this.value=!this.value;else if(e==="1")this.value=!0;else if(e==="0")this.value=!1;else return this.bell();this.render()}render(){this.closed||(this.firstRender?this.out.write(mr.hide):this.out.write(
|
|
37
|
+
`),this.close()}deactivate(){if(this.value===!1)return this.bell();this.value=!1,this.render()}activate(){if(this.value===!0)return this.bell();this.value=!0,this.render()}delete(){this.deactivate()}left(){this.deactivate()}right(){this.activate()}down(){this.deactivate()}up(){this.activate()}next(){this.value=!this.value,this.fire(),this.render()}_(e,t){if(e===" ")this.value=!this.value;else if(e==="1")this.value=!0;else if(e==="0")this.value=!1;else return this.bell();this.render()}render(){this.closed||(this.firstRender?this.out.write(mr.hide):this.out.write(au(this.outputText,this.out.columns)),super.render(),this.outputText=[pr.symbol(this.done,this.aborted),Xe.bold(this.msg),pr.delimiter(this.done),this.value?this.inactive:Xe.cyan().underline(this.inactive),Xe.gray("/"),this.value?Xe.cyan().underline(this.active):this.active].join(" "),this.out.write(lu.line+mr.to(0)+this.outputText))}};wr.exports=Ut});var F=c((Qd,_r)=>{"use strict";var Gt=class i{constructor({token:e,date:t,parts:s,locales:r}){this.token=e,this.date=t||new Date,this.parts=s||[this],this.locales=r||{}}up(){}down(){}next(){let e=this.parts.indexOf(this);return this.parts.find((t,s)=>s>e&&t instanceof i)}setTo(e){}prev(){let e=[].concat(this.parts).reverse(),t=e.indexOf(this);return e.find((s,r)=>r>t&&s instanceof i)}toString(){return String(this.date)}};_r.exports=Gt});var xr=c((ef,vr)=>{"use strict";var uu=F(),Bt=class extends uu{constructor(e={}){super(e)}up(){this.date.setHours((this.date.getHours()+12)%24)}down(){this.up()}toString(){let e=this.date.getHours()>12?"pm":"am";return/\A/.test(this.token)?e.toUpperCase():e}};vr.exports=Bt});var Or=c((tf,Cr)=>{"use strict";var hu=F(),cu=i=>(i=i%10,i===1?"st":i===2?"nd":i===3?"rd":"th"),Yt=class extends hu{constructor(e={}){super(e)}up(){this.date.setDate(this.date.getDate()+1)}down(){this.date.setDate(this.date.getDate()-1)}setTo(e){this.date.setDate(parseInt(e.substr(-2)))}toString(){let e=this.date.getDate(),t=this.date.getDay();return this.token==="DD"?String(e).padStart(2,"0"):this.token==="Do"?e+cu(e):this.token==="d"?t+1:this.token==="ddd"?this.locales.weekdaysShort[t]:this.token==="dddd"?this.locales.weekdays[t]:e}};Cr.exports=Yt});var Ar=c((sf,Sr)=>{"use strict";var du=F(),Wt=class extends du{constructor(e={}){super(e)}up(){this.date.setHours(this.date.getHours()+1)}down(){this.date.setHours(this.date.getHours()-1)}setTo(e){this.date.setHours(parseInt(e.substr(-2)))}toString(){let e=this.date.getHours();return/h/.test(this.token)&&(e=e%12||12),this.token.length>1?String(e).padStart(2,"0"):e}};Sr.exports=Wt});var Er=c((rf,$r)=>{"use strict";var fu=F(),Jt=class extends fu{constructor(e={}){super(e)}up(){this.date.setMilliseconds(this.date.getMilliseconds()+1)}down(){this.date.setMilliseconds(this.date.getMilliseconds()-1)}setTo(e){this.date.setMilliseconds(parseInt(e.substr(-this.token.length)))}toString(){return String(this.date.getMilliseconds()).padStart(4,"0").substr(0,this.token.length)}};$r.exports=Jt});var kr=c((nf,Pr)=>{"use strict";var pu=F(),Kt=class extends pu{constructor(e={}){super(e)}up(){this.date.setMinutes(this.date.getMinutes()+1)}down(){this.date.setMinutes(this.date.getMinutes()-1)}setTo(e){this.date.setMinutes(parseInt(e.substr(-2)))}toString(){let e=this.date.getMinutes();return this.token.length>1?String(e).padStart(2,"0"):e}};Pr.exports=Kt});var Ir=c((of,Tr)=>{"use strict";var mu=F(),zt=class extends mu{constructor(e={}){super(e)}up(){this.date.setMonth(this.date.getMonth()+1)}down(){this.date.setMonth(this.date.getMonth()-1)}setTo(e){e=parseInt(e.substr(-2))-1,this.date.setMonth(e<0?0:e)}toString(){let e=this.date.getMonth(),t=this.token.length;return t===2?String(e+1).padStart(2,"0"):t===3?this.locales.monthsShort[e]:t===4?this.locales.months[e]:String(e+1)}};Tr.exports=zt});var Mr=c((af,qr)=>{"use strict";var gu=F(),Zt=class extends gu{constructor(e={}){super(e)}up(){this.date.setSeconds(this.date.getSeconds()+1)}down(){this.date.setSeconds(this.date.getSeconds()-1)}setTo(e){this.date.setSeconds(parseInt(e.substr(-2)))}toString(){let e=this.date.getSeconds();return this.token.length>1?String(e).padStart(2,"0"):e}};qr.exports=Zt});var Vr=c((lf,Dr)=>{"use strict";var bu=F(),Xt=class extends bu{constructor(e={}){super(e)}up(){this.date.setFullYear(this.date.getFullYear()+1)}down(){this.date.setFullYear(this.date.getFullYear()-1)}setTo(e){this.date.setFullYear(e.substr(-4))}toString(){let e=String(this.date.getFullYear()).padStart(4,"0");return this.token.length===2?e.substr(-2):e}};Dr.exports=Xt});var Hr=c((uf,jr)=>{"use strict";jr.exports={DatePart:F(),Meridiem:xr(),Day:Or(),Hours:Ar(),Milliseconds:Er(),Minutes:kr(),Month:Ir(),Seconds:Mr(),Year:Vr()}});var Jr=c((hf,Wr)=>{"use strict";function Fr(i,e,t,s,r,n,o){try{var a=i[n](o),l=a.value}catch(u){t(u);return}a.done?e(l):Promise.resolve(l).then(s,r)}function Rr(i){return function(){var e=this,t=arguments;return new Promise(function(s,r){var n=i.apply(e,t);function o(l){Fr(n,s,r,o,a,"next",l)}function a(l){Fr(n,s,r,o,a,"throw",l)}o(void 0)})}}var Qt=x(),wu=z(),ti=V(),Nr=ti.style,Lr=ti.clear,yu=ti.figures,Yr=O(),_u=Yr.erase,Ur=Yr.cursor,X=Hr(),Gr=X.DatePart,vu=X.Meridiem,xu=X.Day,Cu=X.Hours,Ou=X.Milliseconds,Su=X.Minutes,Au=X.Month,$u=X.Seconds,Eu=X.Year,Pu=/\\(.)|"((?:\\["\\]|[^"])+)"|(D[Do]?|d{3,4}|d)|(M{1,4})|(YY(?:YY)?)|([aA])|([Hh]{1,2})|(m{1,2})|(s{1,2})|(S{1,4})|./g,Br={1:({token:i})=>i.replace(/\\(.)/g,"$1"),2:i=>new xu(i),3:i=>new Au(i),4:i=>new Eu(i),5:i=>new vu(i),6:i=>new Cu(i),7:i=>new Su(i),8:i=>new $u(i),9:i=>new Ou(i)},ku={months:"January,February,March,April,May,June,July,August,September,October,November,December".split(","),monthsShort:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","),weekdays:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","),weekdaysShort:"Sun,Mon,Tue,Wed,Thu,Fri,Sat".split(",")},ei=class extends wu{constructor(e={}){super(e),this.msg=e.message,this.cursor=0,this.typed="",this.locales=Object.assign(ku,e.locales),this._date=e.initial||new Date,this.errorMsg=e.error||"Please Enter A Valid Value",this.validator=e.validate||(()=>!0),this.mask=e.mask||"YYYY-MM-DD HH:mm:ss",this.clear=Lr("",this.out.columns),this.render()}get value(){return this.date}get date(){return this._date}set date(e){e&&this._date.setTime(e.getTime())}set mask(e){let t;for(this.parts=[];t=Pu.exec(e);){let r=t.shift(),n=t.findIndex(o=>o!=null);this.parts.push(n in Br?Br[n]({token:t[n]||r,date:this.date,parts:this.parts,locales:this.locales}):t[n]||r)}let s=this.parts.reduce((r,n)=>(typeof n=="string"&&typeof r[r.length-1]=="string"?r[r.length-1]+=n:r.push(n),r),[]);this.parts.splice(0),this.parts.push(...s),this.reset()}moveCursor(e){this.typed="",this.cursor=e,this.fire()}reset(){this.moveCursor(this.parts.findIndex(e=>e instanceof Gr)),this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.error=!1,this.fire(),this.render(),this.out.write(`
|
|
38
38
|
`),this.close()}validate(){var e=this;return Rr(function*(){let t=yield e.validator(e.value);typeof t=="string"&&(e.errorMsg=t,t=!1),e.error=!t})()}submit(){var e=this;return Rr(function*(){if(yield e.validate(),e.error){e.color="red",e.fire(),e.render();return}e.done=!0,e.aborted=!1,e.fire(),e.render(),e.out.write(`
|
|
39
39
|
`),e.close()})()}up(){this.typed="",this.parts[this.cursor].up(),this.render()}down(){this.typed="",this.parts[this.cursor].down(),this.render()}left(){let e=this.parts[this.cursor].prev();if(e==null)return this.bell();this.moveCursor(this.parts.indexOf(e)),this.render()}right(){let e=this.parts[this.cursor].next();if(e==null)return this.bell();this.moveCursor(this.parts.indexOf(e)),this.render()}next(){let e=this.parts[this.cursor].next();this.moveCursor(e?this.parts.indexOf(e):this.parts.findIndex(t=>t instanceof Gr)),this.render()}_(e){/\d/.test(e)&&(this.typed+=e,this.parts[this.cursor].setTo(this.typed),this.render())}render(){this.closed||(this.firstRender?this.out.write(Ur.hide):this.out.write(Lr(this.outputText,this.out.columns)),super.render(),this.outputText=[Nr.symbol(this.done,this.aborted),Qt.bold(this.msg),Nr.delimiter(!1),this.parts.reduce((e,t,s)=>e.concat(s===this.cursor&&!this.done?Qt.cyan().underline(t.toString()):t),[]).join("")].join(" "),this.error&&(this.outputText+=this.errorMsg.split(`
|
|
40
40
|
`).reduce((e,t,s)=>e+`
|
|
41
|
-
${s?" ":
|
|
41
|
+
${s?" ":yu.pointerSmall} ${Qt.red().italic(t)}`,"")),this.out.write(_u.line+Ur.to(0)+this.outputText))}};Wr.exports=ei});var tn=c((cf,en)=>{"use strict";function Kr(i,e,t,s,r,n,o){try{var a=i[n](o),l=a.value}catch(u){t(u);return}a.done?e(l):Promise.resolve(l).then(s,r)}function zr(i){return function(){var e=this,t=arguments;return new Promise(function(s,r){var n=i.apply(e,t);function o(l){Kr(n,s,r,o,a,"next",l)}function a(l){Kr(n,s,r,o,a,"throw",l)}o(void 0)})}}var Qe=x(),Tu=z(),Qr=O(),et=Qr.cursor,Iu=Qr.erase,tt=V(),ii=tt.style,qu=tt.figures,Zr=tt.clear,Mu=tt.lines,Du=/[0-9]/,si=i=>i!==void 0,Xr=(i,e)=>{let t=Math.pow(10,e);return Math.round(i*t)/t},ri=class extends Tu{constructor(e={}){super(e),this.transform=ii.render(e.style),this.msg=e.message,this.initial=si(e.initial)?e.initial:"",this.float=!!e.float,this.round=e.round||2,this.inc=e.increment||1,this.min=si(e.min)?e.min:-1/0,this.max=si(e.max)?e.max:1/0,this.errorMsg=e.error||"Please Enter A Valid Value",this.validator=e.validate||(()=>!0),this.color="cyan",this.value="",this.typed="",this.lastHit=0,this.render()}set value(e){!e&&e!==0?(this.placeholder=!0,this.rendered=Qe.gray(this.transform.render(`${this.initial}`)),this._value=""):(this.placeholder=!1,this.rendered=this.transform.render(`${Xr(e,this.round)}`),this._value=Xr(e,this.round)),this.fire()}get value(){return this._value}parse(e){return this.float?parseFloat(e):parseInt(e)}valid(e){return e==="-"||e==="."&&this.float||Du.test(e)}reset(){this.typed="",this.value="",this.fire(),this.render()}exit(){this.abort()}abort(){let e=this.value;this.value=e!==""?e:this.initial,this.done=this.aborted=!0,this.error=!1,this.fire(),this.render(),this.out.write(`
|
|
42
42
|
`),this.close()}validate(){var e=this;return zr(function*(){let t=yield e.validator(e.value);typeof t=="string"&&(e.errorMsg=t,t=!1),e.error=!t})()}submit(){var e=this;return zr(function*(){if(yield e.validate(),e.error){e.color="red",e.fire(),e.render();return}let t=e.value;e.value=t!==""?t:e.initial,e.done=!0,e.aborted=!1,e.error=!1,e.fire(),e.render(),e.out.write(`
|
|
43
|
-
`),e.close()})()}up(){if(this.typed="",this.value===""&&(this.value=this.min-this.inc),this.value>=this.max)return this.bell();this.value+=this.inc,this.color="cyan",this.fire(),this.render()}down(){if(this.typed="",this.value===""&&(this.value=this.min+this.inc),this.value<=this.min)return this.bell();this.value-=this.inc,this.color="cyan",this.fire(),this.render()}delete(){let e=this.value.toString();if(e.length===0)return this.bell();this.value=this.parse(e=e.slice(0,-1))||"",this.value!==""&&this.value<this.min&&(this.value=this.min),this.color="cyan",this.fire(),this.render()}next(){this.value=this.initial,this.fire(),this.render()}_(e,t){if(!this.valid(e))return this.bell();let s=Date.now();if(s-this.lastHit>1e3&&(this.typed=""),this.typed+=e,this.lastHit=s,this.color="cyan",e===".")return this.fire();this.value=Math.min(this.parse(this.typed),this.max),this.value>this.max&&(this.value=this.max),this.value<this.min&&(this.value=this.min),this.fire(),this.render()}render(){this.closed||(this.firstRender||(this.outputError&&this.out.write(et.down(
|
|
43
|
+
`),e.close()})()}up(){if(this.typed="",this.value===""&&(this.value=this.min-this.inc),this.value>=this.max)return this.bell();this.value+=this.inc,this.color="cyan",this.fire(),this.render()}down(){if(this.typed="",this.value===""&&(this.value=this.min+this.inc),this.value<=this.min)return this.bell();this.value-=this.inc,this.color="cyan",this.fire(),this.render()}delete(){let e=this.value.toString();if(e.length===0)return this.bell();this.value=this.parse(e=e.slice(0,-1))||"",this.value!==""&&this.value<this.min&&(this.value=this.min),this.color="cyan",this.fire(),this.render()}next(){this.value=this.initial,this.fire(),this.render()}_(e,t){if(!this.valid(e))return this.bell();let s=Date.now();if(s-this.lastHit>1e3&&(this.typed=""),this.typed+=e,this.lastHit=s,this.color="cyan",e===".")return this.fire();this.value=Math.min(this.parse(this.typed),this.max),this.value>this.max&&(this.value=this.max),this.value<this.min&&(this.value=this.min),this.fire(),this.render()}render(){this.closed||(this.firstRender||(this.outputError&&this.out.write(et.down(Mu(this.outputError,this.out.columns)-1)+Zr(this.outputError,this.out.columns)),this.out.write(Zr(this.outputText,this.out.columns))),super.render(),this.outputError="",this.outputText=[ii.symbol(this.done,this.aborted),Qe.bold(this.msg),ii.delimiter(this.done),!this.done||!this.done&&!this.placeholder?Qe[this.color]().underline(this.rendered):this.rendered].join(" "),this.error&&(this.outputError+=this.errorMsg.split(`
|
|
44
44
|
`).reduce((e,t,s)=>e+`
|
|
45
|
-
${s?" ":
|
|
45
|
+
${s?" ":qu.pointerSmall} ${Qe.red().italic(t)}`,"")),this.out.write(Iu.line+et.to(0)+this.outputText+et.save+this.outputError+et.restore))}};en.exports=ri});var oi=c((df,nn)=>{"use strict";var R=x(),Vu=O(),ju=Vu.cursor,Hu=z(),Te=V(),sn=Te.clear,oe=Te.figures,rn=Te.style,Fu=Te.wrap,Ru=Te.entriesToDisplay,ni=class extends Hu{constructor(e={}){super(e),this.msg=e.message,this.cursor=e.cursor||0,this.scrollIndex=e.cursor||0,this.hint=e.hint||"",this.warn=e.warn||"- This option is disabled -",this.minSelected=e.min,this.showMinError=!1,this.maxChoices=e.max,this.instructions=e.instructions,this.optionsPerPage=e.optionsPerPage||10,this.value=e.choices.map((t,s)=>(typeof t=="string"&&(t={title:t,value:s}),{title:t&&(t.title||t.value||t),description:t&&t.description,value:t&&(t.value===void 0?s:t.value),selected:t&&t.selected,disabled:t&&t.disabled})),this.clear=sn("",this.out.columns),e.overrideRender||this.render()}reset(){this.value.map(e=>!e.selected),this.cursor=0,this.fire(),this.render()}selected(){return this.value.filter(e=>e.selected)}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
|
|
46
46
|
`),this.close()}submit(){let e=this.value.filter(t=>t.selected);this.minSelected&&e.length<this.minSelected?(this.showMinError=!0,this.render()):(this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
47
47
|
`),this.close())}first(){this.cursor=0,this.render()}last(){this.cursor=this.value.length-1,this.render()}next(){this.cursor=(this.cursor+1)%this.value.length,this.render()}up(){this.cursor===0?this.cursor=this.value.length-1:this.cursor--,this.render()}down(){this.cursor===this.value.length-1?this.cursor=0:this.cursor++,this.render()}left(){this.value[this.cursor].selected=!1,this.render()}right(){if(this.value.filter(e=>e.selected).length>=this.maxChoices)return this.bell();this.value[this.cursor].selected=!0,this.render()}handleSpaceToggle(){let e=this.value[this.cursor];if(e.selected)e.selected=!1,this.render();else{if(e.disabled||this.value.filter(t=>t.selected).length>=this.maxChoices)return this.bell();e.selected=!0,this.render()}}toggleAll(){if(this.maxChoices!==void 0||this.value[this.cursor].disabled)return this.bell();let e=!this.value[this.cursor].selected;this.value.filter(t=>!t.disabled).forEach(t=>t.selected=e),this.render()}_(e,t){if(e===" ")this.handleSpaceToggle();else if(e==="a")this.toggleAll();else return this.bell()}renderInstructions(){return this.instructions===void 0||this.instructions?typeof this.instructions=="string"?this.instructions:`
|
|
48
48
|
Instructions:
|
|
@@ -50,15 +50,15 @@ Instructions:
|
|
|
50
50
|
${oe.arrowLeft}/${oe.arrowRight}/[space]: Toggle selection
|
|
51
51
|
`+(this.maxChoices===void 0?` a: Toggle all
|
|
52
52
|
`:"")+" enter/return: Complete answer":""}renderOption(e,t,s,r){let n=(t.selected?R.green(oe.radioOn):oe.radioOff)+" "+r+" ",o,a;return t.disabled?o=e===s?R.gray().underline(t.title):R.strikethrough().gray(t.title):(o=e===s?R.cyan().underline(t.title):t.title,e===s&&t.description&&(a=` - ${t.description}`,(n.length+o.length+a.length>=this.out.columns||t.description.split(/\r?\n/).length>1)&&(a=`
|
|
53
|
-
`+
|
|
53
|
+
`+Fu(t.description,{margin:n.length,width:this.out.columns})))),n+o+R.gray(a||"")}paginateOptions(e){if(e.length===0)return R.red("No matches for this query.");let t=Ru(this.cursor,e.length,this.optionsPerPage),s=t.startIndex,r=t.endIndex,n,o=[];for(let a=s;a<r;a++)a===s&&s>0?n=oe.arrowUp:a===r-1&&r<e.length?n=oe.arrowDown:n=" ",o.push(this.renderOption(this.cursor,e[a],a,n));return`
|
|
54
54
|
`+o.join(`
|
|
55
|
-
`)}renderOptions(e){return this.done?"":this.paginateOptions(e)}renderDoneOrInstructions(){if(this.done)return this.value.filter(t=>t.selected).map(t=>t.title).join(", ");let e=[R.gray(this.hint),this.renderInstructions()];return this.value[this.cursor].disabled&&e.push(R.yellow(this.warn)),e.join(" ")}render(){if(this.closed)return;this.firstRender&&this.out.write(
|
|
55
|
+
`)}renderOptions(e){return this.done?"":this.paginateOptions(e)}renderDoneOrInstructions(){if(this.done)return this.value.filter(t=>t.selected).map(t=>t.title).join(", ");let e=[R.gray(this.hint),this.renderInstructions()];return this.value[this.cursor].disabled&&e.push(R.yellow(this.warn)),e.join(" ")}render(){if(this.closed)return;this.firstRender&&this.out.write(ju.hide),super.render();let e=[rn.symbol(this.done,this.aborted),R.bold(this.msg),rn.delimiter(!1),this.renderDoneOrInstructions()].join(" ");this.showMinError&&(e+=R.red(`You must select a minimum of ${this.minSelected} choices.`),this.showMinError=!1),e+=this.renderOptions(this.value),this.out.write(this.clear+e),this.clear=sn(e,this.out.columns)}};nn.exports=ni});var dn=c((ff,cn)=>{"use strict";function on(i,e,t,s,r,n,o){try{var a=i[n](o),l=a.value}catch(u){t(u);return}a.done?e(l):Promise.resolve(l).then(s,r)}function Nu(i){return function(){var e=this,t=arguments;return new Promise(function(s,r){var n=i.apply(e,t);function o(l){on(n,s,r,o,a,"next",l)}function a(l){on(n,s,r,o,a,"throw",l)}o(void 0)})}}var Ie=x(),Lu=z(),hn=O(),Uu=hn.erase,an=hn.cursor,qe=V(),ai=qe.style,ln=qe.clear,li=qe.figures,Gu=qe.wrap,Bu=qe.entriesToDisplay,un=(i,e)=>i[e]&&(i[e].value||i[e].title||i[e]),Yu=(i,e)=>i[e]&&(i[e].title||i[e].value||i[e]),Wu=(i,e)=>{let t=i.findIndex(s=>s.value===e||s.title===e);return t>-1?t:void 0},ui=class extends Lu{constructor(e={}){super(e),this.msg=e.message,this.suggest=e.suggest,this.choices=e.choices,this.initial=typeof e.initial=="number"?e.initial:Wu(e.choices,e.initial),this.select=this.initial||e.cursor||0,this.i18n={noMatches:e.noMatches||"no matches found"},this.fallback=e.fallback||this.initial,this.clearFirst=e.clearFirst||!1,this.suggestions=[],this.input="",this.limit=e.limit||10,this.cursor=0,this.transform=ai.render(e.style),this.scale=this.transform.scale,this.render=this.render.bind(this),this.complete=this.complete.bind(this),this.clear=ln("",this.out.columns),this.complete(this.render),this.render()}set fallback(e){this._fb=Number.isSafeInteger(parseInt(e))?parseInt(e):e}get fallback(){let e;return typeof this._fb=="number"?e=this.choices[this._fb]:typeof this._fb=="string"&&(e={title:this._fb}),e||this._fb||{title:this.i18n.noMatches}}moveSelect(e){this.select=e,this.suggestions.length>0?this.value=un(this.suggestions,e):this.value=this.fallback.value,this.fire()}complete(e){var t=this;return Nu(function*(){let s=t.completing=t.suggest(t.input,t.choices),r=yield s;if(t.completing!==s)return;t.suggestions=r.map((o,a,l)=>({title:Yu(l,a),value:un(l,a),description:o.description})),t.completing=!1;let n=Math.max(r.length-1,0);t.moveSelect(Math.min(n,t.select)),e&&e()})()}reset(){this.input="",this.complete(()=>{this.moveSelect(this.initial!==void 0?this.initial:0),this.render()}),this.render()}exit(){this.clearFirst&&this.input.length>0?this.reset():(this.done=this.exited=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
56
56
|
`),this.close())}abort(){this.done=this.aborted=!0,this.exited=!1,this.fire(),this.render(),this.out.write(`
|
|
57
57
|
`),this.close()}submit(){this.done=!0,this.aborted=this.exited=!1,this.fire(),this.render(),this.out.write(`
|
|
58
58
|
`),this.close()}_(e,t){let s=this.input.slice(0,this.cursor),r=this.input.slice(this.cursor);this.input=`${s}${e}${r}`,this.cursor=s.length+1,this.complete(this.render),this.render()}delete(){if(this.cursor===0)return this.bell();let e=this.input.slice(0,this.cursor-1),t=this.input.slice(this.cursor);this.input=`${e}${t}`,this.complete(this.render),this.cursor=this.cursor-1,this.render()}deleteForward(){if(this.cursor*this.scale>=this.rendered.length)return this.bell();let e=this.input.slice(0,this.cursor),t=this.input.slice(this.cursor+1);this.input=`${e}${t}`,this.complete(this.render),this.render()}first(){this.moveSelect(0),this.render()}last(){this.moveSelect(this.suggestions.length-1),this.render()}up(){this.select===0?this.moveSelect(this.suggestions.length-1):this.moveSelect(this.select-1),this.render()}down(){this.select===this.suggestions.length-1?this.moveSelect(0):this.moveSelect(this.select+1),this.render()}next(){this.select===this.suggestions.length-1?this.moveSelect(0):this.moveSelect(this.select+1),this.render()}nextPage(){this.moveSelect(Math.min(this.select+this.limit,this.suggestions.length-1)),this.render()}prevPage(){this.moveSelect(Math.max(this.select-this.limit,0)),this.render()}left(){if(this.cursor<=0)return this.bell();this.cursor=this.cursor-1,this.render()}right(){if(this.cursor*this.scale>=this.rendered.length)return this.bell();this.cursor=this.cursor+1,this.render()}renderOption(e,t,s,r){let n,o=s?li.arrowUp:r?li.arrowDown:" ",a=t?Ie.cyan().underline(e.title):e.title;return o=(t?Ie.cyan(li.pointer)+" ":" ")+o,e.description&&(n=` - ${e.description}`,(o.length+a.length+n.length>=this.out.columns||e.description.split(/\r?\n/).length>1)&&(n=`
|
|
59
|
-
`+
|
|
59
|
+
`+Gu(e.description,{margin:3,width:this.out.columns}))),o+" "+a+Ie.gray(n||"")}render(){if(this.closed)return;this.firstRender?this.out.write(an.hide):this.out.write(ln(this.outputText,this.out.columns)),super.render();let e=Bu(this.select,this.choices.length,this.limit),t=e.startIndex,s=e.endIndex;if(this.outputText=[ai.symbol(this.done,this.aborted,this.exited),Ie.bold(this.msg),ai.delimiter(this.completing),this.done&&this.suggestions[this.select]?this.suggestions[this.select].title:this.rendered=this.transform.render(this.input)].join(" "),!this.done){let r=this.suggestions.slice(t,s).map((n,o)=>this.renderOption(n,this.select===o+t,o===0&&t>0,o+t===s-1&&s<this.choices.length)).join(`
|
|
60
60
|
`);this.outputText+=`
|
|
61
|
-
`+(r||Ie.gray(this.fallback.title))}this.out.write(
|
|
61
|
+
`+(r||Ie.gray(this.fallback.title))}this.out.write(Uu.line+an.to(0)+this.outputText)}};cn.exports=ui});var gn=c((pf,mn)=>{"use strict";var Q=x(),Ju=O(),Ku=Ju.cursor,zu=oi(),ci=V(),fn=ci.clear,pn=ci.style,ve=ci.figures,hi=class extends zu{constructor(e={}){e.overrideRender=!0,super(e),this.inputValue="",this.clear=fn("",this.out.columns),this.filteredOptions=this.value,this.render()}last(){this.cursor=this.filteredOptions.length-1,this.render()}next(){this.cursor=(this.cursor+1)%this.filteredOptions.length,this.render()}up(){this.cursor===0?this.cursor=this.filteredOptions.length-1:this.cursor--,this.render()}down(){this.cursor===this.filteredOptions.length-1?this.cursor=0:this.cursor++,this.render()}left(){this.filteredOptions[this.cursor].selected=!1,this.render()}right(){if(this.value.filter(e=>e.selected).length>=this.maxChoices)return this.bell();this.filteredOptions[this.cursor].selected=!0,this.render()}delete(){this.inputValue.length&&(this.inputValue=this.inputValue.substr(0,this.inputValue.length-1),this.updateFilteredOptions())}updateFilteredOptions(){let e=this.filteredOptions[this.cursor];this.filteredOptions=this.value.filter(s=>this.inputValue?!!(typeof s.title=="string"&&s.title.toLowerCase().includes(this.inputValue.toLowerCase())||typeof s.value=="string"&&s.value.toLowerCase().includes(this.inputValue.toLowerCase())):!0);let t=this.filteredOptions.findIndex(s=>s===e);this.cursor=t<0?0:t,this.render()}handleSpaceToggle(){let e=this.filteredOptions[this.cursor];if(e.selected)e.selected=!1,this.render();else{if(e.disabled||this.value.filter(t=>t.selected).length>=this.maxChoices)return this.bell();e.selected=!0,this.render()}}handleInputChange(e){this.inputValue=this.inputValue+e,this.updateFilteredOptions()}_(e,t){e===" "?this.handleSpaceToggle():this.handleInputChange(e)}renderInstructions(){return this.instructions===void 0||this.instructions?typeof this.instructions=="string"?this.instructions:`
|
|
62
62
|
Instructions:
|
|
63
63
|
${ve.arrowUp}/${ve.arrowDown}: Highlight option
|
|
64
64
|
${ve.arrowLeft}/${ve.arrowRight}/[space]: Toggle selection
|
|
@@ -66,31 +66,31 @@ Instructions:
|
|
|
66
66
|
enter/return: Complete answer
|
|
67
67
|
`:""}renderCurrentInput(){return`
|
|
68
68
|
Filtered results for: ${this.inputValue?this.inputValue:Q.gray("Enter something to filter")}
|
|
69
|
-
`}renderOption(e,t,s){let r;return t.disabled?r=e===s?Q.gray().underline(t.title):Q.strikethrough().gray(t.title):r=e===s?Q.cyan().underline(t.title):t.title,(t.selected?Q.green(ve.radioOn):ve.radioOff)+" "+r}renderDoneOrInstructions(){if(this.done)return this.value.filter(t=>t.selected).map(t=>t.title).join(", ");let e=[Q.gray(this.hint),this.renderInstructions(),this.renderCurrentInput()];return this.filteredOptions.length&&this.filteredOptions[this.cursor].disabled&&e.push(Q.yellow(this.warn)),e.join(" ")}render(){if(this.closed)return;this.firstRender&&this.out.write(
|
|
69
|
+
`}renderOption(e,t,s){let r;return t.disabled?r=e===s?Q.gray().underline(t.title):Q.strikethrough().gray(t.title):r=e===s?Q.cyan().underline(t.title):t.title,(t.selected?Q.green(ve.radioOn):ve.radioOff)+" "+r}renderDoneOrInstructions(){if(this.done)return this.value.filter(t=>t.selected).map(t=>t.title).join(", ");let e=[Q.gray(this.hint),this.renderInstructions(),this.renderCurrentInput()];return this.filteredOptions.length&&this.filteredOptions[this.cursor].disabled&&e.push(Q.yellow(this.warn)),e.join(" ")}render(){if(this.closed)return;this.firstRender&&this.out.write(Ku.hide),super.render();let e=[pn.symbol(this.done,this.aborted),Q.bold(this.msg),pn.delimiter(!1),this.renderDoneOrInstructions()].join(" ");this.showMinError&&(e+=Q.red(`You must select a minimum of ${this.minSelected} choices.`),this.showMinError=!1),e+=this.renderOptions(this.filteredOptions),this.out.write(this.clear+e),this.clear=fn(e,this.out.columns)}};mn.exports=hi});var Cn=c((mf,xn)=>{"use strict";var bn=x(),Zu=z(),_n=V(),wn=_n.style,Xu=_n.clear,vn=O(),Qu=vn.erase,yn=vn.cursor,di=class extends Zu{constructor(e={}){super(e),this.msg=e.message,this.value=e.initial,this.initialValue=!!e.initial,this.yesMsg=e.yes||"yes",this.yesOption=e.yesOption||"(Y/n)",this.noMsg=e.no||"no",this.noOption=e.noOption||"(y/N)",this.render()}reset(){this.value=this.initialValue,this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
|
|
70
70
|
`),this.close()}submit(){this.value=this.value||!1,this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
71
|
-
`),this.close()}_(e,t){return e.toLowerCase()==="y"?(this.value=!0,this.submit()):e.toLowerCase()==="n"?(this.value=!1,this.submit()):this.bell()}render(){this.closed||(this.firstRender?this.out.write(yn.hide):this.out.write(
|
|
72
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var n=!0,o=!1,a;return{s:function(){t=t.call(i)},n:function(){var u=t.next();return n=u.done,u},e:function(u){o=!0,a=u},f:function(){try{!n&&t.return!=null&&t.return()}finally{if(o)throw a}}}}function
|
|
71
|
+
`),this.close()}_(e,t){return e.toLowerCase()==="y"?(this.value=!0,this.submit()):e.toLowerCase()==="n"?(this.value=!1,this.submit()):this.bell()}render(){this.closed||(this.firstRender?this.out.write(yn.hide):this.out.write(Xu(this.outputText,this.out.columns)),super.render(),this.outputText=[wn.symbol(this.done,this.aborted),bn.bold(this.msg),wn.delimiter(this.done),this.done?this.value?this.yesMsg:this.noMsg:bn.gray(this.initialValue?this.yesOption:this.noOption)].join(" "),this.out.write(Qu.line+yn.to(0)+this.outputText))}};xn.exports=di});var Sn=c((gf,On)=>{"use strict";On.exports={TextPrompt:ur(),SelectPrompt:fr(),TogglePrompt:yr(),DatePrompt:Jr(),NumberPrompt:tn(),MultiselectPrompt:oi(),AutocompletePrompt:dn(),AutocompleteMultiselectPrompt:gn(),ConfirmPrompt:Cn()}});var $n=c(An=>{"use strict";var k=An,eh=Sn(),it=i=>i;function N(i,e,t={}){return new Promise((s,r)=>{let n=new eh[i](e),o=t.onAbort||it,a=t.onSubmit||it,l=t.onExit||it;n.on("state",e.onState||it),n.on("submit",u=>s(a(u))),n.on("exit",u=>s(l(u))),n.on("abort",u=>r(o(u)))})}k.text=i=>N("TextPrompt",i);k.password=i=>(i.style="password",k.text(i));k.invisible=i=>(i.style="invisible",k.text(i));k.number=i=>N("NumberPrompt",i);k.date=i=>N("DatePrompt",i);k.confirm=i=>N("ConfirmPrompt",i);k.list=i=>{let e=i.separator||",";return N("TextPrompt",i,{onSubmit:t=>t.split(e).map(s=>s.trim())})};k.toggle=i=>N("TogglePrompt",i);k.select=i=>N("SelectPrompt",i);k.multiselect=i=>{i.choices=[].concat(i.choices||[]);let e=t=>t.filter(s=>s.selected).map(s=>s.value);return N("MultiselectPrompt",i,{onAbort:e,onSubmit:e})};k.autocompleteMultiselect=i=>{i.choices=[].concat(i.choices||[]);let e=t=>t.filter(s=>s.selected).map(s=>s.value);return N("AutocompleteMultiselectPrompt",i,{onAbort:e,onSubmit:e})};var th=(i,e)=>Promise.resolve(e.filter(t=>t.title.slice(0,i.length).toLowerCase()===i.toLowerCase()));k.autocomplete=i=>(i.suggest=i.suggest||th,i.choices=[].concat(i.choices||[]),N("AutocompletePrompt",i))});var Dn=c((wf,Mn)=>{"use strict";function En(i,e){var t=Object.keys(i);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(i);e&&(s=s.filter(function(r){return Object.getOwnPropertyDescriptor(i,r).enumerable})),t.push.apply(t,s)}return t}function Pn(i){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?En(Object(t),!0).forEach(function(s){ih(i,s,t[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(t)):En(Object(t)).forEach(function(s){Object.defineProperty(i,s,Object.getOwnPropertyDescriptor(t,s))})}return i}function ih(i,e,t){return e in i?Object.defineProperty(i,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):i[e]=t,i}function sh(i,e){var t=typeof Symbol<"u"&&i[Symbol.iterator]||i["@@iterator"];if(!t){if(Array.isArray(i)||(t=rh(i))||e&&i&&typeof i.length=="number"){t&&(i=t);var s=0,r=function(){};return{s:r,n:function(){return s>=i.length?{done:!0}:{done:!1,value:i[s++]}},e:function(u){throw u},f:r}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
72
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var n=!0,o=!1,a;return{s:function(){t=t.call(i)},n:function(){var u=t.next();return n=u.done,u},e:function(u){o=!0,a=u},f:function(){try{!n&&t.return!=null&&t.return()}finally{if(o)throw a}}}}function rh(i,e){if(i){if(typeof i=="string")return kn(i,e);var t=Object.prototype.toString.call(i).slice(8,-1);if(t==="Object"&&i.constructor&&(t=i.constructor.name),t==="Map"||t==="Set")return Array.from(i);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return kn(i,e)}}function kn(i,e){(e==null||e>i.length)&&(e=i.length);for(var t=0,s=new Array(e);t<e;t++)s[t]=i[t];return s}function Tn(i,e,t,s,r,n,o){try{var a=i[n](o),l=a.value}catch(u){t(u);return}a.done?e(l):Promise.resolve(l).then(s,r)}function In(i){return function(){var e=this,t=arguments;return new Promise(function(s,r){var n=i.apply(e,t);function o(l){Tn(n,s,r,o,a,"next",l)}function a(l){Tn(n,s,r,o,a,"throw",l)}o(void 0)})}}var fi=$n(),nh=["suggest","format","onState","validate","onRender","type"],qn=()=>{};function ae(){return pi.apply(this,arguments)}function pi(){return pi=In(function*(i=[],{onSubmit:e=qn,onCancel:t=qn}={}){let s={},r=ae._override||{};i=[].concat(i);let n,o,a,l,u,d,p=function(){var P=In(function*(J,Be,fs=!1){if(!(!fs&&J.validate&&J.validate(Be)!==!0))return J.format?yield J.format(Be,s):Be});return function(Be,fs){return P.apply(this,arguments)}}();var m=sh(i),v;try{for(m.s();!(v=m.n()).done;){o=v.value;var g=o;if(l=g.name,u=g.type,typeof u=="function"&&(u=yield u(n,Pn({},s),o),o.type=u),!!u){for(let P in o){if(nh.includes(P))continue;let J=o[P];o[P]=typeof J=="function"?yield J(n,Pn({},s),d):J}if(d=o,typeof o.message!="string")throw new Error("prompt message is required");var q=o;if(l=q.name,u=q.type,fi[u]===void 0)throw new Error(`prompt type (${u}) is not defined`);if(r[o.name]!==void 0&&(n=yield p(o,r[o.name]),n!==void 0)){s[l]=n;continue}try{n=ae._injected?oh(ae._injected,o.initial):yield fi[u](o),s[l]=n=yield p(o,n,!0),a=yield e(o,n,s)}catch{a=!(yield t(o,s))}if(a)return s}}}catch(P){m.e(P)}finally{m.f()}return s}),pi.apply(this,arguments)}function oh(i,e){let t=i.shift();if(t instanceof Error)throw t;return t===void 0?e:t}function ah(i){ae._injected=(ae._injected||[]).concat(i)}function lh(i){ae._override=Object.assign({},i)}Mn.exports=Object.assign(ae,{prompt:ae,prompts:fi,inject:ah,override:lh})});var jn=c((yf,Vn)=>{"use strict";Vn.exports=(i,e)=>{if(!(i.meta&&i.name!=="escape")){if(i.ctrl){if(i.name==="a")return"first";if(i.name==="c"||i.name==="d")return"abort";if(i.name==="e")return"last";if(i.name==="g")return"reset"}if(e){if(i.name==="j")return"down";if(i.name==="k")return"up"}return i.name==="return"||i.name==="enter"?"submit":i.name==="backspace"?"delete":i.name==="delete"?"deleteForward":i.name==="abort"?"abort":i.name==="escape"?"exit":i.name==="tab"?"next":i.name==="pagedown"?"nextPage":i.name==="pageup"?"prevPage":i.name==="home"?"home":i.name==="end"?"end":i.name==="up"?"up":i.name==="down"?"down":i.name==="right"?"right":i.name==="left"?"left":!1}}});var st=c((_f,Hn)=>{"use strict";Hn.exports=i=>{let e=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"].join("|"),t=new RegExp(e,"g");return typeof i=="string"?i.replace(t,""):i}});var Nn=c((vf,Rn)=>{"use strict";var uh=st(),{erase:Fn,cursor:hh}=O(),ch=i=>[...uh(i)].length;Rn.exports=function(i,e){if(!e)return Fn.line+hh.to(0);let t=0,s=i.split(/\r?\n/);for(let r of s)t+=1+Math.floor(Math.max(ch(r)-1,0)/e);return Fn.lines(t)}});var mi=c((xf,Ln)=>{"use strict";var Me={arrowUp:"\u2191",arrowDown:"\u2193",arrowLeft:"\u2190",arrowRight:"\u2192",radioOn:"\u25C9",radioOff:"\u25EF",tick:"\u2714",cross:"\u2716",ellipsis:"\u2026",pointerSmall:"\u203A",line:"\u2500",pointer:"\u276F"},dh={arrowUp:Me.arrowUp,arrowDown:Me.arrowDown,arrowLeft:Me.arrowLeft,arrowRight:Me.arrowRight,radioOn:"(*)",radioOff:"( )",tick:"\u221A",cross:"\xD7",ellipsis:"...",pointerSmall:"\xBB",line:"\u2500",pointer:">"},fh=process.platform==="win32"?dh:Me;Ln.exports=fh});var Gn=c((Cf,Un)=>{"use strict";var xe=x(),ge=mi(),gi=Object.freeze({password:{scale:1,render:i=>"*".repeat(i.length)},emoji:{scale:2,render:i=>"\u{1F603}".repeat(i.length)},invisible:{scale:0,render:i=>""},default:{scale:1,render:i=>`${i}`}}),ph=i=>gi[i]||gi.default,De=Object.freeze({aborted:xe.red(ge.cross),done:xe.green(ge.tick),exited:xe.yellow(ge.cross),default:xe.cyan("?")}),mh=(i,e,t)=>e?De.aborted:t?De.exited:i?De.done:De.default,gh=i=>xe.gray(i?ge.ellipsis:ge.pointerSmall),bh=(i,e)=>xe.gray(i?e?ge.pointerSmall:"+":ge.line);Un.exports={styles:gi,render:ph,symbols:De,symbol:mh,delimiter:gh,item:bh}});var Yn=c((Of,Bn)=>{"use strict";var wh=st();Bn.exports=function(i,e){let t=String(wh(i)||"").split(/\r?\n/);return e?t.map(s=>Math.ceil(s.length/e)).reduce((s,r)=>s+r):t.length}});var Jn=c((Sf,Wn)=>{"use strict";Wn.exports=(i,e={})=>{let t=Number.isSafeInteger(parseInt(e.margin))?new Array(parseInt(e.margin)).fill(" ").join(""):e.margin||"",s=e.width;return(i||"").split(/\r?\n/g).map(r=>r.split(/\s+/g).reduce((n,o)=>(o.length+t.length>=s||n[n.length-1].length+o.length+1<s?n[n.length-1]+=` ${o}`:n.push(`${t}${o}`),n),[t]).join(`
|
|
73
73
|
`)).join(`
|
|
74
|
-
`)}});var zn=c((
|
|
74
|
+
`)}});var zn=c((Af,Kn)=>{"use strict";Kn.exports=(i,e,t)=>{t=t||e;let s=Math.min(e-t,i-Math.floor(t/2));s<0&&(s=0);let r=Math.min(s+t,e);return{startIndex:s,endIndex:r}}});var j=c(($f,Zn)=>{"use strict";Zn.exports={action:jn(),clear:Nn(),style:Gn(),strip:st(),figures:mi(),lines:Yn(),wrap:Jn(),entriesToDisplay:zn()}});var ee=c((Ef,Qn)=>{"use strict";var Xn=require("readline"),{action:yh}=j(),_h=require("events"),{beep:vh,cursor:xh}=O(),Ch=x(),bi=class extends _h{constructor(e={}){super(),this.firstRender=!0,this.in=e.stdin||process.stdin,this.out=e.stdout||process.stdout,this.onRender=(e.onRender||(()=>{})).bind(this);let t=Xn.createInterface({input:this.in,escapeCodeTimeout:50});Xn.emitKeypressEvents(this.in,t),this.in.isTTY&&this.in.setRawMode(!0);let s=["SelectPrompt","MultiselectPrompt"].indexOf(this.constructor.name)>-1,r=(n,o)=>{let a=yh(o,s);a===!1?this._&&this._(n,o):typeof this[a]=="function"?this[a](o):this.bell()};this.close=()=>{this.out.write(xh.show),this.in.removeListener("keypress",r),this.in.isTTY&&this.in.setRawMode(!1),t.close(),this.emit(this.aborted?"abort":this.exited?"exit":"submit",this.value),this.closed=!0},this.in.on("keypress",r)}fire(){this.emit("state",{value:this.value,aborted:!!this.aborted,exited:!!this.exited})}bell(){this.out.write(vh)}render(){this.onRender(Ch),this.firstRender&&(this.firstRender=!1)}};Qn.exports=bi});var to=c((Pf,eo)=>{var rt=x(),Oh=ee(),{erase:Sh,cursor:Ve}=O(),{style:wi,clear:yi,lines:Ah,figures:$h}=j(),_i=class extends Oh{constructor(e={}){super(e),this.transform=wi.render(e.style),this.scale=this.transform.scale,this.msg=e.message,this.initial=e.initial||"",this.validator=e.validate||(()=>!0),this.value="",this.errorMsg=e.error||"Please Enter A Valid Value",this.cursor=+!!this.initial,this.cursorOffset=0,this.clear=yi("",this.out.columns),this.render()}set value(e){!e&&this.initial?(this.placeholder=!0,this.rendered=rt.gray(this.transform.render(this.initial))):(this.placeholder=!1,this.rendered=this.transform.render(e)),this._value=e,this.fire()}get value(){return this._value}reset(){this.value="",this.cursor=+!!this.initial,this.cursorOffset=0,this.fire(),this.render()}exit(){this.abort()}abort(){this.value=this.value||this.initial,this.done=this.aborted=!0,this.error=!1,this.red=!1,this.fire(),this.render(),this.out.write(`
|
|
75
75
|
`),this.close()}async validate(){let e=await this.validator(this.value);typeof e=="string"&&(this.errorMsg=e,e=!1),this.error=!e}async submit(){if(this.value=this.value||this.initial,this.cursorOffset=0,this.cursor=this.rendered.length,await this.validate(),this.error){this.red=!0,this.fire(),this.render();return}this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
76
|
-
`),this.close()}next(){if(!this.placeholder)return this.bell();this.value=this.initial,this.cursor=this.rendered.length,this.fire(),this.render()}moveCursor(e){this.placeholder||(this.cursor=this.cursor+e,this.cursorOffset+=e)}_(e,t){let s=this.value.slice(0,this.cursor),r=this.value.slice(this.cursor);this.value=`${s}${e}${r}`,this.red=!1,this.cursor=this.placeholder?0:s.length+1,this.render()}delete(){if(this.isCursorAtStart())return this.bell();let e=this.value.slice(0,this.cursor-1),t=this.value.slice(this.cursor);this.value=`${e}${t}`,this.red=!1,this.isCursorAtStart()?this.cursorOffset=0:(this.cursorOffset++,this.moveCursor(-1)),this.render()}deleteForward(){if(this.cursor*this.scale>=this.rendered.length||this.placeholder)return this.bell();let e=this.value.slice(0,this.cursor),t=this.value.slice(this.cursor+1);this.value=`${e}${t}`,this.red=!1,this.isCursorAtEnd()?this.cursorOffset=0:this.cursorOffset++,this.render()}first(){this.cursor=0,this.render()}last(){this.cursor=this.value.length,this.render()}left(){if(this.cursor<=0||this.placeholder)return this.bell();this.moveCursor(-1),this.render()}right(){if(this.cursor*this.scale>=this.rendered.length||this.placeholder)return this.bell();this.moveCursor(1),this.render()}isCursorAtStart(){return this.cursor===0||this.placeholder&&this.cursor===1}isCursorAtEnd(){return this.cursor===this.rendered.length||this.placeholder&&this.cursor===this.rendered.length+1}render(){this.closed||(this.firstRender||(this.outputError&&this.out.write(Ve.down(
|
|
76
|
+
`),this.close()}next(){if(!this.placeholder)return this.bell();this.value=this.initial,this.cursor=this.rendered.length,this.fire(),this.render()}moveCursor(e){this.placeholder||(this.cursor=this.cursor+e,this.cursorOffset+=e)}_(e,t){let s=this.value.slice(0,this.cursor),r=this.value.slice(this.cursor);this.value=`${s}${e}${r}`,this.red=!1,this.cursor=this.placeholder?0:s.length+1,this.render()}delete(){if(this.isCursorAtStart())return this.bell();let e=this.value.slice(0,this.cursor-1),t=this.value.slice(this.cursor);this.value=`${e}${t}`,this.red=!1,this.isCursorAtStart()?this.cursorOffset=0:(this.cursorOffset++,this.moveCursor(-1)),this.render()}deleteForward(){if(this.cursor*this.scale>=this.rendered.length||this.placeholder)return this.bell();let e=this.value.slice(0,this.cursor),t=this.value.slice(this.cursor+1);this.value=`${e}${t}`,this.red=!1,this.isCursorAtEnd()?this.cursorOffset=0:this.cursorOffset++,this.render()}first(){this.cursor=0,this.render()}last(){this.cursor=this.value.length,this.render()}left(){if(this.cursor<=0||this.placeholder)return this.bell();this.moveCursor(-1),this.render()}right(){if(this.cursor*this.scale>=this.rendered.length||this.placeholder)return this.bell();this.moveCursor(1),this.render()}isCursorAtStart(){return this.cursor===0||this.placeholder&&this.cursor===1}isCursorAtEnd(){return this.cursor===this.rendered.length||this.placeholder&&this.cursor===this.rendered.length+1}render(){this.closed||(this.firstRender||(this.outputError&&this.out.write(Ve.down(Ah(this.outputError,this.out.columns)-1)+yi(this.outputError,this.out.columns)),this.out.write(yi(this.outputText,this.out.columns))),super.render(),this.outputError="",this.outputText=[wi.symbol(this.done,this.aborted),rt.bold(this.msg),wi.delimiter(this.done),this.red?rt.red(this.rendered):this.rendered].join(" "),this.error&&(this.outputError+=this.errorMsg.split(`
|
|
77
77
|
`).reduce((e,t,s)=>e+`
|
|
78
|
-
${s?" "
|
|
78
|
+
${s?" ":$h.pointerSmall} ${rt.red().italic(t)}`,"")),this.out.write(Sh.line+Ve.to(0)+this.outputText+Ve.save+this.outputError+Ve.restore+Ve.move(this.cursorOffset,0)))}};eo.exports=_i});var no=c((kf,ro)=>{"use strict";var te=x(),Eh=ee(),{style:io,clear:so,figures:nt,wrap:Ph,entriesToDisplay:kh}=j(),{cursor:Th}=O(),vi=class extends Eh{constructor(e={}){super(e),this.msg=e.message,this.hint=e.hint||"- Use arrow-keys. Return to submit.",this.warn=e.warn||"- This option is disabled",this.cursor=e.initial||0,this.choices=e.choices.map((t,s)=>(typeof t=="string"&&(t={title:t,value:s}),{title:t&&(t.title||t.value||t),value:t&&(t.value===void 0?s:t.value),description:t&&t.description,selected:t&&t.selected,disabled:t&&t.disabled})),this.optionsPerPage=e.optionsPerPage||10,this.value=(this.choices[this.cursor]||{}).value,this.clear=so("",this.out.columns),this.render()}moveCursor(e){this.cursor=e,this.value=this.choices[e].value,this.fire()}reset(){this.moveCursor(0),this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
|
|
79
79
|
`),this.close()}submit(){this.selection.disabled?this.bell():(this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
80
|
-
`),this.close())}first(){this.moveCursor(0),this.render()}last(){this.moveCursor(this.choices.length-1),this.render()}up(){this.cursor===0?this.moveCursor(this.choices.length-1):this.moveCursor(this.cursor-1),this.render()}down(){this.cursor===this.choices.length-1?this.moveCursor(0):this.moveCursor(this.cursor+1),this.render()}next(){this.moveCursor((this.cursor+1)%this.choices.length),this.render()}_(e,t){if(e===" ")return this.submit()}get selection(){return this.choices[this.cursor]}render(){if(this.closed)return;this.firstRender?this.out.write(
|
|
80
|
+
`),this.close())}first(){this.moveCursor(0),this.render()}last(){this.moveCursor(this.choices.length-1),this.render()}up(){this.cursor===0?this.moveCursor(this.choices.length-1):this.moveCursor(this.cursor-1),this.render()}down(){this.cursor===this.choices.length-1?this.moveCursor(0):this.moveCursor(this.cursor+1),this.render()}next(){this.moveCursor((this.cursor+1)%this.choices.length),this.render()}_(e,t){if(e===" ")return this.submit()}get selection(){return this.choices[this.cursor]}render(){if(this.closed)return;this.firstRender?this.out.write(Th.hide):this.out.write(so(this.outputText,this.out.columns)),super.render();let{startIndex:e,endIndex:t}=kh(this.cursor,this.choices.length,this.optionsPerPage);if(this.outputText=[io.symbol(this.done,this.aborted),te.bold(this.msg),io.delimiter(!1),this.done?this.selection.title:this.selection.disabled?te.yellow(this.warn):te.gray(this.hint)].join(" "),!this.done){this.outputText+=`
|
|
81
81
|
`;for(let s=e;s<t;s++){let r,n,o="",a=this.choices[s];s===e&&e>0?n=nt.arrowUp:s===t-1&&t<this.choices.length?n=nt.arrowDown:n=" ",a.disabled?(r=this.cursor===s?te.gray().underline(a.title):te.strikethrough().gray(a.title),n=(this.cursor===s?te.bold().gray(nt.pointer)+" ":" ")+n):(r=this.cursor===s?te.cyan().underline(a.title):a.title,n=(this.cursor===s?te.cyan(nt.pointer)+" ":" ")+n,a.description&&this.cursor===s&&(o=` - ${a.description}`,(n.length+r.length+o.length>=this.out.columns||a.description.split(/\r?\n/).length>1)&&(o=`
|
|
82
|
-
|
|
83
|
-
`}}this.out.write(this.outputText)}};ro.exports=vi});var uo=c((
|
|
82
|
+
`+Ph(a.description,{margin:3,width:this.out.columns})))),this.outputText+=`${n} ${r}${te.gray(o)}
|
|
83
|
+
`}}this.out.write(this.outputText)}};ro.exports=vi});var uo=c((Tf,lo)=>{var ot=x(),Ih=ee(),{style:oo,clear:qh}=j(),{cursor:ao,erase:Mh}=O(),xi=class extends Ih{constructor(e={}){super(e),this.msg=e.message,this.value=!!e.initial,this.active=e.active||"on",this.inactive=e.inactive||"off",this.initialValue=this.value,this.render()}reset(){this.value=this.initialValue,this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
|
|
84
84
|
`),this.close()}submit(){this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
85
|
-
`),this.close()}deactivate(){if(this.value===!1)return this.bell();this.value=!1,this.render()}activate(){if(this.value===!0)return this.bell();this.value=!0,this.render()}delete(){this.deactivate()}left(){this.deactivate()}right(){this.activate()}down(){this.deactivate()}up(){this.activate()}next(){this.value=!this.value,this.fire(),this.render()}_(e,t){if(e===" ")this.value=!this.value;else if(e==="1")this.value=!0;else if(e==="0")this.value=!1;else return this.bell();this.render()}render(){this.closed||(this.firstRender?this.out.write(ao.hide):this.out.write(
|
|
85
|
+
`),this.close()}deactivate(){if(this.value===!1)return this.bell();this.value=!1,this.render()}activate(){if(this.value===!0)return this.bell();this.value=!0,this.render()}delete(){this.deactivate()}left(){this.deactivate()}right(){this.activate()}down(){this.deactivate()}up(){this.activate()}next(){this.value=!this.value,this.fire(),this.render()}_(e,t){if(e===" ")this.value=!this.value;else if(e==="1")this.value=!0;else if(e==="0")this.value=!1;else return this.bell();this.render()}render(){this.closed||(this.firstRender?this.out.write(ao.hide):this.out.write(qh(this.outputText,this.out.columns)),super.render(),this.outputText=[oo.symbol(this.done,this.aborted),ot.bold(this.msg),oo.delimiter(this.done),this.value?this.inactive:ot.cyan().underline(this.inactive),ot.gray("/"),this.value?ot.cyan().underline(this.active):this.active].join(" "),this.out.write(Mh.line+ao.to(0)+this.outputText))}};lo.exports=xi});var L=c((If,ho)=>{"use strict";var Ci=class i{constructor({token:e,date:t,parts:s,locales:r}){this.token=e,this.date=t||new Date,this.parts=s||[this],this.locales=r||{}}up(){}down(){}next(){let e=this.parts.indexOf(this);return this.parts.find((t,s)=>s>e&&t instanceof i)}setTo(e){}prev(){let e=[].concat(this.parts).reverse(),t=e.indexOf(this);return e.find((s,r)=>r>t&&s instanceof i)}toString(){return String(this.date)}};ho.exports=Ci});var fo=c((qf,co)=>{"use strict";var Dh=L(),Oi=class extends Dh{constructor(e={}){super(e)}up(){this.date.setHours((this.date.getHours()+12)%24)}down(){this.up()}toString(){let e=this.date.getHours()>12?"pm":"am";return/\A/.test(this.token)?e.toUpperCase():e}};co.exports=Oi});var mo=c((Mf,po)=>{"use strict";var Vh=L(),jh=i=>(i=i%10,i===1?"st":i===2?"nd":i===3?"rd":"th"),Si=class extends Vh{constructor(e={}){super(e)}up(){this.date.setDate(this.date.getDate()+1)}down(){this.date.setDate(this.date.getDate()-1)}setTo(e){this.date.setDate(parseInt(e.substr(-2)))}toString(){let e=this.date.getDate(),t=this.date.getDay();return this.token==="DD"?String(e).padStart(2,"0"):this.token==="Do"?e+jh(e):this.token==="d"?t+1:this.token==="ddd"?this.locales.weekdaysShort[t]:this.token==="dddd"?this.locales.weekdays[t]:e}};po.exports=Si});var bo=c((Df,go)=>{"use strict";var Hh=L(),Ai=class extends Hh{constructor(e={}){super(e)}up(){this.date.setHours(this.date.getHours()+1)}down(){this.date.setHours(this.date.getHours()-1)}setTo(e){this.date.setHours(parseInt(e.substr(-2)))}toString(){let e=this.date.getHours();return/h/.test(this.token)&&(e=e%12||12),this.token.length>1?String(e).padStart(2,"0"):e}};go.exports=Ai});var yo=c((Vf,wo)=>{"use strict";var Fh=L(),$i=class extends Fh{constructor(e={}){super(e)}up(){this.date.setMilliseconds(this.date.getMilliseconds()+1)}down(){this.date.setMilliseconds(this.date.getMilliseconds()-1)}setTo(e){this.date.setMilliseconds(parseInt(e.substr(-this.token.length)))}toString(){return String(this.date.getMilliseconds()).padStart(4,"0").substr(0,this.token.length)}};wo.exports=$i});var vo=c((jf,_o)=>{"use strict";var Rh=L(),Ei=class extends Rh{constructor(e={}){super(e)}up(){this.date.setMinutes(this.date.getMinutes()+1)}down(){this.date.setMinutes(this.date.getMinutes()-1)}setTo(e){this.date.setMinutes(parseInt(e.substr(-2)))}toString(){let e=this.date.getMinutes();return this.token.length>1?String(e).padStart(2,"0"):e}};_o.exports=Ei});var Co=c((Hf,xo)=>{"use strict";var Nh=L(),Pi=class extends Nh{constructor(e={}){super(e)}up(){this.date.setMonth(this.date.getMonth()+1)}down(){this.date.setMonth(this.date.getMonth()-1)}setTo(e){e=parseInt(e.substr(-2))-1,this.date.setMonth(e<0?0:e)}toString(){let e=this.date.getMonth(),t=this.token.length;return t===2?String(e+1).padStart(2,"0"):t===3?this.locales.monthsShort[e]:t===4?this.locales.months[e]:String(e+1)}};xo.exports=Pi});var So=c((Ff,Oo)=>{"use strict";var Lh=L(),ki=class extends Lh{constructor(e={}){super(e)}up(){this.date.setSeconds(this.date.getSeconds()+1)}down(){this.date.setSeconds(this.date.getSeconds()-1)}setTo(e){this.date.setSeconds(parseInt(e.substr(-2)))}toString(){let e=this.date.getSeconds();return this.token.length>1?String(e).padStart(2,"0"):e}};Oo.exports=ki});var $o=c((Rf,Ao)=>{"use strict";var Uh=L(),Ti=class extends Uh{constructor(e={}){super(e)}up(){this.date.setFullYear(this.date.getFullYear()+1)}down(){this.date.setFullYear(this.date.getFullYear()-1)}setTo(e){this.date.setFullYear(e.substr(-4))}toString(){let e=String(this.date.getFullYear()).padStart(4,"0");return this.token.length===2?e.substr(-2):e}};Ao.exports=Ti});var Po=c((Nf,Eo)=>{"use strict";Eo.exports={DatePart:L(),Meridiem:fo(),Day:mo(),Hours:bo(),Milliseconds:yo(),Minutes:vo(),Month:Co(),Seconds:So(),Year:$o()}});var Vo=c((Lf,Do)=>{"use strict";var Ii=x(),Gh=ee(),{style:ko,clear:To,figures:Bh}=j(),{erase:Yh,cursor:Io}=O(),{DatePart:qo,Meridiem:Wh,Day:Jh,Hours:Kh,Milliseconds:zh,Minutes:Zh,Month:Xh,Seconds:Qh,Year:ec}=Po(),tc=/\\(.)|"((?:\\["\\]|[^"])+)"|(D[Do]?|d{3,4}|d)|(M{1,4})|(YY(?:YY)?)|([aA])|([Hh]{1,2})|(m{1,2})|(s{1,2})|(S{1,4})|./g,Mo={1:({token:i})=>i.replace(/\\(.)/g,"$1"),2:i=>new Jh(i),3:i=>new Xh(i),4:i=>new ec(i),5:i=>new Wh(i),6:i=>new Kh(i),7:i=>new Zh(i),8:i=>new Qh(i),9:i=>new zh(i)},ic={months:"January,February,March,April,May,June,July,August,September,October,November,December".split(","),monthsShort:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","),weekdays:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","),weekdaysShort:"Sun,Mon,Tue,Wed,Thu,Fri,Sat".split(",")},qi=class extends Gh{constructor(e={}){super(e),this.msg=e.message,this.cursor=0,this.typed="",this.locales=Object.assign(ic,e.locales),this._date=e.initial||new Date,this.errorMsg=e.error||"Please Enter A Valid Value",this.validator=e.validate||(()=>!0),this.mask=e.mask||"YYYY-MM-DD HH:mm:ss",this.clear=To("",this.out.columns),this.render()}get value(){return this.date}get date(){return this._date}set date(e){e&&this._date.setTime(e.getTime())}set mask(e){let t;for(this.parts=[];t=tc.exec(e);){let r=t.shift(),n=t.findIndex(o=>o!=null);this.parts.push(n in Mo?Mo[n]({token:t[n]||r,date:this.date,parts:this.parts,locales:this.locales}):t[n]||r)}let s=this.parts.reduce((r,n)=>(typeof n=="string"&&typeof r[r.length-1]=="string"?r[r.length-1]+=n:r.push(n),r),[]);this.parts.splice(0),this.parts.push(...s),this.reset()}moveCursor(e){this.typed="",this.cursor=e,this.fire()}reset(){this.moveCursor(this.parts.findIndex(e=>e instanceof qo)),this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.error=!1,this.fire(),this.render(),this.out.write(`
|
|
86
86
|
`),this.close()}async validate(){let e=await this.validator(this.value);typeof e=="string"&&(this.errorMsg=e,e=!1),this.error=!e}async submit(){if(await this.validate(),this.error){this.color="red",this.fire(),this.render();return}this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
87
87
|
`),this.close()}up(){this.typed="",this.parts[this.cursor].up(),this.render()}down(){this.typed="",this.parts[this.cursor].down(),this.render()}left(){let e=this.parts[this.cursor].prev();if(e==null)return this.bell();this.moveCursor(this.parts.indexOf(e)),this.render()}right(){let e=this.parts[this.cursor].next();if(e==null)return this.bell();this.moveCursor(this.parts.indexOf(e)),this.render()}next(){let e=this.parts[this.cursor].next();this.moveCursor(e?this.parts.indexOf(e):this.parts.findIndex(t=>t instanceof qo)),this.render()}_(e){/\d/.test(e)&&(this.typed+=e,this.parts[this.cursor].setTo(this.typed),this.render())}render(){this.closed||(this.firstRender?this.out.write(Io.hide):this.out.write(To(this.outputText,this.out.columns)),super.render(),this.outputText=[ko.symbol(this.done,this.aborted),Ii.bold(this.msg),ko.delimiter(!1),this.parts.reduce((e,t,s)=>e.concat(s===this.cursor&&!this.done?Ii.cyan().underline(t.toString()):t),[]).join("")].join(" "),this.error&&(this.outputText+=this.errorMsg.split(`
|
|
88
88
|
`).reduce((e,t,s)=>e+`
|
|
89
|
-
${s?" ":
|
|
89
|
+
${s?" ":Bh.pointerSmall} ${Ii.red().italic(t)}`,"")),this.out.write(Yh.line+Io.to(0)+this.outputText))}};Do.exports=qi});var Ro=c((Uf,Fo)=>{var at=x(),sc=ee(),{cursor:lt,erase:rc}=O(),{style:Mi,figures:nc,clear:jo,lines:oc}=j(),ac=/[0-9]/,Di=i=>i!==void 0,Ho=(i,e)=>{let t=Math.pow(10,e);return Math.round(i*t)/t},Vi=class extends sc{constructor(e={}){super(e),this.transform=Mi.render(e.style),this.msg=e.message,this.initial=Di(e.initial)?e.initial:"",this.float=!!e.float,this.round=e.round||2,this.inc=e.increment||1,this.min=Di(e.min)?e.min:-1/0,this.max=Di(e.max)?e.max:1/0,this.errorMsg=e.error||"Please Enter A Valid Value",this.validator=e.validate||(()=>!0),this.color="cyan",this.value="",this.typed="",this.lastHit=0,this.render()}set value(e){!e&&e!==0?(this.placeholder=!0,this.rendered=at.gray(this.transform.render(`${this.initial}`)),this._value=""):(this.placeholder=!1,this.rendered=this.transform.render(`${Ho(e,this.round)}`),this._value=Ho(e,this.round)),this.fire()}get value(){return this._value}parse(e){return this.float?parseFloat(e):parseInt(e)}valid(e){return e==="-"||e==="."&&this.float||ac.test(e)}reset(){this.typed="",this.value="",this.fire(),this.render()}exit(){this.abort()}abort(){let e=this.value;this.value=e!==""?e:this.initial,this.done=this.aborted=!0,this.error=!1,this.fire(),this.render(),this.out.write(`
|
|
90
90
|
`),this.close()}async validate(){let e=await this.validator(this.value);typeof e=="string"&&(this.errorMsg=e,e=!1),this.error=!e}async submit(){if(await this.validate(),this.error){this.color="red",this.fire(),this.render();return}let e=this.value;this.value=e!==""?e:this.initial,this.done=!0,this.aborted=!1,this.error=!1,this.fire(),this.render(),this.out.write(`
|
|
91
|
-
`),this.close()}up(){if(this.typed="",this.value===""&&(this.value=this.min-this.inc),this.value>=this.max)return this.bell();this.value+=this.inc,this.color="cyan",this.fire(),this.render()}down(){if(this.typed="",this.value===""&&(this.value=this.min+this.inc),this.value<=this.min)return this.bell();this.value-=this.inc,this.color="cyan",this.fire(),this.render()}delete(){let e=this.value.toString();if(e.length===0)return this.bell();this.value=this.parse(e=e.slice(0,-1))||"",this.value!==""&&this.value<this.min&&(this.value=this.min),this.color="cyan",this.fire(),this.render()}next(){this.value=this.initial,this.fire(),this.render()}_(e,t){if(!this.valid(e))return this.bell();let s=Date.now();if(s-this.lastHit>1e3&&(this.typed=""),this.typed+=e,this.lastHit=s,this.color="cyan",e===".")return this.fire();this.value=Math.min(this.parse(this.typed),this.max),this.value>this.max&&(this.value=this.max),this.value<this.min&&(this.value=this.min),this.fire(),this.render()}render(){this.closed||(this.firstRender||(this.outputError&&this.out.write(lt.down(
|
|
91
|
+
`),this.close()}up(){if(this.typed="",this.value===""&&(this.value=this.min-this.inc),this.value>=this.max)return this.bell();this.value+=this.inc,this.color="cyan",this.fire(),this.render()}down(){if(this.typed="",this.value===""&&(this.value=this.min+this.inc),this.value<=this.min)return this.bell();this.value-=this.inc,this.color="cyan",this.fire(),this.render()}delete(){let e=this.value.toString();if(e.length===0)return this.bell();this.value=this.parse(e=e.slice(0,-1))||"",this.value!==""&&this.value<this.min&&(this.value=this.min),this.color="cyan",this.fire(),this.render()}next(){this.value=this.initial,this.fire(),this.render()}_(e,t){if(!this.valid(e))return this.bell();let s=Date.now();if(s-this.lastHit>1e3&&(this.typed=""),this.typed+=e,this.lastHit=s,this.color="cyan",e===".")return this.fire();this.value=Math.min(this.parse(this.typed),this.max),this.value>this.max&&(this.value=this.max),this.value<this.min&&(this.value=this.min),this.fire(),this.render()}render(){this.closed||(this.firstRender||(this.outputError&&this.out.write(lt.down(oc(this.outputError,this.out.columns)-1)+jo(this.outputError,this.out.columns)),this.out.write(jo(this.outputText,this.out.columns))),super.render(),this.outputError="",this.outputText=[Mi.symbol(this.done,this.aborted),at.bold(this.msg),Mi.delimiter(this.done),!this.done||!this.done&&!this.placeholder?at[this.color]().underline(this.rendered):this.rendered].join(" "),this.error&&(this.outputError+=this.errorMsg.split(`
|
|
92
92
|
`).reduce((e,t,s)=>e+`
|
|
93
|
-
${s?" ":
|
|
93
|
+
${s?" ":nc.pointerSmall} ${at.red().italic(t)}`,"")),this.out.write(rc.line+lt.to(0)+this.outputText+lt.save+this.outputError+lt.restore))}};Fo.exports=Vi});var Hi=c((Gf,Uo)=>{"use strict";var U=x(),{cursor:lc}=O(),uc=ee(),{clear:No,figures:le,style:Lo,wrap:hc,entriesToDisplay:cc}=j(),ji=class extends uc{constructor(e={}){super(e),this.msg=e.message,this.cursor=e.cursor||0,this.scrollIndex=e.cursor||0,this.hint=e.hint||"",this.warn=e.warn||"- This option is disabled -",this.minSelected=e.min,this.showMinError=!1,this.maxChoices=e.max,this.instructions=e.instructions,this.optionsPerPage=e.optionsPerPage||10,this.value=e.choices.map((t,s)=>(typeof t=="string"&&(t={title:t,value:s}),{title:t&&(t.title||t.value||t),description:t&&t.description,value:t&&(t.value===void 0?s:t.value),selected:t&&t.selected,disabled:t&&t.disabled})),this.clear=No("",this.out.columns),e.overrideRender||this.render()}reset(){this.value.map(e=>!e.selected),this.cursor=0,this.fire(),this.render()}selected(){return this.value.filter(e=>e.selected)}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
|
|
94
94
|
`),this.close()}submit(){let e=this.value.filter(t=>t.selected);this.minSelected&&e.length<this.minSelected?(this.showMinError=!0,this.render()):(this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
95
95
|
`),this.close())}first(){this.cursor=0,this.render()}last(){this.cursor=this.value.length-1,this.render()}next(){this.cursor=(this.cursor+1)%this.value.length,this.render()}up(){this.cursor===0?this.cursor=this.value.length-1:this.cursor--,this.render()}down(){this.cursor===this.value.length-1?this.cursor=0:this.cursor++,this.render()}left(){this.value[this.cursor].selected=!1,this.render()}right(){if(this.value.filter(e=>e.selected).length>=this.maxChoices)return this.bell();this.value[this.cursor].selected=!0,this.render()}handleSpaceToggle(){let e=this.value[this.cursor];if(e.selected)e.selected=!1,this.render();else{if(e.disabled||this.value.filter(t=>t.selected).length>=this.maxChoices)return this.bell();e.selected=!0,this.render()}}toggleAll(){if(this.maxChoices!==void 0||this.value[this.cursor].disabled)return this.bell();let e=!this.value[this.cursor].selected;this.value.filter(t=>!t.disabled).forEach(t=>t.selected=e),this.render()}_(e,t){if(e===" ")this.handleSpaceToggle();else if(e==="a")this.toggleAll();else return this.bell()}renderInstructions(){return this.instructions===void 0||this.instructions?typeof this.instructions=="string"?this.instructions:`
|
|
96
96
|
Instructions:
|
|
@@ -98,15 +98,15 @@ Instructions:
|
|
|
98
98
|
${le.arrowLeft}/${le.arrowRight}/[space]: Toggle selection
|
|
99
99
|
`+(this.maxChoices===void 0?` a: Toggle all
|
|
100
100
|
`:"")+" enter/return: Complete answer":""}renderOption(e,t,s,r){let n=(t.selected?U.green(le.radioOn):le.radioOff)+" "+r+" ",o,a;return t.disabled?o=e===s?U.gray().underline(t.title):U.strikethrough().gray(t.title):(o=e===s?U.cyan().underline(t.title):t.title,e===s&&t.description&&(a=` - ${t.description}`,(n.length+o.length+a.length>=this.out.columns||t.description.split(/\r?\n/).length>1)&&(a=`
|
|
101
|
-
`+
|
|
101
|
+
`+hc(t.description,{margin:n.length,width:this.out.columns})))),n+o+U.gray(a||"")}paginateOptions(e){if(e.length===0)return U.red("No matches for this query.");let{startIndex:t,endIndex:s}=cc(this.cursor,e.length,this.optionsPerPage),r,n=[];for(let o=t;o<s;o++)o===t&&t>0?r=le.arrowUp:o===s-1&&s<e.length?r=le.arrowDown:r=" ",n.push(this.renderOption(this.cursor,e[o],o,r));return`
|
|
102
102
|
`+n.join(`
|
|
103
|
-
`)}renderOptions(e){return this.done?"":this.paginateOptions(e)}renderDoneOrInstructions(){if(this.done)return this.value.filter(t=>t.selected).map(t=>t.title).join(", ");let e=[U.gray(this.hint),this.renderInstructions()];return this.value[this.cursor].disabled&&e.push(U.yellow(this.warn)),e.join(" ")}render(){if(this.closed)return;this.firstRender&&this.out.write(
|
|
103
|
+
`)}renderOptions(e){return this.done?"":this.paginateOptions(e)}renderDoneOrInstructions(){if(this.done)return this.value.filter(t=>t.selected).map(t=>t.title).join(", ");let e=[U.gray(this.hint),this.renderInstructions()];return this.value[this.cursor].disabled&&e.push(U.yellow(this.warn)),e.join(" ")}render(){if(this.closed)return;this.firstRender&&this.out.write(lc.hide),super.render();let e=[Lo.symbol(this.done,this.aborted),U.bold(this.msg),Lo.delimiter(!1),this.renderDoneOrInstructions()].join(" ");this.showMinError&&(e+=U.red(`You must select a minimum of ${this.minSelected} choices.`),this.showMinError=!1),e+=this.renderOptions(this.value),this.out.write(this.clear+e),this.clear=No(e,this.out.columns)}};Uo.exports=ji});var Jo=c((Bf,Wo)=>{"use strict";var je=x(),dc=ee(),{erase:fc,cursor:Go}=O(),{style:Fi,clear:Bo,figures:Ri,wrap:pc,entriesToDisplay:mc}=j(),Yo=(i,e)=>i[e]&&(i[e].value||i[e].title||i[e]),gc=(i,e)=>i[e]&&(i[e].title||i[e].value||i[e]),bc=(i,e)=>{let t=i.findIndex(s=>s.value===e||s.title===e);return t>-1?t:void 0},Ni=class extends dc{constructor(e={}){super(e),this.msg=e.message,this.suggest=e.suggest,this.choices=e.choices,this.initial=typeof e.initial=="number"?e.initial:bc(e.choices,e.initial),this.select=this.initial||e.cursor||0,this.i18n={noMatches:e.noMatches||"no matches found"},this.fallback=e.fallback||this.initial,this.clearFirst=e.clearFirst||!1,this.suggestions=[],this.input="",this.limit=e.limit||10,this.cursor=0,this.transform=Fi.render(e.style),this.scale=this.transform.scale,this.render=this.render.bind(this),this.complete=this.complete.bind(this),this.clear=Bo("",this.out.columns),this.complete(this.render),this.render()}set fallback(e){this._fb=Number.isSafeInteger(parseInt(e))?parseInt(e):e}get fallback(){let e;return typeof this._fb=="number"?e=this.choices[this._fb]:typeof this._fb=="string"&&(e={title:this._fb}),e||this._fb||{title:this.i18n.noMatches}}moveSelect(e){this.select=e,this.suggestions.length>0?this.value=Yo(this.suggestions,e):this.value=this.fallback.value,this.fire()}async complete(e){let t=this.completing=this.suggest(this.input,this.choices),s=await t;if(this.completing!==t)return;this.suggestions=s.map((n,o,a)=>({title:gc(a,o),value:Yo(a,o),description:n.description})),this.completing=!1;let r=Math.max(s.length-1,0);this.moveSelect(Math.min(r,this.select)),e&&e()}reset(){this.input="",this.complete(()=>{this.moveSelect(this.initial!==void 0?this.initial:0),this.render()}),this.render()}exit(){this.clearFirst&&this.input.length>0?this.reset():(this.done=this.exited=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
104
104
|
`),this.close())}abort(){this.done=this.aborted=!0,this.exited=!1,this.fire(),this.render(),this.out.write(`
|
|
105
105
|
`),this.close()}submit(){this.done=!0,this.aborted=this.exited=!1,this.fire(),this.render(),this.out.write(`
|
|
106
106
|
`),this.close()}_(e,t){let s=this.input.slice(0,this.cursor),r=this.input.slice(this.cursor);this.input=`${s}${e}${r}`,this.cursor=s.length+1,this.complete(this.render),this.render()}delete(){if(this.cursor===0)return this.bell();let e=this.input.slice(0,this.cursor-1),t=this.input.slice(this.cursor);this.input=`${e}${t}`,this.complete(this.render),this.cursor=this.cursor-1,this.render()}deleteForward(){if(this.cursor*this.scale>=this.rendered.length)return this.bell();let e=this.input.slice(0,this.cursor),t=this.input.slice(this.cursor+1);this.input=`${e}${t}`,this.complete(this.render),this.render()}first(){this.moveSelect(0),this.render()}last(){this.moveSelect(this.suggestions.length-1),this.render()}up(){this.select===0?this.moveSelect(this.suggestions.length-1):this.moveSelect(this.select-1),this.render()}down(){this.select===this.suggestions.length-1?this.moveSelect(0):this.moveSelect(this.select+1),this.render()}next(){this.select===this.suggestions.length-1?this.moveSelect(0):this.moveSelect(this.select+1),this.render()}nextPage(){this.moveSelect(Math.min(this.select+this.limit,this.suggestions.length-1)),this.render()}prevPage(){this.moveSelect(Math.max(this.select-this.limit,0)),this.render()}left(){if(this.cursor<=0)return this.bell();this.cursor=this.cursor-1,this.render()}right(){if(this.cursor*this.scale>=this.rendered.length)return this.bell();this.cursor=this.cursor+1,this.render()}renderOption(e,t,s,r){let n,o=s?Ri.arrowUp:r?Ri.arrowDown:" ",a=t?je.cyan().underline(e.title):e.title;return o=(t?je.cyan(Ri.pointer)+" ":" ")+o,e.description&&(n=` - ${e.description}`,(o.length+a.length+n.length>=this.out.columns||e.description.split(/\r?\n/).length>1)&&(n=`
|
|
107
|
-
`+
|
|
107
|
+
`+pc(e.description,{margin:3,width:this.out.columns}))),o+" "+a+je.gray(n||"")}render(){if(this.closed)return;this.firstRender?this.out.write(Go.hide):this.out.write(Bo(this.outputText,this.out.columns)),super.render();let{startIndex:e,endIndex:t}=mc(this.select,this.choices.length,this.limit);if(this.outputText=[Fi.symbol(this.done,this.aborted,this.exited),je.bold(this.msg),Fi.delimiter(this.completing),this.done&&this.suggestions[this.select]?this.suggestions[this.select].title:this.rendered=this.transform.render(this.input)].join(" "),!this.done){let s=this.suggestions.slice(e,t).map((r,n)=>this.renderOption(r,this.select===n+e,n===0&&e>0,n+e===t-1&&t<this.choices.length)).join(`
|
|
108
108
|
`);this.outputText+=`
|
|
109
|
-
`+(s||je.gray(this.fallback.title))}this.out.write(
|
|
109
|
+
`+(s||je.gray(this.fallback.title))}this.out.write(fc.line+Go.to(0)+this.outputText)}};Wo.exports=Ni});var Xo=c((Yf,Zo)=>{"use strict";var ie=x(),{cursor:wc}=O(),yc=Hi(),{clear:Ko,style:zo,figures:Ce}=j(),Li=class extends yc{constructor(e={}){e.overrideRender=!0,super(e),this.inputValue="",this.clear=Ko("",this.out.columns),this.filteredOptions=this.value,this.render()}last(){this.cursor=this.filteredOptions.length-1,this.render()}next(){this.cursor=(this.cursor+1)%this.filteredOptions.length,this.render()}up(){this.cursor===0?this.cursor=this.filteredOptions.length-1:this.cursor--,this.render()}down(){this.cursor===this.filteredOptions.length-1?this.cursor=0:this.cursor++,this.render()}left(){this.filteredOptions[this.cursor].selected=!1,this.render()}right(){if(this.value.filter(e=>e.selected).length>=this.maxChoices)return this.bell();this.filteredOptions[this.cursor].selected=!0,this.render()}delete(){this.inputValue.length&&(this.inputValue=this.inputValue.substr(0,this.inputValue.length-1),this.updateFilteredOptions())}updateFilteredOptions(){let e=this.filteredOptions[this.cursor];this.filteredOptions=this.value.filter(s=>this.inputValue?!!(typeof s.title=="string"&&s.title.toLowerCase().includes(this.inputValue.toLowerCase())||typeof s.value=="string"&&s.value.toLowerCase().includes(this.inputValue.toLowerCase())):!0);let t=this.filteredOptions.findIndex(s=>s===e);this.cursor=t<0?0:t,this.render()}handleSpaceToggle(){let e=this.filteredOptions[this.cursor];if(e.selected)e.selected=!1,this.render();else{if(e.disabled||this.value.filter(t=>t.selected).length>=this.maxChoices)return this.bell();e.selected=!0,this.render()}}handleInputChange(e){this.inputValue=this.inputValue+e,this.updateFilteredOptions()}_(e,t){e===" "?this.handleSpaceToggle():this.handleInputChange(e)}renderInstructions(){return this.instructions===void 0||this.instructions?typeof this.instructions=="string"?this.instructions:`
|
|
110
110
|
Instructions:
|
|
111
111
|
${Ce.arrowUp}/${Ce.arrowDown}: Highlight option
|
|
112
112
|
${Ce.arrowLeft}/${Ce.arrowRight}/[space]: Toggle selection
|
|
@@ -114,24 +114,24 @@ Instructions:
|
|
|
114
114
|
enter/return: Complete answer
|
|
115
115
|
`:""}renderCurrentInput(){return`
|
|
116
116
|
Filtered results for: ${this.inputValue?this.inputValue:ie.gray("Enter something to filter")}
|
|
117
|
-
`}renderOption(e,t,s){let r;return t.disabled?r=e===s?ie.gray().underline(t.title):ie.strikethrough().gray(t.title):r=e===s?ie.cyan().underline(t.title):t.title,(t.selected?ie.green(Ce.radioOn):Ce.radioOff)+" "+r}renderDoneOrInstructions(){if(this.done)return this.value.filter(t=>t.selected).map(t=>t.title).join(", ");let e=[ie.gray(this.hint),this.renderInstructions(),this.renderCurrentInput()];return this.filteredOptions.length&&this.filteredOptions[this.cursor].disabled&&e.push(ie.yellow(this.warn)),e.join(" ")}render(){if(this.closed)return;this.firstRender&&this.out.write(
|
|
117
|
+
`}renderOption(e,t,s){let r;return t.disabled?r=e===s?ie.gray().underline(t.title):ie.strikethrough().gray(t.title):r=e===s?ie.cyan().underline(t.title):t.title,(t.selected?ie.green(Ce.radioOn):Ce.radioOff)+" "+r}renderDoneOrInstructions(){if(this.done)return this.value.filter(t=>t.selected).map(t=>t.title).join(", ");let e=[ie.gray(this.hint),this.renderInstructions(),this.renderCurrentInput()];return this.filteredOptions.length&&this.filteredOptions[this.cursor].disabled&&e.push(ie.yellow(this.warn)),e.join(" ")}render(){if(this.closed)return;this.firstRender&&this.out.write(wc.hide),super.render();let e=[zo.symbol(this.done,this.aborted),ie.bold(this.msg),zo.delimiter(!1),this.renderDoneOrInstructions()].join(" ");this.showMinError&&(e+=ie.red(`You must select a minimum of ${this.minSelected} choices.`),this.showMinError=!1),e+=this.renderOptions(this.filteredOptions),this.out.write(this.clear+e),this.clear=Ko(e,this.out.columns)}};Zo.exports=Li});var sa=c((Wf,ia)=>{var Qo=x(),_c=ee(),{style:ea,clear:vc}=j(),{erase:xc,cursor:ta}=O(),Ui=class extends _c{constructor(e={}){super(e),this.msg=e.message,this.value=e.initial,this.initialValue=!!e.initial,this.yesMsg=e.yes||"yes",this.yesOption=e.yesOption||"(Y/n)",this.noMsg=e.no||"no",this.noOption=e.noOption||"(y/N)",this.render()}reset(){this.value=this.initialValue,this.fire(),this.render()}exit(){this.abort()}abort(){this.done=this.aborted=!0,this.fire(),this.render(),this.out.write(`
|
|
118
118
|
`),this.close()}submit(){this.value=this.value||!1,this.done=!0,this.aborted=!1,this.fire(),this.render(),this.out.write(`
|
|
119
|
-
`),this.close()}_(e,t){return e.toLowerCase()==="y"?(this.value=!0,this.submit()):e.toLowerCase()==="n"?(this.value=!1,this.submit()):this.bell()}render(){this.closed||(this.firstRender?this.out.write(ta.hide):this.out.write(yc(this.outputText,this.out.columns)),super.render(),this.outputText=[ea.symbol(this.done,this.aborted),Qo.bold(this.msg),ea.delimiter(this.done),this.done?this.value?this.yesMsg:this.noMsg:Qo.gray(this.initialValue?this.yesOption:this.noOption)].join(" "),this.out.write(_c.line+ta.to(0)+this.outputText))}};ia.exports=Ui});var na=c((Bf,ra)=>{"use strict";ra.exports={TextPrompt:to(),SelectPrompt:no(),TogglePrompt:uo(),DatePrompt:Vo(),NumberPrompt:Ro(),MultiselectPrompt:Hi(),AutocompletePrompt:Jo(),AutocompleteMultiselectPrompt:Xo(),ConfirmPrompt:sa()}});var aa=c(oa=>{"use strict";var T=oa,vc=na(),ut=i=>i;function G(i,e,t={}){return new Promise((s,r)=>{let n=new vc[i](e),o=t.onAbort||ut,a=t.onSubmit||ut,l=t.onExit||ut;n.on("state",e.onState||ut),n.on("submit",u=>s(a(u))),n.on("exit",u=>s(l(u))),n.on("abort",u=>r(o(u)))})}T.text=i=>G("TextPrompt",i);T.password=i=>(i.style="password",T.text(i));T.invisible=i=>(i.style="invisible",T.text(i));T.number=i=>G("NumberPrompt",i);T.date=i=>G("DatePrompt",i);T.confirm=i=>G("ConfirmPrompt",i);T.list=i=>{let e=i.separator||",";return G("TextPrompt",i,{onSubmit:t=>t.split(e).map(s=>s.trim())})};T.toggle=i=>G("TogglePrompt",i);T.select=i=>G("SelectPrompt",i);T.multiselect=i=>{i.choices=[].concat(i.choices||[]);let e=t=>t.filter(s=>s.selected).map(s=>s.value);return G("MultiselectPrompt",i,{onAbort:e,onSubmit:e})};T.autocompleteMultiselect=i=>{i.choices=[].concat(i.choices||[]);let e=t=>t.filter(s=>s.selected).map(s=>s.value);return G("AutocompleteMultiselectPrompt",i,{onAbort:e,onSubmit:e})};var xc=(i,e)=>Promise.resolve(e.filter(t=>t.title.slice(0,i.length).toLowerCase()===i.toLowerCase()));T.autocomplete=i=>(i.suggest=i.suggest||xc,i.choices=[].concat(i.choices||[]),G("AutocompletePrompt",i))});var ha=c((Wf,ua)=>{"use strict";var Gi=aa(),Cc=["suggest","format","onState","validate","onRender","type"],la=()=>{};async function ue(i=[],{onSubmit:e=la,onCancel:t=la}={}){let s={},r=ue._override||{};i=[].concat(i);let n,o,a,l,u,d,p=async(m,v,w=!1)=>{if(!(!w&&m.validate&&m.validate(v)!==!0))return m.format?await m.format(v,s):v};for(o of i)if({name:l,type:u}=o,typeof u=="function"&&(u=await u(n,{...s},o),o.type=u),!!u){for(let m in o){if(Cc.includes(m))continue;let v=o[m];o[m]=typeof v=="function"?await v(n,{...s},d):v}if(d=o,typeof o.message!="string")throw new Error("prompt message is required");if({name:l,type:u}=o,Gi[u]===void 0)throw new Error(`prompt type (${u}) is not defined`);if(r[o.name]!==void 0&&(n=await p(o,r[o.name]),n!==void 0)){s[l]=n;continue}try{n=ue._injected?Oc(ue._injected,o.initial):await Gi[u](o),s[l]=n=await p(o,n,!0),a=await e(o,n,s)}catch{a=!await t(o,s)}if(a)return s}return s}function Oc(i,e){let t=i.shift();if(t instanceof Error)throw t;return t===void 0?e:t}function Sc(i){ue._injected=(ue._injected||[]).concat(i)}function Ac(i){ue._override=Object.assign({},i)}ua.exports=Object.assign(ue,{prompt:ue,prompts:Gi,inject:Sc,override:Ac})});var He=c((Jf,ca)=>{function $c(i){i=(Array.isArray(i)?i:i.split(".")).map(Number);let e=0,t=process.versions.node.split(".").map(Number);for(;e<i.length;e++){if(t[e]>i[e])return!1;if(i[e]>t[e])return!0}return!1}ca.exports=$c("8.6.0")?Dn():ha()});var $s=$(As(),1),{program:Od,createCommand:Sd,createArgument:Ad,createOption:$d,CommanderError:Ed,InvalidArgumentError:Pd,InvalidOptionArgumentError:kd,Command:Es,Argument:Td,Option:Ps,Help:Id}=$s.default;var qt,Ts,Is,qs,Ms=!0;typeof process<"u"&&({FORCE_COLOR:qt,NODE_DISABLE_COLORS:Ts,NO_COLOR:Is,TERM:qs}=process.env||{},Ms=process.stdout&&process.stdout.isTTY);var g={enabled:!Ts&&Is==null&&qs!=="dumb"&&(qt!=null&&qt!=="0"||Ms),reset:y(0,0),bold:y(1,22),dim:y(2,22),italic:y(3,23),underline:y(4,24),inverse:y(7,27),hidden:y(8,28),strikethrough:y(9,29),black:y(30,39),red:y(31,39),green:y(32,39),yellow:y(33,39),blue:y(34,39),magenta:y(35,39),cyan:y(36,39),white:y(37,39),gray:y(90,39),grey:y(90,39),bgBlack:y(40,49),bgRed:y(41,49),bgGreen:y(42,49),bgYellow:y(43,49),bgBlue:y(44,49),bgMagenta:y(45,49),bgCyan:y(46,49),bgWhite:y(47,49)};function ks(i,e){let t=0,s,r="",n="";for(;t<i.length;t++)s=i[t],r+=s.open,n+=s.close,~e.indexOf(s.close)&&(e=e.replace(s.rgx,s.close+s.open));return r+e+n}function Cl(i,e){let t={has:i,keys:e};return t.reset=g.reset.bind(t),t.bold=g.bold.bind(t),t.dim=g.dim.bind(t),t.italic=g.italic.bind(t),t.underline=g.underline.bind(t),t.inverse=g.inverse.bind(t),t.hidden=g.hidden.bind(t),t.strikethrough=g.strikethrough.bind(t),t.black=g.black.bind(t),t.red=g.red.bind(t),t.green=g.green.bind(t),t.yellow=g.yellow.bind(t),t.blue=g.blue.bind(t),t.magenta=g.magenta.bind(t),t.cyan=g.cyan.bind(t),t.white=g.white.bind(t),t.gray=g.gray.bind(t),t.grey=g.grey.bind(t),t.bgBlack=g.bgBlack.bind(t),t.bgRed=g.bgRed.bind(t),t.bgGreen=g.bgGreen.bind(t),t.bgYellow=g.bgYellow.bind(t),t.bgBlue=g.bgBlue.bind(t),t.bgMagenta=g.bgMagenta.bind(t),t.bgCyan=g.bgCyan.bind(t),t.bgWhite=g.bgWhite.bind(t),t}function y(i,e){let t={open:`\x1B[${i}m`,close:`\x1B[${e}m`,rgx:new RegExp(`\\x1b\\[${e}m`,"g")};return function(s){return this!==void 0&&this.has!==void 0?(~this.has.indexOf(i)||(this.has.push(i),this.keys.push(t)),s===void 0?this:g.enabled?ks(this.keys,s+""):s+""):s===void 0?Cl([i],[t]):g.enabled?ks([t],s+""):s+""}}var h=g;var ht=$(He(),1),Wi=$(require("node:readline"),1);var be=$(require("node:fs"),1),Oe=$(require("node:path"),1),fa=$(require("node:os"),1),pa=require("node:crypto"),Ec=Oe.default.join(fa.default.homedir(),".flapcode"),Pc=Oe.default.join(Ec,"config.json"),kc=Oe.default.join(process.cwd(),".flapcode"),da=Oe.default.join(kc,"config.json"),Bi={api_base:"https://flapcode.com",api_token:null,current_claude_account:null,current_codex_account:null,machine_id:null};function A(){let i=ba();if(!be.default.existsSync(i))return{...Bi};try{return{...Bi,...JSON.parse(be.default.readFileSync(i,"utf8"))}}catch{return{...Bi}}}function D(i){let e=ba(),t=Oe.default.dirname(e);be.default.existsSync(t)||be.default.mkdirSync(t,{recursive:!0});let s=A();be.default.writeFileSync(e,JSON.stringify({...s,...i},null,2),"utf8")}function ma(){D({api_token:null})}function ga(){let i=A();if(i.machine_id)return i.machine_id;let e=(0,pa.randomBytes)(32).toString("hex");return D({machine_id:e}),e}function ba(){return be.default.existsSync(da)?da:Pc}var he=class extends Error{constructor(e,t){super(e),this.statusCode=t}};async function Fe(i,e={}){let t=A();if(!t.api_token)throw new he("\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u8FD0\u884C flapcode login",401);let s=`${t.api_base}${i}`,r=await fetch(s,{...e,headers:{Authorization:`Bearer ${t.api_token}`,"Content-Type":"application/json",...e.headers}}),n=await r.json().catch(()=>({statusMessage:r.statusText}));if(!r.ok)throw new he(n.statusMessage||n.message||`HTTP ${r.status}`,r.status);return n}async function Tc(i,e={}){let s=`${A().api_base}${i}`,r=await fetch(s,{...e,headers:{"Content-Type":"application/json",...e.headers}}),n=await r.json().catch(()=>({statusMessage:r.statusText}));if(!r.ok)throw new he(n.statusMessage||n.message||`HTTP ${r.status}`,r.status);return n}async function H(i){return Fe(`/api/cli/accounts?provider=${encodeURIComponent(i)}`)}async function se(i,e){let t=e?`?provider=${encodeURIComponent(i)}&account_email=${encodeURIComponent(e)}`:`?provider=${encodeURIComponent(i)}`;return Fe(`/api/cli/config${t}`)}async function wa(){return Fe("/api/cli/me")}async function ya(i,e){let t=await Tc("/api/auth/login",{method:"POST",body:JSON.stringify({email:i,password:e})});if(t?.code!==0||!t?.data?.token)throw new he(t?.message||"\u767B\u5F55\u5931\u8D25",401);return t.data}async function _a(i){let t=`${A().api_base}/api/user/get-api-token`,s=await fetch(t,{method:"GET",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"}}),r=await s.json().catch(()=>({statusMessage:s.statusText}));if(!s.ok)throw new he(r.statusMessage||r.message||`HTTP ${s.status}`,s.status);if(r?.code!==0||!r?.data?.api_token)throw new he(r?.message||"\u83B7\u53D6 API Token \u5931\u8D25",500);return r.data.api_token}async function va(i={}){if(A().api_token)if(console.log(h.yellow("\u5DF2\u767B\u5F55\u3002\u5982\u9700\u91CD\u65B0\u767B\u5F55\uFF0C\u8BF7\u5148\u8FD0\u884C flapcode logout")),i.token)console.log(h.dim("\u68C0\u6D4B\u5230 --token\uFF0C\u8986\u76D6\u73B0\u6709 token"));else{let{confirm:n}=await(0,ht.default)({type:"confirm",name:"confirm",message:"\u662F\u5426\u8986\u76D6\u73B0\u6709 token\uFF1F",initial:!1});if(!n)return}let t=i.token?.trim(),s=i.email?.trim(),r;if(!t&&s&&(r=await Yi("\u8BF7\u8F93\u5165\u767B\u5F55\u5BC6\u7801: ")),!t&&!s&&(await qc()==="password"?(s=(await Mc("\u8BF7\u8F93\u5165\u767B\u5F55\u90AE\u7BB1: ")).trim(),r=await Yi("\u8BF7\u8F93\u5165\u767B\u5F55\u5BC6\u7801: ")):t=await Yi("\u8BF7\u7C98\u8D34 Flapcode API Token\uFF08\u53EF\u5728\u201C\u4E2A\u4EBA\u4E2D\u5FC3\u201D -> \u201CAPI \u8BBF\u95EE\u4EE4\u724C\u201D\u4E2D\u83B7\u53D6\uFF09: ")),!t&&s){if(!r){console.log(h.red("\u5DF2\u53D6\u6D88"));return}let n=await ya(s,r);t=await _a(n.token)}if(!t){console.log(h.red("\u5DF2\u53D6\u6D88"));return}D({api_token:t});try{let n=await Fe("/api/cli/me");await Ic(),console.log(h.green(`\u2713 \u767B\u5F55\u6210\u529F\uFF01\u5F53\u524D\u7528\u6237\uFF1A${n.email??n.username??JSON.stringify(n)}`))}catch(n){D({api_token:null}),console.error(h.red(`\u2717 Token \u9A8C\u8BC1\u5931\u8D25\uFF1A${n.message}`)),process.exit(1)}}async function Ic(){let i=A(),e={};if(!i.current_claude_account){let t=await H("claude").catch(()=>[]);t.length>0&&(e.current_claude_account=t[0].account_email)}if(!i.current_codex_account){let t=await H("codex").catch(()=>[]);t.length>0&&(e.current_codex_account=t[0].account_email)}Object.keys(e).length>0&&D(e)}async function qc(){return(await(0,ht.default)({type:"select",name:"mode",message:"\u9009\u62E9\u767B\u5F55\u65B9\u5F0F",choices:[{title:"API Token",value:"token"},{title:"\u90AE\u7BB1\u548C\u5BC6\u7801",value:"password"}],initial:0})).mode??"token"}async function Mc(i){return await new Promise(e=>{let t=Wi.default.createInterface({input:process.stdin,output:process.stdout});t.question(i,s=>{t.close(),process.stdin.isTTY&&process.stdin.pause(),e(s)})})}async function Yi(i){return!process.stdin.isTTY||!process.stdout.isTTY?(await(0,ht.default)({type:"password",name:"token",message:i.trim(),validate:t=>t.trim().length>0||"\u4E0D\u80FD\u4E3A\u7A7A"})).token?.trim():await new Promise(e=>{let t=process.stdin,s=process.stdout,r=t.isRaw===!0,n="";Wi.default.emitKeypressEvents(t),t.setRawMode(!0),t.resume(),s.write(i);let o=(l,u)=>{if(u?.ctrl&&u.name==="c"&&(a(),s.write(`
|
|
119
|
+
`),this.close()}_(e,t){return e.toLowerCase()==="y"?(this.value=!0,this.submit()):e.toLowerCase()==="n"?(this.value=!1,this.submit()):this.bell()}render(){this.closed||(this.firstRender?this.out.write(ta.hide):this.out.write(vc(this.outputText,this.out.columns)),super.render(),this.outputText=[ea.symbol(this.done,this.aborted),Qo.bold(this.msg),ea.delimiter(this.done),this.done?this.value?this.yesMsg:this.noMsg:Qo.gray(this.initialValue?this.yesOption:this.noOption)].join(" "),this.out.write(xc.line+ta.to(0)+this.outputText))}};ia.exports=Ui});var na=c((Jf,ra)=>{"use strict";ra.exports={TextPrompt:to(),SelectPrompt:no(),TogglePrompt:uo(),DatePrompt:Vo(),NumberPrompt:Ro(),MultiselectPrompt:Hi(),AutocompletePrompt:Jo(),AutocompleteMultiselectPrompt:Xo(),ConfirmPrompt:sa()}});var aa=c(oa=>{"use strict";var T=oa,Cc=na(),ut=i=>i;function G(i,e,t={}){return new Promise((s,r)=>{let n=new Cc[i](e),o=t.onAbort||ut,a=t.onSubmit||ut,l=t.onExit||ut;n.on("state",e.onState||ut),n.on("submit",u=>s(a(u))),n.on("exit",u=>s(l(u))),n.on("abort",u=>r(o(u)))})}T.text=i=>G("TextPrompt",i);T.password=i=>(i.style="password",T.text(i));T.invisible=i=>(i.style="invisible",T.text(i));T.number=i=>G("NumberPrompt",i);T.date=i=>G("DatePrompt",i);T.confirm=i=>G("ConfirmPrompt",i);T.list=i=>{let e=i.separator||",";return G("TextPrompt",i,{onSubmit:t=>t.split(e).map(s=>s.trim())})};T.toggle=i=>G("TogglePrompt",i);T.select=i=>G("SelectPrompt",i);T.multiselect=i=>{i.choices=[].concat(i.choices||[]);let e=t=>t.filter(s=>s.selected).map(s=>s.value);return G("MultiselectPrompt",i,{onAbort:e,onSubmit:e})};T.autocompleteMultiselect=i=>{i.choices=[].concat(i.choices||[]);let e=t=>t.filter(s=>s.selected).map(s=>s.value);return G("AutocompleteMultiselectPrompt",i,{onAbort:e,onSubmit:e})};var Oc=(i,e)=>Promise.resolve(e.filter(t=>t.title.slice(0,i.length).toLowerCase()===i.toLowerCase()));T.autocomplete=i=>(i.suggest=i.suggest||Oc,i.choices=[].concat(i.choices||[]),G("AutocompletePrompt",i))});var ha=c((zf,ua)=>{"use strict";var Gi=aa(),Sc=["suggest","format","onState","validate","onRender","type"],la=()=>{};async function ue(i=[],{onSubmit:e=la,onCancel:t=la}={}){let s={},r=ue._override||{};i=[].concat(i);let n,o,a,l,u,d,p=async(m,v,g=!1)=>{if(!(!g&&m.validate&&m.validate(v)!==!0))return m.format?await m.format(v,s):v};for(o of i)if({name:l,type:u}=o,typeof u=="function"&&(u=await u(n,{...s},o),o.type=u),!!u){for(let m in o){if(Sc.includes(m))continue;let v=o[m];o[m]=typeof v=="function"?await v(n,{...s},d):v}if(d=o,typeof o.message!="string")throw new Error("prompt message is required");if({name:l,type:u}=o,Gi[u]===void 0)throw new Error(`prompt type (${u}) is not defined`);if(r[o.name]!==void 0&&(n=await p(o,r[o.name]),n!==void 0)){s[l]=n;continue}try{n=ue._injected?Ac(ue._injected,o.initial):await Gi[u](o),s[l]=n=await p(o,n,!0),a=await e(o,n,s)}catch{a=!await t(o,s)}if(a)return s}return s}function Ac(i,e){let t=i.shift();if(t instanceof Error)throw t;return t===void 0?e:t}function $c(i){ue._injected=(ue._injected||[]).concat(i)}function Ec(i){ue._override=Object.assign({},i)}ua.exports=Object.assign(ue,{prompt:ue,prompts:Gi,inject:$c,override:Ec})});var He=c((Zf,ca)=>{function Pc(i){i=(Array.isArray(i)?i:i.split(".")).map(Number);let e=0,t=process.versions.node.split(".").map(Number);for(;e<i.length;e++){if(t[e]>i[e])return!1;if(i[e]>t[e])return!0}return!1}ca.exports=Pc("8.6.0")?Dn():ha()});var $s=$(As(),1),{program:$d,createCommand:Ed,createArgument:Pd,createOption:kd,CommanderError:Td,InvalidArgumentError:Id,InvalidOptionArgumentError:qd,Command:Es,Argument:Md,Option:Ps,Help:Dd}=$s.default;var qt,Ts,Is,qs,Ms=!0;typeof process<"u"&&({FORCE_COLOR:qt,NODE_DISABLE_COLORS:Ts,NO_COLOR:Is,TERM:qs}=process.env||{},Ms=process.stdout&&process.stdout.isTTY);var b={enabled:!Ts&&Is==null&&qs!=="dumb"&&(qt!=null&&qt!=="0"||Ms),reset:y(0,0),bold:y(1,22),dim:y(2,22),italic:y(3,23),underline:y(4,24),inverse:y(7,27),hidden:y(8,28),strikethrough:y(9,29),black:y(30,39),red:y(31,39),green:y(32,39),yellow:y(33,39),blue:y(34,39),magenta:y(35,39),cyan:y(36,39),white:y(37,39),gray:y(90,39),grey:y(90,39),bgBlack:y(40,49),bgRed:y(41,49),bgGreen:y(42,49),bgYellow:y(43,49),bgBlue:y(44,49),bgMagenta:y(45,49),bgCyan:y(46,49),bgWhite:y(47,49)};function ks(i,e){let t=0,s,r="",n="";for(;t<i.length;t++)s=i[t],r+=s.open,n+=s.close,~e.indexOf(s.close)&&(e=e.replace(s.rgx,s.close+s.open));return r+e+n}function Sl(i,e){let t={has:i,keys:e};return t.reset=b.reset.bind(t),t.bold=b.bold.bind(t),t.dim=b.dim.bind(t),t.italic=b.italic.bind(t),t.underline=b.underline.bind(t),t.inverse=b.inverse.bind(t),t.hidden=b.hidden.bind(t),t.strikethrough=b.strikethrough.bind(t),t.black=b.black.bind(t),t.red=b.red.bind(t),t.green=b.green.bind(t),t.yellow=b.yellow.bind(t),t.blue=b.blue.bind(t),t.magenta=b.magenta.bind(t),t.cyan=b.cyan.bind(t),t.white=b.white.bind(t),t.gray=b.gray.bind(t),t.grey=b.grey.bind(t),t.bgBlack=b.bgBlack.bind(t),t.bgRed=b.bgRed.bind(t),t.bgGreen=b.bgGreen.bind(t),t.bgYellow=b.bgYellow.bind(t),t.bgBlue=b.bgBlue.bind(t),t.bgMagenta=b.bgMagenta.bind(t),t.bgCyan=b.bgCyan.bind(t),t.bgWhite=b.bgWhite.bind(t),t}function y(i,e){let t={open:`\x1B[${i}m`,close:`\x1B[${e}m`,rgx:new RegExp(`\\x1b\\[${e}m`,"g")};return function(s){return this!==void 0&&this.has!==void 0?(~this.has.indexOf(i)||(this.has.push(i),this.keys.push(t)),s===void 0?this:b.enabled?ks(this.keys,s+""):s+""):s===void 0?Sl([i],[t]):b.enabled?ks([t],s+""):s+""}}var h=b;var ht=$(He(),1),Wi=$(require("node:readline"),1);var be=$(require("node:fs"),1),Oe=$(require("node:path"),1),fa=$(require("node:os"),1),pa=require("node:crypto"),kc=Oe.default.join(fa.default.homedir(),".flapcode"),Tc=Oe.default.join(kc,"config.json"),Ic=Oe.default.join(process.cwd(),".flapcode"),da=Oe.default.join(Ic,"config.json"),Bi={api_base:"https://flapcode.com",api_token:null,current_claude_account:null,current_codex_account:null,machine_id:null};function A(){let i=ba();if(!be.default.existsSync(i))return{...Bi};try{return{...Bi,...JSON.parse(be.default.readFileSync(i,"utf8"))}}catch{return{...Bi}}}function D(i){let e=ba(),t=Oe.default.dirname(e);be.default.existsSync(t)||be.default.mkdirSync(t,{recursive:!0});let s=A();be.default.writeFileSync(e,JSON.stringify({...s,...i},null,2),"utf8")}function ma(){D({api_token:null})}function ga(){let i=A();if(i.machine_id)return i.machine_id;let e=(0,pa.randomBytes)(32).toString("hex");return D({machine_id:e}),e}function ba(){return be.default.existsSync(da)?da:Tc}var he=class extends Error{constructor(e,t){super(e),this.statusCode=t}};async function Fe(i,e={}){let t=A();if(!t.api_token)throw new he("\u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u8FD0\u884C flapcode login",401);let s=`${t.api_base}${i}`,r=await fetch(s,{...e,headers:{Authorization:`Bearer ${t.api_token}`,"Content-Type":"application/json",...e.headers}}),n=await r.json().catch(()=>({statusMessage:r.statusText}));if(!r.ok)throw new he(n.statusMessage||n.message||`HTTP ${r.status}`,r.status);return n}async function qc(i,e={}){let s=`${A().api_base}${i}`,r=await fetch(s,{...e,headers:{"Content-Type":"application/json",...e.headers}}),n=await r.json().catch(()=>({statusMessage:r.statusText}));if(!r.ok)throw new he(n.statusMessage||n.message||`HTTP ${r.status}`,r.status);return n}async function H(i){return Fe(`/api/cli/accounts?provider=${encodeURIComponent(i)}`)}async function se(i,e){let t=e?`?provider=${encodeURIComponent(i)}&account_email=${encodeURIComponent(e)}`:`?provider=${encodeURIComponent(i)}`;return Fe(`/api/cli/config${t}`)}async function wa(){return Fe("/api/cli/me")}async function ya(i,e){let t=await qc("/api/auth/login",{method:"POST",body:JSON.stringify({email:i,password:e})});if(t?.code!==0||!t?.data?.token)throw new he(t?.message||"\u767B\u5F55\u5931\u8D25",401);return t.data}async function _a(i){let t=`${A().api_base}/api/user/get-api-token`,s=await fetch(t,{method:"GET",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"}}),r=await s.json().catch(()=>({statusMessage:s.statusText}));if(!s.ok)throw new he(r.statusMessage||r.message||`HTTP ${s.status}`,s.status);if(r?.code!==0||!r?.data?.api_token)throw new he(r?.message||"\u83B7\u53D6 API Token \u5931\u8D25",500);return r.data.api_token}async function va(i={}){if(A().api_token)if(console.log(h.yellow("\u5DF2\u767B\u5F55\u3002\u5982\u9700\u91CD\u65B0\u767B\u5F55\uFF0C\u8BF7\u5148\u8FD0\u884C flapcode logout")),i.token)console.log(h.dim("\u68C0\u6D4B\u5230 --token\uFF0C\u8986\u76D6\u73B0\u6709 token"));else{let{confirm:n}=await(0,ht.default)({type:"confirm",name:"confirm",message:"\u662F\u5426\u8986\u76D6\u73B0\u6709 token\uFF1F",initial:!1});if(!n)return}let t=i.token?.trim(),s=i.email?.trim(),r;if(!t&&s&&(r=await Yi("\u8BF7\u8F93\u5165\u767B\u5F55\u5BC6\u7801: ")),!t&&!s&&(await Dc()==="password"?(s=(await Vc("\u8BF7\u8F93\u5165\u767B\u5F55\u90AE\u7BB1: ")).trim(),r=await Yi("\u8BF7\u8F93\u5165\u767B\u5F55\u5BC6\u7801: ")):t=await Yi("\u8BF7\u7C98\u8D34 Flapcode API Token\uFF08\u53EF\u5728\u201C\u4E2A\u4EBA\u4E2D\u5FC3\u201D -> \u201CAPI \u8BBF\u95EE\u4EE4\u724C\u201D\u4E2D\u83B7\u53D6\uFF09: ")),!t&&s){if(!r){console.log(h.red("\u5DF2\u53D6\u6D88"));return}let n=await ya(s,r);t=await _a(n.token)}if(!t){console.log(h.red("\u5DF2\u53D6\u6D88"));return}D({api_token:t});try{let n=await Fe("/api/cli/me");await Mc(),console.log(h.green(`\u2713 \u767B\u5F55\u6210\u529F\uFF01\u5F53\u524D\u7528\u6237\uFF1A${n.email??n.username??JSON.stringify(n)}`))}catch(n){D({api_token:null}),console.error(h.red(`\u2717 Token \u9A8C\u8BC1\u5931\u8D25\uFF1A${n.message}`)),process.exit(1)}}async function Mc(){let i=A(),e={};if(!i.current_claude_account){let t=await H("claude").catch(()=>[]);t.length>0&&(e.current_claude_account=t[0].account_email)}if(!i.current_codex_account){let t=await H("codex").catch(()=>[]);t.length>0&&(e.current_codex_account=t[0].account_email)}Object.keys(e).length>0&&D(e)}async function Dc(){return(await(0,ht.default)({type:"select",name:"mode",message:"\u9009\u62E9\u767B\u5F55\u65B9\u5F0F",choices:[{title:"API Token",value:"token"},{title:"\u90AE\u7BB1\u548C\u5BC6\u7801",value:"password"}],initial:0})).mode??"token"}async function Vc(i){return await new Promise(e=>{let t=Wi.default.createInterface({input:process.stdin,output:process.stdout});t.question(i,s=>{t.close(),process.stdin.isTTY&&process.stdin.pause(),e(s)})})}async function Yi(i){return!process.stdin.isTTY||!process.stdout.isTTY?(await(0,ht.default)({type:"password",name:"token",message:i.trim(),validate:t=>t.trim().length>0||"\u4E0D\u80FD\u4E3A\u7A7A"})).token?.trim():await new Promise(e=>{let t=process.stdin,s=process.stdout,r=t.isRaw===!0,n="";Wi.default.emitKeypressEvents(t),t.setRawMode(!0),t.resume(),s.write(i);let o=(l,u)=>{if(u?.ctrl&&u.name==="c"&&(a(),s.write(`
|
|
120
120
|
`),process.exit(130)),u?.name==="escape"){a(),s.write(`
|
|
121
121
|
`),e("");return}if(u?.name==="return"||u?.name==="enter"){a(),s.write(`
|
|
122
|
-
`),e(n.trim());return}if(u?.name==="backspace"){if(!n.length)return;n=n.slice(0,-1),s.write("\b \b");return}!l||u?.ctrl||u?.meta||(n+=l,s.write("*"))};function a(){t.off("keypress",o),t.isTTY&&t.setRawMode(r),t.pause()}t.on("keypress",o)})}var xa=$(He(),1);async function Ca(){if(!A().api_token){console.log(h.yellow("\u5F53\u524D\u672A\u767B\u5F55"));return}let{confirm:e}=await(0,xa.default)({type:"confirm",name:"confirm",message:"\u786E\u8BA4\u9000\u51FA\u767B\u5F55\uFF1F",initial:!1});if(!e){console.log("\u5DF2\u53D6\u6D88");return}ma(),console.log(h.green("\u2713 \u5DF2\u9000\u51FA\u767B\u5F55"))}var we=require("node:child_process"),
|
|
123
|
-
Claude Code`));let t=
|
|
124
|
-
Codex`));let e=
|
|
125
|
-
${n.toUpperCase()} \u8D26\u53F7`));let a=n==="claude"?t.current_claude_account:t.current_codex_account;o.forEach((l,u)=>{let d=l.account_email===a,p=d?h.green("* "):" ",m=h.dim(`[${u+1}]`),v=d?h.green(l.account_email):l.account_email,
|
|
126
|
-
\u6CA1\u6709\u53EF\u7528\u8D26\u53F7\u3002\u8BF7\u786E\u8BA4\u5DF2\u767B\u5F55\u5E76\u62E5\u6709\u6709\u6548\u8BA2\u9605\u3002`))}function
|
|
122
|
+
`),e(n.trim());return}if(u?.name==="backspace"){if(!n.length)return;n=n.slice(0,-1),s.write("\b \b");return}!l||u?.ctrl||u?.meta||(n+=l,s.write("*"))};function a(){t.off("keypress",o),t.isTTY&&t.setRawMode(r),t.pause()}t.on("keypress",o)})}var xa=$(He(),1);async function Ca(){if(!A().api_token){console.log(h.yellow("\u5F53\u524D\u672A\u767B\u5F55"));return}let{confirm:e}=await(0,xa.default)({type:"confirm",name:"confirm",message:"\u786E\u8BA4\u9000\u51FA\u767B\u5F55\uFF1F",initial:!1});if(!e){console.log("\u5DF2\u53D6\u6D88");return}ma(),console.log(h.green("\u2713 \u5DF2\u9000\u51FA\u767B\u5F55"))}var we=require("node:child_process"),jc="https://registry.npmjs.org",Oa="2.1.113";function ce(){try{Aa(["--version"],{stdio:"ignore"})}catch{throw new Error("\u672A\u627E\u5230 npm\uFF0C\u8BF7\u5148\u5B89\u88C5 Node.js\uFF08https://nodejs.org\uFF09")}}function ct(i){return!!re(i)}function de(i){let e=(0,we.spawnSync)("npm",["install","-g",i],{stdio:"inherit",encoding:"utf8",shell:process.platform==="win32"});if(e.status!==0)throw new Error(`npm install -g ${i} \u5931\u8D25\uFF08${Hc(e)}\uFF09`)}function Hc(i){return i.error?i.error.message:i.signal?`signal ${i.signal}`:`exit code ${i.status}`}function ye(i){try{return(0,we.execSync)(`${i} --version`,{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","ignore"]}).trim().match(/\d+\.\d+\.\d+/)?.[0]??null}catch{return null}}function re(i){return Fc()?.dependencies?.[i]?.version??null}function Sa(){try{return Aa(["root","-g"]).trim()}catch{return null}}function Aa(i,e={}){return(0,we.execFileSync)("npm",i,{encoding:"utf8",shell:process.platform==="win32",...e})}function Fc(){let i=(0,we.spawnSync)("npm",["list","-g","--depth=0","--json"],{encoding:"utf8",shell:process.platform==="win32",stdio:["ignore","pipe","ignore"]});if(!i.stdout)return null;try{return JSON.parse(i.stdout)}catch{return null}}async function dt(i){try{let e=await fetch(`${jc}/${encodeURIComponent(i)}`,{headers:{Accept:"application/json"}});return e.ok?(await e.json())?.["dist-tags"]?.latest??null:null}catch{return null}}function Se(i,e){let t=String(i||"").split(".").map(n=>Number.parseInt(n,10)||0),s=String(e||"").split(".").map(n=>Number.parseInt(n,10)||0),r=Math.max(t.length,s.length);for(let n=0;n<r;n+=1){let o=t[n]??0,a=s[n]??0;if(o>a)return 1;if(o<a)return-1}return 0}function ft(i){if(Se(i,Oa)<0)throw new Error(`\u68C0\u6D4B\u5230 Claude Code ${i}\uFF0Cflapcode \u5DF2\u4E0D\u652F\u6301\u4F4E\u4E8E ${Oa} \u7684\u7248\u672C\uFF0C\u8BF7\u5347\u7EA7\uFF1Anpm install -g @anthropic-ai/claude-code`)}var fe=$(require("node:fs"),1),Ea=$(require("node:os"),1),Re=$(require("node:path"),1);var Rc="gate.takemoon.com",Pa=".flapcode.bak",Nc="@anthropic-ai/claude-code",Lc=Re.default.join("@anthropic-ai","claude-code"),Ji;function pt(){return Ji||(Ji=import("tweakcc")),Ji}function $a(i){try{return fe.default.realpathSync.native(i)}catch{return i}}function ka(){let i=ye("claude")??re(Nc);if(!i)throw new Error("\u65E0\u6CD5\u83B7\u53D6 claude --version,\u8BF7\u786E\u8BA4 claude \u5DF2\u5B89\u88C5\u5E76\u5728 PATH \u4E2D");return ft(i),i}var Uc=/\{([A-Z][A-Z0-9_]*)\}/g,Gc={RECLAUDE_CC_VERSION:()=>ka()};function Ta(i){let e=new Map,t=s=>{if(!e.has(s)){let r=Gc[s];e.set(s,r?r():null)}return e.get(s)};return i.map(s=>{let r=s.template?String(s.to).replace(Uc,(n,o)=>{let a=t(o);return a==null?n:String(a)}):s.to;return{from:s.from,to:r}})}async function Bc(){let i=ka(),e=Re.default.join(Ea.default.homedir(),".local","bin",process.platform==="win32"?"claude.exe":"claude");if(fe.default.existsSync(e))return[{path:$a(e),kind:"native",version:i}];let t=Sa();if(!t)return[];let s=Re.default.join(t,Lc);if(!fe.default.existsSync(s))return[];let r=Re.default.join(s,"bin","claude.exe");if(!fe.default.existsSync(r))throw new Error(`npm \u5305\u76EE\u5F55\u7F3A\u4E8C\u8FDB\u5236: ${r}`);return[{path:$a(r),kind:"native",version:i}]}async function Ki(){let{findAllInstallations:i}=await pt(),e=[...await i(),...await Bc()],t=new Map;for(let s of e){if(s.path.endsWith(".bak"))continue;let r=s.path;try{r=fe.default.realpathSync.native(s.path)}catch{}r.endsWith(".bak")||t.has(r)||t.set(r,{...s,path:r})}return[...t.values()]}async function Yc(i){let e=i.path+Pa;if(fe.default.existsSync(e))return;let{backupFile:t}=await pt();await t(i.path,e)}async function Ia(i,{force:e=!1}={}){let{readContent:t,writeContent:s}=await pt(),r=Ta(i),n=await Ki();if(n.length===0)throw new Error("\u627E\u4E0D\u5230 claude-code \u5B89\u88C5\u76EE\u6807,\u8BF7\u5148\u8FD0\u884C flapcode claude install");let o=!1,a=[];for(let l of n){let u=l.path+Pa,d=fe.default.existsSync(u),p=e&&d?await t({...l,path:u}):await t(l);if(!e&&r.every(({from:g})=>!p.includes(g)))continue;await Yc(l);let m=p;for(let{from:v,to:g}of r)m.includes(v)&&(m=m.split(v).join(g));await s(l,m),o=!0,a.push({path:l.path})}return{patched:o,alreadyPatched:!o,targets:a}}async function qa(i){try{let{readContent:e}=await pt();return await e(i)}catch{return null}}async function Ma(i){let e;try{e=await Ki()}catch{return null}if(e.length===0)return null;let t=Ta(i),s=await Promise.all(e.map(qa));return t.map(({from:r,to:n})=>({from:r,to:n,applied:s.every(o=>o!==null&&!o.includes(r))}))}async function mt(){try{let i=await Ki();return i.length===0?!1:(await Promise.all(i.map(qa))).every(t=>t!==null&&t.includes(Rc))}catch{return!1}}var B="@flapcode/cli";async function Da(i){if(process.env.FLAPCODE_SKIP_AUTO_UPDATE==="1")return;let e=await dt(B);if(!(!e||Se(i,e)>=0)){console.log(h.cyan(`\u53D1\u73B0 Flapcode CLI \u65B0\u7248\u672C v${e}\uFF0C\u6B63\u5728\u81EA\u52A8\u66F4\u65B0...`));try{ce(),de(`${B}@latest`),console.log(h.green(`\u2713 Flapcode CLI \u5DF2\u66F4\u65B0\u5230 v${e}`))}catch(t){console.log(h.yellow(`\u81EA\u52A8\u66F4\u65B0\u5931\u8D25\uFF1A${t.message}`))}}}function Va(i=process.argv.slice(2)){let e=i.find(t=>!t.startsWith("-"));return e!=="update"&&e!=="help"&&!i.includes("--help")&&!i.includes("-h")}var Wc="@openai/codex",Jc="@anthropic-ai/claude-code",Kc=10;async function Ha(){let i=A();if(await zc(),!i.api_token){console.log(),console.log(h.red("\u2717 \u672A\u767B\u5F55")+" \u2192 \u8FD0\u884C flapcode login");return}let e="...";try{let r=await wa();e=r.email??r.username??"(\u672A\u77E5)",I("\u767B\u5F55\u72B6\u6001",h.green("\u2713 \u5DF2\u767B\u5F55"),h.dim(e))}catch(r){I("\u767B\u5F55\u72B6\u6001",h.red("\u2717 \u767B\u5F55\u5931\u6548"),h.dim(r.message))}pe("\u767B\u5F55\u7F51\u7AD9",i.api_base),console.log(h.bold(`
|
|
123
|
+
Claude Code`));let t=Fa("claude",Jc);t.version?I("\u5B89\u88C5\u72B6\u6001",h.green("\u2713 \u5DF2\u5B89\u88C5"),`v${t.version}${t.detail}`):I("\u5B89\u88C5\u72B6\u6001",h.yellow("\u2717 \u672A\u5B89\u88C5"),"\u2192 \u8FD0\u884C flapcode claude install"),i.current_claude_account?pe("\u5F53\u524D\u8D26\u53F7",h.cyan(i.current_claude_account)):pe("\u5F53\u524D\u8D26\u53F7",h.dim("\u672A\u8BBE\u7F6E"));let s=i.current_claude_account?await se("claude",i.current_claude_account).catch(()=>null):null;if(s?.config_mode&&pe("\u914D\u7F6E\u6A21\u5F0F",Xc(s.config_mode)),t.version)try{if(await mt())return I("Patch",h.green("\u2713 \u5DF2\u751F\u6548")),ja(i);let r=s?.patch_rules;r?.length?(await Ma(r))?.every(a=>a.applied)?I("Patch",h.green("\u2713 \u5DF2\u751F\u6548")):I("Patch",h.yellow("\u2717 \u672A\u751F\u6548"),"\u2192 \u8FD0\u884C flapcode claude patch"):i.current_claude_account?I("Patch",h.dim("\u672A\u77E5"),"\uFF08\u65E0\u6CD5\u83B7\u53D6 patch \u89C4\u5219\uFF09"):I("Patch",h.dim("\u672A\u77E5"),"\uFF08\u672A\u8BBE\u7F6E Claude \u8D26\u53F7\uFF0C\u65E0\u6CD5\u83B7\u53D6 patch \u89C4\u5219\uFF09")}catch{I("Patch",h.dim("\u672A\u77E5"),"\uFF08\u68C0\u67E5\u5931\u8D25\uFF09")}ja(i)}async function zc(){console.log(h.bold("Flapcode CLI"));let i=Zc();I("\u5F53\u524D\u7248\u672C",h.green("\u2713 \u5DF2\u5B89\u88C5"),`v${i}`);let e=await dt(B);if(!e){pe("\u6700\u65B0\u7248\u672C",h.dim("\u68C0\u67E5\u5931\u8D25\u6216\u7F51\u7EDC\u4E0D\u53EF\u7528"));return}pe("\u6700\u65B0\u7248\u672C",`v${e}`),Se(i,e)<0&&I("\u5347\u7EA7\u63D0\u793A",h.yellow("\u21BB \u53EF\u5347\u7EA7"),"\u8FD0\u884C flapcode update")}function ja(i){console.log(h.bold(`
|
|
124
|
+
Codex`));let e=Fa("codex",Wc);e.version?I("\u5B89\u88C5\u72B6\u6001",h.green("\u2713 \u5DF2\u5B89\u88C5"),`v${e.version}${e.detail}`):I("\u5B89\u88C5\u72B6\u6001",h.yellow("\u2717 \u672A\u5B89\u88C5"),"\u2192 \u8FD0\u884C flapcode codex install"),i.current_codex_account?pe("\u5F53\u524D\u8D26\u53F7",h.cyan(i.current_codex_account)):pe("\u5F53\u524D\u8D26\u53F7",h.dim("\u672A\u8BBE\u7F6E")),console.log()}function Zc(){let i=re(B);return i&&Se(i,"1.8.5")>0?i:"1.8.5"}function Fa(i,e){let t=ye(i);if(t)return{version:t,detail:""};let s=re(e);return s?{version:s,detail:h.dim(`\uFF08${i} \u547D\u4EE4\u4E0D\u53EF\u7528\uFF0C\u68C0\u67E5 PATH\uFF09`)}:{version:null,detail:""}}function Xc(i){return i==="oauth"?"oauth"+h.dim("\uFF08\u7531 Claude Code OAuth \u7BA1\u7406\uFF0C\u672C\u5730\u4E0D\u5199 token\uFF09"):i==="managed_token"?"managed token"+h.dim("\uFF08\u8D70 Flapcode API token\uFF09"):i}function pe(i,e){let t=Ra(i);console.log(` ${h.dim(t)} ${e}`)}function I(i,e,t=""){let s=Ra(i);console.log(` ${h.dim(s)} ${e}${t?` ${t}`:""}`)}function Ra(i){let e=`${i}:`,t=Qc(e),s=Math.max(1,Kc-t);return`${e}${" ".repeat(s)}`}function Qc(i){let e=0;for(let t of i)e+=ed(t)?2:1;return e}function ed(i){return/[^\u0000-\u00ff]/.test(i)}var td=new Set(["claude","codex"]);async function Na(i){let e=i.provider??null;e&&!td.has(e)&&(console.error(h.red(`\u2717 provider \u53EA\u80FD\u662F claude \u6216 codex\uFF0C\u5F53\u524D\u4E3A: ${e}`)),process.exit(1));let t=A(),s=e?[e]:["claude","codex"],r=!1;for(let n of s){let o;try{o=await H(n)}catch(l){console.error(h.red(`\u2717 \u83B7\u53D6 ${n} \u8D26\u53F7\u5931\u8D25\uFF1A${l.message}`));continue}if(!Array.isArray(o)||o.length===0){console.log(h.yellow(` ${n}\uFF1A\u6682\u65E0\u53EF\u7528\u8D26\u53F7`));continue}console.log(h.bold(`
|
|
125
|
+
${n.toUpperCase()} \u8D26\u53F7`));let a=n==="claude"?t.current_claude_account:t.current_codex_account;o.forEach((l,u)=>{let d=l.account_email===a,p=d?h.green("* "):" ",m=h.dim(`[${u+1}]`),v=d?h.green(l.account_email):l.account_email,g=l.plan_name?h.dim(` (${l.plan_name})`):"",q=l.expires_at?h.dim(` \u5230\u671F: ${new Date(l.expires_at).toLocaleDateString()}`):"",P=n==="claude"?id(l.config_mode):"";console.log(`${p}${m} ${v}${g}${q}${P}`)}),r=!0}r||console.log(h.yellow(`
|
|
126
|
+
\u6CA1\u6709\u53EF\u7528\u8D26\u53F7\u3002\u8BF7\u786E\u8BA4\u5DF2\u767B\u5F55\u5E76\u62E5\u6709\u6709\u6548\u8BA2\u9605\u3002`))}function id(i){return i==="oauth"?h.dim(" [oauth]"):i==="managed_token"?h.dim(" [managed token]"):""}async function La(){ce();let i=re(B);console.log(i?`${h.dim("\u5F53\u524D\u5168\u5C40\u7248\u672C:")} v${i}`:h.yellow("\u672A\u68C0\u6D4B\u5230\u5168\u5C40\u5B89\u88C5\u7684 Flapcode CLI\uFF0C\u5C06\u76F4\u63A5\u5B89\u88C5\u6700\u65B0\u7248\u672C")),console.log(h.cyan(`
|
|
127
127
|
\u6B63\u5728\u6267\u884C npm install -g ${B}@latest
|
|
128
128
|
`)),de(`${B}@latest`);let e=re(B);console.log(e?`
|
|
129
129
|
${h.green("\u2713")} Flapcode CLI \u5DF2\u66F4\u65B0\u5230 v${e}`:`
|
|
130
|
-
${h.green("\u2713")} Flapcode CLI \u66F4\u65B0\u5B8C\u6210`)}var
|
|
131
|
-
`);return f.default.writeFileSync(t,n,"utf8"),t}function Y(){return
|
|
130
|
+
${h.green("\u2713")} Flapcode CLI \u66F4\u65B0\u5B8C\u6210`)}var Ya=$(require("node:fs"),1),Wa=$(require("node:path"),1);var us=$(He(),1);var f=$(require("node:fs"),1),E=$(require("node:path"),1),Ba=$(require("node:os"),1),Le=require("node:crypto");function Xi(i={},{removeEnvKeys:e=[]}={}){let t=E.default.join(Y(),".claude"),s=E.default.join(t,"settings.json");f.default.mkdirSync(t,{recursive:!0});let r={};if(f.default.existsSync(s))try{r=JSON.parse(f.default.readFileSync(s,"utf8"))}catch{}let n={...r,...i};if(i.env||e.length){n.env={...r.env??{},...i.env??{}};for(let o of e)delete n.env[o]}return f.default.writeFileSync(s,JSON.stringify(n,null,2),"utf8"),s}function Qi(){let i=E.default.join(Y(),".claude.json");if(!f.default.existsSync(i))return null;try{return JSON.parse(f.default.readFileSync(i,"utf8"))?.oauthAccount?.emailAddress??null}catch{return null}}function es(){let i=E.default.join(Y(),".claude","settings.json");if(!f.default.existsSync(i))return!1;try{return!!JSON.parse(f.default.readFileSync(i,"utf8"))?.env?.CLAUDE_CODE_OAUTH_TOKEN}catch{return!1}}function gt(i,{restoreTarget:e=!0,forceBackup:t=!1}={}){let s=Ua(i),r=Ua(Qi()),n=[],o=[],a=[];return s?(r&&(t||r!==s)&&n.push(...sd(r)),e&&(!r||r!==s)&&(nd(s)?o.push(...rd(s)):a.push(...od())),{currentEmail:r,targetEmail:s,backedUp:n,restored:o,cleared:a}):{currentEmail:r,targetEmail:null,backedUp:n,restored:o,cleared:a}}function sd(i){let e=[];for(let{active:t,backup:s}of ts(i))f.default.existsSync(t)&&(ld(t,s),e.push({from:t,to:s}));return e}function rd(i){let e=[];for(let{active:t,backup:s}of ts(i))f.default.existsSync(s)&&(ud(s,t),e.push({from:s,to:t}));return e}function nd(i){return ts(i).some(({backup:e})=>f.default.existsSync(e))}function od(){let i=[];for(let e of ad())f.default.existsSync(e)&&(f.default.rmSync(e,{recursive:!0,force:!0}),i.push(e));return i}function ts(i){let e=Y();return[{active:E.default.join(e,".claude.json"),backup:E.default.join(e,`.claude.json.${i}.bak`)},{active:E.default.join(e,".claude"),backup:E.default.join(e,`.claude.${i}.bak`)}]}function ad(){let i=Y();return[E.default.join(i,".claude.json"),E.default.join(i,".claude")]}function ld(i,e){let t=zi(e,"old"),s=!1;try{f.default.existsSync(e)&&(f.default.renameSync(e,t),s=!0),f.default.renameSync(i,e),s&&Zi(t)}catch(r){if(s&&!f.default.existsSync(e)&&f.default.existsSync(t))try{f.default.renameSync(t,e)}catch{}throw r}}function ud(i,e){let t=zi(e,"new"),s=zi(e,"old"),r=!1;try{f.default.existsSync(t)&&f.default.rmSync(t,{recursive:!0,force:!0}),f.default.cpSync(i,t,{recursive:!0}),f.default.existsSync(e)&&(f.default.renameSync(e,s),r=!0),f.default.renameSync(t,e),r&&Zi(s)}catch(n){if(r&&!f.default.existsSync(e)&&f.default.existsSync(s))try{f.default.renameSync(s,e)}catch{}throw Zi(t),n}}function zi(i,e){return`${i}.flapcode-${e}-${process.pid}-${(0,Le.randomBytes)(6).toString("hex")}.tmp`}function Zi(i){try{f.default.existsSync(i)&&f.default.rmSync(i,{recursive:!0,force:!0})}catch{}}function Ua(i){return String(i??"").trim().toLowerCase()||null}function is(i,e){let t=E.default.join(Y(),".claude.json"),s={};if(f.default.existsSync(t))try{s=JSON.parse(f.default.readFileSync(t,"utf8"))}catch{}let r={numStartups:1,firstStartTime:new Date().toISOString(),opusProMigrationComplete:!0,sonnet1m45MigrationComplete:!0,hasCompletedOnboarding:!0,voiceNoticeSeenCount:1,officialMarketplaceAutoInstallAttempted:!0,officialMarketplaceAutoInstalled:!0};for(let[n,o]of Object.entries(r))s[n]===void 0&&(s[n]=o);return s.userID=cd(i),s.lastOnboardingVersion=e,s.lastReleaseNotesSeen=e,s.oauthAccount=hd(i,s.oauthAccount),f.default.writeFileSync(t,JSON.stringify(s,null,2),"utf8"),t}function ss(i,{resetIdentity:e=!1}={}){let t=E.default.join(Y(),".claude.json");if(!f.default.existsSync(t))return null;let s={};try{s=JSON.parse(f.default.readFileSync(t,"utf8"))}catch{}let r={numStartups:1,firstStartTime:new Date().toISOString(),opusProMigrationComplete:!0,sonnet1m45MigrationComplete:!0,hasCompletedOnboarding:!0,voiceNoticeSeenCount:1,officialMarketplaceAutoInstallAttempted:!0,officialMarketplaceAutoInstalled:!0};for(let[n,o]of Object.entries(r))s[n]===void 0&&(s[n]=o);return i&&(s.lastOnboardingVersion=i,s.lastReleaseNotesSeen=i),e?(s.userID=Ga(),delete s.oauthAccount):s.userID||(s.userID=Ga()),f.default.writeFileSync(t,JSON.stringify(s,null,2),"utf8"),t}function Ga(){return(0,Le.randomBytes)(32).toString("hex")}function rs(){let i=E.default.join(Y(),".claude.json");if(!f.default.existsSync(i))return null;let e={};try{e=JSON.parse(f.default.readFileSync(i,"utf8"))}catch{return null}return e.oauthAccount===void 0?null:(delete e.oauthAccount,f.default.writeFileSync(i,JSON.stringify(e,null,2),"utf8"),i)}function hd(i,e){return{accountUuid:i.account_uuid,emailAddress:i.email,organizationUuid:i.org_uuid??e?.organizationUuid??e?.organizationId??""}}function cd(i){if(!i?.account_uuid)throw new Error("account.account_uuid \u7F3A\u5931\uFF0C\u65E0\u6CD5\u751F\u6210 userID");let e=ga();return(0,Le.createHash)("sha256").update(`${e}:${i.account_uuid}`).digest("hex")}function ns(i){let e=E.default.join(Y(),".codex");f.default.mkdirSync(e,{recursive:!0});let t=E.default.join(e,"auth.json");return f.default.writeFileSync(t,JSON.stringify({OPENAI_API_KEY:i.api_token},null,2),"utf8"),t}function os(i){let e=E.default.join(Y(),".codex");f.default.mkdirSync(e,{recursive:!0});let t=E.default.join(e,"config.toml"),s=i.provider_name??"openai",r=i.model??"o4-mini",n=[`model = ${Ne(r)}`,`model_provider = ${Ne(s)}`,'model_reasoning_effort = "medium"',"disable_response_storage = true","",`[model_providers.${Ne(s)}]`,`name = ${Ne(s)}`,`base_url = ${Ne(i.base_url)}`,'wire_api = "responses"',""].join(`
|
|
131
|
+
`);return f.default.writeFileSync(t,n,"utf8"),t}function Y(){return Ba.default.homedir()}function Ne(i){return JSON.stringify(String(i??""))}var Ue="@anthropic-ai/claude-code";async function Ja(i={}){ce(),ct(Ue)?console.log(h.dim(`${Ue} \u5DF2\u5B89\u88C5\uFF0C\u8DF3\u8FC7`)):(console.log(h.cyan(`\u6B63\u5728\u5B89\u88C5 ${Ue}...`)),de(Ue),console.log(h.green(`\u2713 ${Ue} \u5B89\u88C5\u5B8C\u6210`)));let e=ye("claude");e||(console.error(h.red("\u2717 \u65E0\u6CD5\u83B7\u53D6 claude \u7248\u672C\uFF0C\u8BF7\u786E\u8BA4 claude \u547D\u4EE4\u5728 PATH \u4E2D\u53EF\u7528")),process.exit(1));try{ft(e)}catch(u){console.error(h.red(`\u2717 ${u.message}`)),process.exit(1)}let t=await fd(),s=await md(t);if(!s)return;console.log(h.dim("\u6B63\u5728\u62C9\u53D6\u914D\u7F6E..."));let r=await se("claude",s.account_email);await ls(r.patch_rules);let n=hs(r),o=new Set(t.map(u=>String(u.account_email).toLowerCase())),a=pd(o);if(i.reset||a){let u=gt(s.account_email,{restoreTarget:!1,forceBackup:!0});if(as(u),u.backedUp.length){let d=i.reset?"--reset":"\u68C0\u6D4B\u5230\u73B0\u6709 ~/.claude \u914D\u7F6E\u4E0D\u5C5E\u4E8E\u4F60\u7684 flapcode \u8D26\u53F7";console.log(h.yellow(`\u5DF2\u4ECE\u7A7A\u914D\u7F6E\u7EE7\u7EED\uFF08${d}\uFF09`))}else i.reset&&console.log(h.dim("--reset\uFF1A\u672A\u53D1\u73B0 ~/.claude.json \u6216 ~/.claude/\uFF0C\u65E0\u9700\u5907\u4EFD"))}else as(gt(s.account_email));let l=n&&es();if(Xi(r.settings??{},{removeEnvKeys:Xa(r)}),n?ss(e,{resetIdentity:l}):Za(r.account)?is(r.account,e):rs(),D({current_claude_account:s.account_email}),n){Qa(s.account_email,{identityReset:l});return}console.log(h.green(`
|
|
132
132
|
\u2713 Claude Code \u914D\u7F6E\u5B8C\u6210\uFF01`)),console.log(` \u8D26\u53F7: ${h.cyan(s.account_email)}`),console.log(` \u8FD0\u884C ${h.bold("claude")} \u5373\u53EF\u5F00\u59CB\u4F7F\u7528
|
|
133
|
-
`)}async function
|
|
134
|
-
\u2713 Claude Code OAuth \u6A21\u5F0F\u914D\u7F6E\u5B8C\u6210`)),console.log(` \u8D26\u53F7: ${h.cyan(i)}`),console.log(e?h.dim(" \u5DF2\u6E05\u7406 managed \u6B8B\u7559\u8EAB\u4EFD\uFF0C\u672A\u5199\u5165\u771F\u5B9E token"):h.dim(" \u672A\u5199\u5165\u771F\u5B9E token\uFF0C\u4FDD\u7559\u5DF2\u6709\u767B\u5F55\u8EAB\u4EFD\uFF08\u5982\u6709\uFF09")),console.log(` \u8BF7\u8FD0\u884C ${h.bold("claude")} \u5E76\u6309\u63D0\u793A\u5B8C\u6210 OAuth \u767B\u5F55`)}function as({backedUp:i=[],restored:e=[],cleared:t=[]}={}){if(i.length){console.log(h.dim("\u5DF2\u5907\u4EFD\u5F53\u524D Claude \u914D\u7F6E\u5FEB\u7167\uFF1A"));for(let s of i)console.log(h.dim(` ${s.from} \u2192 ${s.to}`))}if(e.length){console.log(h.dim("\u5DF2\u6062\u590D\u76EE\u6807 Claude \u914D\u7F6E\u5FEB\u7167\uFF1A"));for(let s of e)console.log(h.dim(` ${s.from} \u2192 ${s.to}`))}if(t.length){console.log(h.dim("\u5DF2\u6E05\u7A7A\u5F53\u524D Claude \u6D3B\u8DC3\u914D\u7F6E\uFF1A"));for(let s of t)console.log(h.dim(` ${s}`))}}async function
|
|
135
|
-
`))}async function
|
|
133
|
+
`)}async function Ka(i={}){if(i.rules){let s=Wa.default.resolve(i.rules);console.log(h.dim(`\u6B63\u5728\u8BFB\u53D6\u672C\u5730 patch \u89C4\u5219: ${s}`));let r=gd(s);await ls(r,"\u672C\u5730 patch \u89C4\u5219\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7",{force:i.force});return}let e=A();console.log(h.dim("\u6B63\u5728\u62C9\u53D6 patch \u89C4\u5219..."));let t=await se("claude",e.current_claude_account);await ls(t.patch_rules,void 0,{force:i.force})}async function za(i){let e=i;if(!e||/^\d+$/.test(e)){let o=await H("claude");(!Array.isArray(o)||o.length===0)&&(console.error(h.red("\u2717 \u6CA1\u6709\u53EF\u7528\u7684 Claude \u8D26\u53F7")),process.exit(1));let a=/^\d+$/.test(e)?parseInt(e,10)-1:null;if(a!==null)(a<0||a>=o.length)&&(console.error(h.red(`\u2717 \u5E8F\u53F7 ${e} \u8D85\u51FA\u8303\u56F4\uFF08\u5171 ${o.length} \u4E2A\u8D26\u53F7\uFF09`)),process.exit(1)),e=o[a].account_email;else{let l=await(0,us.default)({type:"select",name:"email",message:"\u9009\u62E9 Claude \u8D26\u53F7",choices:o.map(u=>({title:u.account_email,value:u.account_email}))});if(!l.email){console.log("\u5DF2\u53D6\u6D88");return}e=l.email}}console.log(h.dim(`\u6B63\u5728\u5207\u6362\u5230 ${e}...`));let t=await se("claude",e),s=hs(t),r=ye("claude");as(gt(e));let n=s&&es();if(Xi(t.settings??{},{removeEnvKeys:Xa(t)}),s?ss(r,{resetIdentity:n}):Za(t.account)?is(t.account,r):rs(),D({current_claude_account:e}),s){Qa(e,{identityReset:n}),await dd();return}console.log(h.green(`\u2713 \u5DF2\u5207\u6362\u5230 ${e}`))}function hs(i){return i?.config_mode==="oauth"}function Za(i){return!!(i?.account_uuid&&i?.org_uuid)}function Xa(i){let e=i?.settings?.env??{},t=[];return e.DISABLE_AUTOUPDATER!==void 0&&t.push("CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC","CLAUDE_CODE_OAUTH_TOKEN"),e.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC!==void 0&&t.push("DISABLE_AUTOUPDATER"),hs(i)&&t.push("CLAUDE_CODE_OAUTH_TOKEN"),[...new Set(t)]}function Qa(i,{identityReset:e=!1}={}){console.log(h.green(`
|
|
134
|
+
\u2713 Claude Code OAuth \u6A21\u5F0F\u914D\u7F6E\u5B8C\u6210`)),console.log(` \u8D26\u53F7: ${h.cyan(i)}`),console.log(e?h.dim(" \u5DF2\u6E05\u7406 managed \u6B8B\u7559\u8EAB\u4EFD\uFF0C\u672A\u5199\u5165\u771F\u5B9E token"):h.dim(" \u672A\u5199\u5165\u771F\u5B9E token\uFF0C\u4FDD\u7559\u5DF2\u6709\u767B\u5F55\u8EAB\u4EFD\uFF08\u5982\u6709\uFF09")),console.log(` \u8BF7\u8FD0\u884C ${h.bold("claude")} \u5E76\u6309\u63D0\u793A\u5B8C\u6210 OAuth \u767B\u5F55`)}function as({backedUp:i=[],restored:e=[],cleared:t=[]}={}){if(i.length){console.log(h.dim("\u5DF2\u5907\u4EFD\u5F53\u524D Claude \u914D\u7F6E\u5FEB\u7167\uFF1A"));for(let s of i)console.log(h.dim(` ${s.from} \u2192 ${s.to}`))}if(e.length){console.log(h.dim("\u5DF2\u6062\u590D\u76EE\u6807 Claude \u914D\u7F6E\u5FEB\u7167\uFF1A"));for(let s of e)console.log(h.dim(` ${s.from} \u2192 ${s.to}`))}if(t.length){console.log(h.dim("\u5DF2\u6E05\u7A7A\u5F53\u524D Claude \u6D3B\u8DC3\u914D\u7F6E\uFF1A"));for(let s of t)console.log(h.dim(` ${s}`))}}async function dd(){let i=!1;try{i=await mt()}catch{i=!1}i||(console.log(h.yellow(" \u26A0 \u68C0\u6D4B\u5230\u5C1A\u672A\u5E94\u7528 patch\uFF0COAuth \u6D41\u7A0B\u53EF\u80FD\u4E0D\u4F1A\u8D70 Flapcode \u94FE\u8DEF")),console.log(` \u8BF7\u5148\u8FD0\u884C ${h.bold("flapcode claude install")} \u6216 ${h.bold("flapcode claude patch")}
|
|
135
|
+
`))}async function fd(){let i;try{i=await H("claude")}catch(e){console.error(h.red(`\u2717 \u83B7\u53D6\u8D26\u53F7\u5217\u8868\u5931\u8D25\uFF1A${e.message}`)),process.exit(1)}return(!Array.isArray(i)||i.length===0)&&(console.error(h.red("\u2717 \u6CA1\u6709\u53EF\u7528\u8D26\u53F7\uFF0C\u8BF7\u786E\u8BA4\u8BA2\u9605\u6709\u6548")),process.exit(1)),i}function pd(i){let e=Qi();return e?!i.has(e.toLowerCase()):!1}async function md(i){if(i.length===1)return console.log(h.dim(`\u4F7F\u7528\u8D26\u53F7: ${i[0].account_email}`)),i[0];let t=A().current_claude_account,{email:s}=await(0,us.default)({type:"select",name:"email",message:"\u9009\u62E9\u8981\u4F7F\u7528\u7684 Claude \u8D26\u53F7",choices:i.map(r=>({title:r.account_email+(r.plan_name?` (${r.plan_name})`:""),value:r.account_email,selected:r.account_email===t}))});return s?i.find(r=>r.account_email===s):(console.log("\u5DF2\u53D6\u6D88"),null)}function gd(i){let e;try{e=JSON.parse(Ya.default.readFileSync(i,"utf8"))}catch(t){throw new Error(`\u8BFB\u53D6\u672C\u5730 patch \u89C4\u5219\u5931\u8D25: ${t.message}`)}if(!Array.isArray(e))throw new Error('\u672C\u5730 patch \u89C4\u5219\u5FC5\u987B\u662F\u6570\u7EC4\uFF0C\u683C\u5F0F\u4E3A [{ "from": "...", "to": "..." }]');for(let[t,s]of e.entries()){if(!s||typeof s.from!="string"||typeof s.to!="string")throw new Error(`\u672C\u5730 patch \u89C4\u5219\u7B2C ${t+1} \u6761\u65E0\u6548\uFF0Cfrom/to \u5FC5\u987B\u662F\u5B57\u7B26\u4E32`);if(!s.from)throw new Error(`\u672C\u5730 patch \u89C4\u5219\u7B2C ${t+1} \u6761\u65E0\u6548\uFF0Cfrom \u4E0D\u80FD\u4E3A\u7A7A`)}return e}async function ls(i,e="\u670D\u52A1\u7AEF\u672A\u4E0B\u53D1 patch \u89C4\u5219\uFF0C\u8DF3\u8FC7",{force:t=!1}={}){if(!i?.length){console.log(h.dim(e));return}console.log(h.dim(t?"\u6B63\u5728\u5F3A\u5236\u91CD\u65B0\u5E94\u7528 patch...":"\u6B63\u5728\u5E94\u7528 patch..."));let{patched:s,alreadyPatched:r,targets:n}=await Ia(i,{force:t});for(let o of n)console.log(` ${h.dim("Patch \u76EE\u6807:")} ${o.path}`);r?console.log(h.dim("Patch \u5DF2\u751F\u6548\uFF0C\u65E0\u9700\u91CD\u590D\u64CD\u4F5C")):s&&console.log(h.green("\u2713 Patch \u5E94\u7528\u6210\u529F"))}var el=$(require("node:fs"),1),cs=$(He(),1);var Ge="@openai/codex";async function tl(){ce(),ct(Ge)?console.log(h.dim(`${Ge} \u5DF2\u5B89\u88C5\uFF0C\u8DF3\u8FC7`)):(console.log(h.cyan(`\u6B63\u5728\u5B89\u88C5 ${Ge}...`)),de(Ge),console.log(h.green(`\u2713 ${Ge} \u5B89\u88C5\u5B8C\u6210`)));let i=await bd();if(!i)return;console.log(h.dim("\u6B63\u5728\u62C9\u53D6\u914D\u7F6E..."));let e=await se("codex",i.account_email),t=ns({api_token:e.api_token}),s=os({base_url:e.base_url,provider_name:e.provider_name,model:e.model});bt(t,"Codex auth.json"),bt(s,"Codex config.toml"),D({current_codex_account:i.account_email}),console.log(h.green(`
|
|
136
136
|
\u2713 Codex \u914D\u7F6E\u5B8C\u6210\uFF01`)),console.log(` \u8D26\u53F7: ${h.cyan(i.account_email)}`),console.log(` Auth: ${h.dim(t)}`),console.log(` Config: ${h.dim(s)}`),console.log(` \u8FD0\u884C ${h.bold("codex")} \u5373\u53EF\u5F00\u59CB\u4F7F\u7528
|
|
137
|
-
`)}async function
|
|
137
|
+
`)}async function il(i){let e=i;if(!e||/^\d+$/.test(e)){let n=await H("codex");(!Array.isArray(n)||n.length===0)&&(console.error(h.red("\u2717 \u6CA1\u6709\u53EF\u7528\u7684 Codex \u8D26\u53F7")),process.exit(1));let o=/^\d+$/.test(e)?parseInt(e,10)-1:null;if(o!==null)(o<0||o>=n.length)&&(console.error(h.red(`\u2717 \u5E8F\u53F7 ${e} \u8D85\u51FA\u8303\u56F4\uFF08\u5171 ${n.length} \u4E2A\u8D26\u53F7\uFF09`)),process.exit(1)),e=n[o].account_email;else{let a=await(0,cs.default)({type:"select",name:"email",message:"\u9009\u62E9 Codex \u8D26\u53F7",choices:n.map(l=>({title:l.account_email,value:l.account_email}))});if(!a.email){console.log("\u5DF2\u53D6\u6D88");return}e=a.email}}console.log(h.dim(`\u6B63\u5728\u5207\u6362\u5230 ${e}...`));let t=await se("codex",e),s=ns({api_token:t.api_token}),r=os({base_url:t.base_url,provider_name:t.provider_name,model:t.model});bt(s,"Codex auth.json"),bt(r,"Codex config.toml"),D({current_codex_account:e}),console.log(h.green(`\u2713 \u5DF2\u5207\u6362\u5230 ${e}`)),console.log(` Auth: ${h.dim(s)}`),console.log(` Config: ${h.dim(r)}`)}async function bd(){let i;try{i=await H("codex")}catch(r){console.error(h.red(`\u2717 \u83B7\u53D6\u8D26\u53F7\u5217\u8868\u5931\u8D25\uFF1A${r.message}`)),process.exit(1)}if((!Array.isArray(i)||i.length===0)&&(console.error(h.red("\u2717 \u6CA1\u6709\u53EF\u7528\u8D26\u53F7\uFF0C\u8BF7\u786E\u8BA4\u8BA2\u9605\u6709\u6548")),process.exit(1)),i.length===1)return console.log(h.dim(`\u4F7F\u7528\u8D26\u53F7: ${i[0].account_email}`)),i[0];let t=A().current_codex_account,{email:s}=await(0,cs.default)({type:"select",name:"email",message:"\u9009\u62E9\u8981\u4F7F\u7528\u7684 Codex \u8D26\u53F7",choices:i.map(r=>({title:r.account_email+(r.plan_name?` (${r.plan_name})`:""),value:r.account_email,selected:r.account_email===t}))});return s?i.find(r=>r.account_email===s):(console.log("\u5DF2\u53D6\u6D88"),null)}function bt(i,e){if(!el.default.existsSync(i))throw new Error(`${e} \u5199\u5165\u5931\u8D25\uFF1A${i}`)}var ne=new Es;ne.name("flapcode").description("Flapcode CLI \u2014 \u7EDF\u4E00\u7BA1\u7406 Claude Code / Codex \u5B89\u88C5\u4E0E\u8D26\u53F7\u914D\u7F6E").version("1.8.5","-v, --version","\u663E\u793A\u7248\u672C\u53F7");ne.command("login").description("\u4F7F\u7528 API Token \u6216\u90AE\u7BB1\u767B\u5F55").option("--token <token>","\u975E\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u76F4\u63A5\u4F20\u5165 API Token").option("--email <email>","\u4F7F\u7528\u90AE\u7BB1\u767B\u5F55").action(W(va));ne.command("logout").description("\u9000\u51FA\u767B\u5F55\uFF0C\u6E05\u9664\u672C\u5730\u914D\u7F6E").action(W(Ca));ne.command("status").description("\u663E\u793A\u5F53\u524D\u7528\u6237\u3001\u8D26\u53F7\u3001CC/Codex \u7248\u672C\u53CA patch \u72B6\u6001").action(W(Ha));ne.command("update").description("\u5347\u7EA7 Flapcode CLI \u5230\u6700\u65B0\u7248\u672C").action(W(La));ne.command("accounts").description("\u5217\u51FA\u5F53\u524D\u7528\u6237\u53EF\u7528\u7684\u8D26\u53F7").option("--provider <provider>","\u8FC7\u6EE4 provider\uFF08claude \u6216 codex\uFF09").action(W(Na));var ds=ne.command("claude").description("\u7BA1\u7406 Claude Code");ds.command("install").description("\u9996\u6B21\u5B8C\u6574\u914D\u7F6E\uFF1A\u5B89\u88C5 CC + patch + \u5199\u914D\u7F6E\u6587\u4EF6").option("--reset","\u5168\u65B0\u914D\u7F6E\uFF1A\u5148\u6309\u90AE\u7BB1\u5907\u4EFD ~/.claude.json \u4E0E ~/.claude/\uFF0C\u518D\u4ECE\u96F6\u914D\u7F6E").action(W(Ja));ds.command("patch").description("\u4EC5\u91CD\u6253 patch\uFF08\u5E94\u5BF9 CC \u5347\u7EA7\u540E URL \u88AB\u8986\u76D6\uFF09").option("--force","\u5F3A\u5236\u91CD\u65B0\u6253 patch\uFF08patch \u4E0D\u751F\u6548\u65F6\u7528\u8FD9\u4E2A\u4FEE\u590D\uFF09").addOption(new Ps("--rules <file>","\u4ECE\u672C\u5730 JSON \u6587\u4EF6\u8BFB\u53D6 patch \u89C4\u5219\uFF08\u7528\u4E8E\u8C03\u8BD5\uFF09").hideHelp()).action(W(Ka));ds.command("use [account]").description("\u5207\u6362 Claude \u8D26\u53F7\uFF08\u4F20 email \u6216\u5E8F\u53F7\uFF0C\u7559\u7A7A\u8FDB\u884C\u4EA4\u4E92\u9009\u62E9\uFF09").action(W(za));var sl=ne.command("codex").description("\u7BA1\u7406 Codex");sl.command("install").description("\u9996\u6B21\u5B8C\u6574\u914D\u7F6E\uFF1A\u5B89\u88C5 Codex + \u5199\u914D\u7F6E\u6587\u4EF6").action(W(tl));sl.command("use [account]").description("\u5207\u6362 Codex \u8D26\u53F7\uFF08\u4F20 email \u6216\u5E8F\u53F7\uFF0C\u7559\u7A7A\u8FDB\u884C\u4EA4\u4E92\u9009\u62E9\uFF09").action(W(il));wd();async function wd(){Va()&&await Da("1.8.5"),ne.parse()}function W(i){return async(...e)=>{try{await i(...e)}catch(t){console.error(h.red(`\u2717 ${t.message}`)),process.env.DEBUG&&console.error(t),process.exit(1)}}}
|