hofii 0.0.1 → 0.0.3
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/main.js +35 -32
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,58 +1,61 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
3
|
+
var b9=Object.create;var{getPrototypeOf:C9,defineProperty:W1,getOwnPropertyNames:R9}=Object;var A9=Object.prototype.hasOwnProperty;function E9(Z){return this[Z]}var D9,I9,z1=(Z,J,Q)=>{var F=Z!=null&&typeof Z==="object";if(F){var Y=J?D9??=new WeakMap:I9??=new WeakMap,H=Y.get(Z);if(H)return H}Q=Z!=null?b9(C9(Z)):{};let z=J||!Z||!Z.__esModule?W1(Q,"default",{value:Z,enumerable:!0}):Q;for(let U of R9(Z))if(!A9.call(z,U))W1(z,U,{get:E9.bind(Z,U),enumerable:!0});if(F)Y.set(Z,z);return z};var x9=(Z,J)=>()=>(J||Z((J={exports:{}}).exports,J),J.exports);var l0=x9((h6,v1)=>{var g0={to(Z,J){if(!J)return`\x1B[${Z+1}G`;return`\x1B[${J+1};${Z+1}H`},move(Z,J){let Q="";if(Z<0)Q+=`\x1B[${-Z}D`;else if(Z>0)Q+=`\x1B[${Z}C`;if(J<0)Q+=`\x1B[${-J}A`;else if(J>0)Q+=`\x1B[${J}B`;return Q},up:(Z=1)=>`\x1B[${Z}A`,down:(Z=1)=>`\x1B[${Z}B`,forward:(Z=1)=>`\x1B[${Z}C`,backward:(Z=1)=>`\x1B[${Z}D`,nextLine:(Z=1)=>"\x1B[E".repeat(Z),prevLine:(Z=1)=>"\x1B[F".repeat(Z),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},z8={up:(Z=1)=>"\x1B[S".repeat(Z),down:(Z=1)=>"\x1B[T".repeat(Z)},U8={screen:"\x1B[2J",up:(Z=1)=>"\x1B[1J".repeat(Z),down:(Z=1)=>"\x1B[J".repeat(Z),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(Z){let J="";for(let Q=0;Q<Z;Q++)J+=this.line+(Q<Z-1?g0.up():"");if(Z)J+=g0.left;return J}};v1.exports={cursor:g0,scroll:z8,erase:U8,beep:"\x07"}});function S0(Z){return Z==null?[]:Array.isArray(Z)?Z:[Z]}function T9(Z,J,Q,F){var Y,H=Z[J],z=~F.string.indexOf(J)?Q==null||Q===!0?"":String(Q):typeof Q==="boolean"?Q:~F.boolean.indexOf(J)?Q==="false"?!1:Q==="true"||(Z._.push((Y=+Q,Y*0===0)?Y:Q),!!Q):(Y=+Q,Y*0===0)?Y:Q;Z[J]=H==null?z:Array.isArray(H)?H.concat(z):[H,z]}function S9(Z,J){Z=Z||[],J=J||{};var Q,F,Y,H,z,U={_:[]},W=0,L=0,K=0,X=Z.length;let M=J.alias!==void 0,N=J.unknown!==void 0,j=J.default!==void 0;if(J.alias=J.alias||{},J.string=S0(J.string),J.boolean=S0(J.boolean),M)for(Q in J.alias){F=J.alias[Q]=S0(J.alias[Q]);for(W=0;W<F.length;W++)(J.alias[F[W]]=F.concat(Q)).splice(W,1)}for(W=J.boolean.length;W-- >0;){F=J.alias[J.boolean[W]]||[];for(L=F.length;L-- >0;)J.boolean.push(F[L])}for(W=J.string.length;W-- >0;){F=J.alias[J.string[W]]||[];for(L=F.length;L-- >0;)J.string.push(F[L])}if(j){for(Q in J.default)if(H=typeof J.default[Q],F=J.alias[Q]=J.alias[Q]||[],J[H]!==void 0){J[H].push(Q);for(W=0;W<F.length;W++)J[H].push(F[W])}}let w=N?Object.keys(J.alias):[];for(W=0;W<X;W++){if(Y=Z[W],Y==="--"){U._=U._.concat(Z.slice(++W));break}for(L=0;L<Y.length;L++)if(Y.charCodeAt(L)!==45)break;if(L===0)U._.push(Y);else if(Y.substring(L,L+3)==="no-"){if(H=Y.substring(L+3),N&&!~w.indexOf(H))return J.unknown(Y);U[H]=!1}else{for(K=L+1;K<Y.length;K++)if(Y.charCodeAt(K)===61)break;H=Y.substring(L,K),z=Y.substring(++K)||W+1===X||(""+Z[W+1]).charCodeAt(0)===45||Z[++W],F=L===2?[H]:H;for(K=0;K<F.length;K++){if(H=F[K],N&&!~w.indexOf(H))return J.unknown("-".repeat(L)+H);T9(U,H,K+1<F.length||z,J)}}}if(j){for(Q in J.default)if(U[Q]===void 0)U[Q]=J.default[Q]}if(M)for(Q in U){F=J.alias[Q]||[];while(F.length>0)U[F.shift()]=U[Q]}return U}function K1(Z){return Z.replace(/[<[].+/,"").trim()}function k9(Z){let J=/<([^>]+)>/g,Q=/\[([^\]]+)\]/g,F=[],Y=(U)=>{let W=!1,L=U[1];if(L.startsWith("..."))L=L.slice(3),W=!0;return{required:U[0].startsWith("<"),value:L,variadic:W}},H;while(H=J.exec(Z))F.push(Y(H));let z;while(z=Q.exec(Z))F.push(Y(z));return F}function h9(Z){let J={alias:{},boolean:[]};for(let[Q,F]of Z.entries()){if(F.names.length>1)J.alias[F.names[0]]=F.names.slice(1);if(F.isBoolean)if(F.negated){if(!Z.some((Y,H)=>{return H!==Q&&Y.names.some((z)=>F.names.includes(z))&&typeof Y.required==="boolean"}))J.boolean.push(F.names[0])}else J.boolean.push(F.names[0])}return J}function U1(Z){return Z.sort((J,Q)=>{return J.length>Q.length?-1:1})[0]}function L1(Z,J){return Z.length>=J?Z:`${Z}${" ".repeat(J-Z.length)}`}function v9(Z){return Z.replaceAll(/([a-z])-([a-z])/g,(J,Q,F)=>{return Q+F.toUpperCase()})}function _9(Z,J,Q){let F=Z;for(let Y=0;Y<J.length;Y++){let H=J[Y];if(Y===J.length-1){F[H]=Q;return}if(F[H]==null){let z=+J[Y+1]>-1;F[H]=z?[]:{}}F=F[H]}}function f9(Z,J){for(let Q of Object.keys(J)){let F=J[Q];if(F.shouldTransform){if(Z[Q]=[Z[Q]].flat(),typeof F.transformFunction==="function")Z[Q]=Z[Q].map(F.transformFunction)}}}function y9(Z){let J=/([^\\/]+)$/.exec(Z);return J?J[1]:""}function X1(Z){return Z.split(".").map((J,Q)=>{return Q===0?v9(J):J}).join(".")}var U0=class extends Error{constructor(Z){super(Z);if(this.name="CACError",typeof Error.captureStackTrace!=="function")this.stack=Error(Z).stack}},$9=class{rawName;description;name;names;isBoolean;required;config;negated;constructor(Z,J,Q){if(this.rawName=Z,this.description=J,this.config=Object.assign({},Q),Z=Z.replaceAll(".*",""),this.negated=!1,this.names=K1(Z).split(",").map((F)=>{let Y=F.trim().replace(/^-{1,2}/,"");if(Y.startsWith("no-"))this.negated=!0,Y=Y.replace(/^no-/,"");return X1(Y)}).sort((F,Y)=>F.length>Y.length?1:-1),this.name=this.names.at(-1),this.negated&&this.config.default==null)this.config.default=!0;if(Z.includes("<"))this.required=!0;else if(Z.includes("["))this.required=!1;else this.isBoolean=!0}},k0,L0;if(typeof process<"u"){let Z;if(typeof Deno<"u"&&typeof Deno.version?.deno==="string")Z="deno";else if(typeof Bun<"u"&&typeof Bun.version==="string")Z="bun";else Z="node";L0=`${process.platform}-${process.arch} ${Z}-${process.version}`,k0=process.argv}else if(typeof navigator>"u")L0="unknown";else L0=`${navigator.platform} ${navigator.userAgent}`;var M1=class{rawName;description;config;cli;options;aliasNames;name;args;commandAction;usageText;versionNumber;examples;helpCallback;globalCommand;constructor(Z,J,Q={},F){this.rawName=Z,this.description=J,this.config=Q,this.cli=F,this.options=[],this.aliasNames=[],this.name=K1(Z),this.args=k9(Z),this.examples=[]}usage(Z){return this.usageText=Z,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(Z,J="-v, --version"){return this.versionNumber=Z,this.option(J,"Display version number"),this}example(Z){return this.examples.push(Z),this}option(Z,J,Q){let F=new $9(Z,J,Q);return this.options.push(F),this}alias(Z){return this.aliasNames.push(Z),this}action(Z){return this.commandAction=Z,this}isMatched(Z){return this.name===Z||this.aliasNames.includes(Z)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof G1}hasOption(Z){return Z=Z.split(".")[0],this.options.find((J)=>{return J.names.includes(Z)})}outputHelp(){let{name:Z,commands:J}=this.cli,{versionNumber:Q,options:F,helpCallback:Y}=this.cli.globalCommand,H=[{body:`${Z}${Q?`/${Q}`:""}`}];if(H.push({title:"Usage",body:` $ ${Z} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&J.length>0){let U=U1(J.map((W)=>W.rawName));H.push({title:"Commands",body:J.map((W)=>{return` ${L1(W.rawName,U.length)} ${W.description}`}).join(`
|
|
4
4
|
`)},{title:"For more info, run any command with the `--help` flag",body:J.map((W)=>` $ ${Z}${W.name===""?"":` ${W.name}`} --help`).join(`
|
|
5
|
-
`)})}let z=this.isGlobalCommand?F:[...this.options,...F||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)z=z.filter((U)=>U.name!=="version");if(z.length>0){let U=
|
|
5
|
+
`)})}let z=this.isGlobalCommand?F:[...this.options,...F||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)z=z.filter((U)=>U.name!=="version");if(z.length>0){let U=U1(z.map((W)=>W.rawName));H.push({title:"Options",body:z.map((W)=>{return` ${L1(W.rawName,U.length)} ${W.description} ${W.config.default===void 0?"":`(default: ${W.config.default})`}`}).join(`
|
|
6
6
|
`)})}if(this.examples.length>0)H.push({title:"Examples",body:this.examples.map((U)=>{if(typeof U==="function")return U(Z);return U}).join(`
|
|
7
7
|
`)});if(Y)H=Y(H)||H;console.info(H.map((U)=>{return U.title?`${U.title}:
|
|
8
8
|
${U.body}`:U.body}).join(`
|
|
9
9
|
|
|
10
|
-
`))}outputVersion(){let{name:Z}=this.cli,{versionNumber:J}=this.cli.globalCommand;if(J)console.info(`${Z}/${J} ${L0}`)}checkRequiredArgs(){let Z=this.args.filter((J)=>J.required).length;if(this.cli.args.length<Z)throw new U0(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:Z,globalCommand:J}=this.cli;if(!this.config.allowUnknownOptions){for(let Q of Object.keys(Z))if(Q!=="--"&&!this.hasOption(Q)&&!J.hasOption(Q))throw new U0(`Unknown option \`${Q.length>1?`--${Q}`:`-${Q}`}\``)}}checkOptionValue(){let{options:Z,globalCommand:J}=this.cli,Q=[...J.options,...this.options];for(let F of Q){let Y=Z[F.name.split(".")[0]];if(F.required){let H=Q.some((z)=>z.negated&&z.names.includes(F.name));if(Y===!0||Y===!1&&!H)throw new U0(`option \`${F.rawName}\` value is missing`)}}}checkUnusedArgs(){let Z=this.args.some((J)=>J.variadic)?1/0:this.args.length;if(Z<this.cli.args.length)throw new U0(`Unused args: ${this.cli.args.slice(Z).map((J)=>`\`${J}\``).join(", ")}`)}},L1=class extends U1{constructor(Z){super("@@global@@","",{},Z)}},$9=class extends EventTarget{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;constructor(Z=""){super();this.name=Z,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new L1(this),this.globalCommand.usage("<command> [options]")}usage(Z){return this.globalCommand.usage(Z),this}command(Z,J,Q){let F=new U1(Z,J||"",Q,this);return F.globalCommand=this.globalCommand,this.commands.push(F),F}option(Z,J,Q){return this.globalCommand.option(Z,J,Q),this}help(Z){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=Z,this.showHelpOnExit=!0,this}version(Z,J="-v, --version"){return this.globalCommand.version(Z,J),this.showVersionOnExit=!0,this}example(Z){return this.globalCommand.example(Z),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:Z,options:J},Q,F){if(this.args=Z,this.options=J,Q)this.matchedCommand=Q;if(F)this.matchedCommandName=F;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(Z,{run:J=!0}={}){if(!Z){if(!x0)throw Error("No argv provided and runtime process argv is not available.");Z=x0}if(this.rawArgs=Z,!this.name)this.name=Z[1]?f9(Z[1]):"cli";let Q=!0;for(let Y of this.commands){let H=this.mri(Z.slice(2),Y),z=H.args[0];if(Y.isMatched(z)){Q=!1;let U={...H,args:H.args.slice(1)};this.setParsedInfo(U,Y,z),this.dispatchEvent(new CustomEvent(`command:${z}`,{detail:Y}))}}if(Q){for(let Y of this.commands)if(Y.isDefaultCommand){Q=!1;let H=this.mri(Z.slice(2),Y);this.setParsedInfo(H,Y),this.dispatchEvent(new CustomEvent("command:!",{detail:Y}))}}if(Q){let Y=this.mri(Z.slice(2));this.setParsedInfo(Y)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),J=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),J=!1,this.unsetMatchedCommand();let F={args:this.args,options:this.options};if(J)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.dispatchEvent(new CustomEvent("command:*",{detail:this.args[0]}));return F}mri(Z,J){let Q=[...this.globalCommand.options,...J?J.options:[]],F=k9(Q),Y=[],H=Z.indexOf("--");if(H!==-1)Y=Z.slice(H+1),Z=Z.slice(0,H);let z=T9(Z,F);z=Object.keys(z).reduce((X,M)=>{return{...X,[z1(M)]:z[M]}},{_:[]});let U=z._,W={"--":Y},L=J&&J.config.ignoreOptionDefaultValue?J.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,K=Object.create(null);for(let X of Q){if(!L&&X.config.default!==void 0)for(let M of X.names)W[M]=X.config.default;if(Array.isArray(X.config.type)&&K[X.name]===void 0)K[X.name]=Object.create(null),K[X.name].shouldTransform=!0,K[X.name].transformFunction=X.config.type[0]}for(let X of Object.keys(z))if(X!=="_")v9(W,X.split("."),z[X]),_9(W,K);return{args:U,options:W}}runMatchedCommand(){let{args:Z,options:J,matchedCommand:Q}=this;if(!Q||!Q.commandAction)return;Q.checkUnknownOptions(),Q.checkOptionValue(),Q.checkRequiredArgs(),Q.checkUnusedArgs();let F=[];return Q.args.forEach((Y,H)=>{if(Y.variadic)F.push(Z.slice(H));else F.push(Z[H])}),F.push(J),Q.commandAction.apply(this,F)}},K1=(Z="")=>new $9(Z);import V6 from"path";import{styleText as f0}from"util";import{stdout as g0,stdin as x1}from"process";import*as u from"readline";import Z8 from"readline";var X1=(()=>{let Z=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(J)=>{let Q=0;Z.lastIndex=0;while(Z.test(J))Q+=1;return J.length-Q}})(),M1=(Z)=>{return Z===12288||Z>=65281&&Z<=65376||Z>=65504&&Z<=65510},G1=(Z)=>{return Z===8987||Z===9001||Z>=12272&&Z<=12287||Z>=12289&&Z<=12350||Z>=12441&&Z<=12543||Z>=12549&&Z<=12591||Z>=12593&&Z<=12686||Z>=12688&&Z<=12771||Z>=12783&&Z<=12830||Z>=12832&&Z<=12871||Z>=12880&&Z<=19903||Z>=65040&&Z<=65049||Z>=65072&&Z<=65106||Z>=65108&&Z<=65126||Z>=65128&&Z<=65131||Z>=127488&&Z<=127490||Z>=127504&&Z<=127547||Z>=127552&&Z<=127560||Z>=131072&&Z<=196605||Z>=196608&&Z<=262141};var p9=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,g9=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,j1=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,l9=/\t{1,1000}/y,N1=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,c9=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,m9=/\p{M}+/gu,u9={limit:1/0,ellipsis:""},w1=(Z,J={},Q={})=>{let F=J.limit??1/0,Y=J.ellipsis??"",H=J?.ellipsisWidth??(Y?w1(Y,u9,Q).width:0),z=0,U=Q.controlWidth??0,W=Q.tabWidth??8,L=Q.emojiWidth??2,K=2,X=Q.regularWidth??1,M=Q.wideWidth??2,N=[[c9,X],[p9,0],[g9,U],[l9,W],[N1,L],[j1,M]],j=0,w=0,k=Z.length,l=0,c=!1,x=k,h=Math.max(0,F-H),A=0,d=0,T=0,R=0;Z:while(!0){if(d>A||w>=k&&w>j){let m=Z.slice(A,d)||Z.slice(j,w);l=0;for(let i of m.replaceAll(m9,"")){let E=i.codePointAt(0)||0;if(M1(E))R=2;else if(G1(E))R=M;else R=X;if(T+R>h)x=Math.min(x,Math.max(A,j)+l);if(T+R>F){c=!0;break Z}l+=i.length,T+=R}A=d=0}if(w>=k)break Z;for(let m=0,i=N.length;m<i;m++){let[E,W0]=N[m];if(E.lastIndex=w,E.test(Z)){if(l=E===j1?X1(Z.slice(w,E.lastIndex)):E===N1?1:E.lastIndex-w,R=l*W0,T+R>h)x=Math.min(x,w+Math.floor((h-T)/W0));if(T+R>F){c=!0;break Z}T+=R,A=j,d=w,w=j=E.lastIndex;continue Z}}w+=1}return{width:c?h:T,index:c?x:k,truncated:c,ellipsed:c&&F>=H}},V1=w1;var r9={limit:1/0,ellipsis:"",ellipsisWidth:0},o9=(Z,J={})=>{return V1(Z,r9,J).width},b=o9;var K0="\x1B",b1="\x9B",n9=39,S0="\x07",C1="[",i9="]",R1="m",k0=`${i9}8;;`,B1=new RegExp(`(?:\\${C1}(?<code>\\d+)m|\\${k0}(?<uri>.*)${S0})`,"y"),q1=(Z)=>{if(Z>=30&&Z<=37)return 39;if(Z>=90&&Z<=97)return 39;if(Z>=40&&Z<=47)return 49;if(Z>=100&&Z<=107)return 49;if(Z===1||Z===2)return 22;if(Z===3)return 23;if(Z===4)return 24;if(Z===7)return 27;if(Z===8)return 28;if(Z===9)return 29;if(Z===0)return 0;return},P1=(Z)=>`${K0}${C1}${Z}${R1}`,O1=(Z)=>`${K0}${k0}${Z}${S0}`,T0=(Z,J,Q)=>{let F=J[Symbol.iterator](),Y=!1,H=!1,z=Z.at(-1),U=z===void 0?0:b(z),W=F.next(),L=F.next(),K=0;while(!W.done){let X=W.value,M=b(X);if(U+M<=Q)Z[Z.length-1]+=X;else Z.push(X),U=0;if(X===K0||X===b1)Y=!0,H=J.startsWith(k0,K+1);if(Y){if(H){if(X===S0)Y=!1,H=!1}else if(X===R1)Y=!1}else if(U+=M,U===Q&&!L.done)Z.push(""),U=0;W=L,L=F.next(),K+=X.length}if(z=Z.at(-1),!U&&z!==void 0&&z.length&&Z.length>1)Z[Z.length-2]+=Z.pop()},d9=(Z)=>{let J=Z.split(" "),Q=J.length;while(Q){if(b(J[Q-1]))break;Q--}if(Q===J.length)return Z;return J.slice(0,Q).join(" ")+J.slice(Q).join("")},s9=(Z,J,Q={})=>{if(Q.trim!==!1&&Z.trim()==="")return"";let F="",Y,H,z=Z.split(" "),U=[""],W=0;for(let X=0;X<z.length;X++){let M=z[X];if(Q.trim!==!1){let j=U.at(-1)??"",w=j.trimStart();if(j.length!==w.length)U[U.length-1]=w,W=b(w)}if(X!==0){if(W>=J&&(Q.wordWrap===!1||Q.trim===!1))U.push(""),W=0;if(W||Q.trim===!1)U[U.length-1]+=" ",W++}let N=b(M);if(Q.hard&&N>J){let j=J-W,w=1+Math.floor((N-j-1)/J);if(Math.floor((N-1)/J)<w)U.push("");T0(U,M,J),W=b(U.at(-1)??"");continue}if(W+N>J&&W&&N){if(Q.wordWrap===!1&&W<J){T0(U,M,J),W=b(U.at(-1)??"");continue}U.push(""),W=0}if(W+N>J&&Q.wordWrap===!1){T0(U,M,J),W=b(U.at(-1)??"");continue}U[U.length-1]+=M,W+=N}if(Q.trim!==!1)U=U.map((X)=>d9(X));let L=U.join(`
|
|
11
|
-
`),K=!1;for(let X=0;X<L.length;X++){let M=L[X];if(F+=M,!K){if(K=M>="\uD800"&&M<="\uDBFF",K)continue}else K=!1;if(M===
|
|
12
|
-
`){if(H)F+=
|
|
13
|
-
`){if(Y&&
|
|
14
|
-
`)}var P=
|
|
15
|
-
`),H=0,z=Z;for(let W of Y){if(z<=W.length)break;z-=W.length+1,H++}for(H=Math.max(0,Math.min(Y.length-1,H+Q)),z=Math.min(z,Y[H].length)+J;z<0&&H>0;)H--,z+=Y[H].length+1;for(;z>Y[H].length&&H<Y.length-1;)z-=Y[H].length+1,H++;z=Math.max(0,Math.min(Y[H].length,z));let U=0;for(let W=0;W<H;W++)U+=Y[W].length+1;return U+z}var
|
|
10
|
+
`))}outputVersion(){let{name:Z}=this.cli,{versionNumber:J}=this.cli.globalCommand;if(J)console.info(`${Z}/${J} ${L0}`)}checkRequiredArgs(){let Z=this.args.filter((J)=>J.required).length;if(this.cli.args.length<Z)throw new U0(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:Z,globalCommand:J}=this.cli;if(!this.config.allowUnknownOptions){for(let Q of Object.keys(Z))if(Q!=="--"&&!this.hasOption(Q)&&!J.hasOption(Q))throw new U0(`Unknown option \`${Q.length>1?`--${Q}`:`-${Q}`}\``)}}checkOptionValue(){let{options:Z,globalCommand:J}=this.cli,Q=[...J.options,...this.options];for(let F of Q){let Y=Z[F.name.split(".")[0]];if(F.required){let H=Q.some((z)=>z.negated&&z.names.includes(F.name));if(Y===!0||Y===!1&&!H)throw new U0(`option \`${F.rawName}\` value is missing`)}}}checkUnusedArgs(){let Z=this.args.some((J)=>J.variadic)?1/0:this.args.length;if(Z<this.cli.args.length)throw new U0(`Unused args: ${this.cli.args.slice(Z).map((J)=>`\`${J}\``).join(", ")}`)}},G1=class extends M1{constructor(Z){super("@@global@@","",{},Z)}},p9=class extends EventTarget{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;constructor(Z=""){super();this.name=Z,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new G1(this),this.globalCommand.usage("<command> [options]")}usage(Z){return this.globalCommand.usage(Z),this}command(Z,J,Q){let F=new M1(Z,J||"",Q,this);return F.globalCommand=this.globalCommand,this.commands.push(F),F}option(Z,J,Q){return this.globalCommand.option(Z,J,Q),this}help(Z){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=Z,this.showHelpOnExit=!0,this}version(Z,J="-v, --version"){return this.globalCommand.version(Z,J),this.showVersionOnExit=!0,this}example(Z){return this.globalCommand.example(Z),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:Z,options:J},Q,F){if(this.args=Z,this.options=J,Q)this.matchedCommand=Q;if(F)this.matchedCommandName=F;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(Z,{run:J=!0}={}){if(!Z){if(!k0)throw Error("No argv provided and runtime process argv is not available.");Z=k0}if(this.rawArgs=Z,!this.name)this.name=Z[1]?y9(Z[1]):"cli";let Q=!0;for(let Y of this.commands){let H=this.mri(Z.slice(2),Y),z=H.args[0];if(Y.isMatched(z)){Q=!1;let U={...H,args:H.args.slice(1)};this.setParsedInfo(U,Y,z),this.dispatchEvent(new CustomEvent(`command:${z}`,{detail:Y}))}}if(Q){for(let Y of this.commands)if(Y.isDefaultCommand){Q=!1;let H=this.mri(Z.slice(2),Y);this.setParsedInfo(H,Y),this.dispatchEvent(new CustomEvent("command:!",{detail:Y}))}}if(Q){let Y=this.mri(Z.slice(2));this.setParsedInfo(Y)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),J=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),J=!1,this.unsetMatchedCommand();let F={args:this.args,options:this.options};if(J)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.dispatchEvent(new CustomEvent("command:*",{detail:this.args[0]}));return F}mri(Z,J){let Q=[...this.globalCommand.options,...J?J.options:[]],F=h9(Q),Y=[],H=Z.indexOf("--");if(H!==-1)Y=Z.slice(H+1),Z=Z.slice(0,H);let z=S9(Z,F);z=Object.keys(z).reduce((X,M)=>{return{...X,[X1(M)]:z[M]}},{_:[]});let U=z._,W={"--":Y},L=J&&J.config.ignoreOptionDefaultValue?J.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,K=Object.create(null);for(let X of Q){if(!L&&X.config.default!==void 0)for(let M of X.names)W[M]=X.config.default;if(Array.isArray(X.config.type)&&K[X.name]===void 0)K[X.name]=Object.create(null),K[X.name].shouldTransform=!0,K[X.name].transformFunction=X.config.type[0]}for(let X of Object.keys(z))if(X!=="_")_9(W,X.split("."),z[X]),f9(W,K);return{args:U,options:W}}runMatchedCommand(){let{args:Z,options:J,matchedCommand:Q}=this;if(!Q||!Q.commandAction)return;Q.checkUnknownOptions(),Q.checkOptionValue(),Q.checkRequiredArgs(),Q.checkUnusedArgs();let F=[];return Q.args.forEach((Y,H)=>{if(Y.variadic)F.push(Z.slice(H));else F.push(Z[H])}),F.push(J),Q.commandAction.apply(this,F)}},j1=(Z="")=>new p9(Z);import V6 from"path";var K0,g9={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function V1(Z){if(!Z&&!K0)return g9;return{lang:Z?.lang??K0?.lang,message:Z?.message,abortEarly:Z?.abortEarly??K0?.abortEarly,abortPipeEarly:Z?.abortPipeEarly??K0?.abortPipeEarly}}var l9;function c9(Z){return l9?.get(Z)}var m9;function u9(Z){return m9?.get(Z)}var r9;function o9(Z,J){return r9?.get(Z)?.get(J)}function h0(Z){let J=typeof Z;if(J==="string")return`"${Z}"`;if(J==="number"||J==="bigint"||J==="boolean")return`${Z}`;if(J==="object"||J==="function")return(Z&&Object.getPrototypeOf(Z)?.constructor?.name)??"null";return J}function f(Z,J,Q,F,Y){let H=Y&&"input"in Y?Y.input:Q.value,z=Y?.expected??Z.expects??null,U=Y?.received??h0(H),W={kind:Z.kind,type:Z.type,input:H,expected:z,received:U,message:`Invalid ${J}: ${z?`Expected ${z} but r`:"R"}eceived ${U}`,requirement:Z.requirement,path:Y?.path,issues:Y?.issues,lang:F.lang,abortEarly:F.abortEarly,abortPipeEarly:F.abortPipeEarly},L=Z.kind==="schema",K=Y?.message??Z.message??o9(Z.reference,W.lang)??(L?u9(W.lang):null)??F.message??c9(W.lang);if(K!==void 0)W.message=typeof K==="function"?K(W):K;if(L)Q.typed=!1;if(Q.issues)Q.issues.push(W);else Q.issues=[W]}var N1=new WeakMap;function y(Z){let J=N1.get(Z);if(!J)J={version:1,vendor:"valibot",validate(Q){return Z["~run"]({value:Q},V1())}},N1.set(Z,J);return J}function B1(Z,J){let Q=[...new Set(Z)];if(Q.length>1)return`(${Q.join(` ${J} `)})`;return Q[0]??"never"}var v0=class extends Error{constructor(Z){super(Z[0].message);this.name="ValiError",this.issues=Z}};function n9(Z,J,Q){return typeof Z.fallback==="function"?Z.fallback(J,Q):Z.fallback}function q1(Z,J,Q){return typeof Z.default==="function"?Z.default(J,Q):Z.default}function $(Z,J){return{kind:"schema",type:"array",reference:$,expects:"Array",async:!1,item:Z,message:J,get "~standard"(){return y(this)},"~run"(Q,F){let Y=Q.value;if(Array.isArray(Y)){Q.typed=!0,Q.value=[];for(let H=0;H<Y.length;H++){let z=Y[H],U=this.item["~run"]({value:z},F);if(U.issues){let W={type:"array",origin:"value",input:Y,key:H,value:z};for(let L of U.issues){if(L.path)L.path.unshift(W);else L.path=[W];Q.issues?.push(L)}if(!Q.issues)Q.issues=U.issues;if(F.abortEarly){Q.typed=!1;break}}if(!U.typed)Q.typed=!1;Q.value.push(U.value)}}else f(this,"type",Q,F);return Q}}}function t(Z){return{kind:"schema",type:"boolean",reference:t,expects:"boolean",async:!1,message:Z,get "~standard"(){return y(this)},"~run"(J,Q){if(typeof J.value==="boolean")J.typed=!0;else f(this,"type",J,Q);return J}}}function _0(Z,J){return{kind:"schema",type:"literal",reference:_0,expects:h0(Z),async:!1,literal:Z,message:J,get "~standard"(){return y(this)},"~run"(Q,F){if(Q.value===this.literal)Q.typed=!0;else f(this,"type",Q,F);return Q}}}function u(Z,J){return{kind:"schema",type:"object",reference:u,expects:"Object",async:!1,entries:Z,message:J,get "~standard"(){return y(this)},"~run"(Q,F){let Y=Q.value;if(Y&&typeof Y==="object"){Q.typed=!0,Q.value={};for(let H in this.entries){let z=this.entries[H];if(H in Y||(z.type==="exact_optional"||z.type==="optional"||z.type==="nullish")&&z.default!==void 0){let U=H in Y?Y[H]:q1(z),W=z["~run"]({value:U},F);if(W.issues){let L={type:"object",origin:"value",input:Y,key:H,value:U};for(let K of W.issues){if(K.path)K.path.unshift(L);else K.path=[L];Q.issues?.push(K)}if(!Q.issues)Q.issues=W.issues;if(F.abortEarly){Q.typed=!1;break}}if(!W.typed)Q.typed=!1;Q.value[H]=W.value}else if(z.fallback!==void 0)Q.value[H]=n9(z);else if(z.type!=="exact_optional"&&z.type!=="optional"&&z.type!=="nullish"){if(f(this,"key",Q,F,{input:void 0,expected:`"${H}"`,path:[{type:"object",origin:"key",input:Y,key:H,value:Y[H]}]}),F.abortEarly)break}}}else f(this,"type",Q,F);return Q}}}function Z0(Z,J){return{kind:"schema",type:"optional",reference:Z0,expects:`(${Z.expects} | undefined)`,async:!1,wrapped:Z,default:J,get "~standard"(){return y(this)},"~run"(Q,F){if(Q.value===void 0){if(this.default!==void 0)Q.value=q1(this,Q,F);if(Q.value===void 0)return Q.typed=!0,Q}return this.wrapped["~run"](Q,F)}}}function J0(Z,J){return{kind:"schema",type:"picklist",reference:J0,expects:B1(Z.map(h0),"|"),async:!1,options:Z,message:J,get "~standard"(){return y(this)},"~run"(Q,F){if(this.options.includes(Q.value))Q.typed=!0;else f(this,"type",Q,F);return Q}}}function S(Z){return{kind:"schema",type:"string",reference:S,expects:"string",async:!1,message:Z,get "~standard"(){return y(this)},"~run"(J,Q){if(typeof J.value==="string")J.typed=!0;else f(this,"type",J,Q);return J}}}function w1(Z){let J;if(Z)for(let Q of Z)if(J)for(let F of Q.issues)J.push(F);else J=Q.issues;return J}function Q0(Z,J){return{kind:"schema",type:"union",reference:Q0,expects:B1(Z.map((Q)=>Q.expects),"|"),async:!1,options:Z,message:J,get "~standard"(){return y(this)},"~run"(Q,F){let Y,H,z;for(let U of this.options){let W=U["~run"]({value:Q.value},F);if(W.typed)if(W.issues)if(H)H.push(W);else H=[W];else{Y=W;break}else if(z)z.push(W);else z=[W]}if(Y)return Y;if(H){if(H.length===1)return H[0];f(this,"type",Q,F,{issues:w1(H)}),Q.typed=!0}else if(z?.length===1)return z[0];else f(this,"type",Q,F,{issues:w1(z)});return Q}}}function X0(Z,J,Q){let F=Z["~run"]({value:J},V1(Q));if(F.issues)throw new v0(F.issues);return F.value}function f0(Z,J){let Q={};for(let F in Z.entries)Q[F]=!J||J.includes(F)?Z0(Z.entries[F]):Z.entries[F];return{...Z,entries:Q,get "~standard"(){return y(this)}}}import{styleText as m0}from"util";import{stdout as n0,stdin as $1}from"process";import*as r from"readline";import L8 from"readline";var P1=(()=>{let Z=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(J)=>{let Q=0;Z.lastIndex=0;while(Z.test(J))Q+=1;return J.length-Q}})(),O1=(Z)=>{return Z===12288||Z>=65281&&Z<=65376||Z>=65504&&Z<=65510},b1=(Z)=>{return Z===8987||Z===9001||Z>=12272&&Z<=12287||Z>=12289&&Z<=12350||Z>=12441&&Z<=12543||Z>=12549&&Z<=12591||Z>=12593&&Z<=12686||Z>=12688&&Z<=12771||Z>=12783&&Z<=12830||Z>=12832&&Z<=12871||Z>=12880&&Z<=19903||Z>=65040&&Z<=65049||Z>=65072&&Z<=65106||Z>=65108&&Z<=65126||Z>=65128&&Z<=65131||Z>=127488&&Z<=127490||Z>=127504&&Z<=127547||Z>=127552&&Z<=127560||Z>=131072&&Z<=196605||Z>=196608&&Z<=262141};var i9=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,d9=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,C1=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,s9=/\t{1,1000}/y,R1=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,a9=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,e9=/\p{M}+/gu,t9={limit:1/0,ellipsis:""},A1=(Z,J={},Q={})=>{let F=J.limit??1/0,Y=J.ellipsis??"",H=J?.ellipsisWidth??(Y?A1(Y,t9,Q).width:0),z=0,U=Q.controlWidth??0,W=Q.tabWidth??8,L=Q.emojiWidth??2,K=2,X=Q.regularWidth??1,M=Q.wideWidth??2,N=[[a9,X],[i9,0],[d9,U],[s9,W],[R1,L],[C1,M]],j=0,w=0,k=Z.length,l=0,c=!1,x=k,h=Math.max(0,F-H),A=0,d=0,T=0,R=0;Z:while(!0){if(d>A||w>=k&&w>j){let m=Z.slice(A,d)||Z.slice(j,w);l=0;for(let i of m.replaceAll(e9,"")){let E=i.codePointAt(0)||0;if(O1(E))R=2;else if(b1(E))R=M;else R=X;if(T+R>h)x=Math.min(x,Math.max(A,j)+l);if(T+R>F){c=!0;break Z}l+=i.length,T+=R}A=d=0}if(w>=k)break Z;for(let m=0,i=N.length;m<i;m++){let[E,W0]=N[m];if(E.lastIndex=w,E.test(Z)){if(l=E===C1?P1(Z.slice(w,E.lastIndex)):E===R1?1:E.lastIndex-w,R=l*W0,T+R>h)x=Math.min(x,w+Math.floor((h-T)/W0));if(T+R>F){c=!0;break Z}T+=R,A=j,d=w,w=j=E.lastIndex;continue Z}}w+=1}return{width:c?h:T,index:c?x:k,truncated:c,ellipsed:c&&F>=H}},E1=A1;var Z8={limit:1/0,ellipsis:"",ellipsisWidth:0},J8=(Z,J={})=>{return E1(Z,Z8,J).width},b=J8;var G0="\x1B",S1="\x9B",Q8=39,$0="\x07",k1="[",F8="]",h1="m",p0=`${F8}8;;`,D1=new RegExp(`(?:\\${k1}(?<code>\\d+)m|\\${p0}(?<uri>.*)${$0})`,"y"),I1=(Z)=>{if(Z>=30&&Z<=37)return 39;if(Z>=90&&Z<=97)return 39;if(Z>=40&&Z<=47)return 49;if(Z>=100&&Z<=107)return 49;if(Z===1||Z===2)return 22;if(Z===3)return 23;if(Z===4)return 24;if(Z===7)return 27;if(Z===8)return 28;if(Z===9)return 29;if(Z===0)return 0;return},x1=(Z)=>`${G0}${k1}${Z}${h1}`,T1=(Z)=>`${G0}${p0}${Z}${$0}`,y0=(Z,J,Q)=>{let F=J[Symbol.iterator](),Y=!1,H=!1,z=Z.at(-1),U=z===void 0?0:b(z),W=F.next(),L=F.next(),K=0;while(!W.done){let X=W.value,M=b(X);if(U+M<=Q)Z[Z.length-1]+=X;else Z.push(X),U=0;if(X===G0||X===S1)Y=!0,H=J.startsWith(p0,K+1);if(Y){if(H){if(X===$0)Y=!1,H=!1}else if(X===h1)Y=!1}else if(U+=M,U===Q&&!L.done)Z.push(""),U=0;W=L,L=F.next(),K+=X.length}if(z=Z.at(-1),!U&&z!==void 0&&z.length&&Z.length>1)Z[Z.length-2]+=Z.pop()},Y8=(Z)=>{let J=Z.split(" "),Q=J.length;while(Q){if(b(J[Q-1]))break;Q--}if(Q===J.length)return Z;return J.slice(0,Q).join(" ")+J.slice(Q).join("")},H8=(Z,J,Q={})=>{if(Q.trim!==!1&&Z.trim()==="")return"";let F="",Y,H,z=Z.split(" "),U=[""],W=0;for(let X=0;X<z.length;X++){let M=z[X];if(Q.trim!==!1){let j=U.at(-1)??"",w=j.trimStart();if(j.length!==w.length)U[U.length-1]=w,W=b(w)}if(X!==0){if(W>=J&&(Q.wordWrap===!1||Q.trim===!1))U.push(""),W=0;if(W||Q.trim===!1)U[U.length-1]+=" ",W++}let N=b(M);if(Q.hard&&N>J){let j=J-W,w=1+Math.floor((N-j-1)/J);if(Math.floor((N-1)/J)<w)U.push("");y0(U,M,J),W=b(U.at(-1)??"");continue}if(W+N>J&&W&&N){if(Q.wordWrap===!1&&W<J){y0(U,M,J),W=b(U.at(-1)??"");continue}U.push(""),W=0}if(W+N>J&&Q.wordWrap===!1){y0(U,M,J),W=b(U.at(-1)??"");continue}U[U.length-1]+=M,W+=N}if(Q.trim!==!1)U=U.map((X)=>Y8(X));let L=U.join(`
|
|
11
|
+
`),K=!1;for(let X=0;X<L.length;X++){let M=L[X];if(F+=M,!K){if(K=M>="\uD800"&&M<="\uDBFF",K)continue}else K=!1;if(M===G0||M===S1){D1.lastIndex=X+1;let j=D1.exec(L)?.groups;if(j?.code!==void 0){let w=Number.parseFloat(j.code);Y=w===Q8?void 0:w}else if(j?.uri!==void 0)H=j.uri.length===0?void 0:j.uri}if(L[X+1]===`
|
|
12
|
+
`){if(H)F+=T1("");let N=Y?I1(Y):void 0;if(Y&&N)F+=x1(N)}else if(M===`
|
|
13
|
+
`){if(Y&&I1(Y))F+=x1(Y);if(H)F+=T1(H)}}return F},W8=/\r?\n/;function p(Z,J,Q){return String(Z).normalize().split(W8).map((F)=>H8(F,J,Q)).join(`
|
|
14
|
+
`)}var P=z1(l0(),1);import{ReadStream as _1}from"tty";function u0(Z,J,Q){if(!Q.some((z)=>!z.disabled))return Z;let F=Z+J,Y=Math.max(Q.length-1,0),H=F<0?Y:F>Y?0:F;return Q[H]?.disabled?u0(H,J<0?-1:1,Q):H}function j0(Z,J,Q,F){let Y=F.split(`
|
|
15
|
+
`),H=0,z=Z;for(let W of Y){if(z<=W.length)break;z-=W.length+1,H++}for(H=Math.max(0,Math.min(Y.length-1,H+Q)),z=Math.min(z,Y[H].length)+J;z<0&&H>0;)H--,z+=Y[H].length+1;for(;z>Y[H].length&&H<Y.length-1;)z-=Y[H].length+1,H++;z=Math.max(0,Math.min(Y[H].length,z));let U=0;for(let W=0;W<H;W++)U+=Y[W].length+1;return U+z}var K8=["up","down","left","right","space","enter","cancel"],X8=["January","February","March","April","May","June","July","August","September","October","November","December"],O={actions:new Set(K8),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...X8],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(Z,J)=>`There are only ${Z} days in ${J}`,afterMin:(Z)=>`Date must be on or after ${Z.toISOString().slice(0,10)}`,beforeMax:(Z)=>`Date must be on or before ${Z.toISOString().slice(0,10)}`}}};function i0(Z,J){if(typeof Z=="string")return O.aliases.get(Z)===J;for(let Q of Z)if(Q!==void 0&&i0(Q,J))return!0;return!1}function M8(Z,J){if(Z===J)return;let Q=Z.split(`
|
|
16
16
|
`),F=J.split(`
|
|
17
|
-
`),Y=Math.max(Q.length,F.length),H=[];for(let z=0;z<Y;z++)Q[z]!==F[z]&&H.push(z);return{lines:H,numLinesBefore:Q.length,numLinesAfter:F.length,numLines:Y}}var
|
|
17
|
+
`),Y=Math.max(Q.length,F.length),H=[];for(let z=0;z<Y;z++)Q[z]!==F[z]&&H.push(z);return{lines:H,numLinesBefore:Q.length,numLinesAfter:F.length,numLines:Y}}var G8=globalThis.process.platform.startsWith("win"),r0=Symbol("clack:cancel");function V0(Z){return Z===r0}function N0(Z,J){let Q=Z;Q.isTTY&&Q.setRawMode(J)}function p1({input:Z=$1,output:J=n0,overwrite:Q=!0,hideCursor:F=!0}={}){let Y=r.createInterface({input:Z,output:J,prompt:"",tabSize:1});r.emitKeypressEvents(Z,Y),Z instanceof _1&&Z.isTTY&&Z.setRawMode(!0);let H=(z,{name:U,sequence:W})=>{let L=String(z);if(i0([L,U,W],"cancel")){F&&J.write(P.cursor.show),process.exit(0);return}if(!Q)return;r.moveCursor(J,U==="return"?0:-1,U==="return"?-1:0,()=>{r.clearLine(J,1,()=>{Z.once("keypress",H)})})};return F&&J.write(P.cursor.hide),Z.once("keypress",H),()=>{Z.off("keypress",H),F&&J.write(P.cursor.show),Z instanceof _1&&Z.isTTY&&!G8&&Z.setRawMode(!1),Y.terminal=!1,Y.close()}}var B0=(Z)=>("columns"in Z)&&typeof Z.columns=="number"?Z.columns:80,g1=(Z)=>("rows"in Z)&&typeof Z.rows=="number"?Z.rows:20;function l1(Z,J,Q,F=Q,Y=Q,H){let z=B0(Z??n0);return p(J,z-Q.length,{hard:!0,trim:!1}).split(`
|
|
18
18
|
`).map((U,W,L)=>{let K=H?H(U,W):U;return W===0?`${F}${K}`:W===L.length-1?`${Y}${K}`:`${Q}${K}`}).join(`
|
|
19
|
-
`)}function
|
|
20
|
-
`),
|
|
21
|
-
`).length-1;this.output.write(P.cursor.move(-999,Z*-1))}render(){let Z=
|
|
19
|
+
`)}function c1(Z,J){if("~standard"in Z){let Q=Z["~standard"].validate(J);if(Q instanceof Promise)throw TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");return Q.issues?.at(0)?.message}return Z(J)}class s{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(Z,J=!0){let{input:Q=$1,output:F=n0,render:Y,signal:H,...z}=Z;this.opts=z,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=Y.bind(this),this._track=J,this._abortSignal=H,this.input=Q,this.output=F}unsubscribe(){this._subscribers.clear()}setSubscriber(Z,J){let Q=this._subscribers.get(Z)??[];Q.push(J),this._subscribers.set(Z,Q)}on(Z,J){this.setSubscriber(Z,{cb:J})}once(Z,J){this.setSubscriber(Z,{cb:J,once:!0})}emit(Z,...J){let Q=this._subscribers.get(Z)??[],F=[];for(let Y of Q)Y.cb(...J),Y.once&&F.push(()=>Q.splice(Q.indexOf(Y),1));for(let Y of F)Y()}prompt(){return new Promise((Z)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),Z(r0);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=L8.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),N0(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(P.cursor.show),this.output.off("resize",this.render),N0(this.input,!1),Z(this.value)}),this.once("cancel",()=>{this.output.write(P.cursor.show),this.output.off("resize",this.render),N0(this.input,!1),Z(r0)})})}_isActionKey(Z,J){return Z==="\t"}_shouldSubmit(Z,J){return!0}_setValue(Z){this.value=Z,this.emit("value",this.value)}_setUserInput(Z,J){this.userInput=Z??"",this.emit("userInput",this.userInput),J&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(Z,J){if(this._track&&J.name!=="return"&&(J.name&&this._isActionKey(Z,J)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),J?.name&&(!this._track&&O.aliases.has(J.name)&&this.emit("cursor",O.aliases.get(J.name)),O.actions.has(J.name)&&this.emit("cursor",J.name)),Z&&(Z.toLowerCase()==="y"||Z.toLowerCase()==="n")&&this.emit("confirm",Z.toLowerCase()==="y"),this.emit("key",Z,J),J?.name==="return"&&this._shouldSubmit(Z,J)){if(this.opts.validate){let Q=c1(this.opts.validate,this.value);Q&&(this.error=Q instanceof Error?Q.message:Q,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}i0([Z,J?.name,J?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
|
|
20
|
+
`),N0(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let Z=p(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
|
|
21
|
+
`).length-1;this.output.write(P.cursor.move(-999,Z*-1))}render(){let Z=p(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(Z!==this._prevFrame){if(this.state==="initial")this.output.write(P.cursor.hide);else{let J=M8(this._prevFrame,Z),Q=g1(this.output);if(this.restoreCursor(),J){let F=Math.max(0,J.numLinesAfter-Q),Y=Math.max(0,J.numLinesBefore-Q),H=J.lines.find((z)=>z>=F);if(H===void 0){this._prevFrame=Z;return}if(J.lines.length===1){this.output.write(P.cursor.move(0,H-Y)),this.output.write(P.erase.lines(1));let z=Z.split(`
|
|
22
22
|
`);this.output.write(z[H]),this._prevFrame=Z,this.output.write(P.cursor.move(0,z.length-H-1));return}else if(J.lines.length>1){if(F<Y)H=F;else{let U=H-Y;U>0&&this.output.write(P.cursor.move(0,U))}this.output.write(P.erase.down());let z=Z.split(`
|
|
23
23
|
`).slice(H);this.output.write(z.join(`
|
|
24
|
-
`)),this._prevFrame=Z;return}}this.output.write(P.erase.down())}this.output.write(Z),this.state==="initial"&&(this.state="active"),this._prevFrame=Z}}}function H8(Z,J){if(Z===void 0||J.length===0)return 0;let Q=J.findIndex((F)=>F.value===Z);return Q!==-1?Q:0}function W8(Z,J){return(J.label??String(J.value)).toLowerCase().includes(Z.toLowerCase())}function z8(Z,J){if(J)return Z?J:J[0]}var U8=class extends s{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#J=0;#Y="";#Z;#H;#z;get cursor(){return this.#J}get userInputWithCursor(){if(!this.userInput)return f0(["inverse","hidden"],"_");if(this._cursor>=this.userInput.length)return`${this.userInput}\u2588`;let J=this.userInput.slice(0,this.cursor),Q=this.userInput.slice(this.cursor,this.cursor+1),F=this.userInput.slice(this.cursor+1);return`${J}${f0("inverse",Q)}${F}`}get options(){return typeof this.#H=="function"?this.#H():this.#H}constructor(J){super(J),this.#H=J.options,this.#z=J.placeholder;let Q=this.options;this.filteredOptions=[...Q],this.multiple=J.multiple===!0,this.#Z=typeof J.options=="function"?J.filter:J.filter??W8;let F;if(J.initialValue&&Array.isArray(J.initialValue)?this.multiple?F=J.initialValue:F=J.initialValue.slice(0,1):!this.multiple&&this.options.length>0&&(F=[this.options[0]?.value]),F)for(let Y of F){let H=Q.findIndex((z)=>z.value===Y);H!==-1&&(this.toggleSelected(Y),this.#J=H)}this.focusedValue=this.options[this.#J]?.value,this.on("key",(Y,H)=>this.#Q(Y,H)),this.on("userInput",(Y)=>this.#F(Y))}_isActionKey(J,Q){return J==="\t"||this.multiple&&this.isNavigating&&Q.name==="space"&&J!==void 0&&J!==""}#Q(J,Q){let F=Q.name==="up",Y=Q.name==="down",H=Q.name==="return",z=this.userInput===""||this.userInput==="\t",U=this.#z,W=this.options,L=U!==void 0&&U!==""&&W.some((K)=>!K.disabled&&(this.#Z?this.#Z(U,K):!0));if(Q.name==="tab"&&z&&L){this.userInput==="\t"&&this._clearUserInput(),this._setUserInput(U,!0),this.isNavigating=!1;return}F||Y?(this.#J=y0(this.#J,F?-1:1,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#J]?.value,this.multiple||(this.selectedValues=[this.focusedValue]),this.isNavigating=!0):H?this.value=z8(this.multiple,this.selectedValues):this.multiple?this.focusedValue!==void 0&&(Q.name==="tab"||this.isNavigating&&Q.name==="space")?this.toggleSelected(this.focusedValue):this.isNavigating=!1:(this.focusedValue&&(this.selectedValues=[this.focusedValue]),this.isNavigating=!1)}deselectAll(){this.selectedValues=[]}toggleSelected(J){this.filteredOptions.length!==0&&(this.multiple?this.selectedValues.includes(J)?this.selectedValues=this.selectedValues.filter((Q)=>Q!==J):this.selectedValues=[...this.selectedValues,J]:this.selectedValues=[J])}#F(J){if(J!==this.#Y){this.#Y=J;let Q=this.options;J&&this.#Z?this.filteredOptions=Q.filter((H)=>this.#Z?.(J,H)):this.filteredOptions=[...Q];let F=H8(this.focusedValue,this.filteredOptions);this.#J=y0(F,0,this.filteredOptions);let Y=this.filteredOptions[this.#J];Y&&!Y.disabled?this.focusedValue=Y.value:this.focusedValue=void 0,this.multiple||(this.focusedValue!==void 0?this.toggleSelected(this.focusedValue):this.deselectAll())}}};class c0 extends s{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(Z){super(Z,!1),this.value=!!Z.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",(J)=>{this.output.write(P.cursor.move(0,-1)),this.value=J,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}var L8={Y:{type:"year",len:4},M:{type:"month",len:2},D:{type:"day",len:2}};function D1(Z){return[...Z].map((J)=>L8[J])}function K8(Z){let J=new Intl.DateTimeFormat(Z,{year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(new Date(2000,0,15)),Q=[],F="/";for(let Y of J)Y.type==="literal"?F=Y.value.trim()||Y.value:(Y.type==="year"||Y.type==="month"||Y.type==="day")&&Q.push({type:Y.type,len:Y.type==="year"?4:2});return{segments:Q,separator:F}}function _0(Z){return Number.parseInt((Z||"0").replace(/_/g,"0"),10)||0}function G0(Z){return{year:_0(Z.year),month:_0(Z.month),day:_0(Z.day)}}function p0(Z,J){return new Date(Z||2001,J||1,0).getDate()}function v1(Z){let{year:J,month:Q,day:F}=G0(Z);if(!J||J<0||J>9999||!Q||Q<1||Q>12||!F||F<1)return;let Y=new Date(Date.UTC(J,Q-1,F));if(!(Y.getUTCFullYear()!==J||Y.getUTCMonth()!==Q-1||Y.getUTCDate()!==F))return{year:J,month:Q,day:F}}function I1(Z){let J=v1(Z);return J?new Date(Date.UTC(J.year,J.month-1,J.day)):void 0}function X8(Z,J,Q,F){let Y=Q?{year:Q.getUTCFullYear(),month:Q.getUTCMonth()+1,day:Q.getUTCDate()}:null,H=F?{year:F.getUTCFullYear(),month:F.getUTCMonth()+1,day:F.getUTCDate()}:null;return Z==="year"?{min:Y?.year??1,max:H?.year??9999}:Z==="month"?{min:Y&&J.year===Y.year?Y.month:1,max:H&&J.year===H.year?H.month:12}:{min:Y&&J.year===Y.year&&J.month===Y.month?Y.day:1,max:H&&J.year===H.year&&J.month===H.month?H.day:p0(J.year,J.month)}}class _1 extends s{#J;#Y;#Z;#H;#z;#Q={segmentIndex:0,positionInSegment:0};#F=!0;#W=null;inlineError="";get segmentCursor(){return{...this.#Q}}get segmentValues(){return{...this.#Z}}get segments(){return this.#J}get separator(){return this.#Y}get formattedValue(){return this.#X(this.#Z)}#X(Z){return this.#J.map((J)=>Z[J.type]).join(this.#Y)}#U(){this._setUserInput(this.#X(this.#Z)),this._setValue(I1(this.#Z)??void 0)}constructor(Z){let J=Z.format?{segments:D1(Z.format),separator:Z.separator??"/"}:K8(Z.locale),Q=Z.separator??J.separator,F=Z.format?D1(Z.format):J.segments,Y=Z.initialValue??Z.defaultValue,H=Y?{year:String(Y.getUTCFullYear()).padStart(4,"0"),month:String(Y.getUTCMonth()+1).padStart(2,"0"),day:String(Y.getUTCDate()).padStart(2,"0")}:{year:"____",month:"__",day:"__"},z=F.map((U)=>H[U.type]).join(Q);super({...Z,initialUserInput:z},!1),this.#J=F,this.#Y=Q,this.#Z=H,this.#H=Z.minDate,this.#z=Z.maxDate,this.#U(),this.on("cursor",(U)=>this.#j(U)),this.on("key",(U,W)=>this.#N(U,W)),this.on("finalize",()=>this.#w(Z))}#L(){let Z=Math.max(0,Math.min(this.#Q.segmentIndex,this.#J.length-1)),J=this.#J[Z];if(J)return this.#Q.positionInSegment=Math.max(0,Math.min(this.#Q.positionInSegment,J.len-1)),{segment:J,index:Z}}#K(Z){this.inlineError="",this.#W=null;let J=this.#L();J&&(this.#Q.segmentIndex=Math.max(0,Math.min(this.#J.length-1,J.index+Z)),this.#Q.positionInSegment=0,this.#F=!0)}#M(Z){let J=this.#L();if(!J)return;let{segment:Q}=J,F=this.#Z[Q.type],Y=!F||F.replace(/_/g,"")==="",H=Number.parseInt((F||"0").replace(/_/g,"0"),10)||0,z=X8(Q.type,G0(this.#Z),this.#H,this.#z),U;Y?U=Z===1?z.min:z.max:U=Math.max(Math.min(z.max,H+Z),z.min),this.#Z={...this.#Z,[Q.type]:U.toString().padStart(Q.len,"0")},this.#F=!0,this.#W=null,this.#U()}#j(Z){if(Z)switch(Z){case"right":return this.#K(1);case"left":return this.#K(-1);case"up":return this.#M(1);case"down":return this.#M(-1)}}#N(Z,J){if(J?.name==="backspace"||J?.sequence==="\x7F"||J?.sequence==="\b"||Z==="\x7F"||Z==="\b"){this.inlineError="";let Q=this.#L();if(!Q)return;if(!this.#Z[Q.segment.type].replace(/_/g,"")){this.#K(-1);return}this.#Z[Q.segment.type]="_".repeat(Q.segment.len),this.#F=!0,this.#Q.positionInSegment=0,this.#U();return}if(J?.name==="tab"){this.inlineError="";let Q=this.#L();if(!Q)return;let F=J.shift?-1:1,Y=Q.index+F;Y>=0&&Y<this.#J.length&&(this.#Q.segmentIndex=Y,this.#Q.positionInSegment=0,this.#F=!0);return}if(Z&&/^[0-9]$/.test(Z)){let Q=this.#L();if(!Q)return;let{segment:F}=Q,Y=!this.#Z[F.type].replace(/_/g,"");if(this.#F&&this.#W!==null&&!Y){let M=this.#W+Z,N={...this.#Z,[F.type]:M},j=this.#G(N,F);if(j){this.inlineError=j,this.#W=null,this.#F=!1;return}this.inlineError="",this.#Z[F.type]=M,this.#W=null,this.#F=!1,this.#U(),Q.index<this.#J.length-1&&(this.#Q.segmentIndex=Q.index+1,this.#Q.positionInSegment=0,this.#F=!0);return}this.#F&&!Y&&(this.#Z[F.type]="_".repeat(F.len),this.#Q.positionInSegment=0),this.#F=!1,this.#W=null;let H=this.#Z[F.type],z=H.indexOf("_"),U=z>=0?z:Math.min(this.#Q.positionInSegment,F.len-1);if(U<0||U>=F.len)return;let W=H.slice(0,U)+Z+H.slice(U+1),L=!1;if(U===0&&H==="__"&&(F.type==="month"||F.type==="day")){let M=Number.parseInt(Z,10);W=`0${Z}`,L=M<=(F.type==="month"?1:2)}if(F.type==="year"&&(W=(H.replace(/_/g,"")+Z).padStart(F.len,"_")),!W.includes("_")){let M={...this.#Z,[F.type]:W},N=this.#G(M,F);if(N){this.inlineError=N;return}}this.inlineError="",this.#Z[F.type]=W;let K=W.includes("_")?void 0:v1(this.#Z);if(K){let{year:M,month:N}=K,j=p0(M,N);this.#Z={year:String(Math.max(0,Math.min(9999,M))).padStart(4,"0"),month:String(Math.max(1,Math.min(12,N))).padStart(2,"0"),day:String(Math.max(1,Math.min(j,K.day))).padStart(2,"0")}}this.#U();let X=W.indexOf("_");L?(this.#F=!0,this.#W=Z):X>=0?this.#Q.positionInSegment=X:z>=0&&Q.index<this.#J.length-1?(this.#Q.segmentIndex=Q.index+1,this.#Q.positionInSegment=0,this.#F=!0):this.#Q.positionInSegment=Math.min(U+1,F.len-1)}}#G(Z,J){let{month:Q,day:F}=G0(Z);if(J.type==="month"&&(Q<0||Q>12))return O.date.messages.invalidMonth;if(J.type==="day"&&(F<0||F>31))return O.date.messages.invalidDay(31,"any month")}#w(Z){let{year:J,month:Q,day:F}=G0(this.#Z);if(J&&Q&&F){let Y=p0(J,Q);this.#Z={...this.#Z,day:String(Math.min(F,Y)).padStart(2,"0")}}this.value=I1(this.#Z)??Z.defaultValue??void 0}}var M8=class extends s{options;cursor=0;#J;getGroupItems(J){return this.options.filter((Q)=>Q.group===J)}isGroupSelected(J){let Q=this.getGroupItems(J),F=this.value;return F===void 0?!1:Q.every((Y)=>F.includes(Y.value))}toggleValue(){let J=this.options[this.cursor];if(J!==void 0)if(this.value===void 0&&(this.value=[]),J.group===!0){let Q=J.value,F=this.getGroupItems(Q);this.isGroupSelected(Q)?this.value=this.value.filter((Y)=>F.findIndex((H)=>H.value===Y)===-1):this.value=[...this.value,...F.map((Y)=>Y.value)],this.value=Array.from(new Set(this.value))}else{let Q=this.value.includes(J.value);this.value=Q?this.value.filter((F)=>F!==J.value):[...this.value,J.value]}}constructor(J){super(J,!1);let{options:Q}=J;this.#J=J.selectableGroups!==!1,this.options=Object.entries(Q).flatMap(([F,Y])=>[{value:F,group:!0,label:F},...Y.map((H)=>({...H,group:F}))]),this.value=[...J.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:F})=>F===J.cursorAt),this.#J?0:1),this.on("cursor",(F)=>{switch(F){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;let Y=this.options[this.cursor]?.group===!0;!this.#J&&Y&&(this.cursor=this.cursor===0?this.options.length-1:this.cursor-1);break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;let Y=this.options[this.cursor]?.group===!0;!this.#J&&Y&&(this.cursor=this.cursor===this.options.length-1?0:this.cursor+1);break}case"space":this.toggleValue();break}})}},G8=new Set(["up","down","left","right"]);class f1 extends s{#J=!1;#Y;focused="editor";get userInputWithCursor(){if(this.state==="submit")return this.userInput;let Z=this.userInput;if(this.cursor>=Z.length)return`${Z}\u2588`;let J=Z.slice(0,this.cursor),Q=Z.slice(this.cursor,this.cursor+1),F=Z.slice(this.cursor+1);return Q===`
|
|
24
|
+
`)),this._prevFrame=Z;return}}this.output.write(P.erase.down())}this.output.write(Z),this.state==="initial"&&(this.state="active"),this._prevFrame=Z}}}function j8(Z,J){if(Z===void 0||J.length===0)return 0;let Q=J.findIndex((F)=>F.value===Z);return Q!==-1?Q:0}function N8(Z,J){return(J.label??String(J.value)).toLowerCase().includes(Z.toLowerCase())}function w8(Z,J){if(J)return Z?J:J[0]}var V8=class extends s{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#J=0;#Y="";#Z;#H;#z;get cursor(){return this.#J}get userInputWithCursor(){if(!this.userInput)return m0(["inverse","hidden"],"_");if(this._cursor>=this.userInput.length)return`${this.userInput}\u2588`;let J=this.userInput.slice(0,this.cursor),Q=this.userInput.slice(this.cursor,this.cursor+1),F=this.userInput.slice(this.cursor+1);return`${J}${m0("inverse",Q)}${F}`}get options(){return typeof this.#H=="function"?this.#H():this.#H}constructor(J){super(J),this.#H=J.options,this.#z=J.placeholder;let Q=this.options;this.filteredOptions=[...Q],this.multiple=J.multiple===!0,this.#Z=typeof J.options=="function"?J.filter:J.filter??N8;let F;if(J.initialValue&&Array.isArray(J.initialValue)?this.multiple?F=J.initialValue:F=J.initialValue.slice(0,1):!this.multiple&&this.options.length>0&&(F=[this.options[0]?.value]),F)for(let Y of F){let H=Q.findIndex((z)=>z.value===Y);H!==-1&&(this.toggleSelected(Y),this.#J=H)}this.focusedValue=this.options[this.#J]?.value,this.on("key",(Y,H)=>this.#Q(Y,H)),this.on("userInput",(Y)=>this.#F(Y))}_isActionKey(J,Q){return J==="\t"||this.multiple&&this.isNavigating&&Q.name==="space"&&J!==void 0&&J!==""}#Q(J,Q){let F=Q.name==="up",Y=Q.name==="down",H=Q.name==="return",z=this.userInput===""||this.userInput==="\t",U=this.#z,W=this.options,L=U!==void 0&&U!==""&&W.some((K)=>!K.disabled&&(this.#Z?this.#Z(U,K):!0));if(Q.name==="tab"&&z&&L){this.userInput==="\t"&&this._clearUserInput(),this._setUserInput(U,!0),this.isNavigating=!1;return}F||Y?(this.#J=u0(this.#J,F?-1:1,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#J]?.value,this.multiple||(this.selectedValues=[this.focusedValue]),this.isNavigating=!0):H?this.value=w8(this.multiple,this.selectedValues):this.multiple?this.focusedValue!==void 0&&(Q.name==="tab"||this.isNavigating&&Q.name==="space")?this.toggleSelected(this.focusedValue):this.isNavigating=!1:(this.focusedValue&&(this.selectedValues=[this.focusedValue]),this.isNavigating=!1)}deselectAll(){this.selectedValues=[]}toggleSelected(J){this.filteredOptions.length!==0&&(this.multiple?this.selectedValues.includes(J)?this.selectedValues=this.selectedValues.filter((Q)=>Q!==J):this.selectedValues=[...this.selectedValues,J]:this.selectedValues=[J])}#F(J){if(J!==this.#Y){this.#Y=J;let Q=this.options;J&&this.#Z?this.filteredOptions=Q.filter((H)=>this.#Z?.(J,H)):this.filteredOptions=[...Q];let F=j8(this.focusedValue,this.filteredOptions);this.#J=u0(F,0,this.filteredOptions);let Y=this.filteredOptions[this.#J];Y&&!Y.disabled?this.focusedValue=Y.value:this.focusedValue=void 0,this.multiple||(this.focusedValue!==void 0?this.toggleSelected(this.focusedValue):this.deselectAll())}}};class d0 extends s{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(Z){super(Z,!1),this.value=!!Z.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",(J)=>{this.output.write(P.cursor.move(0,-1)),this.value=J,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}var B8={Y:{type:"year",len:4},M:{type:"month",len:2},D:{type:"day",len:2}};function f1(Z){return[...Z].map((J)=>B8[J])}function q8(Z){let J=new Intl.DateTimeFormat(Z,{year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(new Date(2000,0,15)),Q=[],F="/";for(let Y of J)Y.type==="literal"?F=Y.value.trim()||Y.value:(Y.type==="year"||Y.type==="month"||Y.type==="day")&&Q.push({type:Y.type,len:Y.type==="year"?4:2});return{segments:Q,separator:F}}function c0(Z){return Number.parseInt((Z||"0").replace(/_/g,"0"),10)||0}function w0(Z){return{year:c0(Z.year),month:c0(Z.month),day:c0(Z.day)}}function o0(Z,J){return new Date(Z||2001,J||1,0).getDate()}function m1(Z){let{year:J,month:Q,day:F}=w0(Z);if(!J||J<0||J>9999||!Q||Q<1||Q>12||!F||F<1)return;let Y=new Date(Date.UTC(J,Q-1,F));if(!(Y.getUTCFullYear()!==J||Y.getUTCMonth()!==Q-1||Y.getUTCDate()!==F))return{year:J,month:Q,day:F}}function y1(Z){let J=m1(Z);return J?new Date(Date.UTC(J.year,J.month-1,J.day)):void 0}function P8(Z,J,Q,F){let Y=Q?{year:Q.getUTCFullYear(),month:Q.getUTCMonth()+1,day:Q.getUTCDate()}:null,H=F?{year:F.getUTCFullYear(),month:F.getUTCMonth()+1,day:F.getUTCDate()}:null;return Z==="year"?{min:Y?.year??1,max:H?.year??9999}:Z==="month"?{min:Y&&J.year===Y.year?Y.month:1,max:H&&J.year===H.year?H.month:12}:{min:Y&&J.year===Y.year&&J.month===Y.month?Y.day:1,max:H&&J.year===H.year&&J.month===H.month?H.day:o0(J.year,J.month)}}class u1 extends s{#J;#Y;#Z;#H;#z;#Q={segmentIndex:0,positionInSegment:0};#F=!0;#W=null;inlineError="";get segmentCursor(){return{...this.#Q}}get segmentValues(){return{...this.#Z}}get segments(){return this.#J}get separator(){return this.#Y}get formattedValue(){return this.#X(this.#Z)}#X(Z){return this.#J.map((J)=>Z[J.type]).join(this.#Y)}#U(){this._setUserInput(this.#X(this.#Z)),this._setValue(y1(this.#Z)??void 0)}constructor(Z){let J=Z.format?{segments:f1(Z.format),separator:Z.separator??"/"}:q8(Z.locale),Q=Z.separator??J.separator,F=Z.format?f1(Z.format):J.segments,Y=Z.initialValue??Z.defaultValue,H=Y?{year:String(Y.getUTCFullYear()).padStart(4,"0"),month:String(Y.getUTCMonth()+1).padStart(2,"0"),day:String(Y.getUTCDate()).padStart(2,"0")}:{year:"____",month:"__",day:"__"},z=F.map((U)=>H[U.type]).join(Q);super({...Z,initialUserInput:z},!1),this.#J=F,this.#Y=Q,this.#Z=H,this.#H=Z.minDate,this.#z=Z.maxDate,this.#U(),this.on("cursor",(U)=>this.#j(U)),this.on("key",(U,W)=>this.#N(U,W)),this.on("finalize",()=>this.#w(Z))}#L(){let Z=Math.max(0,Math.min(this.#Q.segmentIndex,this.#J.length-1)),J=this.#J[Z];if(J)return this.#Q.positionInSegment=Math.max(0,Math.min(this.#Q.positionInSegment,J.len-1)),{segment:J,index:Z}}#K(Z){this.inlineError="",this.#W=null;let J=this.#L();J&&(this.#Q.segmentIndex=Math.max(0,Math.min(this.#J.length-1,J.index+Z)),this.#Q.positionInSegment=0,this.#F=!0)}#M(Z){let J=this.#L();if(!J)return;let{segment:Q}=J,F=this.#Z[Q.type],Y=!F||F.replace(/_/g,"")==="",H=Number.parseInt((F||"0").replace(/_/g,"0"),10)||0,z=P8(Q.type,w0(this.#Z),this.#H,this.#z),U;Y?U=Z===1?z.min:z.max:U=Math.max(Math.min(z.max,H+Z),z.min),this.#Z={...this.#Z,[Q.type]:U.toString().padStart(Q.len,"0")},this.#F=!0,this.#W=null,this.#U()}#j(Z){if(Z)switch(Z){case"right":return this.#K(1);case"left":return this.#K(-1);case"up":return this.#M(1);case"down":return this.#M(-1)}}#N(Z,J){if(J?.name==="backspace"||J?.sequence==="\x7F"||J?.sequence==="\b"||Z==="\x7F"||Z==="\b"){this.inlineError="";let Q=this.#L();if(!Q)return;if(!this.#Z[Q.segment.type].replace(/_/g,"")){this.#K(-1);return}this.#Z[Q.segment.type]="_".repeat(Q.segment.len),this.#F=!0,this.#Q.positionInSegment=0,this.#U();return}if(J?.name==="tab"){this.inlineError="";let Q=this.#L();if(!Q)return;let F=J.shift?-1:1,Y=Q.index+F;Y>=0&&Y<this.#J.length&&(this.#Q.segmentIndex=Y,this.#Q.positionInSegment=0,this.#F=!0);return}if(Z&&/^[0-9]$/.test(Z)){let Q=this.#L();if(!Q)return;let{segment:F}=Q,Y=!this.#Z[F.type].replace(/_/g,"");if(this.#F&&this.#W!==null&&!Y){let M=this.#W+Z,N={...this.#Z,[F.type]:M},j=this.#G(N,F);if(j){this.inlineError=j,this.#W=null,this.#F=!1;return}this.inlineError="",this.#Z[F.type]=M,this.#W=null,this.#F=!1,this.#U(),Q.index<this.#J.length-1&&(this.#Q.segmentIndex=Q.index+1,this.#Q.positionInSegment=0,this.#F=!0);return}this.#F&&!Y&&(this.#Z[F.type]="_".repeat(F.len),this.#Q.positionInSegment=0),this.#F=!1,this.#W=null;let H=this.#Z[F.type],z=H.indexOf("_"),U=z>=0?z:Math.min(this.#Q.positionInSegment,F.len-1);if(U<0||U>=F.len)return;let W=H.slice(0,U)+Z+H.slice(U+1),L=!1;if(U===0&&H==="__"&&(F.type==="month"||F.type==="day")){let M=Number.parseInt(Z,10);W=`0${Z}`,L=M<=(F.type==="month"?1:2)}if(F.type==="year"&&(W=(H.replace(/_/g,"")+Z).padStart(F.len,"_")),!W.includes("_")){let M={...this.#Z,[F.type]:W},N=this.#G(M,F);if(N){this.inlineError=N;return}}this.inlineError="",this.#Z[F.type]=W;let K=W.includes("_")?void 0:m1(this.#Z);if(K){let{year:M,month:N}=K,j=o0(M,N);this.#Z={year:String(Math.max(0,Math.min(9999,M))).padStart(4,"0"),month:String(Math.max(1,Math.min(12,N))).padStart(2,"0"),day:String(Math.max(1,Math.min(j,K.day))).padStart(2,"0")}}this.#U();let X=W.indexOf("_");L?(this.#F=!0,this.#W=Z):X>=0?this.#Q.positionInSegment=X:z>=0&&Q.index<this.#J.length-1?(this.#Q.segmentIndex=Q.index+1,this.#Q.positionInSegment=0,this.#F=!0):this.#Q.positionInSegment=Math.min(U+1,F.len-1)}}#G(Z,J){let{month:Q,day:F}=w0(Z);if(J.type==="month"&&(Q<0||Q>12))return O.date.messages.invalidMonth;if(J.type==="day"&&(F<0||F>31))return O.date.messages.invalidDay(31,"any month")}#w(Z){let{year:J,month:Q,day:F}=w0(this.#Z);if(J&&Q&&F){let Y=o0(J,Q);this.#Z={...this.#Z,day:String(Math.min(F,Y)).padStart(2,"0")}}this.value=y1(this.#Z)??Z.defaultValue??void 0}}var O8=class extends s{options;cursor=0;#J;getGroupItems(J){return this.options.filter((Q)=>Q.group===J)}isGroupSelected(J){let Q=this.getGroupItems(J),F=this.value;return F===void 0?!1:Q.every((Y)=>F.includes(Y.value))}toggleValue(){let J=this.options[this.cursor];if(J!==void 0)if(this.value===void 0&&(this.value=[]),J.group===!0){let Q=J.value,F=this.getGroupItems(Q);this.isGroupSelected(Q)?this.value=this.value.filter((Y)=>F.findIndex((H)=>H.value===Y)===-1):this.value=[...this.value,...F.map((Y)=>Y.value)],this.value=Array.from(new Set(this.value))}else{let Q=this.value.includes(J.value);this.value=Q?this.value.filter((F)=>F!==J.value):[...this.value,J.value]}}constructor(J){super(J,!1);let{options:Q}=J;this.#J=J.selectableGroups!==!1,this.options=Object.entries(Q).flatMap(([F,Y])=>[{value:F,group:!0,label:F},...Y.map((H)=>({...H,group:F}))]),this.value=[...J.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:F})=>F===J.cursorAt),this.#J?0:1),this.on("cursor",(F)=>{switch(F){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;let Y=this.options[this.cursor]?.group===!0;!this.#J&&Y&&(this.cursor=this.cursor===0?this.options.length-1:this.cursor-1);break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;let Y=this.options[this.cursor]?.group===!0;!this.#J&&Y&&(this.cursor=this.cursor===this.options.length-1?0:this.cursor+1);break}case"space":this.toggleValue();break}})}},b8=new Set(["up","down","left","right"]);class r1 extends s{#J=!1;#Y;focused="editor";get userInputWithCursor(){if(this.state==="submit")return this.userInput;let Z=this.userInput;if(this.cursor>=Z.length)return`${Z}\u2588`;let J=Z.slice(0,this.cursor),Q=Z.slice(this.cursor,this.cursor+1),F=Z.slice(this.cursor+1);return Q===`
|
|
25
25
|
`?`${J}\u2588
|
|
26
|
-
${F}`:`${J}${
|
|
26
|
+
${F}`:`${J}${m0("inverse",Q)}${F}`}get cursor(){return this._cursor}#Z(Z){if(this.userInput.length===0){this._setUserInput(Z);return}this._setUserInput(this.userInput.slice(0,this.cursor)+Z+this.userInput.slice(this.cursor))}#H(Z){let J=this.value??"";switch(Z){case"up":this._cursor=j0(this._cursor,0,-1,J);return;case"down":this._cursor=j0(this._cursor,0,1,J);return;case"left":this._cursor=j0(this._cursor,-1,0,J);return;case"right":this._cursor=j0(this._cursor,1,0,J);return}}_shouldSubmit(Z,J){if(this.#Y)return this.focused==="submit"?!0:(this.#Z(`
|
|
27
27
|
`),this._cursor++,!1);let Q=this.#J;return this.#J=!0,Q&&this.cursor===this.userInput.length?(this.userInput[this.cursor-1]===`
|
|
28
28
|
`&&(this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--),!0):(this.#Z(`
|
|
29
|
-
`),this._cursor++,!1)}constructor(Z){let J=Z.initialUserInput??Z.initialValue;super({...Z,initialUserInput:J},!1),J!==void 0&&(this._cursor=J.length),this.#Y=Z.showSubmit??!1,this.on("key",(Q,F)=>{if(F?.name&&
|
|
29
|
+
`),this._cursor++,!1)}constructor(Z){let J=Z.initialUserInput??Z.initialValue;super({...Z,initialUserInput:J},!1),J!==void 0&&(this._cursor=J.length),this.#Y=Z.showSubmit??!1,this.on("key",(Q,F)=>{if(F?.name&&b8.has(F.name)){this.#J=!1,this.#H(F.name);return}if(Q==="\t"&&this.#Y){this.focused=this.focused==="editor"?"submit":"editor";return}if(F?.name!=="return"){if(this.#J=!1,F?.name==="backspace"&&this.cursor>0){this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--;return}if(F?.name==="delete"&&this.cursor<this.userInput.length){this._setUserInput(this.userInput.slice(0,this.cursor)+this.userInput.slice(this.cursor+1));return}Q&&(this.#Y&&this.focused==="submit"&&(this.focused="editor"),this.#Z(Q??""),this._cursor++)}}),this.on("userInput",(Q)=>{this._setValue(Q)}),this.on("finalize",()=>{this.value||(this.value=Z.defaultValue),this.value===void 0&&(this.value="")})}}import{styleText as G,stripVTControlCharacters as i6}from"util";import I from"process";var F0=z1(l0(),1);function C8(){if(I.platform!=="win32")return I.env.TERM!=="linux";return Boolean(I.env.CI)||Boolean(I.env.WT_SESSION)||Boolean(I.env.TERMINUS_SUBLIME)||I.env.ConEmuTask==="{cmd::Cmder}"||I.env.TERM_PROGRAM==="Terminus-Sublime"||I.env.TERM_PROGRAM==="vscode"||I.env.TERM==="xterm-256color"||I.env.TERM==="alacritty"||I.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var s0=C8(),R8=()=>process.env.CI==="true";var V=(Z,J)=>s0?Z:J,A8=V("\u25C6","*"),d1=V("\u25A0","x"),s1=V("\u25B2","x"),q0=V("\u25C7","o"),E8=V("\u250C","T"),C=V("\u2502","|"),a1=V("\u2514","\u2014"),e6=V("\u2510","T"),t6=V("\u2518","\u2014"),o1=V("\u25CF",">"),n1=V("\u25CB"," "),Z7=V("\u25FB","[\u2022]"),J7=V("\u25FC","[+]"),Q7=V("\u25FB","[ ]"),F7=V("\u25AA","\u2022"),i1=V("\u2500","-"),D8=V("\u256E","+"),I8=V("\u251C","+"),x8=V("\u256F","+"),T8=V("\u2570","+"),Y7=V("\u256D","+"),S8=V("\u25CF","\u2022"),k8=V("\u25C6","*"),h8=V("\u25B2","!"),v8=V("\u25A0","x"),_8=(Z)=>{switch(Z){case"initial":case"active":return G("cyan",A8);case"cancel":return G("red",d1);case"error":return G("yellow",s1);case"submit":return G("green",q0)}};var e1=(Z)=>{let J=Z.active??"Yes",Q=Z.inactive??"No";return new d0({active:J,inactive:Q,signal:Z.signal,input:Z.input,output:Z.output,initialValue:Z.initialValue??!0,render(){let F=Z.withGuide??O.withGuide,Y=`${_8(this.state)} `,H=F?`${G("gray",C)} `:"",z=l1(Z.output,Z.message,H,Y),U=`${F?`${G("gray",C)}
|
|
30
30
|
`:""}${z}
|
|
31
31
|
`,W=this.value?J:Q;switch(this.state){case"submit":{let L=F?`${G("gray",C)} `:"";return`${U}${L}${G("dim",W)}`}case"cancel":{let L=F?`${G("gray",C)} `:"";return`${U}${L}${G(["strikethrough","dim"],W)}${F?`
|
|
32
|
-
${G("gray",C)}`:""}`}default:{let L=F?`${G("cyan",C)} `:"",K=F?G("cyan",
|
|
32
|
+
${G("gray",C)}`:""}`}default:{let L=F?`${G("cyan",C)} `:"",K=F?G("cyan",a1):"";return`${U}${L}${this.value?`${G("green",o1)} ${J}`:`${G("dim",n1)} ${G("dim",J)}`}${Z.vertical?F?`
|
|
33
33
|
${G("cyan",C)} `:`
|
|
34
|
-
`:` ${G("dim","/")} `}${this.value?`${G("dim"
|
|
34
|
+
`:` ${G("dim","/")} `}${this.value?`${G("dim",n1)} ${G("dim",Q)}`:`${G("green",o1)} ${Q}`}
|
|
35
35
|
${K}
|
|
36
|
-
`}}}}).prompt()};var
|
|
36
|
+
`}}}}).prompt()};var H7=[`${G("dim","\u2191/\u2193")} to navigate`,`${G("dim","Space:")} select`,`${G("dim","Enter:")} confirm`];var B={message:(Z=[],{symbol:J=G("gray",C),secondarySymbol:Q=G("gray",C),output:F=process.stdout,spacing:Y=1,withGuide:H}={})=>{let z=[],U=H??O.withGuide,W=U?Q:"",L=U?`${J} `:"",K=U?`${Q} `:"";for(let M=0;M<Y;M++)z.push(W);let X=Array.isArray(Z)?Z:Z.split(`
|
|
37
37
|
`);if(X.length>0){let[M,...N]=X;M.length>0?z.push(`${L}${M}`):z.push(U?J:"");for(let j of N)j.length>0?z.push(`${K}${j}`):z.push(U?Q:"")}F.write(`${z.join(`
|
|
38
38
|
`)}
|
|
39
|
-
`)},info:(Z,J)=>{B.message(Z,{...J,symbol:G("blue",
|
|
40
|
-
`)},
|
|
41
|
-
${G("gray",
|
|
39
|
+
`)},info:(Z,J)=>{B.message(Z,{...J,symbol:G("blue",S8)})},success:(Z,J)=>{B.message(Z,{...J,symbol:G("green",k8)})},step:(Z,J)=>{B.message(Z,{...J,symbol:G("green",q0)})},warn:(Z,J)=>{B.message(Z,{...J,symbol:G("yellow",h8)})},warning:(Z,J)=>{B.warn(Z,J)},error:(Z,J)=>{B.message(Z,{...J,symbol:G("red",v8)})}};var P0=(Z="",J)=>{let Q=J?.output??process.stdout,F=J?.withGuide??O.withGuide?`${G("gray",E8)} `:"";Q.write(`${F}${Z}
|
|
40
|
+
`)},t1=(Z="",J)=>{let Q=J?.output??process.stdout,F=J?.withGuide??O.withGuide?`${G("gray",C)}
|
|
41
|
+
${G("gray",a1)} `:"";Q.write(`${F}${Z}
|
|
42
42
|
|
|
43
|
-
`)};var
|
|
44
|
-
`),H=Y.reduce((W,L)=>Math.max(b(L),W),0),z=Y.map(Q).reduce((W,L)=>Math.max(b(L),W),0),U=J-(z-H);return
|
|
43
|
+
`)};var f8=(Z)=>Z,y8=(Z,J,Q)=>{let F={hard:!0,trim:!1},Y=p(Z,J,F).split(`
|
|
44
|
+
`),H=Y.reduce((W,L)=>Math.max(b(L),W),0),z=Y.map(Q).reduce((W,L)=>Math.max(b(L),W),0),U=J-(z-H);return p(Z,U,F)},O0=(Z="",J="",Q)=>{let F=Q?.output??I.stdout,Y=Q?.withGuide??O.withGuide,H=Q?.format??f8,z=["",...y8(Z,B0(F)-6,H).split(`
|
|
45
45
|
`).map(H),""],U=b(J),W=Math.max(z.reduce((M,N)=>{let j=b(N);return j>M?j:M},0),U)+2,L=z.map((M)=>`${G("gray",C)} ${M}${" ".repeat(W-b(M))}${G("gray",C)}`).join(`
|
|
46
46
|
`),K=Y?`${G("gray",C)}
|
|
47
|
-
`:"",X=Y?
|
|
47
|
+
`:"",X=Y?I8:T8;F.write(`${K}${G("green",q0)} ${G("reset",J)} ${G("gray",i1.repeat(Math.max(W-U-1,1))+D8)}
|
|
48
48
|
${L}
|
|
49
|
-
${G("gray",X+
|
|
50
|
-
`)};var
|
|
51
|
-
`);let q=
|
|
52
|
-
`);q.length>1&&Q.write(
|
|
53
|
-
`);let D=0,v=0;d(),X=setInterval(()=>{if(L&&j===w)return;R(),w=j;let _=c(H[D]),z0;if(L)z0=`${_} ${j}...`;else if(Z==="timer")z0=`${_} ${j} ${i(k)}`;else{let
|
|
49
|
+
${G("gray",X+i1.repeat(W+2)+x8)}
|
|
50
|
+
`)};var $8=(Z)=>G("magenta",Z),b0=({indicator:Z="dots",onCancel:J,output:Q=process.stdout,cancelMessage:F,errorMessage:Y,frames:H=s0?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:z=s0?80:120,signal:U,...W}={})=>{let L=R8(),K,X,M=!1,N=!1,j="",w,k=performance.now(),l=B0(Q),c=W?.styleFrame??$8,x=(q)=>{let D=q>1?Y??O.messages.error:F??O.messages.cancel;N=q===1,M&&(e(D,q),N&&typeof J=="function"&&J())},h=()=>x(2),A=()=>x(1),d=()=>{process.on("uncaughtExceptionMonitor",h),process.on("unhandledRejection",h),process.on("SIGINT",A),process.on("SIGTERM",A),process.on("exit",x),U&&U.addEventListener("abort",A)},T=()=>{process.removeListener("uncaughtExceptionMonitor",h),process.removeListener("unhandledRejection",h),process.removeListener("SIGINT",A),process.removeListener("SIGTERM",A),process.removeListener("exit",x),U&&U.removeEventListener("abort",A)},R=()=>{if(w===void 0)return;L&&Q.write(`
|
|
51
|
+
`);let q=p(w,l,{hard:!0,trim:!1}).split(`
|
|
52
|
+
`);q.length>1&&Q.write(F0.cursor.up(q.length-1)),Q.write(F0.cursor.to(0)),Q.write(F0.erase.down())},m=(q)=>q.replace(/\.+$/,""),i=(q)=>{let D=(performance.now()-q)/1000,v=Math.floor(D/60),_=Math.floor(D%60);return v>0?`[${v}m ${_}s]`:`[${_}s]`},E=W.withGuide??O.withGuide,W0=(q="")=>{M=!0,K=p1({output:Q}),j=m(q),k=performance.now(),E&&Q.write(`${G("gray",C)}
|
|
53
|
+
`);let D=0,v=0;d(),X=setInterval(()=>{if(L&&j===w)return;R(),w=j;let _=c(H[D]),z0;if(L)z0=`${_} ${j}...`;else if(Z==="timer")z0=`${_} ${j} ${i(k)}`;else{let O9=".".repeat(Math.floor(v)).slice(0,3);z0=`${_} ${j}${O9}`}let P9=p(z0,l,{hard:!0,trim:!1});Q.write(P9),D=D+1<H.length?D+1:0,v=v<4?v+0.125:0},z)},e=(q="",D=0,v=!1)=>{if(!M)return;M=!1,clearInterval(X),R();let _=D===0?G("green",q0):D===1?G("red",d1):G("red",s1);j=q??j,v||(Z==="timer"?Q.write(`${_} ${j} ${i(k)}
|
|
54
54
|
`):Q.write(`${_} ${j}
|
|
55
|
-
`)),T(),K()};return{start:W0,stop:(q="")=>e(q,0),message:(q="")=>{j=m(q??j)},cancel:(q="")=>e(q,1),error:(q="")=>e(q,2),clear:()=>e("",0,!0),get isCancelled(){return N}}},
|
|
56
|
-
`),"System Environment",{withGuide:!0}),u1("Scan completed"),J}var O0,h8={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function s1(Z){if(!Z&&!O0)return h8;return{lang:Z?.lang??O0?.lang,message:Z?.message,abortEarly:Z?.abortEarly??O0?.abortEarly,abortPipeEarly:Z?.abortPipeEarly??O0?.abortPipeEarly}}var v8;function _8(Z){return v8?.get(Z)}var f8;function y8(Z){return f8?.get(Z)}var $8;function p8(Z,J){return $8?.get(Z)?.get(J)}function o0(Z){let J=typeof Z;if(J==="string")return`"${Z}"`;if(J==="number"||J==="bigint"||J==="boolean")return`${Z}`;if(J==="object"||J==="function")return(Z&&Object.getPrototypeOf(Z)?.constructor?.name)??"null";return J}function $(Z,J,Q,F,Y){let H=Y&&"input"in Y?Y.input:Q.value,z=Y?.expected??Z.expects??null,U=Y?.received??o0(H),W={kind:Z.kind,type:Z.type,input:H,expected:z,received:U,message:`Invalid ${J}: ${z?`Expected ${z} but r`:"R"}eceived ${U}`,requirement:Z.requirement,path:Y?.path,issues:Y?.issues,lang:F.lang,abortEarly:F.abortEarly,abortPipeEarly:F.abortPipeEarly},L=Z.kind==="schema",K=Y?.message??Z.message??p8(Z.reference,W.lang)??(L?y8(W.lang):null)??F.message??_8(W.lang);if(K!==void 0)W.message=typeof K==="function"?K(W):K;if(L)Q.typed=!1;if(Q.issues)Q.issues.push(W);else Q.issues=[W]}var i1=new WeakMap;function p(Z){let J=i1.get(Z);if(!J)J={version:1,vendor:"valibot",validate(Q){return Z["~run"]({value:Q},s1())}},i1.set(Z,J);return J}function a1(Z,J){let Q=[...new Set(Z)];if(Q.length>1)return`(${Q.join(` ${J} `)})`;return Q[0]??"never"}var g8=class extends Error{constructor(Z){super(Z[0].message);this.name="ValiError",this.issues=Z}};function l8(Z,J,Q){return typeof Z.fallback==="function"?Z.fallback(J,Q):Z.fallback}function e1(Z,J,Q){return typeof Z.default==="function"?Z.default(J,Q):Z.default}function g(Z,J){return{kind:"schema",type:"array",reference:g,expects:"Array",async:!1,item:Z,message:J,get "~standard"(){return p(this)},"~run"(Q,F){let Y=Q.value;if(Array.isArray(Y)){Q.typed=!0,Q.value=[];for(let H=0;H<Y.length;H++){let z=Y[H],U=this.item["~run"]({value:z},F);if(U.issues){let W={type:"array",origin:"value",input:Y,key:H,value:z};for(let L of U.issues){if(L.path)L.path.unshift(W);else L.path=[W];Q.issues?.push(L)}if(!Q.issues)Q.issues=U.issues;if(F.abortEarly){Q.typed=!1;break}}if(!U.typed)Q.typed=!1;Q.value.push(U.value)}}else $(this,"type",Q,F);return Q}}}function J0(Z){return{kind:"schema",type:"boolean",reference:J0,expects:"boolean",async:!1,message:Z,get "~standard"(){return p(this)},"~run"(J,Q){if(typeof J.value==="boolean")J.typed=!0;else $(this,"type",J,Q);return J}}}function n0(Z,J){return{kind:"schema",type:"literal",reference:n0,expects:o0(Z),async:!1,literal:Z,message:J,get "~standard"(){return p(this)},"~run"(Q,F){if(Q.value===this.literal)Q.typed=!0;else $(this,"type",Q,F);return Q}}}function o(Z,J){return{kind:"schema",type:"object",reference:o,expects:"Object",async:!1,entries:Z,message:J,get "~standard"(){return p(this)},"~run"(Q,F){let Y=Q.value;if(Y&&typeof Y==="object"){Q.typed=!0,Q.value={};for(let H in this.entries){let z=this.entries[H];if(H in Y||(z.type==="exact_optional"||z.type==="optional"||z.type==="nullish")&&z.default!==void 0){let U=H in Y?Y[H]:e1(z),W=z["~run"]({value:U},F);if(W.issues){let L={type:"object",origin:"value",input:Y,key:H,value:U};for(let K of W.issues){if(K.path)K.path.unshift(L);else K.path=[L];Q.issues?.push(K)}if(!Q.issues)Q.issues=W.issues;if(F.abortEarly){Q.typed=!1;break}}if(!W.typed)Q.typed=!1;Q.value[H]=W.value}else if(z.fallback!==void 0)Q.value[H]=l8(z);else if(z.type!=="exact_optional"&&z.type!=="optional"&&z.type!=="nullish"){if($(this,"key",Q,F,{input:void 0,expected:`"${H}"`,path:[{type:"object",origin:"key",input:Y,key:H,value:Y[H]}]}),F.abortEarly)break}}}else $(this,"type",Q,F);return Q}}}function Q0(Z,J){return{kind:"schema",type:"optional",reference:Q0,expects:`(${Z.expects} | undefined)`,async:!1,wrapped:Z,default:J,get "~standard"(){return p(this)},"~run"(Q,F){if(Q.value===void 0){if(this.default!==void 0)Q.value=e1(this,Q,F);if(Q.value===void 0)return Q.typed=!0,Q}return this.wrapped["~run"](Q,F)}}}function F0(Z,J){return{kind:"schema",type:"picklist",reference:F0,expects:a1(Z.map(o0),"|"),async:!1,options:Z,message:J,get "~standard"(){return p(this)},"~run"(Q,F){if(this.options.includes(Q.value))Q.typed=!0;else $(this,"type",Q,F);return Q}}}function S(Z){return{kind:"schema",type:"string",reference:S,expects:"string",async:!1,message:Z,get "~standard"(){return p(this)},"~run"(J,Q){if(typeof J.value==="string")J.typed=!0;else $(this,"type",J,Q);return J}}}function d1(Z){let J;if(Z)for(let Q of Z)if(J)for(let F of Q.issues)J.push(F);else J=Q.issues;return J}function Y0(Z,J){return{kind:"schema",type:"union",reference:Y0,expects:a1(Z.map((Q)=>Q.expects),"|"),async:!1,options:Z,message:J,get "~standard"(){return p(this)},"~run"(Q,F){let Y,H,z;for(let U of this.options){let W=U["~run"]({value:Q.value},F);if(W.typed)if(W.issues)if(H)H.push(W);else H=[W];else{Y=W;break}else if(z)z.push(W);else z=[W]}if(Y)return Y;if(H){if(H.length===1)return H[0];$(this,"type",Q,F,{issues:d1(H)}),Q.typed=!0}else if(z?.length===1)return z[0];else $(this,"type",Q,F,{issues:d1(z)});return Q}}}function t1(Z,J,Q){let F=Z["~run"]({value:J},s1(Q));if(F.issues)throw new g8(F.issues);return F.value}function i0(Z,J){let Q={};for(let F in Z.entries)Q[F]=!J||J.includes(F)?Q0(Z.entries[F]):Z.entries[F];return{...Z,entries:Q,get "~standard"(){return p(this)}}}import J9 from"path";import{homedir as c8}from"os";function b0(Z){if(Z.startsWith("~"))return J9.join(c8(),Z.slice(1));return J9.resolve(Z)}var m8=i0(o({flatpak:J0(),backup:J0(),aur_helper:F0(["yay","paru"])})),u8=o({source:S(),target:S(),sudo:Q0(J0())}),r8=F0(["aur","pacman"]),o8=Y0([S(),g(S()),g(g(S()))]),n8=o({name:S(),post_hooks:Q0(o8)}),Q9=g(Y0([S(),n8])),i8=o({manager:r8,items:Q9}),d8=o({manager:n0("flatpak"),scope:F0(["system","user"]),items:Q9}),F9=i0(o({imports:g(S()),settings:m8,packages:g(Y0([d8,i8])),symlinks:g(u8)}));import R0 from"path";var n={defaultMerge:Symbol("deepmerge-ts: default merge"),skip:Symbol("deepmerge-ts: skip")},C7={defaultMerge:n.defaultMerge};function s8(Z,J){return J}function a8(Z,J){return Z.filter((Q)=>Q!==void 0)}var Y9;(function(Z){Z[Z.NOT=0]="NOT",Z[Z.RECORD=1]="RECORD",Z[Z.ARRAY=2]="ARRAY",Z[Z.SET=3]="SET",Z[Z.MAP=4]="MAP",Z[Z.OTHER=5]="OTHER"})(Y9||(Y9={}));function H9(Z){if(typeof Z!=="object"||Z===null)return 0;if(Array.isArray(Z))return 2;if(Z6(Z))return 1;if(Z instanceof Set)return 3;if(Z instanceof Map)return 4;return 5}function e8(Z){let J=new Set;for(let Q of Z)for(let F of[...Object.keys(Q),...Object.getOwnPropertySymbols(Q)])J.add(F);return J}function t8(Z,J){return typeof Z==="object"&&Object.prototype.propertyIsEnumerable.call(Z,J)}function z9(Z){let J=0,Q=Z[0]?.[Symbol.iterator]();return{[Symbol.iterator](){return{next(){do{if(Q===void 0)return{done:!0,value:void 0};let F=Q.next();if(F.done===!0){J+=1,Q=Z[J]?.[Symbol.iterator]();continue}return{done:!1,value:F.value}}while(!0)}}}}}var W9=["[object Object]","[object Module]"];function Z6(Z){if(!W9.includes(Object.prototype.toString.call(Z)))return!1;let{constructor:J}=Z;if(J===void 0)return!0;let Q=J.prototype;if(Q===null||typeof Q!=="object"||!W9.includes(Object.prototype.toString.call(Q)))return!1;if(!Q.hasOwnProperty("isPrototypeOf"))return!1;return!0}function J6(Z,J,Q){let F={};for(let Y of e8(Z)){let H=[];for(let W of Z)if(t8(W,Y))H.push(W[Y]);if(H.length===0)continue;let z=J.metaDataUpdater(Q,{key:Y,parents:Z}),U=U9(H,J,z);if(U===n.skip)continue;if(Y==="__proto__")Object.defineProperty(F,Y,{value:U,configurable:!0,enumerable:!0,writable:!0});else F[Y]=U}return F}function Q6(Z){return Z.flat()}function F6(Z){return new Set(z9(Z))}function Y6(Z){return new Map(z9(Z))}function H6(Z){return Z.at(-1)}var C0={mergeRecords:J6,mergeArrays:Q6,mergeSets:F6,mergeMaps:Y6,mergeOthers:H6};function H0(...Z){return W6({})(...Z)}function W6(Z,J){let Q=z6(Z,F);function F(...Y){return U9(Y,Q,J)}return F}function z6(Z,J){return{defaultMergeFunctions:C0,mergeFunctions:{...C0,...Object.fromEntries(Object.entries(Z).filter(([Q,F])=>Object.hasOwn(C0,Q)).map(([Q,F])=>F===!1?[Q,C0.mergeOthers]:[Q,F]))},metaDataUpdater:Z.metaDataUpdater??s8,deepmerge:J,useImplicitDefaultMerging:Z.enableImplicitDefaultMerging??!1,filterValues:Z.filterValues===!1?void 0:Z.filterValues??a8,actions:n}}function U9(Z,J,Q){let F=J.filterValues?.(Z,Q)??Z;if(F.length===0)return;if(F.length===1)return d0(F,J,Q);let Y=H9(F[0]);if(Y!==0&&Y!==5)for(let H=1;H<F.length;H++){if(H9(F[H])===Y)continue;return d0(F,J,Q)}switch(Y){case 1:return U6(F,J,Q);case 2:return L6(F,J,Q);case 3:return K6(F,J,Q);case 4:return X6(F,J,Q);default:return d0(F,J,Q)}}function U6(Z,J,Q){let F=J.mergeFunctions.mergeRecords(Z,J,Q);if(F===n.defaultMerge||J.useImplicitDefaultMerging&&F===void 0&&J.mergeFunctions.mergeRecords!==J.defaultMergeFunctions.mergeRecords)return J.defaultMergeFunctions.mergeRecords(Z,J,Q);return F}function L6(Z,J,Q){let F=J.mergeFunctions.mergeArrays(Z,J,Q);if(F===n.defaultMerge||J.useImplicitDefaultMerging&&F===void 0&&J.mergeFunctions.mergeArrays!==J.defaultMergeFunctions.mergeArrays)return J.defaultMergeFunctions.mergeArrays(Z);return F}function K6(Z,J,Q){let F=J.mergeFunctions.mergeSets(Z,J,Q);if(F===n.defaultMerge||J.useImplicitDefaultMerging&&F===void 0&&J.mergeFunctions.mergeSets!==J.defaultMergeFunctions.mergeSets)return J.defaultMergeFunctions.mergeSets(Z);return F}function X6(Z,J,Q){let F=J.mergeFunctions.mergeMaps(Z,J,Q);if(F===n.defaultMerge||J.useImplicitDefaultMerging&&F===void 0&&J.mergeFunctions.mergeMaps!==J.defaultMergeFunctions.mergeMaps)return J.defaultMergeFunctions.mergeMaps(Z);return F}function d0(Z,J,Q){let F=J.mergeFunctions.mergeOthers(Z,J,Q);if(F===n.defaultMerge||J.useImplicitDefaultMerging&&F===void 0&&J.mergeFunctions.mergeOthers!==J.defaultMergeFunctions.mergeOthers)return J.defaultMergeFunctions.mergeOthers(Z);return F}async function s0(Z,J=new Set){let Q=R0.resolve(Z);if(J.has(Q))throw Error(`Circular dependency detected: ${Q}`);J.add(Q);let F=await Bun.file(Q).text(),Y=Bun.TOML.parse(F),{imports:H=[],symlinks:z=[]}=Y;delete Y.imports;let U=R0.dirname(Q);Y.symlinks=M6(U,z);let W={};for(let L of H){let K=R0.resolve(U,L),X=await s0(K,J);W=H0(W,X)}return H0(Y,W)}function M6(Z,J){if(!J||J.length===0)return[];let Q=[];for(let F of J){if(!F)continue;let{source:Y,target:H}=F,z=R0.resolve(Z,Y),U=b0(H);Q.push({source:z,target:U})}return Q}async function A0(Z){let J=b0(Z);B.step("Validating Configuration");let Q=q0();Q.start("Validating...");let F=await s0(J),Y=t1(F9,F);return Q.stop("Successfully validated with no errors!"),Y}import w6 from"path";var{deepEquals:M9}=globalThis.Bun;import a0 from"path";import e0 from"fs/promises";var E0={};function D0(){return E0}function L9(Z,J){E0[Z]=J}async function K9(Z){let J=Z??r("configDir"),Q=a0.resolve(J||".",".state/hofii-lock.json");if(await e0.exists(Q)){let F=await Bun.file(Q).json();Object.assign(E0,F.config)}}async function X9(){let Z=a0.resolve(r("configDir")||".",".state");if(!await e0.exists(Z))await e0.mkdir(Z,{recursive:!0});let J={config:E0};await Bun.write(a0.resolve(Z,"hofii-lock.json"),JSON.stringify(J,null,2))}function G6(Z,J){let Q=J?.filter((Y)=>!Z?.some((H)=>M9(Y,H,!0))),F=Z?.filter((Y)=>!J?.some((H)=>M9(Y,H,!0)));return{added:Q,removed:F}}function G9(Z){let J=D0();return{symlinks:G6(J.symlinks,Z.symlinks)}}import j6 from"fs/promises";var{deepEquals:N6}=globalThis.Bun;import Z1 from"fs/promises";async function t0({cmd:Z,errMsg:J,opt:Q={stdin:"inherit",stdout:"inherit",stderr:"inherit"}}){let F=Bun.spawn(Z,{stdin:Q.stdin,stdout:Q.stdout,stderr:Q.stderr}),Y=Q.stdout==="pipe"?new Response(F.stdout).text():void 0,H=Q.stderr==="pipe"?new Response(F.stderr).text():void 0,z=F.exited,[U,W,L]=await Promise.all([Y,H,z]);if(L!==0)throw Error(J??`Error caused with exit code ${L}`);return{stdout:U,stderr:W,exitCode:L}}async function j9(Z,J,Q=!1){let F=[Z,"->",J].join(" ");if(Q){if(r("platform")!=="linux"){B.warn("Sudo only support in Linux");return}await t0({cmd:["sudo","ln","-s",Z,J],errMsg:`Failed create symlink ${F}`})}else await Z1.symlink(Z,J);B.success(`Succesfully create symlink ${F}`)}async function N9(Z,J=!1){let Q=Z;if(J){if(r("platform")!=="linux"){B.warn("Sudo only support in Linux");return}await t0({cmd:["sudo","rm",Z],errMsg:`Failed remove symlink ${Q}`})}else await Z1.unlink(Z);B.success(`Succesfully remove symlink ${Q}`)}async function J1(Z){try{return await Z1.lstat(Z)}catch(J){return null}}async function V9(Z){if(!Z)return;let J=r("settings")?.backup??"",{added:Q=[],removed:F=[]}=Z,Y=[],H=[];try{let z=(await Promise.allSettled(F.map(async(W)=>{let L=await J1(W.target);if(!L){B.warn(`Target doesn't exist: ${W.target}, did you remove it manually?`),H.push(W);return}if(!L.isSymbolicLink()){B.warn(`File ${W.target} not a symlink, did you remove it manually?`),H.push(W);return}await N9(W.target,W.sudo),H.push(W)}))).filter((W)=>W.status==="rejected"),U=(await Promise.allSettled(Q.map(async(W)=>{if(await J1(W.target))if(J)await j6.rename(W.target,W.target+".bak");else{B.error(`Target already exists, skip create: ${W.target}`);return}await j9(W.source,W.target,W.sudo),Y.push(W)}))).filter((W)=>W.status==="rejected");for(let W of U)console.error(`Failed to add symlink: ${w9(W)}`);for(let W of z)console.error(`Failed to remove symlink: ${w9(W)}`);if(U.length>0||z.length>0)B.error(" [FATAL] Failed to apply symlinks"),process.exitCode=1}catch(z){console.error(z),B.error(" [FATAL] Failed to apply symlinks"),process.exitCode=1}finally{let W=((D0()??{}).symlinks??[]).filter((L)=>!H.some((K)=>N6(K,L))).concat(Y);B.info(`Updated symlinks state: ${W.length}`),L9("symlinks",W)}}function w9(Z){if(Z instanceof Error)return`[${"code"in Z?String(Z.code):"ERROR"}] ${Z.message}`;return`[ERROR] ${String(Z)}`}async function B9(Z){let J=w6.join(Z,"config.toml");y("configDir",Z),await K9(Z),V0("Switching configuration"),B.info("Scanning system environment..."),await P0();let Q=await A0(J);y("settings",H0(Q.settings,{backup:!0}));let F=G9(Q);B0((()=>{let z=["SYMLINKS"],U=F.symlinks,{added:W=[],removed:L=[]}=U;if(W?.length===0&&L?.length===0)return z.push(" - No changes to apply with symlinks"),z.join(`
|
|
55
|
+
`)),T(),K()};return{start:W0,stop:(q="")=>e(q,0),message:(q="")=>{j=m(q??j)},cancel:(q="")=>e(q,1),error:(q="")=>e(q,2),clear:()=>e("",0,!0),get isCancelled(){return N}}},W7={light:V("\u2500","-"),heavy:V("\u2501","="),block:V("\u2588","#")};var z7=[`${G("dim","\u2191/\u2193")} to navigate`,`${G("dim","Enter:")} confirm`];var U7=`${G("gray",C)} `;var{$:a0}=globalThis.Bun;var p8={pacman:["arch","endeavouros","manjaro","garuda","cachyos","arcolinux","rebornos","blendos","steamos","chimeraos"],dnf:["fedora","nobara","bazzite","ultramarine"]},Z9=(Z)=>{for(let[J,Q]of Object.entries(p8))if(Q.includes(Z))return J;return null};var J9={osName:void 0,osId:void 0,platform:"linux",packageManager:void 0,helperAur:null,isFlatpak:!1,flatpak:!1};function o(Z){return J9[Z]}function g(Z,J){J9[Z]=J}async function e0(Z){try{return await a0`which ${Z}`.quiet(),!0}catch{return!1}}async function g8(){let Z=[];if(await e0("yay"))Z.push("yay");if(await e0("paru"))Z.push("paru");return Z}async function l8(){if(process.platform==="linux"){let Z=await a0`cat /etc/os-release | grep ^NAME`.quiet().text()||"",J=await a0`cat /etc/os-release | grep ^ID`.quiet().text()||"",Q=Z.trim().slice(5).replace(/"/g,"");return{id:J.trim().slice(3).replace(/"/g,""),name:Q}}return{id:"unknown",name:"unknown"}}async function C0(){let{name:Z="",id:J=""}=await l8(),Q=Z9(J),F=Q==="pacman"?await g8():null,Y=await e0("flatpak");if(g("osName",Z),g("osId",J),g("flatpak",Y),F)g("helperAur",F[0]);if(Q)g("packageManager",Q);return{osName:Z,osId:J,packageManager:Q,aurHelper:F,flatpak:Y}}async function Q9(){P0("\uD83D\uDD0D Scanning system");let Z=b0();Z.start("Detecting environment...");let J=await C0();return Z.stop("Environment detected"),O0([`OS ${J.osName} (${J.osId})`,`Package Manager ${J.packageManager}`,J.aurHelper?`AUR Helper ${J.aurHelper}`:null,`Flatpak ${J.flatpak?"Enabled":"Disabled"}`].filter(Boolean).join(`
|
|
56
|
+
`),"System Environment",{withGuide:!0}),t1("Scan completed"),J}import F9 from"path";import{homedir as c8}from"os";function R0(Z){if(Z.startsWith("~"))return F9.join(c8(),Z.slice(1));return F9.resolve(Z)}var m8=f0(u({flatpak:t(),backup:t(),aur_helper:J0(["yay","paru"])})),u8=u({source:S(),target:S(),sudo:Z0(t())}),r8=J0(["aur","pacman"]),o8=Q0([S(),$(S()),$($(S()))]),n8=u({name:S(),post_hooks:Z0(o8)}),Y9=$(Q0([S(),n8])),i8=u({manager:r8,items:Y9}),d8=u({manager:_0("flatpak"),scope:J0(["system","user"]),items:Y9}),A0=f0(u({imports:$(S()),settings:m8,packages:$(Q0([d8,i8])),symlinks:$(u8)}));import D0 from"path";var n={defaultMerge:Symbol("deepmerge-ts: default merge"),skip:Symbol("deepmerge-ts: skip")},C7={defaultMerge:n.defaultMerge};function s8(Z,J){return J}function a8(Z,J){return Z.filter((Q)=>Q!==void 0)}var H9;(function(Z){Z[Z.NOT=0]="NOT",Z[Z.RECORD=1]="RECORD",Z[Z.ARRAY=2]="ARRAY",Z[Z.SET=3]="SET",Z[Z.MAP=4]="MAP",Z[Z.OTHER=5]="OTHER"})(H9||(H9={}));function W9(Z){if(typeof Z!=="object"||Z===null)return 0;if(Array.isArray(Z))return 2;if(Z6(Z))return 1;if(Z instanceof Set)return 3;if(Z instanceof Map)return 4;return 5}function e8(Z){let J=new Set;for(let Q of Z)for(let F of[...Object.keys(Q),...Object.getOwnPropertySymbols(Q)])J.add(F);return J}function t8(Z,J){return typeof Z==="object"&&Object.prototype.propertyIsEnumerable.call(Z,J)}function U9(Z){let J=0,Q=Z[0]?.[Symbol.iterator]();return{[Symbol.iterator](){return{next(){do{if(Q===void 0)return{done:!0,value:void 0};let F=Q.next();if(F.done===!0){J+=1,Q=Z[J]?.[Symbol.iterator]();continue}return{done:!1,value:F.value}}while(!0)}}}}}var z9=["[object Object]","[object Module]"];function Z6(Z){if(!z9.includes(Object.prototype.toString.call(Z)))return!1;let{constructor:J}=Z;if(J===void 0)return!0;let Q=J.prototype;if(Q===null||typeof Q!=="object"||!z9.includes(Object.prototype.toString.call(Q)))return!1;if(!Q.hasOwnProperty("isPrototypeOf"))return!1;return!0}function J6(Z,J,Q){let F={};for(let Y of e8(Z)){let H=[];for(let W of Z)if(t8(W,Y))H.push(W[Y]);if(H.length===0)continue;let z=J.metaDataUpdater(Q,{key:Y,parents:Z}),U=L9(H,J,z);if(U===n.skip)continue;if(Y==="__proto__")Object.defineProperty(F,Y,{value:U,configurable:!0,enumerable:!0,writable:!0});else F[Y]=U}return F}function Q6(Z){return Z.flat()}function F6(Z){return new Set(U9(Z))}function Y6(Z){return new Map(U9(Z))}function H6(Z){return Z.at(-1)}var E0={mergeRecords:J6,mergeArrays:Q6,mergeSets:F6,mergeMaps:Y6,mergeOthers:H6};function H0(...Z){return W6({})(...Z)}function W6(Z,J){let Q=z6(Z,F);function F(...Y){return L9(Y,Q,J)}return F}function z6(Z,J){return{defaultMergeFunctions:E0,mergeFunctions:{...E0,...Object.fromEntries(Object.entries(Z).filter(([Q,F])=>Object.hasOwn(E0,Q)).map(([Q,F])=>F===!1?[Q,E0.mergeOthers]:[Q,F]))},metaDataUpdater:Z.metaDataUpdater??s8,deepmerge:J,useImplicitDefaultMerging:Z.enableImplicitDefaultMerging??!1,filterValues:Z.filterValues===!1?void 0:Z.filterValues??a8,actions:n}}function L9(Z,J,Q){let F=J.filterValues?.(Z,Q)??Z;if(F.length===0)return;if(F.length===1)return t0(F,J,Q);let Y=W9(F[0]);if(Y!==0&&Y!==5)for(let H=1;H<F.length;H++){if(W9(F[H])===Y)continue;return t0(F,J,Q)}switch(Y){case 1:return U6(F,J,Q);case 2:return L6(F,J,Q);case 3:return K6(F,J,Q);case 4:return X6(F,J,Q);default:return t0(F,J,Q)}}function U6(Z,J,Q){let F=J.mergeFunctions.mergeRecords(Z,J,Q);if(F===n.defaultMerge||J.useImplicitDefaultMerging&&F===void 0&&J.mergeFunctions.mergeRecords!==J.defaultMergeFunctions.mergeRecords)return J.defaultMergeFunctions.mergeRecords(Z,J,Q);return F}function L6(Z,J,Q){let F=J.mergeFunctions.mergeArrays(Z,J,Q);if(F===n.defaultMerge||J.useImplicitDefaultMerging&&F===void 0&&J.mergeFunctions.mergeArrays!==J.defaultMergeFunctions.mergeArrays)return J.defaultMergeFunctions.mergeArrays(Z);return F}function K6(Z,J,Q){let F=J.mergeFunctions.mergeSets(Z,J,Q);if(F===n.defaultMerge||J.useImplicitDefaultMerging&&F===void 0&&J.mergeFunctions.mergeSets!==J.defaultMergeFunctions.mergeSets)return J.defaultMergeFunctions.mergeSets(Z);return F}function X6(Z,J,Q){let F=J.mergeFunctions.mergeMaps(Z,J,Q);if(F===n.defaultMerge||J.useImplicitDefaultMerging&&F===void 0&&J.mergeFunctions.mergeMaps!==J.defaultMergeFunctions.mergeMaps)return J.defaultMergeFunctions.mergeMaps(Z);return F}function t0(Z,J,Q){let F=J.mergeFunctions.mergeOthers(Z,J,Q);if(F===n.defaultMerge||J.useImplicitDefaultMerging&&F===void 0&&J.mergeFunctions.mergeOthers!==J.defaultMergeFunctions.mergeOthers)return J.defaultMergeFunctions.mergeOthers(Z);return F}async function Z1(Z,J=new Set){let Q=D0.resolve(Z);if(J.has(Q))throw Error(`Circular dependency detected: ${Q}`);J.add(Q);let F=await Bun.file(Q).text(),Y=Bun.TOML.parse(F),H=X0(A0,Y),{imports:z=[],symlinks:U=[]}=H;delete H.imports;let W=D0.dirname(Q);H.symlinks=M6(W,U);let L={};for(let K of z){let X=D0.resolve(W,K),M=await Z1(X,J);L=H0(L,M)}return H0(H,L)}function M6(Z,J){if(!J||J.length===0)return[];let Q=[];for(let F of J){if(!F)continue;let{source:Y,target:H}=F,z=D0.resolve(Z,Y),U=R0(H);Q.push({source:z,target:U})}return Q}async function I0(Z){let J=R0(Z);B.step("Validating Configuration");let Q=b0();Q.start("Validating...");let F=await Z1(J),Y=X0(A0,F);return Q.stop("Successfully validated with no errors!"),Y}import w6 from"path";var{deepEquals:G9}=globalThis.Bun;import J1 from"path";import Q1 from"fs/promises";var x0={};function T0(){return x0}function K9(Z,J){x0[Z]=J}async function X9(Z){let J=Z??o("configDir"),Q=J1.resolve(J||".",".state/hofii-lock.json");if(await Q1.exists(Q)){let F=await Bun.file(Q).json();Object.assign(x0,F.config)}}async function M9(){let Z=J1.resolve(o("configDir")||".",".state");if(!await Q1.exists(Z))await Q1.mkdir(Z,{recursive:!0});let J={config:x0};await Bun.write(J1.resolve(Z,"hofii-lock.json"),JSON.stringify(J,null,2))}function G6(Z,J){let Q=J?.filter((Y)=>!Z?.some((H)=>G9(Y,H,!0))),F=Z?.filter((Y)=>!J?.some((H)=>G9(Y,H,!0)));return{added:Q,removed:F}}function j9(Z){let J=T0();return{symlinks:G6(J.symlinks,Z.symlinks)}}import j6 from"fs/promises";var{deepEquals:N6}=globalThis.Bun;import Y1 from"fs/promises";async function F1({cmd:Z,errMsg:J,opt:Q={stdin:"inherit",stdout:"inherit",stderr:"inherit"}}){let F=Bun.spawn(Z,{stdin:Q.stdin,stdout:Q.stdout,stderr:Q.stderr}),Y=Q.stdout==="pipe"?new Response(F.stdout).text():void 0,H=Q.stderr==="pipe"?new Response(F.stderr).text():void 0,z=F.exited,[U,W,L]=await Promise.all([Y,H,z]);if(L!==0)throw Error(J??`Error caused with exit code ${L}`);return{stdout:U,stderr:W,exitCode:L}}async function N9(Z,J,Q=!1){let F=[Z,"->",J].join(" ");if(Q){if(o("platform")!=="linux"){B.warn("Sudo only support in Linux");return}await F1({cmd:["sudo","ln","-s",Z,J],errMsg:`Failed create symlink ${F}`})}else await Y1.symlink(Z,J);B.success(`Succesfully create symlink ${F}`)}async function w9(Z,J=!1){let Q=Z;if(J){if(o("platform")!=="linux"){B.warn("Sudo only support in Linux");return}await F1({cmd:["sudo","rm",Z],errMsg:`Failed remove symlink ${Q}`})}else await Y1.unlink(Z);B.success(`Succesfully remove symlink ${Q}`)}async function H1(Z){try{return await Y1.lstat(Z)}catch(J){return null}}async function B9(Z){if(!Z)return;let J=o("settings")?.backup??"",{added:Q=[],removed:F=[]}=Z,Y=[],H=[];try{let z=(await Promise.allSettled(F.map(async(W)=>{let L=await H1(W.target);if(!L){B.warn(`Target doesn't exist: ${W.target}, did you remove it manually?`),H.push(W);return}if(!L.isSymbolicLink()){B.warn(`File ${W.target} not a symlink, did you remove it manually?`),H.push(W);return}await w9(W.target,W.sudo),H.push(W)}))).filter((W)=>W.status==="rejected"),U=(await Promise.allSettled(Q.map(async(W)=>{if(await H1(W.target))if(J)await j6.rename(W.target,W.target+".bak");else{B.error(`Target already exists, skip create: ${W.target}`);return}await N9(W.source,W.target,W.sudo),Y.push(W)}))).filter((W)=>W.status==="rejected");for(let W of U)console.error(`Failed to add symlink: ${V9(W)}`);for(let W of z)console.error(`Failed to remove symlink: ${V9(W)}`);if(U.length>0||z.length>0)B.error(" [FATAL] Failed to apply symlinks"),process.exitCode=1}catch(z){console.error(z),B.error(" [FATAL] Failed to apply symlinks"),process.exitCode=1}finally{let W=((T0()??{}).symlinks??[]).filter((L)=>!H.some((K)=>N6(K,L))).concat(Y);B.info(`Updated symlinks state: ${W.length}`),K9("symlinks",W)}}function V9(Z){if(Z instanceof Error)return`[${"code"in Z?String(Z.code):"ERROR"}] ${Z.message}`;return`[ERROR] ${String(Z)}`}async function q9(Z){let J=w6.join(Z,"config.toml");g("configDir",Z),await X9(Z),P0("Switching configuration"),B.info("Scanning system environment..."),await C0();let Q=await I0(J);g("settings",H0(Q.settings,{backup:!0}));let F=j9(Q);O0((()=>{let z=["SYMLINKS"],U=F.symlinks,{added:W=[],removed:L=[]}=U;if(W?.length===0&&L?.length===0)return z.push(" - No changes to apply with symlinks"),z.join(`
|
|
57
57
|
`);for(let K of W)z.push(` - [ADDED] ${K.sudo?"(sudo) ":""}${K.source} -> ${K.target}`);for(let K of L)z.push(` - [REMOVED] ${K.sudo?"(sudo) ":""}${K.source} -> ${K.target}`);return z.join(`
|
|
58
|
-
`)})(),"Config To Apply");let H=await
|
|
58
|
+
`)})(),"Config To Apply");let H=await e1({message:"Apply config changes? (Please review the changes first!!)"});if(!H||V0(H))B.warn("Config changes not applied."),process.exit(0);await B9(F.symlinks)}var a=j1("hofii");a.version("0.0.1");a.command("scan","Detect system environment").alias("s").action(async()=>{await Q9()});a.command("validate [dir]","Validate configuration files").alias("v").action(async(Z)=>{await I0(Z)});a.command("switch [dir]","Switch to new configuration").alias("sw").action(async(Z)=>{let J=V6.resolve(Z);await q9(J)});try{a.help().parse(process.argv,{run:!1}),await a.runMatchedCommand()}catch(Z){if(Z instanceof v0){let J=Z.issues.map((Q)=>{let F=Q.path.at(-1)?.input;return[`\u2717 ${Q.message}`,` at: ${JSON.stringify(F)}`].join(`
|
|
59
|
+
`)}).join(`
|
|
60
|
+
|
|
61
|
+
`);console.error(J)}process.exit(1)}finally{await M9()}
|
package/package.json
CHANGED