@easbot/gateway 0.1.14 → 0.2.0
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/chunks/chunk-CARHGEJK.mjs +2 -0
- package/dist/chunks/chunk-FZTG3VNV.cjs +1 -0
- package/dist/chunks/chunk-KUXDGVJI.cjs +2 -0
- package/dist/chunks/{chunk-CTTZF7B6.cjs → chunk-NJHJCACX.cjs} +1 -1
- package/dist/chunks/{chunk-YAKKDECJ.mjs → chunk-O3U6QY4W.mjs} +1 -1
- package/dist/chunks/chunk-P3MN336E.cjs +8 -0
- package/dist/chunks/chunk-SJCNB4N6.mjs +1 -0
- package/dist/chunks/chunk-SSKI3TXN.mjs +8 -0
- package/dist/chunks/{global-P3VKF3YI.mjs → global-32ULBSTN.mjs} +1 -1
- package/dist/chunks/{global-Q2ANDP2N.cjs → global-CQ3PKQYB.cjs} +1 -1
- package/dist/chunks/package-7MRYS3LJ.cjs +1 -0
- package/dist/chunks/package-L5UHZZQF.mjs +1 -0
- package/dist/chunks/server-5P63VGLE.mjs +1 -0
- package/dist/chunks/server-EFOLB7OJ.cjs +1 -0
- package/dist/cli.cjs +8 -8
- package/dist/cli.mjs +7 -7
- package/dist/index.cjs +8 -8
- package/dist/index.mjs +1 -1
- package/package.json +25 -23
- package/dist/chunks/chunk-5B5ZM3Q7.mjs +0 -2
- package/dist/chunks/chunk-EKLLH53Y.cjs +0 -9
- package/dist/chunks/chunk-ETYFY7SI.mjs +0 -9
- package/dist/chunks/chunk-LV4EDVUL.cjs +0 -1
- package/dist/chunks/chunk-OLIHERIJ.cjs +0 -2
- package/dist/chunks/chunk-UHALF3PM.mjs +0 -1
- package/dist/chunks/package-WJU2NXN3.cjs +0 -1
- package/dist/chunks/package-ZGPC2F6B.mjs +0 -1
- package/dist/chunks/server-3CBE5XNJ.cjs +0 -1
- package/dist/chunks/server-GVEVKN4C.mjs +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkFZTG3VNV_cjs=require('./chunks/chunk-FZTG3VNV.cjs'),chunkP3MN336E_cjs=require('./chunks/chunk-P3MN336E.cjs'),chunkSIOB4FC7_cjs=require('./chunks/chunk-SIOB4FC7.cjs'),chunkXQVVSJRM_cjs=require('./chunks/chunk-XQVVSJRM.cjs'),utils=require('@easbot/utils');var v=chunkXQVVSJRM_cjs.c(F=>{chunkSIOB4FC7_cjs.a();var T=class extends Error{constructor(t,e,i){super(i),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0;}},W=class extends T{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name;}};F.CommanderError=T;F.InvalidArgumentError=W;});var H=chunkXQVVSJRM_cjs.c(D=>{chunkSIOB4FC7_cjs.a();var{InvalidArgumentError:Vt}=v(),R=class{constructor(t,e){switch(this.description=e||"",this.variadic=false,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case "<":this.required=true,this._name=t.slice(1,-1);break;case "[":this.required=false,this._name=t.slice(1,-1);break;default:this.required=true,this._name=t;break}this._name.endsWith("...")&&(this.variadic=true,this._name=this._name.slice(0,-3));}name(){return this._name}_collectValue(t,e){return e===this.defaultValue||!Array.isArray(e)?[t]:(e.push(t),e)}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}argParser(t){return this.parseArg=t,this}choices(t){return this.argChoices=t.slice(),this.parseArg=(e,i)=>{if(!this.argChoices.includes(e))throw new Vt(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,i):e},this}argRequired(){return this.required=true,this}argOptional(){return this.required=false,this}};function Lt(r){let t=r.name()+(r.variadic===true?"...":"");return r.required?"<"+t+">":"["+t+"]"}D.Argument=R;D.humanReadableArgName=Lt;});var q=chunkXQVVSJRM_cjs.c(M=>{chunkSIOB4FC7_cjs.a();var{humanReadableArgName:It}=H(),N=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=false,this.sortOptions=false,this.showGlobalOptions=false;}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80;}visibleCommands(t){let e=t.commands.filter(n=>!n._hidden),i=t._getHelpCommand();return i&&!i._hidden&&e.push(i),this.sortSubcommands&&e.sort((n,s)=>n.name().localeCompare(s.name())),e}compareOptions(t,e){let i=n=>n.short?n.short.replace(/^-/,""):n.long.replace(/^--/,"");return i(t).localeCompare(i(e))}visibleOptions(t){let e=t.options.filter(n=>!n.hidden),i=t._getHelpOption();if(i&&!i.hidden){let n=i.short&&t._findOption(i.short),s=i.long&&t._findOption(i.long);!n&&!s?e.push(i):i.long&&!s?e.push(t.createOption(i.long,i.description)):i.short&&!n&&e.push(t.createOption(i.short,i.description));}return this.sortOptions&&e.sort(this.compareOptions),e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return [];let e=[];for(let i=t.parent;i;i=i.parent){let n=i.options.filter(s=>!s.hidden);e.push(...n);}return this.sortOptions&&e.sort(this.compareOptions),e}visibleArguments(t){return t._argsDescription&&t.registeredArguments.forEach(e=>{e.description=e.description||t._argsDescription[e.name()]||"";}),t.registeredArguments.find(e=>e.description)?t.registeredArguments:[]}subcommandTerm(t){let e=t.registeredArguments.map(i=>It(i)).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(e?" "+e:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce((i,n)=>Math.max(i,this.displayWidth(e.styleSubcommandTerm(e.subcommandTerm(n)))),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce((i,n)=>Math.max(i,this.displayWidth(e.styleOptionTerm(e.optionTerm(n)))),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce((i,n)=>Math.max(i,this.displayWidth(e.styleOptionTerm(e.optionTerm(n)))),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce((i,n)=>Math.max(i,this.displayWidth(e.styleArgumentTerm(e.argumentTerm(n)))),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let i="";for(let n=t.parent;n;n=n.parent)i=n.name()+" "+i;return i+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){let e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(i=>JSON.stringify(i)).join(", ")}`),t.defaultValue!==void 0&&(t.required||t.optional||t.isBoolean()&&typeof t.defaultValue=="boolean")&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),t.presetArg!==void 0&&t.optional&&e.push(`preset: ${JSON.stringify(t.presetArg)}`),t.envVar!==void 0&&e.push(`env: ${t.envVar}`),e.length>0){let i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}argumentDescription(t){let e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(i=>JSON.stringify(i)).join(", ")}`),t.defaultValue!==void 0&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),e.length>0){let i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}formatItemList(t,e,i){return e.length===0?[]:[i.styleTitle(t),...e,""]}groupItems(t,e,i){let n=new Map;return t.forEach(s=>{let o=i(s);n.has(o)||n.set(o,[]);}),e.forEach(s=>{let o=i(s);n.has(o)||n.set(o,[]),n.get(o).push(s);}),n}formatHelp(t,e){let i=e.padWidth(t,e),n=e.helpWidth??80;function s(c,d){return e.formatItem(c,i,d,e)}let o=[`${e.styleTitle("Usage:")} ${e.styleUsage(e.commandUsage(t))}`,""],a=e.commandDescription(t);a.length>0&&(o=o.concat([e.boxWrap(e.styleCommandDescription(a),n),""]));let h=e.visibleArguments(t).map(c=>s(e.styleArgumentTerm(e.argumentTerm(c)),e.styleArgumentDescription(e.argumentDescription(c))));if(o=o.concat(this.formatItemList("Arguments:",h,e)),this.groupItems(t.options,e.visibleOptions(t),c=>c.helpGroupHeading??"Options:").forEach((c,d)=>{let E=c.map(b=>s(e.styleOptionTerm(e.optionTerm(b)),e.styleOptionDescription(e.optionDescription(b))));o=o.concat(this.formatItemList(d,E,e));}),e.showGlobalOptions){let c=e.visibleGlobalOptions(t).map(d=>s(e.styleOptionTerm(e.optionTerm(d)),e.styleOptionDescription(e.optionDescription(d))));o=o.concat(this.formatItemList("Global Options:",c,e));}return this.groupItems(t.commands,e.visibleCommands(t),c=>c.helpGroup()||"Commands:").forEach((c,d)=>{let E=c.map(b=>s(e.styleSubcommandTerm(e.subcommandTerm(b)),e.styleSubcommandDescription(e.subcommandDescription(b))));o=o.concat(this.formatItemList(d,E,e));}),o.join(`
|
|
2
2
|
`)}displayWidth(t){return ot(t).length}styleTitle(t){return t}styleUsage(t){return t.split(" ").map(e=>e==="[options]"?this.styleOptionText(e):e==="[command]"?this.styleSubcommandText(e):e[0]==="["||e[0]==="<"?this.styleArgumentText(e):this.styleCommandText(e)).join(" ")}styleCommandDescription(t){return this.styleDescriptionText(t)}styleOptionDescription(t){return this.styleDescriptionText(t)}styleSubcommandDescription(t){return this.styleDescriptionText(t)}styleArgumentDescription(t){return this.styleDescriptionText(t)}styleDescriptionText(t){return t}styleOptionTerm(t){return this.styleOptionText(t)}styleSubcommandTerm(t){return t.split(" ").map(e=>e==="[options]"?this.styleOptionText(e):e[0]==="["||e[0]==="<"?this.styleArgumentText(e):this.styleSubcommandText(e)).join(" ")}styleArgumentTerm(t){return this.styleArgumentText(t)}styleOptionText(t){return t}styleArgumentText(t){return t}styleSubcommandText(t){return t}styleCommandText(t){return t}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestGlobalOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}preformatted(t){return /\n[^\S\r\n]/.test(t)}formatItem(t,e,i,n){let o=" ".repeat(2);if(!i)return o+t;let a=t.padEnd(e+t.length-n.displayWidth(t)),h=2,l=(this.helpWidth??80)-e-h-2,c;return l<this.minWidthToWrap||n.preformatted(i)?c=i:c=n.boxWrap(i,l).replace(/\n/g,`
|
|
3
3
|
`+" ".repeat(e+h)),o+a+" ".repeat(h)+c.replace(/\n/g,`
|
|
4
4
|
${o}`)}boxWrap(t,e){if(e<this.minWidthToWrap)return t;let i=t.split(/\r\n|\n/),n=/[\s]*[^\s]+/g,s=[];return i.forEach(o=>{let a=o.match(n);if(a===null){s.push("");return}let h=[a.shift()],p=this.displayWidth(h[0]);a.forEach(l=>{let c=this.displayWidth(l);if(p+c<=e){h.push(l),p+=c;return}s.push(h.join(""));let d=l.trimStart();h=[d],p=this.displayWidth(d);}),s.push(h.join(""));}),s.join(`
|
|
5
|
-
`)}};function ot(r){let t=/\x1b\[\d*(;\d*)*m/g;return r.replace(t,"")}M.Help=N;M.stripColor=ot;});var z=chunkXQVVSJRM_cjs.c(U=>{chunkSIOB4FC7_cjs.a();var{InvalidArgumentError:
|
|
5
|
+
`)}};function ot(r){let t=/\x1b\[\d*(;\d*)*m/g;return r.replace(t,"")}M.Help=N;M.stripColor=ot;});var z=chunkXQVVSJRM_cjs.c(U=>{chunkSIOB4FC7_cjs.a();var{InvalidArgumentError:Pt}=v(),j=class{constructor(t,e){this.flags=t,this.description=e||"",this.required=t.includes("<"),this.optional=t.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(t),this.mandatory=false;let i=Wt(t);this.short=i.shortFlag,this.long=i.longFlag,this.negate=false,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=false,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0;}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}preset(t){return this.presetArg=t,this}conflicts(t){return this.conflictsWith=this.conflictsWith.concat(t),this}implies(t){let e=t;return typeof t=="string"&&(e={[t]:true}),this.implied=Object.assign(this.implied||{},e),this}env(t){return this.envVar=t,this}argParser(t){return this.parseArg=t,this}makeOptionMandatory(t=true){return this.mandatory=!!t,this}hideHelp(t=true){return this.hidden=!!t,this}_collectValue(t,e){return e===this.defaultValue||!Array.isArray(e)?[t]:(e.push(t),e)}choices(t){return this.argChoices=t.slice(),this.parseArg=(e,i)=>{if(!this.argChoices.includes(e))throw new Pt(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,i):e},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?at(this.name().replace(/^no-/,"")):at(this.name())}helpGroup(t){return this.helpGroupHeading=t,this}is(t){return this.short===t||this.long===t}isBoolean(){return !this.required&&!this.optional&&!this.negate}},B=class{constructor(t){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,t.forEach(e=>{e.negate?this.negativeOptions.set(e.attributeName(),e):this.positiveOptions.set(e.attributeName(),e);}),this.negativeOptions.forEach((e,i)=>{this.positiveOptions.has(i)&&this.dualOptions.add(i);});}valueFromOption(t,e){let i=e.attributeName();if(!this.dualOptions.has(i))return true;let n=this.negativeOptions.get(i).presetArg,s=n!==void 0?n:false;return e.negate===(s===t)}};function at(r){return r.split("-").reduce((t,e)=>t+e[0].toUpperCase()+e.slice(1))}function Wt(r){let t,e,i=/^-[^-]$/,n=/^--[^-]/,s=r.split(/[ |,]+/).concat("guard");if(i.test(s[0])&&(t=s.shift()),n.test(s[0])&&(e=s.shift()),!t&&i.test(s[0])&&(t=s.shift()),!t&&n.test(s[0])&&(t=e,e=s.shift()),s[0].startsWith("-")){let o=s[0],a=`option creation failed due to '${o}' in option flags '${r}'`;throw /^-[^-][^-]/.test(o)?new Error(`${a}
|
|
6
6
|
- a short flag is a single dash and a single character
|
|
7
7
|
- either use a single dash and a single character (for a short flag)
|
|
8
8
|
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`):i.test(o)?new Error(`${a}
|
|
@@ -10,24 +10,24 @@ ${o}`)}boxWrap(t,e){if(e<this.minWidthToWrap)return t;let i=t.split(/\r\n|\n/),n
|
|
|
10
10
|
- too many long flags`):new Error(`${a}
|
|
11
11
|
- unrecognised flag format`)}if(t===void 0&&e===void 0)throw new Error(`option creation failed due to no flags found in '${r}'.`);return {shortFlag:t,longFlag:e}}U.Option=j;U.DualOptions=B;});var ct=chunkXQVVSJRM_cjs.c(lt=>{chunkSIOB4FC7_cjs.a();function Ft(r,t){if(Math.abs(r.length-t.length)>3)return Math.max(r.length,t.length);let e=[];for(let i=0;i<=r.length;i++)e[i]=[i];for(let i=0;i<=t.length;i++)e[0][i]=i;for(let i=1;i<=t.length;i++)for(let n=1;n<=r.length;n++){let s=1;r[n-1]===t[i-1]?s=0:s=1,e[n][i]=Math.min(e[n-1][i]+1,e[n][i-1]+1,e[n-1][i-1]+s),n>1&&i>1&&r[n-1]===t[i-2]&&r[n-2]===t[i-1]&&(e[n][i]=Math.min(e[n][i],e[n-2][i-2]+1));}return e[r.length][t.length]}function Rt(r,t){if(!t||t.length===0)return "";t=Array.from(new Set(t));let e=r.startsWith("--");e&&(r=r.slice(2),t=t.map(o=>o.slice(2)));let i=[],n=3,s=.4;return t.forEach(o=>{if(o.length<=1)return;let a=Ft(r,o),h=Math.max(r.length,o.length);(h-a)/h>s&&(a<n?(n=a,i=[o]):a===n&&i.push(o));}),i.sort((o,a)=>o.localeCompare(a)),e&&(i=i.map(o=>`--${o}`)),i.length>1?`
|
|
12
12
|
(Did you mean one of ${i.join(", ")}?)`:i.length===1?`
|
|
13
|
-
(Did you mean ${i[0]}?)`:""}lt.suggestSimilar=Rt;});var dt=chunkXQVVSJRM_cjs.c(Z=>{chunkSIOB4FC7_cjs.a();var Dt=chunkXQVVSJRM_cjs.a("events").EventEmitter,
|
|
13
|
+
(Did you mean ${i[0]}?)`:""}lt.suggestSimilar=Rt;});var dt=chunkXQVVSJRM_cjs.c(Z=>{chunkSIOB4FC7_cjs.a();var Dt=chunkXQVVSJRM_cjs.a("events").EventEmitter,J=chunkXQVVSJRM_cjs.a("child_process"),w=chunkXQVVSJRM_cjs.a("path"),k=chunkXQVVSJRM_cjs.a("fs"),m=chunkXQVVSJRM_cjs.a("process"),{Argument:Nt,humanReadableArgName:Mt}=H(),{CommanderError:K}=v(),{Help:qt,stripColor:jt}=q(),{Option:ut,DualOptions:Bt}=z(),{suggestSimilar:ht}=ct(),X=class r extends Dt{constructor(t){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=false,this._allowExcessArguments=false,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=t||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=false,this._actionHandler=null,this._executableHandler=false,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=true,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=false,this._passThroughOptions=false,this._lifeCycleHooks={},this._showHelpAfterError=false,this._showSuggestionAfterError=true,this._savedState=null,this._outputConfiguration={writeOut:e=>m.stdout.write(e),writeErr:e=>m.stderr.write(e),outputError:(e,i)=>i(e),getOutHelpWidth:()=>m.stdout.isTTY?m.stdout.columns:void 0,getErrHelpWidth:()=>m.stderr.isTTY?m.stderr.columns:void 0,getOutHasColors:()=>Y()??(m.stdout.isTTY&&m.stdout.hasColors?.()),getErrHasColors:()=>Y()??(m.stderr.isTTY&&m.stderr.hasColors?.()),stripColor:e=>jt(e)},this._hidden=false,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0;}copyInheritedSettings(t){return this._outputConfiguration=t._outputConfiguration,this._helpOption=t._helpOption,this._helpCommand=t._helpCommand,this._helpConfiguration=t._helpConfiguration,this._exitCallback=t._exitCallback,this._storeOptionsAsProperties=t._storeOptionsAsProperties,this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue,this._allowExcessArguments=t._allowExcessArguments,this._enablePositionalOptions=t._enablePositionalOptions,this._showHelpAfterError=t._showHelpAfterError,this._showSuggestionAfterError=t._showSuggestionAfterError,this}_getCommandAndAncestors(){let t=[];for(let e=this;e;e=e.parent)t.push(e);return t}command(t,e,i){let n=e,s=i;typeof n=="object"&&n!==null&&(s=n,n=null),s=s||{};let[,o,a]=t.match(/([^ ]+) *(.*)/),h=this.createCommand(o);return n&&(h.description(n),h._executableHandler=true),s.isDefault&&(this._defaultCommandName=h._name),h._hidden=!!(s.noHelp||s.hidden),h._executableFile=s.executableFile||null,a&&h.arguments(a),this._registerCommand(h),h.parent=this,h.copyInheritedSettings(this),n?this:h}createCommand(t){return new r(t)}createHelp(){return Object.assign(new qt,this.configureHelp())}configureHelp(t){return t===void 0?this._helpConfiguration:(this._helpConfiguration=t,this)}configureOutput(t){return t===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...t},this)}showHelpAfterError(t=true){return typeof t!="string"&&(t=!!t),this._showHelpAfterError=t,this}showSuggestionAfterError(t=true){return this._showSuggestionAfterError=!!t,this}addCommand(t,e){if(!t._name)throw new Error(`Command passed to .addCommand() must have a name
|
|
14
14
|
- specify the name in Command constructor or using .name()`);return e=e||{},e.isDefault&&(this._defaultCommandName=t._name),(e.noHelp||e.hidden)&&(t._hidden=true),this._registerCommand(t),t.parent=this,t._checkForBrokenPassThrough(),this}createArgument(t,e){return new Nt(t,e)}argument(t,e,i,n){let s=this.createArgument(t,e);return typeof i=="function"?s.default(n).argParser(i):s.default(i),this.addArgument(s),this}arguments(t){return t.trim().split(/ +/).forEach(e=>{this.argument(e);}),this}addArgument(t){let e=this.registeredArguments.slice(-1)[0];if(e?.variadic)throw new Error(`only the last argument can be variadic '${e.name()}'`);if(t.required&&t.defaultValue!==void 0&&t.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${t.name()}'`);return this.registeredArguments.push(t),this}helpCommand(t,e){if(typeof t=="boolean")return this._addImplicitHelpCommand=t,t&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let i=t??"help [command]",[,n,s]=i.match(/([^ ]+) *(.*)/),o=e??"display help for command",a=this.createCommand(n);return a.helpOption(false),s&&a.arguments(s),o&&a.description(o),this._addImplicitHelpCommand=true,this._helpCommand=a,(t||e)&&this._initCommandGroup(a),this}addHelpCommand(t,e){return typeof t!="object"?(this.helpCommand(t,e),this):(this._addImplicitHelpCommand=true,this._helpCommand=t,this._initCommandGroup(t),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(t,e){let i=["preSubcommand","preAction","postAction"];if(!i.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.
|
|
15
|
-
Expecting one of '${i.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(e):this._lifeCycleHooks[t]=[e],this}exitOverride(t){return t?this._exitCallback=t:this._exitCallback=e=>{if(e.code!=="commander.executeSubCommandAsync")throw e},this}_exit(t,e,i){this._exitCallback&&this._exitCallback(new
|
|
15
|
+
Expecting one of '${i.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(e):this._lifeCycleHooks[t]=[e],this}exitOverride(t){return t?this._exitCallback=t:this._exitCallback=e=>{if(e.code!=="commander.executeSubCommandAsync")throw e},this}_exit(t,e,i){this._exitCallback&&this._exitCallback(new K(t,e,i)),m.exit(t);}action(t){let e=i=>{let n=this.registeredArguments.length,s=i.slice(0,n);return this._storeOptionsAsProperties?s[n]=this:s[n]=this.opts(),s.push(this),t.apply(this,s)};return this._actionHandler=e,this}createOption(t,e){return new ut(t,e)}_callParseArg(t,e,i,n){try{return t.parseArg(e,i)}catch(s){if(s.code==="commander.invalidArgument"){let o=`${n} ${s.message}`;this.error(o,{exitCode:s.exitCode,code:s.code});}throw s}}_registerOption(t){let e=t.short&&this._findOption(t.short)||t.long&&this._findOption(t.long);if(e){let i=t.long&&this._findOption(t.long)?t.long:t.short;throw new Error(`Cannot add option '${t.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${i}'
|
|
16
16
|
- already used by option '${e.flags}'`)}this._initOptionGroup(t),this.options.push(t);}_registerCommand(t){let e=n=>[n.name()].concat(n.aliases()),i=e(t).find(n=>this._findCommand(n));if(i){let n=e(this._findCommand(i)).join("|"),s=e(t).join("|");throw new Error(`cannot add command '${s}' as already have command '${n}'`)}this._initCommandGroup(t),this.commands.push(t);}addOption(t){this._registerOption(t);let e=t.name(),i=t.attributeName();if(t.negate){let s=t.long.replace(/^--no-/,"--");this._findOption(s)||this.setOptionValueWithSource(i,t.defaultValue===void 0?true:t.defaultValue,"default");}else t.defaultValue!==void 0&&this.setOptionValueWithSource(i,t.defaultValue,"default");let n=(s,o,a)=>{s==null&&t.presetArg!==void 0&&(s=t.presetArg);let h=this.getOptionValue(i);s!==null&&t.parseArg?s=this._callParseArg(t,s,h,o):s!==null&&t.variadic&&(s=t._collectValue(s,h)),s==null&&(t.negate?s=false:t.isBoolean()||t.optional?s=true:s=""),this.setOptionValueWithSource(i,s,a);};return this.on("option:"+e,s=>{let o=`error: option '${t.flags}' argument '${s}' is invalid.`;n(s,o,"cli");}),t.envVar&&this.on("optionEnv:"+e,s=>{let o=`error: option '${t.flags}' value '${s}' from env '${t.envVar}' is invalid.`;n(s,o,"env");}),this}_optionEx(t,e,i,n,s){if(typeof e=="object"&&e instanceof ut)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let o=this.createOption(e,i);if(o.makeOptionMandatory(!!t.mandatory),typeof n=="function")o.default(s).argParser(n);else if(n instanceof RegExp){let a=n;n=(h,p)=>{let l=a.exec(h);return l?l[0]:p},o.default(s).argParser(n);}else o.default(n);return this.addOption(o)}option(t,e,i,n){return this._optionEx({},t,e,i,n)}requiredOption(t,e,i,n){return this._optionEx({mandatory:true},t,e,i,n)}combineFlagAndOptionalValue(t=true){return this._combineFlagAndOptionalValue=!!t,this}allowUnknownOption(t=true){return this._allowUnknownOption=!!t,this}allowExcessArguments(t=true){return this._allowExcessArguments=!!t,this}enablePositionalOptions(t=true){return this._enablePositionalOptions=!!t,this}passThroughOptions(t=true){return this._passThroughOptions=!!t,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(t=true){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=!!t,this}getOptionValue(t){return this._storeOptionsAsProperties?this[t]:this._optionValues[t]}setOptionValue(t,e){return this.setOptionValueWithSource(t,e,void 0)}setOptionValueWithSource(t,e,i){return this._storeOptionsAsProperties?this[t]=e:this._optionValues[t]=e,this._optionValueSources[t]=i,this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let e;return this._getCommandAndAncestors().forEach(i=>{i.getOptionValueSource(t)!==void 0&&(e=i.getOptionValueSource(t));}),e}_prepareUserArgs(t,e){if(t!==void 0&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");if(e=e||{},t===void 0&&e.from===void 0){m.versions?.electron&&(e.from="electron");let n=m.execArgv??[];(n.includes("-e")||n.includes("--eval")||n.includes("-p")||n.includes("--print"))&&(e.from="eval");}t===void 0&&(t=m.argv),this.rawArgs=t.slice();let i;switch(e.from){case void 0:case "node":this._scriptPath=t[1],i=t.slice(2);break;case "electron":m.defaultApp?(this._scriptPath=t[1],i=t.slice(2)):i=t.slice(1);break;case "user":i=t.slice(0);break;case "eval":i=t.slice(1);break;default:throw new Error(`unexpected parse option { from: '${e.from}' }`)}return !this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",i}parse(t,e){this._prepareForParse();let i=this._prepareUserArgs(t,e);return this._parseCommand([],i),this}async parseAsync(t,e){this._prepareForParse();let i=this._prepareUserArgs(t,e);return await this._parseCommand([],i),this}_prepareForParse(){this._savedState===null?this.saveStateBeforeParse():this.restoreStateBeforeParse();}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}};}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
17
17
|
- either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[];}_checkForMissingExecutable(t,e,i){if(k.existsSync(t))return;let n=e?`searched for local subcommand relative to directory '${e}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",s=`'${t}' does not exist
|
|
18
18
|
- if '${i}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
19
19
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
20
|
-
- ${n}`;throw new Error(s)}_executeSubCommand(t,e){e=e.slice();let i=false,n=[".js",".ts",".tsx",".mjs",".cjs"];function s(l,c){let d=w.resolve(l,c);if(k.existsSync(d))return d;if(n.includes(w.extname(c)))return;let E=n.find(b=>k.existsSync(`${d}${b}`));if(E)return `${d}${E}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=t._executableFile||`${this._name}-${t._name}`,a=this._executableDir||"";if(this._scriptPath){let l;try{l=k.realpathSync(this._scriptPath);}catch{l=this._scriptPath;}a=w.resolve(w.dirname(l),a);}if(a){let l=s(a,o);if(!l&&!t._executableFile&&this._scriptPath){let c=w.basename(this._scriptPath,w.extname(this._scriptPath));c!==this._name&&(l=s(a,`${c}-${t._name}`));}o=l||o;}i=n.includes(w.extname(o));let h;m.platform!=="win32"?i?(e.unshift(o),e=pt(m.execArgv).concat(e),h=
|
|
20
|
+
- ${n}`;throw new Error(s)}_executeSubCommand(t,e){e=e.slice();let i=false,n=[".js",".ts",".tsx",".mjs",".cjs"];function s(l,c){let d=w.resolve(l,c);if(k.existsSync(d))return d;if(n.includes(w.extname(c)))return;let E=n.find(b=>k.existsSync(`${d}${b}`));if(E)return `${d}${E}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=t._executableFile||`${this._name}-${t._name}`,a=this._executableDir||"";if(this._scriptPath){let l;try{l=k.realpathSync(this._scriptPath);}catch{l=this._scriptPath;}a=w.resolve(w.dirname(l),a);}if(a){let l=s(a,o);if(!l&&!t._executableFile&&this._scriptPath){let c=w.basename(this._scriptPath,w.extname(this._scriptPath));c!==this._name&&(l=s(a,`${c}-${t._name}`));}o=l||o;}i=n.includes(w.extname(o));let h;m.platform!=="win32"?i?(e.unshift(o),e=pt(m.execArgv).concat(e),h=J.spawn(m.argv[0],e,{stdio:"inherit"})):h=J.spawn(o,e,{stdio:"inherit"}):(this._checkForMissingExecutable(o,a,t._name),e.unshift(o),e=pt(m.execArgv).concat(e),h=J.spawn(m.execPath,e,{stdio:"inherit"})),h.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(c=>{m.on(c,()=>{h.killed===false&&h.exitCode===null&&h.kill(c);});});let p=this._exitCallback;h.on("close",l=>{l=l??1,p?p(new K(l,"commander.executeSubCommandAsync","(close)")):m.exit(l);}),h.on("error",l=>{if(l.code==="ENOENT")this._checkForMissingExecutable(o,a,t._name);else if(l.code==="EACCES")throw new Error(`'${o}' not executable`);if(!p)m.exit(1);else {let c=new K(1,"commander.executeSubCommandAsync","(error)");c.nestedError=l,p(c);}}),this.runningCommand=h;}_dispatchSubcommand(t,e,i){let n=this._findCommand(t);n||this.help({error:true}),n._prepareForParse();let s;return s=this._chainOrCallSubCommandHook(s,n,"preSubcommand"),s=this._chainOrCall(s,()=>{if(n._executableHandler)this._executeSubCommand(n,e.concat(i));else return n._parseCommand(e,i)}),s}_dispatchHelpCommand(t){t||this.help();let e=this._findCommand(t);return e&&!e._executableHandler&&e.help(),this._dispatchSubcommand(t,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((t,e)=>{t.required&&this.args[e]==null&&this.missingArgument(t.name());}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args);}_processArguments(){let t=(i,n,s)=>{let o=n;if(n!==null&&i.parseArg){let a=`error: command-argument value '${n}' is invalid for argument '${i.name()}'.`;o=this._callParseArg(i,n,s,a);}return o};this._checkNumberOfArguments();let e=[];this.registeredArguments.forEach((i,n)=>{let s=i.defaultValue;i.variadic?n<this.args.length?(s=this.args.slice(n),i.parseArg&&(s=s.reduce((o,a)=>t(i,a,o),i.defaultValue))):s===void 0&&(s=[]):n<this.args.length&&(s=this.args[n],i.parseArg&&(s=t(i,s,i.defaultValue))),e[n]=s;}),this.processedArgs=e;}_chainOrCall(t,e){return t?.then&&typeof t.then=="function"?t.then(()=>e()):e()}_chainOrCallHooks(t,e){let i=t,n=[];return this._getCommandAndAncestors().reverse().filter(s=>s._lifeCycleHooks[e]!==void 0).forEach(s=>{s._lifeCycleHooks[e].forEach(o=>{n.push({hookedCommand:s,callback:o});});}),e==="postAction"&&n.reverse(),n.forEach(s=>{i=this._chainOrCall(i,()=>s.callback(s.hookedCommand,this));}),i}_chainOrCallSubCommandHook(t,e,i){let n=t;return this._lifeCycleHooks[i]!==void 0&&this._lifeCycleHooks[i].forEach(s=>{n=this._chainOrCall(n,()=>s(this,e));}),n}_parseCommand(t,e){let i=this.parseOptions(e);if(this._parseOptionsEnv(),this._parseOptionsImplied(),t=t.concat(i.operands),e=i.unknown,this.args=t.concat(e),t&&this._findCommand(t[0]))return this._dispatchSubcommand(t[0],t.slice(1),e);if(this._getHelpCommand()&&t[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(t[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(e),this._dispatchSubcommand(this._defaultCommandName,t,e);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:true}),this._outputHelpIfRequested(i.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let n=()=>{i.unknown.length>0&&this.unknownOption(i.unknown[0]);},s=`command:${this.name()}`;if(this._actionHandler){n(),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(s,t,e);})),o=this._chainOrCallHooks(o,"postAction"),o}if(this.parent?.listenerCount(s))n(),this._processArguments(),this.parent.emit(s,t,e);else if(t.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",t,e);this.listenerCount("command:*")?this.emit("command:*",t,e):this.commands.length?this.unknownCommand():(n(),this._processArguments());}else this.commands.length?(n(),this.help({error:true})):(n(),this._processArguments());}_findCommand(t){if(t)return this.commands.find(e=>e._name===t||e._aliases.includes(t))}_findOption(t){return this.options.find(e=>e.is(t))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(t=>{t.options.forEach(e=>{e.mandatory&&t.getOptionValue(e.attributeName())===void 0&&t.missingMandatoryOptionValue(e);});});}_checkForConflictingLocalOptions(){let t=this.options.filter(i=>{let n=i.attributeName();return this.getOptionValue(n)===void 0?false:this.getOptionValueSource(n)!=="default"});t.filter(i=>i.conflictsWith.length>0).forEach(i=>{let n=t.find(s=>i.conflictsWith.includes(s.attributeName()));n&&this._conflictingOption(i,n);});}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(t=>{t._checkForConflictingLocalOptions();});}parseOptions(t){let e=[],i=[],n=e;function s(l){return l.length>1&&l[0]==="-"}let o=l=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(l)?!this._getCommandAndAncestors().some(c=>c.options.map(d=>d.short).some(d=>/^-\d$/.test(d))):false,a=null,h=null,p=0;for(;p<t.length||h;){let l=h??t[p++];if(h=null,l==="--"){n===i&&n.push(l),n.push(...t.slice(p));break}if(a&&(!s(l)||o(l))){this.emit(`option:${a.name()}`,l);continue}if(a=null,s(l)){let c=this._findOption(l);if(c){if(c.required){let d=t[p++];d===void 0&&this.optionMissingArgument(c),this.emit(`option:${c.name()}`,d);}else if(c.optional){let d=null;p<t.length&&(!s(t[p])||o(t[p]))&&(d=t[p++]),this.emit(`option:${c.name()}`,d);}else this.emit(`option:${c.name()}`);a=c.variadic?c:null;continue}}if(l.length>2&&l[0]==="-"&&l[1]!=="-"){let c=this._findOption(`-${l[1]}`);if(c){c.required||c.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${c.name()}`,l.slice(2)):(this.emit(`option:${c.name()}`),h=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let c=l.indexOf("="),d=this._findOption(l.slice(0,c));if(d&&(d.required||d.optional)){this.emit(`option:${d.name()}`,l.slice(c+1));continue}}if(n===e&&s(l)&&!(this.commands.length===0&&o(l))&&(n=i),(this._enablePositionalOptions||this._passThroughOptions)&&e.length===0&&i.length===0){if(this._findCommand(l)){e.push(l),i.push(...t.slice(p));break}else if(this._getHelpCommand()&&l===this._getHelpCommand().name()){e.push(l,...t.slice(p));break}else if(this._defaultCommandName){i.push(l,...t.slice(p));break}}if(this._passThroughOptions){n.push(l,...t.slice(p));break}n.push(l);}return {operands:e,unknown:i}}opts(){if(this._storeOptionsAsProperties){let t={},e=this.options.length;for(let i=0;i<e;i++){let n=this.options[i].attributeName();t[n]=n===this._versionOptionName?this._version:this[n];}return t}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((t,e)=>Object.assign(t,e.opts()),{})}error(t,e){this._outputConfiguration.outputError(`${t}
|
|
21
21
|
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
22
22
|
`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
23
23
|
`),this.outputHelp({error:true}));let i=e||{},n=i.exitCode||1,s=i.code||"commander.error";this._exit(n,s,t);}_parseOptionsEnv(){this.options.forEach(t=>{if(t.envVar&&t.envVar in m.env){let e=t.attributeName();(this.getOptionValue(e)===void 0||["default","config","env"].includes(this.getOptionValueSource(e)))&&(t.required||t.optional?this.emit(`optionEnv:${t.name()}`,m.env[t.envVar]):this.emit(`optionEnv:${t.name()}`));}});}_parseOptionsImplied(){let t=new Bt(this.options),e=i=>this.getOptionValue(i)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(i));this.options.filter(i=>i.implied!==void 0&&e(i.attributeName())&&t.valueFromOption(this.getOptionValue(i.attributeName()),i)).forEach(i=>{Object.keys(i.implied).filter(n=>!e(n)).forEach(n=>{this.setOptionValueWithSource(n,i.implied[n],"implied");});});}missingArgument(t){let e=`error: missing required argument '${t}'`;this.error(e,{code:"commander.missingArgument"});}optionMissingArgument(t){let e=`error: option '${t.flags}' argument missing`;this.error(e,{code:"commander.optionMissingArgument"});}missingMandatoryOptionValue(t){let e=`error: required option '${t.flags}' not specified`;this.error(e,{code:"commander.missingMandatoryOptionValue"});}_conflictingOption(t,e){let i=o=>{let a=o.attributeName(),h=this.getOptionValue(a),p=this.options.find(c=>c.negate&&a===c.attributeName()),l=this.options.find(c=>!c.negate&&a===c.attributeName());return p&&(p.presetArg===void 0&&h===false||p.presetArg!==void 0&&h===p.presetArg)?p:l||o},n=o=>{let a=i(o),h=a.attributeName();return this.getOptionValueSource(h)==="env"?`environment variable '${a.envVar}'`:`option '${a.flags}'`},s=`error: ${n(t)} cannot be used with ${n(e)}`;this.error(s,{code:"commander.conflictingOption"});}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let n=[],s=this;do{let o=s.createHelp().visibleOptions(s).filter(a=>a.long).map(a=>a.long);n=n.concat(o),s=s.parent;}while(s&&!s._enablePositionalOptions);e=ht(t,n);}let i=`error: unknown option '${t}'${e}`;this.error(i,{code:"commander.unknownOption"});}_excessArguments(t){if(this._allowExcessArguments)return;let e=this.registeredArguments.length,i=e===1?"":"s",s=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${e} argument${i} but got ${t.length}.`;this.error(s,{code:"commander.excessArguments"});}unknownCommand(){let t=this.args[0],e="";if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(s=>{n.push(s.name()),s.alias()&&n.push(s.alias());}),e=ht(t,n);}let i=`error: unknown command '${t}'${e}`;this.error(i,{code:"commander.unknownCommand"});}version(t,e,i){if(t===void 0)return this._version;this._version=t,e=e||"-V, --version",i=i||"output the version number";let n=this.createOption(e,i);return this._versionOptionName=n.attributeName(),this._registerOption(n),this.on("option:"+n.name(),()=>{this._outputConfiguration.writeOut(`${t}
|
|
24
24
|
`),this._exit(0,"commander.version",t);}),this}description(t,e){return t===void 0&&e===void 0?this._description:(this._description=t,e&&(this._argsDescription=e),this)}summary(t){return t===void 0?this._summary:(this._summary=t,this)}alias(t){if(t===void 0)return this._aliases[0];let e=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(e=this.commands[this.commands.length-1]),t===e._name)throw new Error("Command alias can't be the same as its name");let i=this.parent?._findCommand(t);if(i){let n=[i.name()].concat(i.aliases()).join("|");throw new Error(`cannot add alias '${t}' to command '${this.name()}' as already have command '${n}'`)}return e._aliases.push(t),this}aliases(t){return t===void 0?this._aliases:(t.forEach(e=>this.alias(e)),this)}usage(t){if(t===void 0){if(this._usage)return this._usage;let e=this.registeredArguments.map(i=>Mt(i));return [].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?e:[]).join(" ")}return this._usage=t,this}name(t){return t===void 0?this._name:(this._name=t,this)}helpGroup(t){return t===void 0?this._helpGroupHeading??"":(this._helpGroupHeading=t,this)}commandsGroup(t){return t===void 0?this._defaultCommandGroup??"":(this._defaultCommandGroup=t,this)}optionsGroup(t){return t===void 0?this._defaultOptionGroup??"":(this._defaultOptionGroup=t,this)}_initOptionGroup(t){this._defaultOptionGroup&&!t.helpGroupHeading&&t.helpGroup(this._defaultOptionGroup);}_initCommandGroup(t){this._defaultCommandGroup&&!t.helpGroup()&&t.helpGroup(this._defaultCommandGroup);}nameFromFilename(t){return this._name=w.basename(t,w.extname(t)),this}executableDir(t){return t===void 0?this._executableDir:(this._executableDir=t,this)}helpInformation(t){let e=this.createHelp(),i=this._getOutputContext(t);e.prepareContext({error:i.error,helpWidth:i.helpWidth,outputHasColors:i.hasColors});let n=e.formatHelp(this,e);return i.hasColors?n:this._outputConfiguration.stripColor(n)}_getOutputContext(t){t=t||{};let e=!!t.error,i,n,s;return e?(i=a=>this._outputConfiguration.writeErr(a),n=this._outputConfiguration.getErrHasColors(),s=this._outputConfiguration.getErrHelpWidth()):(i=a=>this._outputConfiguration.writeOut(a),n=this._outputConfiguration.getOutHasColors(),s=this._outputConfiguration.getOutHelpWidth()),{error:e,write:a=>(n||(a=this._outputConfiguration.stripColor(a)),i(a)),hasColors:n,helpWidth:s}}outputHelp(t){let e;typeof t=="function"&&(e=t,t=void 0);let i=this._getOutputContext(t),n={error:i.error,write:i.write,command:this};this._getCommandAndAncestors().reverse().forEach(o=>o.emit("beforeAllHelp",n)),this.emit("beforeHelp",n);let s=this.helpInformation({error:i.error});if(e&&(s=e(s),typeof s!="string"&&!Buffer.isBuffer(s)))throw new Error("outputHelp callback must return a string or a Buffer");i.write(s),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",n),this._getCommandAndAncestors().forEach(o=>o.emit("afterAllHelp",n));}helpOption(t,e){return typeof t=="boolean"?(t?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(t??"-h, --help",e??"display help for command"),(t||e)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(t){return this._helpOption=t,this._initOptionGroup(t),this}help(t){this.outputHelp(t);let e=Number(m.exitCode??0);e===0&&t&&typeof t!="function"&&t.error&&(e=1),this._exit(e,"commander.help","(outputHelp)");}addHelpText(t,e){let i=["beforeAll","before","after","afterAll"];if(!i.includes(t))throw new Error(`Unexpected value for position to addHelpText.
|
|
25
25
|
Expecting one of '${i.join("', '")}'`);let n=`${t}Help`;return this.on(n,s=>{let o;typeof e=="function"?o=e({error:s.error,command:s.command}):o=e,o&&s.write(`${o}
|
|
26
|
-
`);}),this}_outputHelpIfRequested(t){let e=this._getHelpOption();e&&t.find(n=>e.is(n))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"));}};function pt(r){return r.map(t=>{if(!t.startsWith("--inspect"))return t;let e,i="127.0.0.1",n="9229",s;return (s=t.match(/^(--inspect(-brk)?)$/))!==null?e=s[1]:(s=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(e=s[1],/^\d+$/.test(s[3])?n=s[3]:i=s[3]):(s=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(e=s[1],i=s[3],n=s[4]),e&&n!=="0"?`${e}=${i}:${parseInt(n)+1}`:t})}function Y(){if(m.env.NO_COLOR||m.env.FORCE_COLOR==="0"||m.env.FORCE_COLOR==="false")return false;if(m.env.FORCE_COLOR||m.env.CLICOLOR_FORCE!==void 0)return true}Z.Command=J;Z.useColor=Y;});var _t=chunkXQVVSJRM_cjs.c(C=>{chunkSIOB4FC7_cjs.a();var{Argument:mt}=H(),{Command:Q}=dt(),{CommanderError:Ut,InvalidArgumentError:ft}=v(),{Help:zt}=q(),{Option:gt}=z();C.program=new Q;C.createCommand=r=>new Q(r);C.createOption=(r,t)=>new gt(r,t);C.createArgument=(r,t)=>new mt(r,t);C.Command=Q;C.Option=gt;C.Argument=mt;C.Help=zt;C.CommanderError=Ut;C.InvalidArgumentError=ft;C.InvalidOptionArgumentError=ft;});chunkSIOB4FC7_cjs.a();chunkSIOB4FC7_cjs.a();var Ot=chunkXQVVSJRM_cjs.d(_t(),1),{program:Se,createCommand:ve,createArgument:$e,createOption:Te,CommanderError:He,InvalidArgumentError:ke,InvalidOptionArgumentError:Ge,Command:yt,Argument:Ve,Option:Le,Help:Ie}=Ot.default;chunkSIOB4FC7_cjs.a();chunkSIOB4FC7_cjs.a();var Ct={languages:[{value:"zh-CN",name:"\u7B80\u4F53\u4E2D\u6587",example:"\u4F60\u597D\uFF0CEASBOT\uFF01",supported:true},{value:"en-US",name:"English (United States)",example:"Hello, EASBOT!",supported:true}]};var Xt=Ct.languages,Jt=Xt.filter(r=>r.supported).map(r=>r.value),A={defaultLocale:"zh-CN",locales:Jt},$={},G=(r,t)=>{let e=$[r]||{translation:{}};return $[r]={translation:{...e.translation,...t.translation}},$[r]},V=(r=A.defaultLocale)=>($[r]||G(r,{translation:{}}),{locale:r,resources:$[r]||{translation:{}}});chunkSIOB4FC7_cjs.a();chunkSIOB4FC7_cjs.a();var Yt={translation:{"cli.startup.title":"Gateway WebSocket \u670D\u52A1\u5DF2\u542F\u52A8","cli.startup.status":"\u72B6\u6001","cli.startup.port":"\u7AEF\u53E3","cli.startup.hostname":"\u4E3B\u673A\u5730\u5740","cli.startup.protocol":"\u534F\u8BAE","cli.startup.connections":"\u8FDE\u63A5\u6570","cli.startup.running":"\u8FD0\u884C\u4E2D","cli.startup.stopped":"\u5DF2\u505C\u6B62","cli.startup.mode":"\u6A21\u5F0F","cli.startup.mode_standalone":"\u72EC\u7ACB\u6A21\u5F0F","cli.startup.mode_integrated":"\u96C6\u6210\u6A21\u5F0F","cli.status.title":"Gateway WebSocket \u670D\u52A1\u72B6\u6001","cli.stop.title":"Gateway WebSocket \u670D\u52A1\u5DF2\u505C\u6B62","cli.already_running":"Gateway \u670D\u52A1\u5DF2\u5728\u8FD0\u884C\u4E2D","cli.already_stopped":"Gateway \u670D\u52A1\u5DF2\u505C\u6B62","cli.shutdown_signal":"\u6536\u5230 {{signal}}\uFF0C\u6B63\u5728\u4F18\u96C5\u5173\u95ED...","cli.shutdown_success":"Gateway \u670D\u52A1\u5DF2\u6210\u529F\u505C\u6B62","cli.unknown_command":"\u672A\u77E5\u547D\u4EE4: {{command}}","cli.error.start_failed":"\u542F\u52A8 Gateway \u5931\u8D25","cli.error.stop_failed":"\u505C\u6B62 Gateway \u5931\u8D25","cli.error.restart_failed":"\u91CD\u542F Gateway \u5931\u8D25","cli.error.status_failed":"\u83B7\u53D6 Gateway \u72B6\u6001\u5931\u8D25","cli.error.shutdown":"\u5173\u95ED\u65F6\u53D1\u751F\u9519\u8BEF","cli.error.execution_failed":"CLI \u6267\u884C\u5931\u8D25","cli.error.detail":"\u9519\u8BEF\u8BE6\u60C5:","cli.command.start.desc":"\u542F\u52A8 Gateway WebSocket \u670D\u52A1","cli.command.stop.desc":"\u505C\u6B62 Gateway \u670D\u52A1","cli.command.restart.desc":"\u91CD\u542F Gateway \u670D\u52A1","cli.command.status.desc":"\u67E5\u770B Gateway \u670D\u52A1\u72B6\u6001","cli.option.directory":"\u5DE5\u4F5C\u76EE\u5F55","cli.option.port":"\u670D\u52A1\u7AEF\u53E3","cli.option.hostname":"\u4E3B\u673A\u5730\u5740","cli.option.debug":"\u542F\u7528\u8C03\u8BD5\u6A21\u5F0F","cli.help.command":"\u663E\u793A\u5E2E\u52A9\u4FE1\u606F","cli.program.description":"Gateway WebSocket \u670D\u52A1\u7BA1\u7406 CLI","cli.examples.title":"\u793A\u4F8B","cli.example.start":"\u542F\u52A8\u670D\u52A1","cli.example.stop":"\u505C\u6B62\u670D\u52A1","cli.example.restart":"\u91CD\u542F\u670D\u52A1","cli.example.hostname":"\u6307\u5B9A\u76D1\u542C\u5730\u5740"}},wt=Yt;chunkSIOB4FC7_cjs.a();var Zt={translation:{"cli.startup.title":"Gateway WebSocket Server Started","cli.startup.status":"Status","cli.startup.port":"Port","cli.startup.hostname":"Hostname","cli.startup.protocol":"Protocol","cli.startup.connections":"Connections","cli.startup.running":"Running","cli.startup.stopped":"Stopped","cli.startup.mode":"Mode","cli.startup.mode_standalone":"Standalone","cli.startup.mode_integrated":"Integrated","cli.status.title":"Gateway WebSocket Server Status","cli.stop.title":"Gateway WebSocket Server Stopped","cli.already_running":"Gateway server is already running.","cli.already_stopped":"Gateway server is already stopped.","cli.shutdown_signal":"Received {{signal}}, shutting down gracefully...","cli.shutdown_success":"Gateway stopped successfully.","cli.unknown_command":"Unknown command: {{command}}","cli.error.start_failed":"Failed to start gateway","cli.error.stop_failed":"Failed to stop gateway","cli.error.restart_failed":"Failed to restart gateway","cli.error.status_failed":"Failed to get gateway status","cli.error.shutdown":"Error during shutdown","cli.error.execution_failed":"CLI failed to execute","cli.error.detail":"Error detail:","cli.command.start.desc":"Start Gateway WebSocket service","cli.command.stop.desc":"Stop Gateway service","cli.command.restart.desc":"Restart Gateway service","cli.command.status.desc":"Check Gateway service status","cli.option.directory":"Working directory","cli.option.port":"Service port","cli.option.hostname":"Host address","cli.option.debug":"Enable debug mode","cli.help.command":"Display help information","cli.program.description":"Gateway WebSocket service management CLI","cli.examples.title":"Examples","cli.example.start":"Start service","cli.example.stop":"Stop service","cli.example.restart":"Restart service","cli.example.hostname":"Specify listening address"}},bt=Zt;var Qt=()=>{V("zh-CN"),V("en-US"),G("zh-CN",wt),G("en-US",bt);};Qt();var tt=new Map;var et=new Map;var te=r=>{if(et.has(r))return et.get(r);let t=/{{\s*(\w+)\s*}}/g,e=[],i;for(;(i=t.exec(r))!==null;){let o=i[1];o&&!e.includes(o)&&e.push(o);}let n=new RegExp("{{\\s*("+e.join("|")+")\\s*}}","g"),s={keys:e,regex:n};return et.set(r,s),s},xt=(r,t)=>{if(!r||typeof r!="string")return "";if(!t||Object.keys(t).length===0)return r;let{regex:e,keys:i}=te(r);return i.length===0||!i.some(s=>s in t)?r:r.replace(e,(s,o)=>{let a=t[o];return a==null?"":String(a)})},ee=r=>r&&A.locales.includes(r)?r:A.defaultLocale,At=r=>{if(!tt.has(r)){let{resources:t}=V(r);tt.set(r,t);}return tt.get(r)},ie=(r,t={})=>{let e=ee(t.locale),n=At(e)?.translation[r];if(n&&typeof n=="string"){let s=xt(n,t.vars);return s!=null?String(s):String(r)}if(e!==A.defaultLocale){let o=At(A.defaultLocale)?.translation[r];if(o&&typeof o=="string"){let a=xt(o,t.vars);return a!=null?String(a):String(r)}}return String(t.fallback??r)},u=ie;chunkSIOB4FC7_cjs.a();var O=chunkEKLLH53Y_cjs.a.create({service:"cli-gateway"}),I=58,Et="\u2551",St="\u2554",vt="\u255A",$t="\u2560",it="\u2550";function se(r,t=I){let e=t-r.length;return e<=0?r:r+" ".repeat(e)}function _(r){console.log(`${Et} ${se(r)} ${Et}`);}function nt(){console.log(`${St}${it.repeat(I)}${St.replace("\u2554","\u2557")}`);}function Tt(){console.log(`${$t}${it.repeat(I)}${$t.replace("\u2560","\u2563")}`);}function st(){console.log(`${vt}${it.repeat(I)}${vt.replace("\u255A","\u255D")}`);}function Ht(r){console.log(""),nt(),_(u("cli.startup.title")),Tt(),_(`${u("cli.startup.status")}: ${u("cli.startup.running").padEnd(37-u("cli.startup.status").length)}`),_(`${u("cli.startup.port")}: ${String(r.port).padEnd(37-u("cli.startup.port").length)}`),_(`${u("cli.startup.hostname")}: ${r.hostname.padEnd(37-u("cli.startup.hostname").length)}`),_(`${u("cli.startup.protocol")}: ws${" ".repeat(32)}`),r.connections!==void 0&&_(`${u("cli.startup.connections")}:${String(r.connections).padEnd(37-u("cli.startup.connections").length)}`),_(`${u("cli.startup.mode")}: ${(r.mode==="standalone"?u("cli.startup.mode_standalone"):u("cli.startup.mode_integrated")).padEnd(37-u("cli.startup.mode").length)}`),st(),console.log("");}function re(){console.log(""),nt(),_(u("cli.stop.title")),st(),console.log("");}async function oe(){try{let r=chunkLV4EDVUL_cjs.a.getStatus(),e=(await chunkLV4EDVUL_cjs.a.get())?.getStatus();console.log(""),nt(),_(u("cli.status.title")),Tt(),_(`${u("cli.startup.status")}: ${r.toUpperCase().padEnd(37-u("cli.startup.status").length)}`),e&&(_(`${u("cli.startup.port")}: ${String(e.port).padEnd(37-u("cli.startup.port").length)}`),_(`${u("cli.startup.hostname")}: ${(e.hostname||"localhost").padEnd(37-u("cli.startup.hostname").length)}`),_(`${u("cli.startup.connections")}:${String(e.connections||0).padEnd(37-u("cli.startup.connections").length)}`)),st(),console.log("");}catch(r){O.error("Failed to get gateway status",{error:r instanceof Error?r.message:String(r)}),console.error(`${u("cli.error.status_failed")}: ${r instanceof Error?r.message:String(r)}`),process.exit(1);}}async function ae(r){let t=r.directory||process.cwd();O.info("Starting gateway service",{port:r.port,hostname:r.hostname,directory:t});try{if(await chunkLV4EDVUL_cjs.a.init({directory:t,printLogs:r.debug,logLevel:r.debug?"DEBUG":"INFO"}),chunkLV4EDVUL_cjs.a.getStatus()==="running"){console.log(u("cli.already_running"));return}let i={};r.port&&(i.port=r.port),r.hostname&&(i.hostname=r.hostname),await chunkLV4EDVUL_cjs.a.start(i);let s=(await chunkLV4EDVUL_cjs.a.get())?.getStatus();Ht({port:s?.port||r.port||8080,hostname:s?.hostname||r.hostname||"localhost",connections:s?.connections||0,mode:chunkEKLLH53Y_cjs.O()?"integrated":"standalone"}),kt();}catch(e){O.error("Failed to start gateway",{error:e instanceof Error?e.message:String(e)}),console.error(`${u("cli.error.start_failed")}: ${e instanceof Error?e.message:String(e)}`),process.exit(1);}}async function le(){O.info("Stopping gateway service");try{if(chunkLV4EDVUL_cjs.a.getStatus()==="stopped"){console.log(u("cli.already_stopped"));return}await chunkLV4EDVUL_cjs.a.stop(),re(),O.info("Gateway stopped successfully");}catch(r){O.error("Failed to stop gateway",{error:r instanceof Error?r.message:String(r)}),console.error(`${u("cli.error.stop_failed")}: ${r instanceof Error?r.message:String(r)}`),process.exit(1);}}async function ce(r){O.info("Restarting gateway service");try{let t={};r.port&&(t.port=r.port),r.hostname&&(t.hostname=r.hostname),await chunkLV4EDVUL_cjs.a.restart(t);let i=(await chunkLV4EDVUL_cjs.a.get())?.getStatus();Ht({port:i?.port||r.port||8080,hostname:i?.hostname||r.hostname||"localhost",connections:i?.connections||0,mode:chunkEKLLH53Y_cjs.O()?"integrated":"standalone"}),kt(),O.info("Gateway restarted successfully");}catch(t){O.error("Failed to restart gateway",{error:t instanceof Error?t.message:String(t)}),console.error(`${u("cli.error.restart_failed")}: ${t instanceof Error?t.message:String(t)}`),process.exit(1);}}function kt(){let r=async t=>{O.debug(`Received ${t}, shutting down gracefully...`),console.log(`
|
|
27
|
-
${u("cli.shutdown_signal",{vars:{signal:t}})}`);try{await
|
|
26
|
+
`);}),this}_outputHelpIfRequested(t){let e=this._getHelpOption();e&&t.find(n=>e.is(n))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"));}};function pt(r){return r.map(t=>{if(!t.startsWith("--inspect"))return t;let e,i="127.0.0.1",n="9229",s;return (s=t.match(/^(--inspect(-brk)?)$/))!==null?e=s[1]:(s=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(e=s[1],/^\d+$/.test(s[3])?n=s[3]:i=s[3]):(s=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(e=s[1],i=s[3],n=s[4]),e&&n!=="0"?`${e}=${i}:${parseInt(n)+1}`:t})}function Y(){if(m.env.NO_COLOR||m.env.FORCE_COLOR==="0"||m.env.FORCE_COLOR==="false")return false;if(m.env.FORCE_COLOR||m.env.CLICOLOR_FORCE!==void 0)return true}Z.Command=X;Z.useColor=Y;});var _t=chunkXQVVSJRM_cjs.c(C=>{chunkSIOB4FC7_cjs.a();var{Argument:mt}=H(),{Command:Q}=dt(),{CommanderError:Ut,InvalidArgumentError:ft}=v(),{Help:zt}=q(),{Option:gt}=z();C.program=new Q;C.createCommand=r=>new Q(r);C.createOption=(r,t)=>new gt(r,t);C.createArgument=(r,t)=>new mt(r,t);C.Command=Q;C.Option=gt;C.Argument=mt;C.Help=zt;C.CommanderError=Ut;C.InvalidArgumentError=ft;C.InvalidOptionArgumentError=ft;});chunkSIOB4FC7_cjs.a();chunkSIOB4FC7_cjs.a();var Ot=chunkXQVVSJRM_cjs.d(_t(),1),{program:Se,createCommand:ve,createArgument:$e,createOption:Te,CommanderError:He,InvalidArgumentError:ke,InvalidOptionArgumentError:Ge,Command:yt,Argument:Ve,Option:Le,Help:Ie}=Ot.default;chunkSIOB4FC7_cjs.a();chunkSIOB4FC7_cjs.a();var Ct={languages:[{value:"zh-CN",name:"\u7B80\u4F53\u4E2D\u6587",example:"\u4F60\u597D\uFF0CEASBOT\uFF01",supported:true},{value:"en-US",name:"English (United States)",example:"Hello, EASBOT!",supported:true}]};var Kt=Ct.languages,Xt=Kt.filter(r=>r.supported).map(r=>r.value),A={defaultLocale:"zh-CN",locales:Xt},$={},G=(r,t)=>{let e=$[r]||{translation:{}};return $[r]={translation:{...e.translation,...t.translation}},$[r]},V=(r=A.defaultLocale)=>($[r]||G(r,{translation:{}}),{locale:r,resources:$[r]||{translation:{}}});chunkSIOB4FC7_cjs.a();chunkSIOB4FC7_cjs.a();var Yt={translation:{"cli.startup.title":"Gateway WebSocket \u670D\u52A1\u5DF2\u542F\u52A8","cli.startup.status":"\u72B6\u6001","cli.startup.port":"\u7AEF\u53E3","cli.startup.hostname":"\u4E3B\u673A\u5730\u5740","cli.startup.protocol":"\u534F\u8BAE","cli.startup.connections":"\u8FDE\u63A5\u6570","cli.startup.running":"\u8FD0\u884C\u4E2D","cli.startup.stopped":"\u5DF2\u505C\u6B62","cli.startup.mode":"\u6A21\u5F0F","cli.startup.mode_standalone":"\u72EC\u7ACB\u6A21\u5F0F","cli.startup.mode_integrated":"\u96C6\u6210\u6A21\u5F0F","cli.status.title":"Gateway WebSocket \u670D\u52A1\u72B6\u6001","cli.stop.title":"Gateway WebSocket \u670D\u52A1\u5DF2\u505C\u6B62","cli.already_running":"Gateway \u670D\u52A1\u5DF2\u5728\u8FD0\u884C\u4E2D","cli.already_stopped":"Gateway \u670D\u52A1\u5DF2\u505C\u6B62","cli.shutdown_signal":"\u6536\u5230 {{signal}}\uFF0C\u6B63\u5728\u4F18\u96C5\u5173\u95ED...","cli.shutdown_success":"Gateway \u670D\u52A1\u5DF2\u6210\u529F\u505C\u6B62","cli.unknown_command":"\u672A\u77E5\u547D\u4EE4: {{command}}","cli.error.start_failed":"\u542F\u52A8 Gateway \u5931\u8D25","cli.error.stop_failed":"\u505C\u6B62 Gateway \u5931\u8D25","cli.error.restart_failed":"\u91CD\u542F Gateway \u5931\u8D25","cli.error.status_failed":"\u83B7\u53D6 Gateway \u72B6\u6001\u5931\u8D25","cli.error.shutdown":"\u5173\u95ED\u65F6\u53D1\u751F\u9519\u8BEF","cli.error.execution_failed":"CLI \u6267\u884C\u5931\u8D25","cli.error.detail":"\u9519\u8BEF\u8BE6\u60C5:","cli.command.start.desc":"\u542F\u52A8 Gateway WebSocket \u670D\u52A1","cli.command.stop.desc":"\u505C\u6B62 Gateway \u670D\u52A1","cli.command.restart.desc":"\u91CD\u542F Gateway \u670D\u52A1","cli.command.status.desc":"\u67E5\u770B Gateway \u670D\u52A1\u72B6\u6001","cli.option.directory":"\u5DE5\u4F5C\u76EE\u5F55","cli.option.port":"\u670D\u52A1\u7AEF\u53E3","cli.option.hostname":"\u4E3B\u673A\u5730\u5740","cli.option.debug":"\u542F\u7528\u8C03\u8BD5\u6A21\u5F0F","cli.help.command":"\u663E\u793A\u5E2E\u52A9\u4FE1\u606F","cli.program.description":"Gateway WebSocket \u670D\u52A1\u7BA1\u7406 CLI","cli.examples.title":"\u793A\u4F8B","cli.example.start":"\u542F\u52A8\u670D\u52A1","cli.example.stop":"\u505C\u6B62\u670D\u52A1","cli.example.restart":"\u91CD\u542F\u670D\u52A1","cli.example.hostname":"\u6307\u5B9A\u76D1\u542C\u5730\u5740"}},wt=Yt;chunkSIOB4FC7_cjs.a();var Zt={translation:{"cli.startup.title":"Gateway WebSocket Server Started","cli.startup.status":"Status","cli.startup.port":"Port","cli.startup.hostname":"Hostname","cli.startup.protocol":"Protocol","cli.startup.connections":"Connections","cli.startup.running":"Running","cli.startup.stopped":"Stopped","cli.startup.mode":"Mode","cli.startup.mode_standalone":"Standalone","cli.startup.mode_integrated":"Integrated","cli.status.title":"Gateway WebSocket Server Status","cli.stop.title":"Gateway WebSocket Server Stopped","cli.already_running":"Gateway server is already running.","cli.already_stopped":"Gateway server is already stopped.","cli.shutdown_signal":"Received {{signal}}, shutting down gracefully...","cli.shutdown_success":"Gateway stopped successfully.","cli.unknown_command":"Unknown command: {{command}}","cli.error.start_failed":"Failed to start gateway","cli.error.stop_failed":"Failed to stop gateway","cli.error.restart_failed":"Failed to restart gateway","cli.error.status_failed":"Failed to get gateway status","cli.error.shutdown":"Error during shutdown","cli.error.execution_failed":"CLI failed to execute","cli.error.detail":"Error detail:","cli.command.start.desc":"Start Gateway WebSocket service","cli.command.stop.desc":"Stop Gateway service","cli.command.restart.desc":"Restart Gateway service","cli.command.status.desc":"Check Gateway service status","cli.option.directory":"Working directory","cli.option.port":"Service port","cli.option.hostname":"Host address","cli.option.debug":"Enable debug mode","cli.help.command":"Display help information","cli.program.description":"Gateway WebSocket service management CLI","cli.examples.title":"Examples","cli.example.start":"Start service","cli.example.stop":"Stop service","cli.example.restart":"Restart service","cli.example.hostname":"Specify listening address"}},bt=Zt;var Qt=()=>{V("zh-CN"),V("en-US"),G("zh-CN",wt),G("en-US",bt);};Qt();var tt=new Map;var et=new Map;var te=r=>{if(et.has(r))return et.get(r);let t=/{{\s*(\w+)\s*}}/g,e=[],i;for(;(i=t.exec(r))!==null;){let o=i[1];o&&!e.includes(o)&&e.push(o);}let n=new RegExp("{{\\s*("+e.join("|")+")\\s*}}","g"),s={keys:e,regex:n};return et.set(r,s),s},xt=(r,t)=>{if(!r||typeof r!="string")return "";if(!t||Object.keys(t).length===0)return r;let{regex:e,keys:i}=te(r);return i.length===0||!i.some(s=>s in t)?r:r.replace(e,(s,o)=>{let a=t[o];return a==null?"":String(a)})},ee=r=>r&&A.locales.includes(r)?r:A.defaultLocale,At=r=>{if(!tt.has(r)){let{resources:t}=V(r);tt.set(r,t);}return tt.get(r)},ie=(r,t={})=>{let e=ee(t.locale),n=At(e)?.translation[r];if(n&&typeof n=="string"){let s=xt(n,t.vars);return s!=null?String(s):String(r)}if(e!==A.defaultLocale){let o=At(A.defaultLocale)?.translation[r];if(o&&typeof o=="string"){let a=xt(o,t.vars);return a!=null?String(a):String(r)}}return String(t.fallback??r)},u=ie;chunkSIOB4FC7_cjs.a();var O=chunkP3MN336E_cjs.a.create({service:"cli-gateway"}),I=58,Et="\u2551",St="\u2554",vt="\u255A",$t="\u2560",it="\u2550";function se(r,t=I){let e=t-r.length;return e<=0?r:r+" ".repeat(e)}function _(r){console.log(`${Et} ${se(r)} ${Et}`);}function nt(){console.log(`${St}${it.repeat(I)}${St.replace("\u2554","\u2557")}`);}function Tt(){console.log(`${$t}${it.repeat(I)}${$t.replace("\u2560","\u2563")}`);}function st(){console.log(`${vt}${it.repeat(I)}${vt.replace("\u255A","\u255D")}`);}function Ht(r){console.log(""),nt(),_(u("cli.startup.title")),Tt(),_(`${u("cli.startup.status")}: ${u("cli.startup.running").padEnd(37-u("cli.startup.status").length)}`),_(`${u("cli.startup.port")}: ${String(r.port).padEnd(37-u("cli.startup.port").length)}`),_(`${u("cli.startup.hostname")}: ${r.hostname.padEnd(37-u("cli.startup.hostname").length)}`),_(`${u("cli.startup.protocol")}: ws${" ".repeat(32)}`),r.connections!==void 0&&_(`${u("cli.startup.connections")}:${String(r.connections).padEnd(37-u("cli.startup.connections").length)}`),_(`${u("cli.startup.mode")}: ${(r.mode==="standalone"?u("cli.startup.mode_standalone"):u("cli.startup.mode_integrated")).padEnd(37-u("cli.startup.mode").length)}`),st(),console.log("");}function re(){console.log(""),nt(),_(u("cli.stop.title")),st(),console.log("");}async function oe(){try{let r=chunkFZTG3VNV_cjs.a.getStatus(),e=(await chunkFZTG3VNV_cjs.a.get())?.getStatus();console.log(""),nt(),_(u("cli.status.title")),Tt(),_(`${u("cli.startup.status")}: ${r.toUpperCase().padEnd(37-u("cli.startup.status").length)}`),e&&(_(`${u("cli.startup.port")}: ${String(e.port).padEnd(37-u("cli.startup.port").length)}`),_(`${u("cli.startup.hostname")}: ${(e.hostname||"localhost").padEnd(37-u("cli.startup.hostname").length)}`),_(`${u("cli.startup.connections")}:${String(e.connections||0).padEnd(37-u("cli.startup.connections").length)}`)),st(),console.log("");}catch(r){O.error("Failed to get gateway status",{error:r instanceof Error?r.message:String(r)}),console.error(`${u("cli.error.status_failed")}: ${r instanceof Error?r.message:String(r)}`),process.exit(1);}}async function ae(r){let t=r.directory||process.cwd();O.info("Starting gateway service",{port:r.port,hostname:r.hostname,directory:t});try{if(await chunkFZTG3VNV_cjs.a.init({directory:t,printLogs:r.debug,logLevel:r.debug?"DEBUG":"INFO"}),chunkFZTG3VNV_cjs.a.getStatus()==="running"){console.log(u("cli.already_running"));return}let i={};r.port&&(i.port=r.port),r.hostname&&(i.hostname=r.hostname),await chunkFZTG3VNV_cjs.a.start(i);let s=(await chunkFZTG3VNV_cjs.a.get())?.getStatus();Ht({port:s?.port||r.port||8080,hostname:s?.hostname||r.hostname||"localhost",connections:s?.connections||0,mode:chunkP3MN336E_cjs.O()?"integrated":"standalone"}),kt();}catch(e){O.error("Failed to start gateway",{error:e instanceof Error?e.message:String(e)}),console.error(`${u("cli.error.start_failed")}: ${e instanceof Error?e.message:String(e)}`),process.exit(1);}}async function le(){O.info("Stopping gateway service");try{if(chunkFZTG3VNV_cjs.a.getStatus()==="stopped"){console.log(u("cli.already_stopped"));return}await chunkFZTG3VNV_cjs.a.stop(),re(),O.info("Gateway stopped successfully");}catch(r){O.error("Failed to stop gateway",{error:r instanceof Error?r.message:String(r)}),console.error(`${u("cli.error.stop_failed")}: ${r instanceof Error?r.message:String(r)}`),process.exit(1);}}async function ce(r){O.info("Restarting gateway service");try{let t={};r.port&&(t.port=r.port),r.hostname&&(t.hostname=r.hostname),await chunkFZTG3VNV_cjs.a.restart(t);let i=(await chunkFZTG3VNV_cjs.a.get())?.getStatus();Ht({port:i?.port||r.port||8080,hostname:i?.hostname||r.hostname||"localhost",connections:i?.connections||0,mode:chunkP3MN336E_cjs.O()?"integrated":"standalone"}),kt(),O.info("Gateway restarted successfully");}catch(t){O.error("Failed to restart gateway",{error:t instanceof Error?t.message:String(t)}),console.error(`${u("cli.error.restart_failed")}: ${t instanceof Error?t.message:String(t)}`),process.exit(1);}}function kt(){let r=async t=>{O.debug(`Received ${t}, shutting down gracefully...`),console.log(`
|
|
27
|
+
${u("cli.shutdown_signal",{vars:{signal:t}})}`);try{await chunkFZTG3VNV_cjs.a.stop(),O.debug("Gateway stopped"),console.log(u("cli.shutdown_success"));}catch(e){O.error("Error during shutdown",{error:e instanceof Error?e.message:String(e)});}process.exit(0);};process.on("SIGINT",()=>{r("SIGINT").catch(console.error);}),process.on("SIGTERM",()=>{r("SIGTERM").catch(console.error);});}async function L(r,t){switch(r){case "start":await ae(t);break;case "stop":await le();break;case "restart":await ce(t);break;case "status":await oe();break;default:console.error(u("cli.unknown_command",{vars:{command:r}})),process.exit(1);}}function ue(r){r.command("start").description(u("cli.command.start.desc")).option("-D, --directory <path>",u("cli.option.directory")).option("-p, --port <number>",u("cli.option.port"),t=>parseInt(t,10)).option("-H, --hostname <address>",u("cli.option.hostname")).option("-d, --debug",u("cli.option.debug"),false).action(async t=>{await L("start",{directory:t.directory,port:t.port,hostname:t.hostname,debug:t.debug});}),r.command("stop").description(u("cli.command.stop.desc")).action(async()=>{await L("stop",{});}),r.command("restart").description(u("cli.command.restart.desc")).option("-D, --directory <path>",u("cli.option.directory")).option("-p, --port <number>",u("cli.option.port"),t=>parseInt(t,10)).option("-H, --hostname <address>",u("cli.option.hostname")).option("-d, --debug",u("cli.option.debug"),false).action(async t=>{await L("restart",{directory:t.directory,port:t.port,hostname:t.hostname,debug:t.debug});}),r.command("status").description(u("cli.command.status.desc")).action(async()=>{await L("status",{});}),r.addHelpCommand("help",u("cli.help.command")).addHelpText("after",`
|
|
28
28
|
|
|
29
29
|
${u("cli.examples.title")}:
|
|
30
30
|
$ gateway start --port 8080 # ${u("cli.example.start")}
|
|
31
31
|
$ gateway stop # ${u("cli.example.stop")}
|
|
32
32
|
$ gateway restart --port 9090 # ${u("cli.example.restart")}
|
|
33
|
-
$ gateway start --hostname 0.0.0.0 # ${u("cli.example.hostname")}`);}async function he(r=process.argv){utils.loadEnv();let t=new yt;t.name("gateway").description(u("cli.program.description")).version("1.0.0"),ue(t),await t.parseAsync(r);}he().catch(r=>{O.error("CLI failed to execute",{error:r});let
|
|
33
|
+
$ gateway start --hostname 0.0.0.0 # ${u("cli.example.hostname")}`);}async function he(r=process.argv){utils.loadEnv();let t=new yt;t.name("gateway").description(u("cli.program.description")).version("1.0.0"),ue(t),await t.parseAsync(r);}he().catch(r=>{let t=r.code==="EPIPE"||r.code==="EIO";t||O.error("CLI failed to execute",{error:r});let e=r instanceof Error?r.message:String(r),i=r instanceof Error?r.stack:"";try{console.error(u("cli.error.execution_failed")),e&&console.error(`${u("cli.error.detail")} ${e}`),i&&console.error(i);}catch{}t||process.exit(1);});exports.main=he;exports.registerGatewayCommand=ue;
|
package/dist/cli.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {a as a$3}from'./chunks/chunk-
|
|
1
|
+
import {a as a$3}from'./chunks/chunk-SJCNB4N6.mjs';import {a as a$2,O as O$1}from'./chunks/chunk-SSKI3TXN.mjs';import {a}from'./chunks/chunk-SJNPXLNN.mjs';import {c,a as a$1,d}from'./chunks/chunk-TY6W6O7O.mjs';import {loadEnv}from'@easbot/utils';var $=c(R=>{a();var H=class extends Error{constructor(t,e,i){super(i),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0;}},F=class extends H{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name;}};R.CommanderError=H;R.InvalidArgumentError=F;});var k=c(N=>{a();var{InvalidArgumentError:Lt}=$(),D=class{constructor(t,e){switch(this.description=e||"",this.variadic=false,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case "<":this.required=true,this._name=t.slice(1,-1);break;case "[":this.required=false,this._name=t.slice(1,-1);break;default:this.required=true,this._name=t;break}this._name.endsWith("...")&&(this.variadic=true,this._name=this._name.slice(0,-3));}name(){return this._name}_collectValue(t,e){return e===this.defaultValue||!Array.isArray(e)?[t]:(e.push(t),e)}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}argParser(t){return this.parseArg=t,this}choices(t){return this.argChoices=t.slice(),this.parseArg=(e,i)=>{if(!this.argChoices.includes(e))throw new Lt(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,i):e},this}argRequired(){return this.required=true,this}argOptional(){return this.required=false,this}};function It(r){let t=r.name()+(r.variadic===true?"...":"");return r.required?"<"+t+">":"["+t+"]"}N.Argument=D;N.humanReadableArgName=It;});var j=c(q=>{a();var{humanReadableArgName:Pt}=k(),M=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=false,this.sortOptions=false,this.showGlobalOptions=false;}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80;}visibleCommands(t){let e=t.commands.filter(n=>!n._hidden),i=t._getHelpCommand();return i&&!i._hidden&&e.push(i),this.sortSubcommands&&e.sort((n,s)=>n.name().localeCompare(s.name())),e}compareOptions(t,e){let i=n=>n.short?n.short.replace(/^-/,""):n.long.replace(/^--/,"");return i(t).localeCompare(i(e))}visibleOptions(t){let e=t.options.filter(n=>!n.hidden),i=t._getHelpOption();if(i&&!i.hidden){let n=i.short&&t._findOption(i.short),s=i.long&&t._findOption(i.long);!n&&!s?e.push(i):i.long&&!s?e.push(t.createOption(i.long,i.description)):i.short&&!n&&e.push(t.createOption(i.short,i.description));}return this.sortOptions&&e.sort(this.compareOptions),e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return [];let e=[];for(let i=t.parent;i;i=i.parent){let n=i.options.filter(s=>!s.hidden);e.push(...n);}return this.sortOptions&&e.sort(this.compareOptions),e}visibleArguments(t){return t._argsDescription&&t.registeredArguments.forEach(e=>{e.description=e.description||t._argsDescription[e.name()]||"";}),t.registeredArguments.find(e=>e.description)?t.registeredArguments:[]}subcommandTerm(t){let e=t.registeredArguments.map(i=>Pt(i)).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(e?" "+e:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce((i,n)=>Math.max(i,this.displayWidth(e.styleSubcommandTerm(e.subcommandTerm(n)))),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce((i,n)=>Math.max(i,this.displayWidth(e.styleOptionTerm(e.optionTerm(n)))),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce((i,n)=>Math.max(i,this.displayWidth(e.styleOptionTerm(e.optionTerm(n)))),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce((i,n)=>Math.max(i,this.displayWidth(e.styleArgumentTerm(e.argumentTerm(n)))),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let i="";for(let n=t.parent;n;n=n.parent)i=n.name()+" "+i;return i+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){let e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(i=>JSON.stringify(i)).join(", ")}`),t.defaultValue!==void 0&&(t.required||t.optional||t.isBoolean()&&typeof t.defaultValue=="boolean")&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),t.presetArg!==void 0&&t.optional&&e.push(`preset: ${JSON.stringify(t.presetArg)}`),t.envVar!==void 0&&e.push(`env: ${t.envVar}`),e.length>0){let i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}argumentDescription(t){let e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(i=>JSON.stringify(i)).join(", ")}`),t.defaultValue!==void 0&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),e.length>0){let i=`(${e.join(", ")})`;return t.description?`${t.description} ${i}`:i}return t.description}formatItemList(t,e,i){return e.length===0?[]:[i.styleTitle(t),...e,""]}groupItems(t,e,i){let n=new Map;return t.forEach(s=>{let o=i(s);n.has(o)||n.set(o,[]);}),e.forEach(s=>{let o=i(s);n.has(o)||n.set(o,[]),n.get(o).push(s);}),n}formatHelp(t,e){let i=e.padWidth(t,e),n=e.helpWidth??80;function s(c,d){return e.formatItem(c,i,d,e)}let o=[`${e.styleTitle("Usage:")} ${e.styleUsage(e.commandUsage(t))}`,""],a=e.commandDescription(t);a.length>0&&(o=o.concat([e.boxWrap(e.styleCommandDescription(a),n),""]));let h=e.visibleArguments(t).map(c=>s(e.styleArgumentTerm(e.argumentTerm(c)),e.styleArgumentDescription(e.argumentDescription(c))));if(o=o.concat(this.formatItemList("Arguments:",h,e)),this.groupItems(t.options,e.visibleOptions(t),c=>c.helpGroupHeading??"Options:").forEach((c,d)=>{let S=c.map(x=>s(e.styleOptionTerm(e.optionTerm(x)),e.styleOptionDescription(e.optionDescription(x))));o=o.concat(this.formatItemList(d,S,e));}),e.showGlobalOptions){let c=e.visibleGlobalOptions(t).map(d=>s(e.styleOptionTerm(e.optionTerm(d)),e.styleOptionDescription(e.optionDescription(d))));o=o.concat(this.formatItemList("Global Options:",c,e));}return this.groupItems(t.commands,e.visibleCommands(t),c=>c.helpGroup()||"Commands:").forEach((c,d)=>{let S=c.map(x=>s(e.styleSubcommandTerm(e.subcommandTerm(x)),e.styleSubcommandDescription(e.subcommandDescription(x))));o=o.concat(this.formatItemList(d,S,e));}),o.join(`
|
|
2
2
|
`)}displayWidth(t){return at(t).length}styleTitle(t){return t}styleUsage(t){return t.split(" ").map(e=>e==="[options]"?this.styleOptionText(e):e==="[command]"?this.styleSubcommandText(e):e[0]==="["||e[0]==="<"?this.styleArgumentText(e):this.styleCommandText(e)).join(" ")}styleCommandDescription(t){return this.styleDescriptionText(t)}styleOptionDescription(t){return this.styleDescriptionText(t)}styleSubcommandDescription(t){return this.styleDescriptionText(t)}styleArgumentDescription(t){return this.styleDescriptionText(t)}styleDescriptionText(t){return t}styleOptionTerm(t){return this.styleOptionText(t)}styleSubcommandTerm(t){return t.split(" ").map(e=>e==="[options]"?this.styleOptionText(e):e[0]==="["||e[0]==="<"?this.styleArgumentText(e):this.styleSubcommandText(e)).join(" ")}styleArgumentTerm(t){return this.styleArgumentText(t)}styleOptionText(t){return t}styleArgumentText(t){return t}styleSubcommandText(t){return t}styleCommandText(t){return t}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestGlobalOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}preformatted(t){return /\n[^\S\r\n]/.test(t)}formatItem(t,e,i,n){let o=" ".repeat(2);if(!i)return o+t;let a=t.padEnd(e+t.length-n.displayWidth(t)),h=2,l=(this.helpWidth??80)-e-h-2,c;return l<this.minWidthToWrap||n.preformatted(i)?c=i:c=n.boxWrap(i,l).replace(/\n/g,`
|
|
3
3
|
`+" ".repeat(e+h)),o+a+" ".repeat(h)+c.replace(/\n/g,`
|
|
4
4
|
${o}`)}boxWrap(t,e){if(e<this.minWidthToWrap)return t;let i=t.split(/\r\n|\n/),n=/[\s]*[^\s]+/g,s=[];return i.forEach(o=>{let a=o.match(n);if(a===null){s.push("");return}let h=[a.shift()],p=this.displayWidth(h[0]);a.forEach(l=>{let c=this.displayWidth(l);if(p+c<=e){h.push(l),p+=c;return}s.push(h.join(""));let d=l.trimStart();h=[d],p=this.displayWidth(d);}),s.push(h.join(""));}),s.join(`
|
|
5
|
-
`)}};function at(r){let t=/\x1b\[\d*(;\d*)*m/g;return r.replace(t,"")}q.Help=M;q.stripColor=at;});var
|
|
5
|
+
`)}};function at(r){let t=/\x1b\[\d*(;\d*)*m/g;return r.replace(t,"")}q.Help=M;q.stripColor=at;});var J=c(z=>{a();var{InvalidArgumentError:Wt}=$(),B=class{constructor(t,e){this.flags=t,this.description=e||"",this.required=t.includes("<"),this.optional=t.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(t),this.mandatory=false;let i=Ft(t);this.short=i.shortFlag,this.long=i.longFlag,this.negate=false,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=false,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0;}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}preset(t){return this.presetArg=t,this}conflicts(t){return this.conflictsWith=this.conflictsWith.concat(t),this}implies(t){let e=t;return typeof t=="string"&&(e={[t]:true}),this.implied=Object.assign(this.implied||{},e),this}env(t){return this.envVar=t,this}argParser(t){return this.parseArg=t,this}makeOptionMandatory(t=true){return this.mandatory=!!t,this}hideHelp(t=true){return this.hidden=!!t,this}_collectValue(t,e){return e===this.defaultValue||!Array.isArray(e)?[t]:(e.push(t),e)}choices(t){return this.argChoices=t.slice(),this.parseArg=(e,i)=>{if(!this.argChoices.includes(e))throw new Wt(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,i):e},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?lt(this.name().replace(/^no-/,"")):lt(this.name())}helpGroup(t){return this.helpGroupHeading=t,this}is(t){return this.short===t||this.long===t}isBoolean(){return !this.required&&!this.optional&&!this.negate}},U=class{constructor(t){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,t.forEach(e=>{e.negate?this.negativeOptions.set(e.attributeName(),e):this.positiveOptions.set(e.attributeName(),e);}),this.negativeOptions.forEach((e,i)=>{this.positiveOptions.has(i)&&this.dualOptions.add(i);});}valueFromOption(t,e){let i=e.attributeName();if(!this.dualOptions.has(i))return true;let n=this.negativeOptions.get(i).presetArg,s=n!==void 0?n:false;return e.negate===(s===t)}};function lt(r){return r.split("-").reduce((t,e)=>t+e[0].toUpperCase()+e.slice(1))}function Ft(r){let t,e,i=/^-[^-]$/,n=/^--[^-]/,s=r.split(/[ |,]+/).concat("guard");if(i.test(s[0])&&(t=s.shift()),n.test(s[0])&&(e=s.shift()),!t&&i.test(s[0])&&(t=s.shift()),!t&&n.test(s[0])&&(t=e,e=s.shift()),s[0].startsWith("-")){let o=s[0],a=`option creation failed due to '${o}' in option flags '${r}'`;throw /^-[^-][^-]/.test(o)?new Error(`${a}
|
|
6
6
|
- a short flag is a single dash and a single character
|
|
7
7
|
- either use a single dash and a single character (for a short flag)
|
|
8
8
|
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`):i.test(o)?new Error(`${a}
|
|
@@ -10,24 +10,24 @@ ${o}`)}boxWrap(t,e){if(e<this.minWidthToWrap)return t;let i=t.split(/\r\n|\n/),n
|
|
|
10
10
|
- too many long flags`):new Error(`${a}
|
|
11
11
|
- unrecognised flag format`)}if(t===void 0&&e===void 0)throw new Error(`option creation failed due to no flags found in '${r}'.`);return {shortFlag:t,longFlag:e}}z.Option=B;z.DualOptions=U;});var ut=c(ct=>{a();function Rt(r,t){if(Math.abs(r.length-t.length)>3)return Math.max(r.length,t.length);let e=[];for(let i=0;i<=r.length;i++)e[i]=[i];for(let i=0;i<=t.length;i++)e[0][i]=i;for(let i=1;i<=t.length;i++)for(let n=1;n<=r.length;n++){let s=1;r[n-1]===t[i-1]?s=0:s=1,e[n][i]=Math.min(e[n-1][i]+1,e[n][i-1]+1,e[n-1][i-1]+s),n>1&&i>1&&r[n-1]===t[i-2]&&r[n-2]===t[i-1]&&(e[n][i]=Math.min(e[n][i],e[n-2][i-2]+1));}return e[r.length][t.length]}function Dt(r,t){if(!t||t.length===0)return "";t=Array.from(new Set(t));let e=r.startsWith("--");e&&(r=r.slice(2),t=t.map(o=>o.slice(2)));let i=[],n=3,s=.4;return t.forEach(o=>{if(o.length<=1)return;let a=Rt(r,o),h=Math.max(r.length,o.length);(h-a)/h>s&&(a<n?(n=a,i=[o]):a===n&&i.push(o));}),i.sort((o,a)=>o.localeCompare(a)),e&&(i=i.map(o=>`--${o}`)),i.length>1?`
|
|
12
12
|
(Did you mean one of ${i.join(", ")}?)`:i.length===1?`
|
|
13
|
-
(Did you mean ${i[0]}?)`:""}ct.suggestSimilar=Dt;});var mt=c(Q=>{a();var Nt=a$1("events").EventEmitter,
|
|
13
|
+
(Did you mean ${i[0]}?)`:""}ct.suggestSimilar=Dt;});var mt=c(Q=>{a();var Nt=a$1("events").EventEmitter,K=a$1("child_process"),b=a$1("path"),G=a$1("fs"),m=a$1("process"),{Argument:Mt,humanReadableArgName:qt}=k(),{CommanderError:X}=$(),{Help:jt,stripColor:Bt}=j(),{Option:ht,DualOptions:Ut}=J(),{suggestSimilar:pt}=ut(),Y=class r extends Nt{constructor(t){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=false,this._allowExcessArguments=false,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=t||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=false,this._actionHandler=null,this._executableHandler=false,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=true,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=false,this._passThroughOptions=false,this._lifeCycleHooks={},this._showHelpAfterError=false,this._showSuggestionAfterError=true,this._savedState=null,this._outputConfiguration={writeOut:e=>m.stdout.write(e),writeErr:e=>m.stderr.write(e),outputError:(e,i)=>i(e),getOutHelpWidth:()=>m.stdout.isTTY?m.stdout.columns:void 0,getErrHelpWidth:()=>m.stderr.isTTY?m.stderr.columns:void 0,getOutHasColors:()=>Z()??(m.stdout.isTTY&&m.stdout.hasColors?.()),getErrHasColors:()=>Z()??(m.stderr.isTTY&&m.stderr.hasColors?.()),stripColor:e=>Bt(e)},this._hidden=false,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0;}copyInheritedSettings(t){return this._outputConfiguration=t._outputConfiguration,this._helpOption=t._helpOption,this._helpCommand=t._helpCommand,this._helpConfiguration=t._helpConfiguration,this._exitCallback=t._exitCallback,this._storeOptionsAsProperties=t._storeOptionsAsProperties,this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue,this._allowExcessArguments=t._allowExcessArguments,this._enablePositionalOptions=t._enablePositionalOptions,this._showHelpAfterError=t._showHelpAfterError,this._showSuggestionAfterError=t._showSuggestionAfterError,this}_getCommandAndAncestors(){let t=[];for(let e=this;e;e=e.parent)t.push(e);return t}command(t,e,i){let n=e,s=i;typeof n=="object"&&n!==null&&(s=n,n=null),s=s||{};let[,o,a]=t.match(/([^ ]+) *(.*)/),h=this.createCommand(o);return n&&(h.description(n),h._executableHandler=true),s.isDefault&&(this._defaultCommandName=h._name),h._hidden=!!(s.noHelp||s.hidden),h._executableFile=s.executableFile||null,a&&h.arguments(a),this._registerCommand(h),h.parent=this,h.copyInheritedSettings(this),n?this:h}createCommand(t){return new r(t)}createHelp(){return Object.assign(new jt,this.configureHelp())}configureHelp(t){return t===void 0?this._helpConfiguration:(this._helpConfiguration=t,this)}configureOutput(t){return t===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...t},this)}showHelpAfterError(t=true){return typeof t!="string"&&(t=!!t),this._showHelpAfterError=t,this}showSuggestionAfterError(t=true){return this._showSuggestionAfterError=!!t,this}addCommand(t,e){if(!t._name)throw new Error(`Command passed to .addCommand() must have a name
|
|
14
14
|
- specify the name in Command constructor or using .name()`);return e=e||{},e.isDefault&&(this._defaultCommandName=t._name),(e.noHelp||e.hidden)&&(t._hidden=true),this._registerCommand(t),t.parent=this,t._checkForBrokenPassThrough(),this}createArgument(t,e){return new Mt(t,e)}argument(t,e,i,n){let s=this.createArgument(t,e);return typeof i=="function"?s.default(n).argParser(i):s.default(i),this.addArgument(s),this}arguments(t){return t.trim().split(/ +/).forEach(e=>{this.argument(e);}),this}addArgument(t){let e=this.registeredArguments.slice(-1)[0];if(e?.variadic)throw new Error(`only the last argument can be variadic '${e.name()}'`);if(t.required&&t.defaultValue!==void 0&&t.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${t.name()}'`);return this.registeredArguments.push(t),this}helpCommand(t,e){if(typeof t=="boolean")return this._addImplicitHelpCommand=t,t&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let i=t??"help [command]",[,n,s]=i.match(/([^ ]+) *(.*)/),o=e??"display help for command",a=this.createCommand(n);return a.helpOption(false),s&&a.arguments(s),o&&a.description(o),this._addImplicitHelpCommand=true,this._helpCommand=a,(t||e)&&this._initCommandGroup(a),this}addHelpCommand(t,e){return typeof t!="object"?(this.helpCommand(t,e),this):(this._addImplicitHelpCommand=true,this._helpCommand=t,this._initCommandGroup(t),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(t,e){let i=["preSubcommand","preAction","postAction"];if(!i.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.
|
|
15
|
-
Expecting one of '${i.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(e):this._lifeCycleHooks[t]=[e],this}exitOverride(t){return t?this._exitCallback=t:this._exitCallback=e=>{if(e.code!=="commander.executeSubCommandAsync")throw e},this}_exit(t,e,i){this._exitCallback&&this._exitCallback(new
|
|
15
|
+
Expecting one of '${i.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(e):this._lifeCycleHooks[t]=[e],this}exitOverride(t){return t?this._exitCallback=t:this._exitCallback=e=>{if(e.code!=="commander.executeSubCommandAsync")throw e},this}_exit(t,e,i){this._exitCallback&&this._exitCallback(new X(t,e,i)),m.exit(t);}action(t){let e=i=>{let n=this.registeredArguments.length,s=i.slice(0,n);return this._storeOptionsAsProperties?s[n]=this:s[n]=this.opts(),s.push(this),t.apply(this,s)};return this._actionHandler=e,this}createOption(t,e){return new ht(t,e)}_callParseArg(t,e,i,n){try{return t.parseArg(e,i)}catch(s){if(s.code==="commander.invalidArgument"){let o=`${n} ${s.message}`;this.error(o,{exitCode:s.exitCode,code:s.code});}throw s}}_registerOption(t){let e=t.short&&this._findOption(t.short)||t.long&&this._findOption(t.long);if(e){let i=t.long&&this._findOption(t.long)?t.long:t.short;throw new Error(`Cannot add option '${t.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${i}'
|
|
16
16
|
- already used by option '${e.flags}'`)}this._initOptionGroup(t),this.options.push(t);}_registerCommand(t){let e=n=>[n.name()].concat(n.aliases()),i=e(t).find(n=>this._findCommand(n));if(i){let n=e(this._findCommand(i)).join("|"),s=e(t).join("|");throw new Error(`cannot add command '${s}' as already have command '${n}'`)}this._initCommandGroup(t),this.commands.push(t);}addOption(t){this._registerOption(t);let e=t.name(),i=t.attributeName();if(t.negate){let s=t.long.replace(/^--no-/,"--");this._findOption(s)||this.setOptionValueWithSource(i,t.defaultValue===void 0?true:t.defaultValue,"default");}else t.defaultValue!==void 0&&this.setOptionValueWithSource(i,t.defaultValue,"default");let n=(s,o,a)=>{s==null&&t.presetArg!==void 0&&(s=t.presetArg);let h=this.getOptionValue(i);s!==null&&t.parseArg?s=this._callParseArg(t,s,h,o):s!==null&&t.variadic&&(s=t._collectValue(s,h)),s==null&&(t.negate?s=false:t.isBoolean()||t.optional?s=true:s=""),this.setOptionValueWithSource(i,s,a);};return this.on("option:"+e,s=>{let o=`error: option '${t.flags}' argument '${s}' is invalid.`;n(s,o,"cli");}),t.envVar&&this.on("optionEnv:"+e,s=>{let o=`error: option '${t.flags}' value '${s}' from env '${t.envVar}' is invalid.`;n(s,o,"env");}),this}_optionEx(t,e,i,n,s){if(typeof e=="object"&&e instanceof ht)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let o=this.createOption(e,i);if(o.makeOptionMandatory(!!t.mandatory),typeof n=="function")o.default(s).argParser(n);else if(n instanceof RegExp){let a=n;n=(h,p)=>{let l=a.exec(h);return l?l[0]:p},o.default(s).argParser(n);}else o.default(n);return this.addOption(o)}option(t,e,i,n){return this._optionEx({},t,e,i,n)}requiredOption(t,e,i,n){return this._optionEx({mandatory:true},t,e,i,n)}combineFlagAndOptionalValue(t=true){return this._combineFlagAndOptionalValue=!!t,this}allowUnknownOption(t=true){return this._allowUnknownOption=!!t,this}allowExcessArguments(t=true){return this._allowExcessArguments=!!t,this}enablePositionalOptions(t=true){return this._enablePositionalOptions=!!t,this}passThroughOptions(t=true){return this._passThroughOptions=!!t,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(t=true){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=!!t,this}getOptionValue(t){return this._storeOptionsAsProperties?this[t]:this._optionValues[t]}setOptionValue(t,e){return this.setOptionValueWithSource(t,e,void 0)}setOptionValueWithSource(t,e,i){return this._storeOptionsAsProperties?this[t]=e:this._optionValues[t]=e,this._optionValueSources[t]=i,this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let e;return this._getCommandAndAncestors().forEach(i=>{i.getOptionValueSource(t)!==void 0&&(e=i.getOptionValueSource(t));}),e}_prepareUserArgs(t,e){if(t!==void 0&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");if(e=e||{},t===void 0&&e.from===void 0){m.versions?.electron&&(e.from="electron");let n=m.execArgv??[];(n.includes("-e")||n.includes("--eval")||n.includes("-p")||n.includes("--print"))&&(e.from="eval");}t===void 0&&(t=m.argv),this.rawArgs=t.slice();let i;switch(e.from){case void 0:case "node":this._scriptPath=t[1],i=t.slice(2);break;case "electron":m.defaultApp?(this._scriptPath=t[1],i=t.slice(2)):i=t.slice(1);break;case "user":i=t.slice(0);break;case "eval":i=t.slice(1);break;default:throw new Error(`unexpected parse option { from: '${e.from}' }`)}return !this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",i}parse(t,e){this._prepareForParse();let i=this._prepareUserArgs(t,e);return this._parseCommand([],i),this}async parseAsync(t,e){this._prepareForParse();let i=this._prepareUserArgs(t,e);return await this._parseCommand([],i),this}_prepareForParse(){this._savedState===null?this.saveStateBeforeParse():this.restoreStateBeforeParse();}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}};}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
17
17
|
- either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[];}_checkForMissingExecutable(t,e,i){if(G.existsSync(t))return;let n=e?`searched for local subcommand relative to directory '${e}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",s=`'${t}' does not exist
|
|
18
18
|
- if '${i}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
19
19
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
20
|
-
- ${n}`;throw new Error(s)}_executeSubCommand(t,e){e=e.slice();let i=false,n=[".js",".ts",".tsx",".mjs",".cjs"];function s(l,c){let d=b.resolve(l,c);if(G.existsSync(d))return d;if(n.includes(b.extname(c)))return;let S=n.find(x=>G.existsSync(`${d}${x}`));if(S)return `${d}${S}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=t._executableFile||`${this._name}-${t._name}`,a=this._executableDir||"";if(this._scriptPath){let l;try{l=G.realpathSync(this._scriptPath);}catch{l=this._scriptPath;}a=b.resolve(b.dirname(l),a);}if(a){let l=s(a,o);if(!l&&!t._executableFile&&this._scriptPath){let c=b.basename(this._scriptPath,b.extname(this._scriptPath));c!==this._name&&(l=s(a,`${c}-${t._name}`));}o=l||o;}i=n.includes(b.extname(o));let h;m.platform!=="win32"?i?(e.unshift(o),e=dt(m.execArgv).concat(e),h=
|
|
20
|
+
- ${n}`;throw new Error(s)}_executeSubCommand(t,e){e=e.slice();let i=false,n=[".js",".ts",".tsx",".mjs",".cjs"];function s(l,c){let d=b.resolve(l,c);if(G.existsSync(d))return d;if(n.includes(b.extname(c)))return;let S=n.find(x=>G.existsSync(`${d}${x}`));if(S)return `${d}${S}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let o=t._executableFile||`${this._name}-${t._name}`,a=this._executableDir||"";if(this._scriptPath){let l;try{l=G.realpathSync(this._scriptPath);}catch{l=this._scriptPath;}a=b.resolve(b.dirname(l),a);}if(a){let l=s(a,o);if(!l&&!t._executableFile&&this._scriptPath){let c=b.basename(this._scriptPath,b.extname(this._scriptPath));c!==this._name&&(l=s(a,`${c}-${t._name}`));}o=l||o;}i=n.includes(b.extname(o));let h;m.platform!=="win32"?i?(e.unshift(o),e=dt(m.execArgv).concat(e),h=K.spawn(m.argv[0],e,{stdio:"inherit"})):h=K.spawn(o,e,{stdio:"inherit"}):(this._checkForMissingExecutable(o,a,t._name),e.unshift(o),e=dt(m.execArgv).concat(e),h=K.spawn(m.execPath,e,{stdio:"inherit"})),h.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(c=>{m.on(c,()=>{h.killed===false&&h.exitCode===null&&h.kill(c);});});let p=this._exitCallback;h.on("close",l=>{l=l??1,p?p(new X(l,"commander.executeSubCommandAsync","(close)")):m.exit(l);}),h.on("error",l=>{if(l.code==="ENOENT")this._checkForMissingExecutable(o,a,t._name);else if(l.code==="EACCES")throw new Error(`'${o}' not executable`);if(!p)m.exit(1);else {let c=new X(1,"commander.executeSubCommandAsync","(error)");c.nestedError=l,p(c);}}),this.runningCommand=h;}_dispatchSubcommand(t,e,i){let n=this._findCommand(t);n||this.help({error:true}),n._prepareForParse();let s;return s=this._chainOrCallSubCommandHook(s,n,"preSubcommand"),s=this._chainOrCall(s,()=>{if(n._executableHandler)this._executeSubCommand(n,e.concat(i));else return n._parseCommand(e,i)}),s}_dispatchHelpCommand(t){t||this.help();let e=this._findCommand(t);return e&&!e._executableHandler&&e.help(),this._dispatchSubcommand(t,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((t,e)=>{t.required&&this.args[e]==null&&this.missingArgument(t.name());}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args);}_processArguments(){let t=(i,n,s)=>{let o=n;if(n!==null&&i.parseArg){let a=`error: command-argument value '${n}' is invalid for argument '${i.name()}'.`;o=this._callParseArg(i,n,s,a);}return o};this._checkNumberOfArguments();let e=[];this.registeredArguments.forEach((i,n)=>{let s=i.defaultValue;i.variadic?n<this.args.length?(s=this.args.slice(n),i.parseArg&&(s=s.reduce((o,a)=>t(i,a,o),i.defaultValue))):s===void 0&&(s=[]):n<this.args.length&&(s=this.args[n],i.parseArg&&(s=t(i,s,i.defaultValue))),e[n]=s;}),this.processedArgs=e;}_chainOrCall(t,e){return t?.then&&typeof t.then=="function"?t.then(()=>e()):e()}_chainOrCallHooks(t,e){let i=t,n=[];return this._getCommandAndAncestors().reverse().filter(s=>s._lifeCycleHooks[e]!==void 0).forEach(s=>{s._lifeCycleHooks[e].forEach(o=>{n.push({hookedCommand:s,callback:o});});}),e==="postAction"&&n.reverse(),n.forEach(s=>{i=this._chainOrCall(i,()=>s.callback(s.hookedCommand,this));}),i}_chainOrCallSubCommandHook(t,e,i){let n=t;return this._lifeCycleHooks[i]!==void 0&&this._lifeCycleHooks[i].forEach(s=>{n=this._chainOrCall(n,()=>s(this,e));}),n}_parseCommand(t,e){let i=this.parseOptions(e);if(this._parseOptionsEnv(),this._parseOptionsImplied(),t=t.concat(i.operands),e=i.unknown,this.args=t.concat(e),t&&this._findCommand(t[0]))return this._dispatchSubcommand(t[0],t.slice(1),e);if(this._getHelpCommand()&&t[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(t[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(e),this._dispatchSubcommand(this._defaultCommandName,t,e);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:true}),this._outputHelpIfRequested(i.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let n=()=>{i.unknown.length>0&&this.unknownOption(i.unknown[0]);},s=`command:${this.name()}`;if(this._actionHandler){n(),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(s,t,e);})),o=this._chainOrCallHooks(o,"postAction"),o}if(this.parent?.listenerCount(s))n(),this._processArguments(),this.parent.emit(s,t,e);else if(t.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",t,e);this.listenerCount("command:*")?this.emit("command:*",t,e):this.commands.length?this.unknownCommand():(n(),this._processArguments());}else this.commands.length?(n(),this.help({error:true})):(n(),this._processArguments());}_findCommand(t){if(t)return this.commands.find(e=>e._name===t||e._aliases.includes(t))}_findOption(t){return this.options.find(e=>e.is(t))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(t=>{t.options.forEach(e=>{e.mandatory&&t.getOptionValue(e.attributeName())===void 0&&t.missingMandatoryOptionValue(e);});});}_checkForConflictingLocalOptions(){let t=this.options.filter(i=>{let n=i.attributeName();return this.getOptionValue(n)===void 0?false:this.getOptionValueSource(n)!=="default"});t.filter(i=>i.conflictsWith.length>0).forEach(i=>{let n=t.find(s=>i.conflictsWith.includes(s.attributeName()));n&&this._conflictingOption(i,n);});}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(t=>{t._checkForConflictingLocalOptions();});}parseOptions(t){let e=[],i=[],n=e;function s(l){return l.length>1&&l[0]==="-"}let o=l=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(l)?!this._getCommandAndAncestors().some(c=>c.options.map(d=>d.short).some(d=>/^-\d$/.test(d))):false,a=null,h=null,p=0;for(;p<t.length||h;){let l=h??t[p++];if(h=null,l==="--"){n===i&&n.push(l),n.push(...t.slice(p));break}if(a&&(!s(l)||o(l))){this.emit(`option:${a.name()}`,l);continue}if(a=null,s(l)){let c=this._findOption(l);if(c){if(c.required){let d=t[p++];d===void 0&&this.optionMissingArgument(c),this.emit(`option:${c.name()}`,d);}else if(c.optional){let d=null;p<t.length&&(!s(t[p])||o(t[p]))&&(d=t[p++]),this.emit(`option:${c.name()}`,d);}else this.emit(`option:${c.name()}`);a=c.variadic?c:null;continue}}if(l.length>2&&l[0]==="-"&&l[1]!=="-"){let c=this._findOption(`-${l[1]}`);if(c){c.required||c.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${c.name()}`,l.slice(2)):(this.emit(`option:${c.name()}`),h=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let c=l.indexOf("="),d=this._findOption(l.slice(0,c));if(d&&(d.required||d.optional)){this.emit(`option:${d.name()}`,l.slice(c+1));continue}}if(n===e&&s(l)&&!(this.commands.length===0&&o(l))&&(n=i),(this._enablePositionalOptions||this._passThroughOptions)&&e.length===0&&i.length===0){if(this._findCommand(l)){e.push(l),i.push(...t.slice(p));break}else if(this._getHelpCommand()&&l===this._getHelpCommand().name()){e.push(l,...t.slice(p));break}else if(this._defaultCommandName){i.push(l,...t.slice(p));break}}if(this._passThroughOptions){n.push(l,...t.slice(p));break}n.push(l);}return {operands:e,unknown:i}}opts(){if(this._storeOptionsAsProperties){let t={},e=this.options.length;for(let i=0;i<e;i++){let n=this.options[i].attributeName();t[n]=n===this._versionOptionName?this._version:this[n];}return t}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((t,e)=>Object.assign(t,e.opts()),{})}error(t,e){this._outputConfiguration.outputError(`${t}
|
|
21
21
|
`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
22
22
|
`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
23
23
|
`),this.outputHelp({error:true}));let i=e||{},n=i.exitCode||1,s=i.code||"commander.error";this._exit(n,s,t);}_parseOptionsEnv(){this.options.forEach(t=>{if(t.envVar&&t.envVar in m.env){let e=t.attributeName();(this.getOptionValue(e)===void 0||["default","config","env"].includes(this.getOptionValueSource(e)))&&(t.required||t.optional?this.emit(`optionEnv:${t.name()}`,m.env[t.envVar]):this.emit(`optionEnv:${t.name()}`));}});}_parseOptionsImplied(){let t=new Ut(this.options),e=i=>this.getOptionValue(i)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(i));this.options.filter(i=>i.implied!==void 0&&e(i.attributeName())&&t.valueFromOption(this.getOptionValue(i.attributeName()),i)).forEach(i=>{Object.keys(i.implied).filter(n=>!e(n)).forEach(n=>{this.setOptionValueWithSource(n,i.implied[n],"implied");});});}missingArgument(t){let e=`error: missing required argument '${t}'`;this.error(e,{code:"commander.missingArgument"});}optionMissingArgument(t){let e=`error: option '${t.flags}' argument missing`;this.error(e,{code:"commander.optionMissingArgument"});}missingMandatoryOptionValue(t){let e=`error: required option '${t.flags}' not specified`;this.error(e,{code:"commander.missingMandatoryOptionValue"});}_conflictingOption(t,e){let i=o=>{let a=o.attributeName(),h=this.getOptionValue(a),p=this.options.find(c=>c.negate&&a===c.attributeName()),l=this.options.find(c=>!c.negate&&a===c.attributeName());return p&&(p.presetArg===void 0&&h===false||p.presetArg!==void 0&&h===p.presetArg)?p:l||o},n=o=>{let a=i(o),h=a.attributeName();return this.getOptionValueSource(h)==="env"?`environment variable '${a.envVar}'`:`option '${a.flags}'`},s=`error: ${n(t)} cannot be used with ${n(e)}`;this.error(s,{code:"commander.conflictingOption"});}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let n=[],s=this;do{let o=s.createHelp().visibleOptions(s).filter(a=>a.long).map(a=>a.long);n=n.concat(o),s=s.parent;}while(s&&!s._enablePositionalOptions);e=pt(t,n);}let i=`error: unknown option '${t}'${e}`;this.error(i,{code:"commander.unknownOption"});}_excessArguments(t){if(this._allowExcessArguments)return;let e=this.registeredArguments.length,i=e===1?"":"s",s=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${e} argument${i} but got ${t.length}.`;this.error(s,{code:"commander.excessArguments"});}unknownCommand(){let t=this.args[0],e="";if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(s=>{n.push(s.name()),s.alias()&&n.push(s.alias());}),e=pt(t,n);}let i=`error: unknown command '${t}'${e}`;this.error(i,{code:"commander.unknownCommand"});}version(t,e,i){if(t===void 0)return this._version;this._version=t,e=e||"-V, --version",i=i||"output the version number";let n=this.createOption(e,i);return this._versionOptionName=n.attributeName(),this._registerOption(n),this.on("option:"+n.name(),()=>{this._outputConfiguration.writeOut(`${t}
|
|
24
24
|
`),this._exit(0,"commander.version",t);}),this}description(t,e){return t===void 0&&e===void 0?this._description:(this._description=t,e&&(this._argsDescription=e),this)}summary(t){return t===void 0?this._summary:(this._summary=t,this)}alias(t){if(t===void 0)return this._aliases[0];let e=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(e=this.commands[this.commands.length-1]),t===e._name)throw new Error("Command alias can't be the same as its name");let i=this.parent?._findCommand(t);if(i){let n=[i.name()].concat(i.aliases()).join("|");throw new Error(`cannot add alias '${t}' to command '${this.name()}' as already have command '${n}'`)}return e._aliases.push(t),this}aliases(t){return t===void 0?this._aliases:(t.forEach(e=>this.alias(e)),this)}usage(t){if(t===void 0){if(this._usage)return this._usage;let e=this.registeredArguments.map(i=>qt(i));return [].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?e:[]).join(" ")}return this._usage=t,this}name(t){return t===void 0?this._name:(this._name=t,this)}helpGroup(t){return t===void 0?this._helpGroupHeading??"":(this._helpGroupHeading=t,this)}commandsGroup(t){return t===void 0?this._defaultCommandGroup??"":(this._defaultCommandGroup=t,this)}optionsGroup(t){return t===void 0?this._defaultOptionGroup??"":(this._defaultOptionGroup=t,this)}_initOptionGroup(t){this._defaultOptionGroup&&!t.helpGroupHeading&&t.helpGroup(this._defaultOptionGroup);}_initCommandGroup(t){this._defaultCommandGroup&&!t.helpGroup()&&t.helpGroup(this._defaultCommandGroup);}nameFromFilename(t){return this._name=b.basename(t,b.extname(t)),this}executableDir(t){return t===void 0?this._executableDir:(this._executableDir=t,this)}helpInformation(t){let e=this.createHelp(),i=this._getOutputContext(t);e.prepareContext({error:i.error,helpWidth:i.helpWidth,outputHasColors:i.hasColors});let n=e.formatHelp(this,e);return i.hasColors?n:this._outputConfiguration.stripColor(n)}_getOutputContext(t){t=t||{};let e=!!t.error,i,n,s;return e?(i=a=>this._outputConfiguration.writeErr(a),n=this._outputConfiguration.getErrHasColors(),s=this._outputConfiguration.getErrHelpWidth()):(i=a=>this._outputConfiguration.writeOut(a),n=this._outputConfiguration.getOutHasColors(),s=this._outputConfiguration.getOutHelpWidth()),{error:e,write:a=>(n||(a=this._outputConfiguration.stripColor(a)),i(a)),hasColors:n,helpWidth:s}}outputHelp(t){let e;typeof t=="function"&&(e=t,t=void 0);let i=this._getOutputContext(t),n={error:i.error,write:i.write,command:this};this._getCommandAndAncestors().reverse().forEach(o=>o.emit("beforeAllHelp",n)),this.emit("beforeHelp",n);let s=this.helpInformation({error:i.error});if(e&&(s=e(s),typeof s!="string"&&!Buffer.isBuffer(s)))throw new Error("outputHelp callback must return a string or a Buffer");i.write(s),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",n),this._getCommandAndAncestors().forEach(o=>o.emit("afterAllHelp",n));}helpOption(t,e){return typeof t=="boolean"?(t?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(t??"-h, --help",e??"display help for command"),(t||e)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(t){return this._helpOption=t,this._initOptionGroup(t),this}help(t){this.outputHelp(t);let e=Number(m.exitCode??0);e===0&&t&&typeof t!="function"&&t.error&&(e=1),this._exit(e,"commander.help","(outputHelp)");}addHelpText(t,e){let i=["beforeAll","before","after","afterAll"];if(!i.includes(t))throw new Error(`Unexpected value for position to addHelpText.
|
|
25
25
|
Expecting one of '${i.join("', '")}'`);let n=`${t}Help`;return this.on(n,s=>{let o;typeof e=="function"?o=e({error:s.error,command:s.command}):o=e,o&&s.write(`${o}
|
|
26
|
-
`);}),this}_outputHelpIfRequested(t){let e=this._getHelpOption();e&&t.find(n=>e.is(n))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"));}};function dt(r){return r.map(t=>{if(!t.startsWith("--inspect"))return t;let e,i="127.0.0.1",n="9229",s;return (s=t.match(/^(--inspect(-brk)?)$/))!==null?e=s[1]:(s=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(e=s[1],/^\d+$/.test(s[3])?n=s[3]:i=s[3]):(s=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(e=s[1],i=s[3],n=s[4]),e&&n!=="0"?`${e}=${i}:${parseInt(n)+1}`:t})}function Z(){if(m.env.NO_COLOR||m.env.FORCE_COLOR==="0"||m.env.FORCE_COLOR==="false")return false;if(m.env.FORCE_COLOR||m.env.CLICOLOR_FORCE!==void 0)return true}Q.Command=Y;Q.useColor=Z;});var Ot=c(w=>{a();var{Argument:ft}=k(),{Command:tt}=mt(),{CommanderError:zt,InvalidArgumentError:gt}=$(),{Help:Kt}=j(),{Option:_t}=K();w.program=new tt;w.createCommand=r=>new tt(r);w.createOption=(r,t)=>new _t(r,t);w.createArgument=(r,t)=>new ft(r,t);w.Command=tt;w.Option=_t;w.Argument=ft;w.Help=Kt;w.CommanderError=zt;w.InvalidArgumentError=gt;w.InvalidOptionArgumentError=gt;});a();a();var yt=d(Ot(),1),{program:ve,createCommand:$e,createArgument:Te,createOption:He,CommanderError:ke,InvalidArgumentError:Ge,InvalidOptionArgumentError:Ve,Command:Ct,Argument:Le,Option:Ie,Help:We}=yt.default;a();a();var wt={languages:[{value:"zh-CN",name:"\u7B80\u4F53\u4E2D\u6587",example:"\u4F60\u597D\uFF0CEASBOT\uFF01",supported:true},{value:"en-US",name:"English (United States)",example:"Hello, EASBOT!",supported:true}]};var Jt=wt.languages,Yt=Jt.filter(r=>r.supported).map(r=>r.value),E={defaultLocale:"zh-CN",locales:Yt},T={},V=(r,t)=>{let e=T[r]||{translation:{}};return T[r]={translation:{...e.translation,...t.translation}},T[r]},L=(r=E.defaultLocale)=>(T[r]||V(r,{translation:{}}),{locale:r,resources:T[r]||{translation:{}}});a();a();var Zt={translation:{"cli.startup.title":"Gateway WebSocket \u670D\u52A1\u5DF2\u542F\u52A8","cli.startup.status":"\u72B6\u6001","cli.startup.port":"\u7AEF\u53E3","cli.startup.hostname":"\u4E3B\u673A\u5730\u5740","cli.startup.protocol":"\u534F\u8BAE","cli.startup.connections":"\u8FDE\u63A5\u6570","cli.startup.running":"\u8FD0\u884C\u4E2D","cli.startup.stopped":"\u5DF2\u505C\u6B62","cli.startup.mode":"\u6A21\u5F0F","cli.startup.mode_standalone":"\u72EC\u7ACB\u6A21\u5F0F","cli.startup.mode_integrated":"\u96C6\u6210\u6A21\u5F0F","cli.status.title":"Gateway WebSocket \u670D\u52A1\u72B6\u6001","cli.stop.title":"Gateway WebSocket \u670D\u52A1\u5DF2\u505C\u6B62","cli.already_running":"Gateway \u670D\u52A1\u5DF2\u5728\u8FD0\u884C\u4E2D","cli.already_stopped":"Gateway \u670D\u52A1\u5DF2\u505C\u6B62","cli.shutdown_signal":"\u6536\u5230 {{signal}}\uFF0C\u6B63\u5728\u4F18\u96C5\u5173\u95ED...","cli.shutdown_success":"Gateway \u670D\u52A1\u5DF2\u6210\u529F\u505C\u6B62","cli.unknown_command":"\u672A\u77E5\u547D\u4EE4: {{command}}","cli.error.start_failed":"\u542F\u52A8 Gateway \u5931\u8D25","cli.error.stop_failed":"\u505C\u6B62 Gateway \u5931\u8D25","cli.error.restart_failed":"\u91CD\u542F Gateway \u5931\u8D25","cli.error.status_failed":"\u83B7\u53D6 Gateway \u72B6\u6001\u5931\u8D25","cli.error.shutdown":"\u5173\u95ED\u65F6\u53D1\u751F\u9519\u8BEF","cli.error.execution_failed":"CLI \u6267\u884C\u5931\u8D25","cli.error.detail":"\u9519\u8BEF\u8BE6\u60C5:","cli.command.start.desc":"\u542F\u52A8 Gateway WebSocket \u670D\u52A1","cli.command.stop.desc":"\u505C\u6B62 Gateway \u670D\u52A1","cli.command.restart.desc":"\u91CD\u542F Gateway \u670D\u52A1","cli.command.status.desc":"\u67E5\u770B Gateway \u670D\u52A1\u72B6\u6001","cli.option.directory":"\u5DE5\u4F5C\u76EE\u5F55","cli.option.port":"\u670D\u52A1\u7AEF\u53E3","cli.option.hostname":"\u4E3B\u673A\u5730\u5740","cli.option.debug":"\u542F\u7528\u8C03\u8BD5\u6A21\u5F0F","cli.help.command":"\u663E\u793A\u5E2E\u52A9\u4FE1\u606F","cli.program.description":"Gateway WebSocket \u670D\u52A1\u7BA1\u7406 CLI","cli.examples.title":"\u793A\u4F8B","cli.example.start":"\u542F\u52A8\u670D\u52A1","cli.example.stop":"\u505C\u6B62\u670D\u52A1","cli.example.restart":"\u91CD\u542F\u670D\u52A1","cli.example.hostname":"\u6307\u5B9A\u76D1\u542C\u5730\u5740"}},bt=Zt;a();var Qt={translation:{"cli.startup.title":"Gateway WebSocket Server Started","cli.startup.status":"Status","cli.startup.port":"Port","cli.startup.hostname":"Hostname","cli.startup.protocol":"Protocol","cli.startup.connections":"Connections","cli.startup.running":"Running","cli.startup.stopped":"Stopped","cli.startup.mode":"Mode","cli.startup.mode_standalone":"Standalone","cli.startup.mode_integrated":"Integrated","cli.status.title":"Gateway WebSocket Server Status","cli.stop.title":"Gateway WebSocket Server Stopped","cli.already_running":"Gateway server is already running.","cli.already_stopped":"Gateway server is already stopped.","cli.shutdown_signal":"Received {{signal}}, shutting down gracefully...","cli.shutdown_success":"Gateway stopped successfully.","cli.unknown_command":"Unknown command: {{command}}","cli.error.start_failed":"Failed to start gateway","cli.error.stop_failed":"Failed to stop gateway","cli.error.restart_failed":"Failed to restart gateway","cli.error.status_failed":"Failed to get gateway status","cli.error.shutdown":"Error during shutdown","cli.error.execution_failed":"CLI failed to execute","cli.error.detail":"Error detail:","cli.command.start.desc":"Start Gateway WebSocket service","cli.command.stop.desc":"Stop Gateway service","cli.command.restart.desc":"Restart Gateway service","cli.command.status.desc":"Check Gateway service status","cli.option.directory":"Working directory","cli.option.port":"Service port","cli.option.hostname":"Host address","cli.option.debug":"Enable debug mode","cli.help.command":"Display help information","cli.program.description":"Gateway WebSocket service management CLI","cli.examples.title":"Examples","cli.example.start":"Start service","cli.example.stop":"Stop service","cli.example.restart":"Restart service","cli.example.hostname":"Specify listening address"}},xt=Qt;var te=()=>{L("zh-CN"),L("en-US"),V("zh-CN",bt),V("en-US",xt);};te();var et=new Map;var it=new Map;var ee=r=>{if(it.has(r))return it.get(r);let t=/{{\s*(\w+)\s*}}/g,e=[],i;for(;(i=t.exec(r))!==null;){let o=i[1];o&&!e.includes(o)&&e.push(o);}let n=new RegExp("{{\\s*("+e.join("|")+")\\s*}}","g"),s={keys:e,regex:n};return it.set(r,s),s},At=(r,t)=>{if(!r||typeof r!="string")return "";if(!t||Object.keys(t).length===0)return r;let{regex:e,keys:i}=ee(r);return i.length===0||!i.some(s=>s in t)?r:r.replace(e,(s,o)=>{let a=t[o];return a==null?"":String(a)})},ie=r=>r&&E.locales.includes(r)?r:E.defaultLocale,Et=r=>{if(!et.has(r)){let{resources:t}=L(r);et.set(r,t);}return et.get(r)},ne=(r,t={})=>{let e=ie(t.locale),n=Et(e)?.translation[r];if(n&&typeof n=="string"){let s=At(n,t.vars);return s!=null?String(s):String(r)}if(e!==E.defaultLocale){let o=Et(E.defaultLocale)?.translation[r];if(o&&typeof o=="string"){let a=At(o,t.vars);return a!=null?String(a):String(r)}}return String(t.fallback??r)},u=ne;a();var y=a$2.create({service:"cli-gateway"}),W=58,St="\u2551",vt="\u2554",$t="\u255A",Tt="\u2560",nt="\u2550";function re(r,t=W){let e=t-r.length;return e<=0?r:r+" ".repeat(e)}function O(r){console.log(`${St} ${re(r)} ${St}`);}function st(){console.log(`${vt}${nt.repeat(W)}${vt.replace("\u2554","\u2557")}`);}function Ht(){console.log(`${Tt}${nt.repeat(W)}${Tt.replace("\u2560","\u2563")}`);}function rt(){console.log(`${$t}${nt.repeat(W)}${$t.replace("\u255A","\u255D")}`);}function kt(r){console.log(""),st(),O(u("cli.startup.title")),Ht(),O(`${u("cli.startup.status")}: ${u("cli.startup.running").padEnd(37-u("cli.startup.status").length)}`),O(`${u("cli.startup.port")}: ${String(r.port).padEnd(37-u("cli.startup.port").length)}`),O(`${u("cli.startup.hostname")}: ${r.hostname.padEnd(37-u("cli.startup.hostname").length)}`),O(`${u("cli.startup.protocol")}: ws${" ".repeat(32)}`),r.connections!==void 0&&O(`${u("cli.startup.connections")}:${String(r.connections).padEnd(37-u("cli.startup.connections").length)}`),O(`${u("cli.startup.mode")}: ${(r.mode==="standalone"?u("cli.startup.mode_standalone"):u("cli.startup.mode_integrated")).padEnd(37-u("cli.startup.mode").length)}`),rt(),console.log("");}function oe(){console.log(""),st(),O(u("cli.stop.title")),rt(),console.log("");}async function ae(){try{let r=a$3.getStatus(),e=(await a$3.get())?.getStatus();console.log(""),st(),O(u("cli.status.title")),Ht(),O(`${u("cli.startup.status")}: ${r.toUpperCase().padEnd(37-u("cli.startup.status").length)}`),e&&(O(`${u("cli.startup.port")}: ${String(e.port).padEnd(37-u("cli.startup.port").length)}`),O(`${u("cli.startup.hostname")}: ${(e.hostname||"localhost").padEnd(37-u("cli.startup.hostname").length)}`),O(`${u("cli.startup.connections")}:${String(e.connections||0).padEnd(37-u("cli.startup.connections").length)}`)),rt(),console.log("");}catch(r){y.error("Failed to get gateway status",{error:r instanceof Error?r.message:String(r)}),console.error(`${u("cli.error.status_failed")}: ${r instanceof Error?r.message:String(r)}`),process.exit(1);}}async function le(r){let t=r.directory||process.cwd();y.info("Starting gateway service",{port:r.port,hostname:r.hostname,directory:t});try{if(await a$3.init({directory:t,printLogs:r.debug,logLevel:r.debug?"DEBUG":"INFO"}),a$3.getStatus()==="running"){console.log(u("cli.already_running"));return}let i={};r.port&&(i.port=r.port),r.hostname&&(i.hostname=r.hostname),await a$3.start(i);let s=(await a$3.get())?.getStatus();kt({port:s?.port||r.port||8080,hostname:s?.hostname||r.hostname||"localhost",connections:s?.connections||0,mode:O$1()?"integrated":"standalone"}),Gt();}catch(e){y.error("Failed to start gateway",{error:e instanceof Error?e.message:String(e)}),console.error(`${u("cli.error.start_failed")}: ${e instanceof Error?e.message:String(e)}`),process.exit(1);}}async function ce(){y.info("Stopping gateway service");try{if(a$3.getStatus()==="stopped"){console.log(u("cli.already_stopped"));return}await a$3.stop(),oe(),y.info("Gateway stopped successfully");}catch(r){y.error("Failed to stop gateway",{error:r instanceof Error?r.message:String(r)}),console.error(`${u("cli.error.stop_failed")}: ${r instanceof Error?r.message:String(r)}`),process.exit(1);}}async function ue(r){y.info("Restarting gateway service");try{let t={};r.port&&(t.port=r.port),r.hostname&&(t.hostname=r.hostname),await a$3.restart(t);let i=(await a$3.get())?.getStatus();kt({port:i?.port||r.port||8080,hostname:i?.hostname||r.hostname||"localhost",connections:i?.connections||0,mode:O$1()?"integrated":"standalone"}),Gt(),y.info("Gateway restarted successfully");}catch(t){y.error("Failed to restart gateway",{error:t instanceof Error?t.message:String(t)}),console.error(`${u("cli.error.restart_failed")}: ${t instanceof Error?t.message:String(t)}`),process.exit(1);}}function Gt(){let r=async t=>{y.debug(`Received ${t}, shutting down gracefully...`),console.log(`
|
|
26
|
+
`);}),this}_outputHelpIfRequested(t){let e=this._getHelpOption();e&&t.find(n=>e.is(n))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"));}};function dt(r){return r.map(t=>{if(!t.startsWith("--inspect"))return t;let e,i="127.0.0.1",n="9229",s;return (s=t.match(/^(--inspect(-brk)?)$/))!==null?e=s[1]:(s=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(e=s[1],/^\d+$/.test(s[3])?n=s[3]:i=s[3]):(s=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(e=s[1],i=s[3],n=s[4]),e&&n!=="0"?`${e}=${i}:${parseInt(n)+1}`:t})}function Z(){if(m.env.NO_COLOR||m.env.FORCE_COLOR==="0"||m.env.FORCE_COLOR==="false")return false;if(m.env.FORCE_COLOR||m.env.CLICOLOR_FORCE!==void 0)return true}Q.Command=Y;Q.useColor=Z;});var Ot=c(w=>{a();var{Argument:ft}=k(),{Command:tt}=mt(),{CommanderError:zt,InvalidArgumentError:gt}=$(),{Help:Jt}=j(),{Option:_t}=J();w.program=new tt;w.createCommand=r=>new tt(r);w.createOption=(r,t)=>new _t(r,t);w.createArgument=(r,t)=>new ft(r,t);w.Command=tt;w.Option=_t;w.Argument=ft;w.Help=Jt;w.CommanderError=zt;w.InvalidArgumentError=gt;w.InvalidOptionArgumentError=gt;});a();a();var yt=d(Ot(),1),{program:ve,createCommand:$e,createArgument:Te,createOption:He,CommanderError:ke,InvalidArgumentError:Ge,InvalidOptionArgumentError:Ve,Command:Ct,Argument:Le,Option:Ie,Help:Pe}=yt.default;a();a();var wt={languages:[{value:"zh-CN",name:"\u7B80\u4F53\u4E2D\u6587",example:"\u4F60\u597D\uFF0CEASBOT\uFF01",supported:true},{value:"en-US",name:"English (United States)",example:"Hello, EASBOT!",supported:true}]};var Xt=wt.languages,Yt=Xt.filter(r=>r.supported).map(r=>r.value),E={defaultLocale:"zh-CN",locales:Yt},T={},V=(r,t)=>{let e=T[r]||{translation:{}};return T[r]={translation:{...e.translation,...t.translation}},T[r]},L=(r=E.defaultLocale)=>(T[r]||V(r,{translation:{}}),{locale:r,resources:T[r]||{translation:{}}});a();a();var Zt={translation:{"cli.startup.title":"Gateway WebSocket \u670D\u52A1\u5DF2\u542F\u52A8","cli.startup.status":"\u72B6\u6001","cli.startup.port":"\u7AEF\u53E3","cli.startup.hostname":"\u4E3B\u673A\u5730\u5740","cli.startup.protocol":"\u534F\u8BAE","cli.startup.connections":"\u8FDE\u63A5\u6570","cli.startup.running":"\u8FD0\u884C\u4E2D","cli.startup.stopped":"\u5DF2\u505C\u6B62","cli.startup.mode":"\u6A21\u5F0F","cli.startup.mode_standalone":"\u72EC\u7ACB\u6A21\u5F0F","cli.startup.mode_integrated":"\u96C6\u6210\u6A21\u5F0F","cli.status.title":"Gateway WebSocket \u670D\u52A1\u72B6\u6001","cli.stop.title":"Gateway WebSocket \u670D\u52A1\u5DF2\u505C\u6B62","cli.already_running":"Gateway \u670D\u52A1\u5DF2\u5728\u8FD0\u884C\u4E2D","cli.already_stopped":"Gateway \u670D\u52A1\u5DF2\u505C\u6B62","cli.shutdown_signal":"\u6536\u5230 {{signal}}\uFF0C\u6B63\u5728\u4F18\u96C5\u5173\u95ED...","cli.shutdown_success":"Gateway \u670D\u52A1\u5DF2\u6210\u529F\u505C\u6B62","cli.unknown_command":"\u672A\u77E5\u547D\u4EE4: {{command}}","cli.error.start_failed":"\u542F\u52A8 Gateway \u5931\u8D25","cli.error.stop_failed":"\u505C\u6B62 Gateway \u5931\u8D25","cli.error.restart_failed":"\u91CD\u542F Gateway \u5931\u8D25","cli.error.status_failed":"\u83B7\u53D6 Gateway \u72B6\u6001\u5931\u8D25","cli.error.shutdown":"\u5173\u95ED\u65F6\u53D1\u751F\u9519\u8BEF","cli.error.execution_failed":"CLI \u6267\u884C\u5931\u8D25","cli.error.detail":"\u9519\u8BEF\u8BE6\u60C5:","cli.command.start.desc":"\u542F\u52A8 Gateway WebSocket \u670D\u52A1","cli.command.stop.desc":"\u505C\u6B62 Gateway \u670D\u52A1","cli.command.restart.desc":"\u91CD\u542F Gateway \u670D\u52A1","cli.command.status.desc":"\u67E5\u770B Gateway \u670D\u52A1\u72B6\u6001","cli.option.directory":"\u5DE5\u4F5C\u76EE\u5F55","cli.option.port":"\u670D\u52A1\u7AEF\u53E3","cli.option.hostname":"\u4E3B\u673A\u5730\u5740","cli.option.debug":"\u542F\u7528\u8C03\u8BD5\u6A21\u5F0F","cli.help.command":"\u663E\u793A\u5E2E\u52A9\u4FE1\u606F","cli.program.description":"Gateway WebSocket \u670D\u52A1\u7BA1\u7406 CLI","cli.examples.title":"\u793A\u4F8B","cli.example.start":"\u542F\u52A8\u670D\u52A1","cli.example.stop":"\u505C\u6B62\u670D\u52A1","cli.example.restart":"\u91CD\u542F\u670D\u52A1","cli.example.hostname":"\u6307\u5B9A\u76D1\u542C\u5730\u5740"}},bt=Zt;a();var Qt={translation:{"cli.startup.title":"Gateway WebSocket Server Started","cli.startup.status":"Status","cli.startup.port":"Port","cli.startup.hostname":"Hostname","cli.startup.protocol":"Protocol","cli.startup.connections":"Connections","cli.startup.running":"Running","cli.startup.stopped":"Stopped","cli.startup.mode":"Mode","cli.startup.mode_standalone":"Standalone","cli.startup.mode_integrated":"Integrated","cli.status.title":"Gateway WebSocket Server Status","cli.stop.title":"Gateway WebSocket Server Stopped","cli.already_running":"Gateway server is already running.","cli.already_stopped":"Gateway server is already stopped.","cli.shutdown_signal":"Received {{signal}}, shutting down gracefully...","cli.shutdown_success":"Gateway stopped successfully.","cli.unknown_command":"Unknown command: {{command}}","cli.error.start_failed":"Failed to start gateway","cli.error.stop_failed":"Failed to stop gateway","cli.error.restart_failed":"Failed to restart gateway","cli.error.status_failed":"Failed to get gateway status","cli.error.shutdown":"Error during shutdown","cli.error.execution_failed":"CLI failed to execute","cli.error.detail":"Error detail:","cli.command.start.desc":"Start Gateway WebSocket service","cli.command.stop.desc":"Stop Gateway service","cli.command.restart.desc":"Restart Gateway service","cli.command.status.desc":"Check Gateway service status","cli.option.directory":"Working directory","cli.option.port":"Service port","cli.option.hostname":"Host address","cli.option.debug":"Enable debug mode","cli.help.command":"Display help information","cli.program.description":"Gateway WebSocket service management CLI","cli.examples.title":"Examples","cli.example.start":"Start service","cli.example.stop":"Stop service","cli.example.restart":"Restart service","cli.example.hostname":"Specify listening address"}},xt=Qt;var te=()=>{L("zh-CN"),L("en-US"),V("zh-CN",bt),V("en-US",xt);};te();var et=new Map;var it=new Map;var ee=r=>{if(it.has(r))return it.get(r);let t=/{{\s*(\w+)\s*}}/g,e=[],i;for(;(i=t.exec(r))!==null;){let o=i[1];o&&!e.includes(o)&&e.push(o);}let n=new RegExp("{{\\s*("+e.join("|")+")\\s*}}","g"),s={keys:e,regex:n};return it.set(r,s),s},At=(r,t)=>{if(!r||typeof r!="string")return "";if(!t||Object.keys(t).length===0)return r;let{regex:e,keys:i}=ee(r);return i.length===0||!i.some(s=>s in t)?r:r.replace(e,(s,o)=>{let a=t[o];return a==null?"":String(a)})},ie=r=>r&&E.locales.includes(r)?r:E.defaultLocale,Et=r=>{if(!et.has(r)){let{resources:t}=L(r);et.set(r,t);}return et.get(r)},ne=(r,t={})=>{let e=ie(t.locale),n=Et(e)?.translation[r];if(n&&typeof n=="string"){let s=At(n,t.vars);return s!=null?String(s):String(r)}if(e!==E.defaultLocale){let o=Et(E.defaultLocale)?.translation[r];if(o&&typeof o=="string"){let a=At(o,t.vars);return a!=null?String(a):String(r)}}return String(t.fallback??r)},u=ne;a();var y=a$2.create({service:"cli-gateway"}),P=58,St="\u2551",vt="\u2554",$t="\u255A",Tt="\u2560",nt="\u2550";function re(r,t=P){let e=t-r.length;return e<=0?r:r+" ".repeat(e)}function O(r){console.log(`${St} ${re(r)} ${St}`);}function st(){console.log(`${vt}${nt.repeat(P)}${vt.replace("\u2554","\u2557")}`);}function Ht(){console.log(`${Tt}${nt.repeat(P)}${Tt.replace("\u2560","\u2563")}`);}function rt(){console.log(`${$t}${nt.repeat(P)}${$t.replace("\u255A","\u255D")}`);}function kt(r){console.log(""),st(),O(u("cli.startup.title")),Ht(),O(`${u("cli.startup.status")}: ${u("cli.startup.running").padEnd(37-u("cli.startup.status").length)}`),O(`${u("cli.startup.port")}: ${String(r.port).padEnd(37-u("cli.startup.port").length)}`),O(`${u("cli.startup.hostname")}: ${r.hostname.padEnd(37-u("cli.startup.hostname").length)}`),O(`${u("cli.startup.protocol")}: ws${" ".repeat(32)}`),r.connections!==void 0&&O(`${u("cli.startup.connections")}:${String(r.connections).padEnd(37-u("cli.startup.connections").length)}`),O(`${u("cli.startup.mode")}: ${(r.mode==="standalone"?u("cli.startup.mode_standalone"):u("cli.startup.mode_integrated")).padEnd(37-u("cli.startup.mode").length)}`),rt(),console.log("");}function oe(){console.log(""),st(),O(u("cli.stop.title")),rt(),console.log("");}async function ae(){try{let r=a$3.getStatus(),e=(await a$3.get())?.getStatus();console.log(""),st(),O(u("cli.status.title")),Ht(),O(`${u("cli.startup.status")}: ${r.toUpperCase().padEnd(37-u("cli.startup.status").length)}`),e&&(O(`${u("cli.startup.port")}: ${String(e.port).padEnd(37-u("cli.startup.port").length)}`),O(`${u("cli.startup.hostname")}: ${(e.hostname||"localhost").padEnd(37-u("cli.startup.hostname").length)}`),O(`${u("cli.startup.connections")}:${String(e.connections||0).padEnd(37-u("cli.startup.connections").length)}`)),rt(),console.log("");}catch(r){y.error("Failed to get gateway status",{error:r instanceof Error?r.message:String(r)}),console.error(`${u("cli.error.status_failed")}: ${r instanceof Error?r.message:String(r)}`),process.exit(1);}}async function le(r){let t=r.directory||process.cwd();y.info("Starting gateway service",{port:r.port,hostname:r.hostname,directory:t});try{if(await a$3.init({directory:t,printLogs:r.debug,logLevel:r.debug?"DEBUG":"INFO"}),a$3.getStatus()==="running"){console.log(u("cli.already_running"));return}let i={};r.port&&(i.port=r.port),r.hostname&&(i.hostname=r.hostname),await a$3.start(i);let s=(await a$3.get())?.getStatus();kt({port:s?.port||r.port||8080,hostname:s?.hostname||r.hostname||"localhost",connections:s?.connections||0,mode:O$1()?"integrated":"standalone"}),Gt();}catch(e){y.error("Failed to start gateway",{error:e instanceof Error?e.message:String(e)}),console.error(`${u("cli.error.start_failed")}: ${e instanceof Error?e.message:String(e)}`),process.exit(1);}}async function ce(){y.info("Stopping gateway service");try{if(a$3.getStatus()==="stopped"){console.log(u("cli.already_stopped"));return}await a$3.stop(),oe(),y.info("Gateway stopped successfully");}catch(r){y.error("Failed to stop gateway",{error:r instanceof Error?r.message:String(r)}),console.error(`${u("cli.error.stop_failed")}: ${r instanceof Error?r.message:String(r)}`),process.exit(1);}}async function ue(r){y.info("Restarting gateway service");try{let t={};r.port&&(t.port=r.port),r.hostname&&(t.hostname=r.hostname),await a$3.restart(t);let i=(await a$3.get())?.getStatus();kt({port:i?.port||r.port||8080,hostname:i?.hostname||r.hostname||"localhost",connections:i?.connections||0,mode:O$1()?"integrated":"standalone"}),Gt(),y.info("Gateway restarted successfully");}catch(t){y.error("Failed to restart gateway",{error:t instanceof Error?t.message:String(t)}),console.error(`${u("cli.error.restart_failed")}: ${t instanceof Error?t.message:String(t)}`),process.exit(1);}}function Gt(){let r=async t=>{y.debug(`Received ${t}, shutting down gracefully...`),console.log(`
|
|
27
27
|
${u("cli.shutdown_signal",{vars:{signal:t}})}`);try{await a$3.stop(),y.debug("Gateway stopped"),console.log(u("cli.shutdown_success"));}catch(e){y.error("Error during shutdown",{error:e instanceof Error?e.message:String(e)});}process.exit(0);};process.on("SIGINT",()=>{r("SIGINT").catch(console.error);}),process.on("SIGTERM",()=>{r("SIGTERM").catch(console.error);});}async function I(r,t){switch(r){case "start":await le(t);break;case "stop":await ce();break;case "restart":await ue(t);break;case "status":await ae();break;default:console.error(u("cli.unknown_command",{vars:{command:r}})),process.exit(1);}}function he(r){r.command("start").description(u("cli.command.start.desc")).option("-D, --directory <path>",u("cli.option.directory")).option("-p, --port <number>",u("cli.option.port"),t=>parseInt(t,10)).option("-H, --hostname <address>",u("cli.option.hostname")).option("-d, --debug",u("cli.option.debug"),false).action(async t=>{await I("start",{directory:t.directory,port:t.port,hostname:t.hostname,debug:t.debug});}),r.command("stop").description(u("cli.command.stop.desc")).action(async()=>{await I("stop",{});}),r.command("restart").description(u("cli.command.restart.desc")).option("-D, --directory <path>",u("cli.option.directory")).option("-p, --port <number>",u("cli.option.port"),t=>parseInt(t,10)).option("-H, --hostname <address>",u("cli.option.hostname")).option("-d, --debug",u("cli.option.debug"),false).action(async t=>{await I("restart",{directory:t.directory,port:t.port,hostname:t.hostname,debug:t.debug});}),r.command("status").description(u("cli.command.status.desc")).action(async()=>{await I("status",{});}),r.addHelpCommand("help",u("cli.help.command")).addHelpText("after",`
|
|
28
28
|
|
|
29
29
|
${u("cli.examples.title")}:
|
|
30
30
|
$ gateway start --port 8080 # ${u("cli.example.start")}
|
|
31
31
|
$ gateway stop # ${u("cli.example.stop")}
|
|
32
32
|
$ gateway restart --port 9090 # ${u("cli.example.restart")}
|
|
33
|
-
$ gateway start --hostname 0.0.0.0 # ${u("cli.example.hostname")}`);}async function pe(r=process.argv){loadEnv();let t=new Ct;t.name("gateway").description(u("cli.program.description")).version("1.0.0"),he(t),await t.parseAsync(r);}pe().catch(r=>{y.error("CLI failed to execute",{error:r});let
|
|
33
|
+
$ gateway start --hostname 0.0.0.0 # ${u("cli.example.hostname")}`);}async function pe(r=process.argv){loadEnv();let t=new Ct;t.name("gateway").description(u("cli.program.description")).version("1.0.0"),he(t),await t.parseAsync(r);}pe().catch(r=>{let t=r.code==="EPIPE"||r.code==="EIO";t||y.error("CLI failed to execute",{error:r});let e=r instanceof Error?r.message:String(r),i=r instanceof Error?r.stack:"";try{console.error(u("cli.error.execution_failed")),e&&console.error(`${u("cli.error.detail")} ${e}`),i&&console.error(i);}catch{}t||process.exit(1);});export{pe as main,he as registerGatewayCommand};
|