@r5n/atlas 0.7.2 → 0.7.4
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/cli.js +41 -41
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
-
import{join as Yu}from"path";class J extends Error{_tag="Cancel";constructor(t="Operation cancelled"){super(t)}}function K(t){return t}function Ee(t){return t==null?[]:Array.isArray(t)?t:[t]}function zi(t,e,n,r){var i,s=t[e],o=~r.string.indexOf(e)?n==null||n===!0?"":String(n):typeof n==="boolean"?n:~r.boolean.indexOf(e)?n==="false"?!1:n==="true"||(t._.push((i=+n,i*0===0)?i:n),!!n):(i=+n,i*0===0)?i:n;t[e]=s==null?o:Array.isArray(s)?s.concat(o):[s,o]}function Te(t,e){t=t||[],e=e||{};var n,r,i,s,o,a={_:[]},u=0,c=0,l=0,d=t.length;let p=e.alias!==void 0,m=e.unknown!==void 0,f=e.default!==void 0;if(e.alias=e.alias||{},e.string=Ee(e.string),e.boolean=Ee(e.boolean),p)for(n in e.alias){r=e.alias[n]=Ee(e.alias[n]);for(u=0;u<r.length;u++)(e.alias[r[u]]=r.concat(n)).splice(u,1)}for(u=e.boolean.length;u-- >0;){r=e.alias[e.boolean[u]]||[];for(c=r.length;c-- >0;)e.boolean.push(r[c])}for(u=e.string.length;u-- >0;){r=e.alias[e.string[u]]||[];for(c=r.length;c-- >0;)e.string.push(r[c])}if(f){for(n in e.default)if(s=typeof e.default[n],r=e.alias[n]=e.alias[n]||[],e[s]!==void 0){e[s].push(n);for(u=0;u<r.length;u++)e[s].push(r[u])}}let h=m?Object.keys(e.alias):[];for(u=0;u<d;u++){if(i=t[u],i==="--"){a._=a._.concat(t.slice(++u));break}for(c=0;c<i.length;c++)if(i.charCodeAt(c)!==45)break;if(c===0)a._.push(i);else if(i.substring(c,c+3)==="no-"){if(s=i.substring(c+3),m&&!~h.indexOf(s))return e.unknown(i);a[s]=!1}else{for(l=c+1;l<i.length;l++)if(i.charCodeAt(l)===61)break;s=i.substring(c,l),o=i.substring(++l)||(u+1===d||(""+t[u+1]).charCodeAt(0)===45||t[++u]),r=c===2?[s]:s;for(l=0;l<r.length;l++){if(s=r[l],m&&!~h.indexOf(s))return e.unknown("-".repeat(c)+s);zi(a,s,l+1<r.length||o,e)}}}if(f){for(n in e.default)if(a[n]===void 0)a[n]=e.default[n]}if(p)for(n in a){r=e.alias[n]||[];while(r.length>0)a[r.shift()]=a[n]}return a}var j=0,vt=1,Tn=2,_n=255;function kt(t){return Number.isInteger(t)&&t>=0&&t<=255}class w extends Error{hint;exitCode;_tag;constructor(t,e,n=1,r={}){super(t,"cause"in r?{cause:r.cause}:void 0);this.hint=e;this.exitCode=n;this._tag=r.tag??"Exit"}}class S extends w{constructor(t,e,n={}){super(t,e,2,{...n,tag:n.tag??"UsageError"})}}var In=1,Qi=2,jt="--",An="-",rt="no-",Zi=new Set(["false","true"]),St=/^--([^=]+)(?:=(.*))?$/s,Et=/^-([^-=][^=]*)(?:=(.*))?$/s,Ie=/^(?:---|-no-|-_|-[^-=][^=]*_)/,ts="_",Ct="\x00";function H(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function mt(t){let e={alias:{},boolean:[],default:{},string:[]};for(let[n,r]of Object.entries(t)){if(r.type==="boolean")e.boolean.push(n);else e.string.push(n);if(r.alias)e.alias[r.alias]=n;let i=H(n);if(i!==n)e.alias[i]=n;if(r.default!==void 0)e.default[n]=r.default}return e}function Nt(t,e){let n={};for(let[o,a]of Object.entries(e.alias))n[a]=[...n[a]??[],o];let{_:r,...i}=Te(Vt(t,es),{alias:n,boolean:[...e.boolean],default:{...e.default},string:[...e.string]}),s=Object.entries(i).map(([o,a])=>[_e(o),_e(a)]);return{...Object.fromEntries(s),_:r.map(_e)}}function es(t){if(t===An)return`${Ct}${t}`;let e=St.exec(t);if(Ie.test(t)||ns(e?.[1]))return`--${Ct}${t}`;return(e?e[2]:Et.exec(t)?.[2])===""?`${t}${Ct}`:t}function ns(t){if(t===void 0)return!1;let e=t.startsWith(rt)?t.slice(rt.length):t;return e===ts||e in Object.prototype}function _e(t){return typeof t==="string"&&t.startsWith(Ct)?t.slice(Ct.length):t}function xt(t,e){return Object.hasOwn(e.alias,t)?e.alias[t]??t:t}function pt(t,e){if(Object.hasOwn(e,t))return`--${H(t)}`;let n=Object.entries(e).find(([,r])=>r.alias===t)?.[0];if(n)return`--${H(n)}`;return t.length===In?`-${t}`:`--${t}`}function Ft(t,e,n,r){let{alias:i}=mt(e),s=Object.keys(t).find((o)=>!Object.hasOwn(e,o)&&!Object.hasOwn(i,o));if(s!==void 0)throw new S(`Unknown option: ${rs(s,r)}`,n)}function rs(t,e){if(t.startsWith("-"))return t;let n=e.indexOf(jt);for(let r of n<0?e:e.slice(0,n)){let i=St.exec(r)?.[1];if(i===t||r===`--${rt}${t}`)return`--${i}`;if(i===void 0&&Et.exec(r)?.[1]?.includes(t))return`-${t}`}return pt(t,{})}function Rn(t,e){for(let[r,i]of Object.entries(t))if(Array.isArray(i))throw new S(`${pt(r,e)} can only be provided once`);let n={...t};for(let[r,i]of Object.entries(e)){let s=t[r];if(s===void 0)continue;if(i.type==="string"&&typeof s==="boolean")throw Pn(pt(r,e));if(i.type!=="number")continue;let o=Number(s);if(typeof s==="boolean"||typeof s==="string"&&s.trim().length===0||!Number.isFinite(o)){let a=pt(r,e);throw new S(`Invalid number for ${a}: "${s}"`,`Use ${a}=<number> with a finite numeric value`)}n[r]=o}return n}function Pn(t){return new S(`${t} needs a value`,`Use ${t}=<value>`)}function Mt(t,e){let n=mt(e),r=Re([...t],n),i=Nt(r,n)._[0],s=i===void 0?-1:r.indexOf(i);return{before:s>=0?t.slice(0,s):[...t],command:i,restArgs:s>=0?t.slice(s+1):[]}}function Dn(t,e){let n=mt(e);for(let r=0;r<t.length;r+=1){let i=t[r]??"";if(i===jt)return-1;if(i===An||!i.startsWith("-"))return r;if(is(i,n,e))r+=1}return-1}function is(t,e,n){if(t.startsWith(`--${rt}`))return!1;let r=St.exec(t),i=r??Et.exec(t);if(!i||i[2]!==void 0)return!1;let s=r?i[1]??"":i[1]?.at(-1)??"",o=n[xt(s,e)]?.type;return o==="string"||o==="number"}function Ae(t,e,n=e){let r=mt(e),{before:i,command:s,restArgs:o}=Mt(t,e),a=mt(n);Oe(i,r,e,!0),Oe(t,a,n,!0);let{_:u,...c}=Nt(Ln(i,r,e),r);Ft(c,e,"Place command options after the command name",i);let{_:l,...d}=Nt(Re(o,a),a),p=Rn({...On(c,e,r),...On(d,n,a)},e);return{command:s,flags:p,restArgs:o}}function On(t,e,n){return Object.fromEntries(Object.entries(t).filter(([r])=>Object.hasOwn(e,r)||Object.hasOwn(n.alias,r)))}function Ut(t,e){return Object.fromEntries(Object.keys(e).flatMap((n)=>{let r=t[n];return r===void 0?[]:[[n,r]]}))}function Tt(t,e={}){let n=mt(e),r=ss(t,n);Oe(r,n,e);let i=Nt(Ln(r,n,e),n),{_:s,...o}=i;return{args:Rn(o,e),rawPositionals:s.map(String)}}function Oe(t,e,n,r=!1){let i=new Set;for(let s of t){if(s===jt)break;let o=s.match(/^-+/)?.[0];if(!o||Ie.test(s))continue;let a=s.slice(o.length),u=a.split("=",In)[0]??"",c=a.startsWith(rt)?[a.slice(rt.length)]:o.length===Qi?[u]:[...u];for(let l of c){let d=xt(l,e);if(r&&!Object.hasOwn(n,d))continue;if(i.has(d))throw new S(`${pt(d,n)} can only be provided once`);i.add(d)}}}function Vt(t,e){let n=t.indexOf(jt);return t.map((r,i)=>n>=0&&i>=n?r:e(r,t[i+1]))}function Re(t,e){return Vt(t,(n)=>{let r=St.exec(n)??Et.exec(n);if(!r||r[2]!==void 0||n.startsWith(`--${rt}`))return n;let i=n.startsWith("--")?r[1]??"":r[1]?.at(-1)??"";return e.boolean.includes(xt(i,e))?`${n}=true`:n})}function Ln(t,e,n){let r=(o)=>n[xt(o,e)]?.type,i=(o)=>o!==void 0&&!o.startsWith("-"),s=Vt(t,(o,a)=>{let u=St.exec(o),c=u?null:Et.exec(o);if(o.startsWith(`--${rt}`)||Ie.test(o))return o;let l=u?[u[1]??""]:[...c?.[1]??""],d=u?u[2]:c?.[2];for(let[p,m]of l.entries()){let f=r(m),h=p===l.length-1,C=pt(xt(m,e),n),_=!h||d===void 0&&!i(a);if(f==="string"&&(_||d===""))throw Pn(C);if(f==="number"&&_)throw new S(`${C} needs a value`,`Use ${C}=<number>`);if(f==="boolean"&&h&&d!==void 0&&!Zi.has(d))throw new S(`Invalid value for ${C}: "${d}"`,`Use ${C}=true or ${C}=false`)}return o});return Re(s,e)}function ss(t,e){return Vt(t,(n)=>n.replace(/^--(no-[^=]+)(=.*)?$/,(r,i,s)=>{let o=e.alias[i];return o&&e.boolean.includes(o)?`--${o}${s??""}`:r}))}function Gt(t,e){let n={},r=Object.entries(e);for(let[i,[s,o]]of r.entries())n[s]=o.variadic?t.slice(i):t[i];return n}function Wt(t,e){for(let[n,r]of Object.entries(e)){if(!r.required)continue;let i=t[n];if(Array.isArray(i)?i.length===0:!i)return`Missing required argument: <${n}${r.variadic?"...":""}>`}return null}function kn(t,e){let n=Object.values(e);if(n.some((r)=>r.variadic))return;return t[n.length]}var os=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,as=new Set(["help","json"]),us=/^[a-zA-Z0-9]$/,cs=new Set(["h","j"]);function Bt(){return(t)=>{let e={args:t.args??{},description:t.description,examples:t.examples??[],json:t.json??!1,name:t.name,passthrough:t.passthrough??!1,positionals:t.positionals??{},prompts:t.prompts??!1,run:t.run,strict:t.strict??!0,subcommands:t.subcommands??[]};return ls(e),Object.freeze(e)}}function Jt(t,e){let n=Pe(e.map((r)=>r.name));if(n!==void 0)throw Error(`${t} has more than one command named "${n}"`)}function ls(t){let e=`Command "${t.name}"`;if(!os.test(t.name))throw Error(`${e} must be named with a lower-case word such as "list" or "dry-run"`);if(!t.run&&t.subcommands.length===0)throw Error(`${e} needs run or subcommands`);for(let[l,d]of Object.entries(t.args)){if(as.has(H(l)))throw Error(`${e} cannot define the option "${l}": --${H(l)} is a global flag`);if(d.alias!==void 0&&cs.has(d.alias))throw Error(`${e} cannot give "${l}" the alias -${d.alias}: it belongs to a global flag`)}let n=Object.keys(t.args).map(H),r=Pe(n);if(r!==void 0)throw Error(`${e} has more than one option named --${r}`);let i=Object.values(t.args).flatMap((l)=>l.alias??[]),s=i.find((l)=>!us.test(l));if(s!==void 0)throw Error(`${e} uses the alias "${s}": an alias is one letter or digit`);let o=i.find((l)=>n.includes(l));if(o!==void 0)throw Error(`${e} uses the alias -${o}, which is also an option's name`);let a=Pe(i);if(a!==void 0)throw Error(`${e} uses the alias -${a} more than once`);let u=Object.keys(t.positionals),c=u.find((l)=>t.positionals[l]?.variadic);if(c!==void 0&&c!==u.at(-1))throw Error(`${e} declares the variadic positional "${c}" before other positionals`);if(t.passthrough&&(!t.run||c===void 0))throw Error(`${e} uses passthrough, which needs run and a variadic last positional`);Jt(e,t.subcommands)}function Pe(t){return t.find((e,n)=>t.indexOf(e)!==n)}function ht(t){return t}import{Console as ws}from"console";import{Writable as vs}from"stream";import{format as Cs,stripVTControlCharacters as xs}from"util";var it={active:!1};var ds=new Set(["0","false"]);function Ht(t){if(process.env.NO_COLOR)return!1;let e=process.env.FORCE_COLOR;if(e!==void 0)return!ds.has(e);return t?.isTTY===!0}var fs=Ht(process.stdout),Fn=["black","blue","cyan","gray","green","magenta","red","white","yellow"],ps=["bold","dim","italic","underline","reset"],Mn={bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",reset:"\x1B[0m",underline:"\x1B[4m"},ms={black:"\x1B[30m",blue:"\x1B[34m",cyan:"\x1B[36m",gray:"\x1B[90m",green:"\x1B[32m",magenta:"\x1B[35m",red:"\x1B[31m",white:"\x1B[37m",yellow:"\x1B[33m"},hs={black:"\x1B[40m",blue:"\x1B[44m",cyan:"\x1B[46m",gray:"\x1B[100m",green:"\x1B[42m",magenta:"\x1B[45m",red:"\x1B[41m",white:"\x1B[47m",yellow:"\x1B[43m"},Nn={"\x1B[30m":"\x1B[90m","\x1B[31m":"\x1B[91m","\x1B[32m":"\x1B[92m","\x1B[33m":"\x1B[93m","\x1B[34m":"\x1B[94m","\x1B[35m":"\x1B[95m","\x1B[36m":"\x1B[96m","\x1B[37m":"\x1B[97m"};function Kt(t){return(e)=>fs&&!it.active?`${t}${e}${Mn.reset}`:e}function gs(t){for(let e=0;e<t.length;e++){let n=t.charCodeAt(e);if(n<32&&n!==27)return!1}return!0}function jn({bright:t=!1,color:e}){let n=Bun.color(e,"ansi"),r=typeof n==="string"&&n.length>0&&gs(n)?n:ms[e];if(!r)return"";return t&&r in Nn?Nn[r]:r}var ys=Fn.reduce((t,e)=>{let n=jn({color:e});if(n)t[e]=Kt(n);let r=jn({bright:!0,color:e});if(r)t[`${e}Bright`]=Kt(r);return t},{}),$s=ps.reduce((t,e)=>(t[e]=Kt(Mn[e]),t),{}),bs=Fn.reduce((t,e)=>{let n=hs[e];if(n){let r=`bg${e.charAt(0).toUpperCase()}${e.slice(1)}`;t[r]=Kt(n)}return t},{}),y={...ys,...$s,...bs};var Ss=2,Gn=["clear","count","countReset","debug","dir","dirxml","group","groupCollapsed","groupEnd","info","log","table"],Es=[...Gn,"trace","write"],Ts=1,_s="EPIPE",Os="EIO",A={closedStreams:new Set,documentWritten:!1,jsonRuns:0,outputGuarded:!1,restoreStdout:void 0,sealed:!1,stdoutClosed:!1,stdoutWrite:void 0};function _t(){return process.stdin.isTTY===!0&&process.stdout.isTTY===!0}function De(t){return _t()&&!it.active&&t?.json!==!0}function Wn(){return it.active}function st(t){let e=JSON.stringify(t??null,null,Ss);if(e===void 0)throw TypeError("JSON cannot represent the value");return`${e}
|
|
4
|
-
`}function
|
|
5
|
-
`).slice(
|
|
6
|
-
`))};return e}function
|
|
7
|
-
`),l=!1;for(let d=0;d<c.length;d++){let p=c[d];if(r+=p,!l){if(l=p>="\uD800"&&p<="\uDBFF",l)continue}else l=!1;if(p===
|
|
8
|
-
`){if(s)r+=
|
|
9
|
-
`){if(i&&
|
|
10
|
-
`)}var X={to(t,e){if(!e)return`\x1B[${t+1}G`;return`\x1B[${e+1};${t+1}H`},move(t,e){let n="";if(t<0)n+=`\x1B[${-t}D`;else if(t>0)n+=`\x1B[${t}C`;if(e<0)n+=`\x1B[${-e}A`;else if(e>0)n+=`\x1B[${e}B`;return n},up:(t=1)=>`\x1B[${t}A`,down:(t=1)=>`\x1B[${t}B`,forward:(t=1)=>`\x1B[${t}C`,backward:(t=1)=>`\x1B[${t}D`,nextLine:(t=1)=>"\x1B[E".repeat(t),prevLine:(t=1)=>"\x1B[F".repeat(t),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"};var
|
|
3
|
+
import{join as ac}from"path";class J extends Error{_tag="Cancel";constructor(t="Operation cancelled"){super(t)}}function K(t){return t}function Oe(t){return t==null?[]:Array.isArray(t)?t:[t]}function ts(t,e,n,r){var i,s=t[e],o=~r.string.indexOf(e)?n==null||n===!0?"":String(n):typeof n==="boolean"?n:~r.boolean.indexOf(e)?n==="false"?!1:n==="true"||(t._.push((i=+n,i*0===0)?i:n),!!n):(i=+n,i*0===0)?i:n;t[e]=s==null?o:Array.isArray(s)?s.concat(o):[s,o]}function Ie(t,e){t=t||[],e=e||{};var n,r,i,s,o,a={_:[]},u=0,c=0,l=0,d=t.length;let p=e.alias!==void 0,m=e.unknown!==void 0,f=e.default!==void 0;if(e.alias=e.alias||{},e.string=Oe(e.string),e.boolean=Oe(e.boolean),p)for(n in e.alias){r=e.alias[n]=Oe(e.alias[n]);for(u=0;u<r.length;u++)(e.alias[r[u]]=r.concat(n)).splice(u,1)}for(u=e.boolean.length;u-- >0;){r=e.alias[e.boolean[u]]||[];for(c=r.length;c-- >0;)e.boolean.push(r[c])}for(u=e.string.length;u-- >0;){r=e.alias[e.string[u]]||[];for(c=r.length;c-- >0;)e.string.push(r[c])}if(f){for(n in e.default)if(s=typeof e.default[n],r=e.alias[n]=e.alias[n]||[],e[s]!==void 0){e[s].push(n);for(u=0;u<r.length;u++)e[s].push(r[u])}}let h=m?Object.keys(e.alias):[];for(u=0;u<d;u++){if(i=t[u],i==="--"){a._=a._.concat(t.slice(++u));break}for(c=0;c<i.length;c++)if(i.charCodeAt(c)!==45)break;if(c===0)a._.push(i);else if(i.substring(c,c+3)==="no-"){if(s=i.substring(c+3),m&&!~h.indexOf(s))return e.unknown(i);a[s]=!1}else{for(l=c+1;l<i.length;l++)if(i.charCodeAt(l)===61)break;s=i.substring(c,l),o=i.substring(++l)||(u+1===d||(""+t[u+1]).charCodeAt(0)===45||t[++u]),r=c===2?[s]:s;for(l=0;l<r.length;l++){if(s=r[l],m&&!~h.indexOf(s))return e.unknown("-".repeat(c)+s);ts(a,s,l+1<r.length||o,e)}}}if(f){for(n in e.default)if(a[n]===void 0)a[n]=e.default[n]}if(p)for(n in a){r=e.alias[n]||[];while(r.length>0)a[r.shift()]=a[n]}return a}var N=0,pt=1,On=2,In=255;function Nt(t){return Number.isInteger(t)&&t>=0&&t<=255}class w extends Error{hint;exitCode;_tag;constructor(t,e,n=1,r={}){super(t,"cause"in r?{cause:r.cause}:void 0);this.hint=e;this.exitCode=n;this._tag=r.tag??"Exit"}}class S extends w{constructor(t,e,n={}){super(t,e,2,{...n,tag:n.tag??"UsageError"})}}var Rn=1,es=2,Mt="--",Pn="-",nt="no-",ns=new Set(["false","true"]),Tt=/^--([^=]+)(?:=(.*))?$/s,_t=/^-([^-=][^=]*)(?:=(.*))?$/s,Pe=/^(?:---|-no-|-_|-[^-=][^=]*_)/,rs="_",St="\x00";function H(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function ht(t){let e={alias:{},boolean:[],default:{},string:[]};for(let[n,r]of Object.entries(t)){if(r.type==="boolean")e.boolean.push(n);else e.string.push(n);if(r.alias)e.alias[r.alias]=n;let i=H(n);if(i!==n)e.alias[i]=n;if(r.default!==void 0)e.default[n]=r.default}return e}function Ft(t,e){let n={};for(let[o,a]of Object.entries(e.alias))n[a]=[...n[a]??[],o];let{_:r,...i}=Ie(Wt(t,is),{alias:n,boolean:[...e.boolean],default:{...e.default},string:[...e.string]}),s=Object.entries(i).map(([o,a])=>[Ae(o),Ae(a)]);return{...Object.fromEntries(s),_:r.map(Ae)}}function is(t){if(t===Pn)return`${St}${t}`;let e=Tt.exec(t);if(Pe.test(t)||ss(e?.[1]))return`--${St}${t}`;return(e?e[2]:_t.exec(t)?.[2])===""?`${t}${St}`:t}function ss(t){if(t===void 0)return!1;let e=t.startsWith(nt)?t.slice(nt.length):t;return e===rs||e in Object.prototype}function Ae(t){return typeof t==="string"&&t.startsWith(St)?t.slice(St.length):t}function Et(t,e){return Object.hasOwn(e.alias,t)?e.alias[t]??t:t}function mt(t,e){if(Object.hasOwn(e,t))return`--${H(t)}`;let n=Object.entries(e).find(([,r])=>r.alias===t)?.[0];if(n)return`--${H(n)}`;return t.length===Rn?`-${t}`:`--${t}`}function Ut(t,e,n,r){let{alias:i}=ht(e),s=Object.keys(t).find((o)=>!Object.hasOwn(e,o)&&!Object.hasOwn(i,o));if(s!==void 0)throw new S(`Unknown option: ${os(s,r)}`,n)}function os(t,e){if(t.startsWith("-"))return t;let n=e.indexOf(Mt);for(let r of n<0?e:e.slice(0,n)){let i=Tt.exec(r)?.[1];if(i===t||r===`--${nt}${t}`)return`--${i}`;if(i===void 0&&_t.exec(r)?.[1]?.includes(t))return`-${t}`}return mt(t,{})}function Dn(t,e){for(let[r,i]of Object.entries(t))if(Array.isArray(i))throw new S(`${mt(r,e)} can only be provided once`);let n={...t};for(let[r,i]of Object.entries(e)){let s=t[r];if(s===void 0)continue;if(i.type==="string"&&typeof s==="boolean")throw Ln(mt(r,e));if(i.type!=="number")continue;let o=Number(s);if(typeof s==="boolean"||typeof s==="string"&&s.trim().length===0||!Number.isFinite(o)){let a=mt(r,e);throw new S(`Invalid number for ${a}: "${s}"`,`Use ${a}=<number> with a finite numeric value`)}n[r]=o}return n}function Ln(t){return new S(`${t} needs a value`,`Use ${t}=<value>`)}function Vt(t,e){let n=ht(e),r=Le([...t],n),i=Ft(r,n)._[0],s=i===void 0?-1:r.indexOf(i);return{before:s>=0?t.slice(0,s):[...t],command:i,restArgs:s>=0?t.slice(s+1):[]}}function kn(t,e){let n=ht(e);for(let r=0;r<t.length;r+=1){let i=t[r]??"";if(i===Mt)return-1;if(i===Pn||!i.startsWith("-"))return r;if(as(i,n,e))r+=1}return-1}function as(t,e,n){if(t.startsWith(`--${nt}`))return!1;let r=Tt.exec(t),i=r??_t.exec(t);if(!i||i[2]!==void 0)return!1;let s=r?i[1]??"":i[1]?.at(-1)??"",o=n[Et(s,e)]?.type;return o==="string"||o==="number"}function De(t,e,n=e){let r=ht(e),{before:i,command:s,restArgs:o}=Vt(t,e),a=ht(n);Re(i,r,e,!0),Re(t,a,n,!0);let{_:u,...c}=Ft(jn(i,r,e),r);Ut(c,e,"Place command options after the command name",i);let{_:l,...d}=Ft(Le(o,a),a),p=Dn({...An(c,e,r),...An(d,n,a)},e);return{command:s,flags:p,restArgs:o}}function An(t,e,n){return Object.fromEntries(Object.entries(t).filter(([r])=>Object.hasOwn(e,r)||Object.hasOwn(n.alias,r)))}function Gt(t,e){return Object.fromEntries(Object.keys(e).flatMap((n)=>{let r=t[n];return r===void 0?[]:[[n,r]]}))}function Ot(t,e={}){let n=ht(e),r=us(t,n);Re(r,n,e);let i=Ft(jn(r,n,e),n),{_:s,...o}=i;return{args:Dn(o,e),rawPositionals:s.map(String)}}function Re(t,e,n,r=!1){let i=new Set;for(let s of t){if(s===Mt)break;let o=s.match(/^-+/)?.[0];if(!o||Pe.test(s))continue;let a=s.slice(o.length),u=a.split("=",Rn)[0]??"",c=a.startsWith(nt)?[a.slice(nt.length)]:o.length===es?[u]:[...u];for(let l of c){let d=Et(l,e);if(r&&!Object.hasOwn(n,d))continue;if(i.has(d))throw new S(`${mt(d,n)} can only be provided once`);i.add(d)}}}function Wt(t,e){let n=t.indexOf(Mt);return t.map((r,i)=>n>=0&&i>=n?r:e(r,t[i+1]))}function Le(t,e){return Wt(t,(n)=>{let r=Tt.exec(n)??_t.exec(n);if(!r||r[2]!==void 0||n.startsWith(`--${nt}`))return n;let i=n.startsWith("--")?r[1]??"":r[1]?.at(-1)??"";return e.boolean.includes(Et(i,e))?`${n}=true`:n})}function jn(t,e,n){let r=(o)=>n[Et(o,e)]?.type,i=(o)=>o!==void 0&&!o.startsWith("-"),s=Wt(t,(o,a)=>{let u=Tt.exec(o),c=u?null:_t.exec(o);if(o.startsWith(`--${nt}`)||Pe.test(o))return o;let l=u?[u[1]??""]:[...c?.[1]??""],d=u?u[2]:c?.[2];for(let[p,m]of l.entries()){let f=r(m),h=p===l.length-1,C=mt(Et(m,e),n),_=!h||d===void 0&&!i(a);if(f==="string"&&(_||d===""))throw Ln(C);if(f==="number"&&_)throw new S(`${C} needs a value`,`Use ${C}=<number>`);if(f==="boolean"&&h&&d!==void 0&&!ns.has(d))throw new S(`Invalid value for ${C}: "${d}"`,`Use ${C}=true or ${C}=false`)}return o});return Le(s,e)}function us(t,e){return Wt(t,(n)=>n.replace(/^--(no-[^=]+)(=.*)?$/,(r,i,s)=>{let o=e.alias[i];return o&&e.boolean.includes(o)?`--${o}${s??""}`:r}))}function Bt(t,e){let n={},r=Object.entries(e);for(let[i,[s,o]]of r.entries())n[s]=o.variadic?t.slice(i):t[i];return n}function Jt(t,e){for(let[n,r]of Object.entries(e)){if(!r.required)continue;let i=t[n];if(Array.isArray(i)?i.length===0:!i)return`Missing required argument: <${n}${r.variadic?"...":""}>`}return null}function Nn(t,e){let n=Object.values(e);if(n.some((r)=>r.variadic))return;return t[n.length]}var cs=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,ls=new Set(["help","json"]),ds=/^[a-zA-Z0-9]$/,fs=new Set(["h","j"]);function Kt(){return(t)=>{let e={args:t.args??{},description:t.description,examples:t.examples??[],json:t.json??!1,name:t.name,passthrough:t.passthrough??!1,positionals:t.positionals??{},prompts:t.prompts??!1,run:t.run,strict:t.strict??!0,subcommands:t.subcommands??[]};return ps(e),Object.freeze(e)}}function Ht(t,e){let n=ke(e.map((r)=>r.name));if(n!==void 0)throw Error(`${t} has more than one command named "${n}"`)}function ps(t){let e=`Command "${t.name}"`;if(!cs.test(t.name))throw Error(`${e} must be named with a lower-case word such as "list" or "dry-run"`);if(!t.run&&t.subcommands.length===0)throw Error(`${e} needs run or subcommands`);for(let[l,d]of Object.entries(t.args)){if(ls.has(H(l)))throw Error(`${e} cannot define the option "${l}": --${H(l)} is a global flag`);if(d.alias!==void 0&&fs.has(d.alias))throw Error(`${e} cannot give "${l}" the alias -${d.alias}: it belongs to a global flag`)}let n=Object.keys(t.args).map(H),r=ke(n);if(r!==void 0)throw Error(`${e} has more than one option named --${r}`);let i=Object.values(t.args).flatMap((l)=>l.alias??[]),s=i.find((l)=>!ds.test(l));if(s!==void 0)throw Error(`${e} uses the alias "${s}": an alias is one letter or digit`);let o=i.find((l)=>n.includes(l));if(o!==void 0)throw Error(`${e} uses the alias -${o}, which is also an option's name`);let a=ke(i);if(a!==void 0)throw Error(`${e} uses the alias -${a} more than once`);let u=Object.keys(t.positionals),c=u.find((l)=>t.positionals[l]?.variadic);if(c!==void 0&&c!==u.at(-1))throw Error(`${e} declares the variadic positional "${c}" before other positionals`);if(t.passthrough&&(!t.run||c===void 0))throw Error(`${e} uses passthrough, which needs run and a variadic last positional`);Ht(e,t.subcommands)}function ke(t){return t.find((e,n)=>t.indexOf(e)!==n)}function gt(t){return t}import{Console as xs}from"console";import{Writable as Ss}from"stream";import{format as Es,stripVTControlCharacters as Ts}from"util";var rt={active:!1};var ms=new Set(["0","false"]);function qt(t){if(process.env.NO_COLOR)return!1;let e=process.env.FORCE_COLOR;if(e!==void 0)return!ms.has(e);return t?.isTTY===!0}var hs=qt(process.stdout),Un=["black","blue","cyan","gray","green","magenta","red","white","yellow"],gs=["bold","dim","italic","underline","reset"],Vn={bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",reset:"\x1B[0m",underline:"\x1B[4m"},ys={black:"\x1B[30m",blue:"\x1B[34m",cyan:"\x1B[36m",gray:"\x1B[90m",green:"\x1B[32m",magenta:"\x1B[35m",red:"\x1B[31m",white:"\x1B[37m",yellow:"\x1B[33m"},$s={black:"\x1B[40m",blue:"\x1B[44m",cyan:"\x1B[46m",gray:"\x1B[100m",green:"\x1B[42m",magenta:"\x1B[45m",red:"\x1B[41m",white:"\x1B[47m",yellow:"\x1B[43m"},Fn={"\x1B[30m":"\x1B[90m","\x1B[31m":"\x1B[91m","\x1B[32m":"\x1B[92m","\x1B[33m":"\x1B[93m","\x1B[34m":"\x1B[94m","\x1B[35m":"\x1B[95m","\x1B[36m":"\x1B[96m","\x1B[37m":"\x1B[97m"};function Xt(t){return(e)=>hs&&!rt.active?`${t}${e}${Vn.reset}`:e}function bs(t){for(let e=0;e<t.length;e++){let n=t.charCodeAt(e);if(n<32&&n!==27)return!1}return!0}function Mn({bright:t=!1,color:e}){let n=Bun.color(e,"ansi"),r=typeof n==="string"&&n.length>0&&bs(n)?n:ys[e];if(!r)return"";return t&&r in Fn?Fn[r]:r}var ws=Un.reduce((t,e)=>{let n=Mn({color:e});if(n)t[e]=Xt(n);let r=Mn({bright:!0,color:e});if(r)t[`${e}Bright`]=Xt(r);return t},{}),vs=gs.reduce((t,e)=>(t[e]=Xt(Vn[e]),t),{}),Cs=Un.reduce((t,e)=>{let n=$s[e];if(n){let r=`bg${e.charAt(0).toUpperCase()}${e.slice(1)}`;t[r]=Xt(n)}return t},{}),y={...ws,...vs,...Cs};var _s=2,Bn=["clear","count","countReset","debug","dir","dirxml","group","groupCollapsed","groupEnd","info","log","table"],Os=[...Bn,"trace","write"],Is=1,As="EPIPE",Rs="EIO",A={closedStreams:new Set,documentWritten:!1,jsonRuns:0,outputGuarded:!1,restoreStdout:void 0,sealed:!1,stdoutClosed:!1,stdoutWrite:void 0};function It(){return process.stdin.isTTY===!0&&process.stdout.isTTY===!0}function je(t){return It()&&!rt.active&&t?.json!==!0}function Jn(){return rt.active}function it(t){let e=JSON.stringify(t??null,null,_s);if(e===void 0)throw TypeError("JSON cannot represent the value");return`${e}
|
|
4
|
+
`}function Kn(){return A.documentWritten}function Hn(){A.sealed=!0}function Q(t){if(A.documentWritten=!0,A.sealed||A.stdoutClosed)return;let e=A.stdoutWrite??process.stdout.write;try{e.call(process.stdout,t)}catch(n){if(!Yt(n,process.stdout))throw n;A.stdoutClosed=!0}}function Xn(){if(A.outputGuarded)return;A.outputGuarded=!0,process.stdout.write=Gn(process.stdout.write,!0),console.write=Gn(console.write,0),process.stdout.on("error",(t)=>{if(!Yt(t,process.stdout))throw t;A.stdoutClosed=!0}),process.stderr.on("error",(t)=>{if(!Yt(t,process.stderr))throw t});for(let t of[process.stdout,process.stderr])t.once("close",()=>A.closedStreams.add(t))}function Gn(t,e){let n=(r)=>{let i=r.at(-1);if(typeof i==="function")queueMicrotask(()=>i());return e};return function(...i){if(A.stdoutClosed)return n(i);try{return t.apply(this,i)}catch(s){if(!Yt(s,process.stdout))throw s;return A.stdoutClosed=!0,n(i)}}}function Yt(t,e){if(!(t instanceof Error))return!1;let n=Reflect.get(t,"code");return n===As||n===Rs&&e.isTTY===!0}function zt(){let t=qt(process.stderr);return new Ss({decodeStrings:!1,write(e,n,r){process.stderr.write(t?e:Ts(e)),r()}})}async function qn(t,e){if(!t)return e();A.jsonRuns+=1,A.restoreStdout??=Ps(),rt.active=!0;try{return await e()}finally{if(A.jsonRuns-=1,rt.active=A.jsonRuns>0,!rt.active&&!A.outputGuarded)A.restoreStdout?.(),A.restoreStdout=void 0}}async function Yn(t){let e=Promise.all([A.stdoutClosed?void 0:Wn(process.stdout),Wn(process.stderr)]);await(t===void 0?e:Promise.race([e,Bun.sleep(t)]))}function Wn(t){if(t.writableFinished||A.closedStreams.has(t))return Promise.resolve();return new Promise((e)=>{t.once("close",e),t.once("finish",e),t.once("error",()=>e()),t.end(()=>e())})}function Ps(){let t=process.stdout.write,e=new xs({stderr:process.stderr,stdout:process.stderr}),n=Object.fromEntries(Os.map((i)=>[i,console[i]])),r=Object.fromEntries(Bn.map((i)=>[i,e[i].bind(e)]));return A.stdoutWrite=t,process.stdout.write=process.stderr.write.bind(process.stderr),Object.assign(console,r,{trace:Ds(e),write:Ls}),()=>{process.stdout.write=t,Object.assign(console,n),A.stdoutWrite=void 0}}function Ds(t){let e=(...n)=>{let r={};Error.captureStackTrace(r,e);let i=r.stack?.split(`
|
|
5
|
+
`).slice(Is)??[];t.error([`Trace: ${Es(...n)}`,...i].join(`
|
|
6
|
+
`))};return e}function Ls(...t){let e=Buffer.concat(t.map(ks));return process.stderr.write(e),e.byteLength}function ks(t){if(typeof t==="string")return Buffer.from(t);return ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}var G={help:{alias:"h",description:"Show help",type:"boolean"},interactive:{alias:"i",description:"Open interactive mode",type:"boolean"},version:{alias:"v",description:"Show version",type:"boolean"},json:{alias:"j",description:"Write one JSON document to stdout",type:"boolean"}},yt={help:G.help,json:G.json},at="help",Qt={[N]:"success",[pt]:"failure",[On]:"usage error"};import{stripVTControlCharacters as Ke}from"util";import{stdout as dr,stdin as qs}from"process";import Ys from"readline";var zn=(()=>{let t=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(e)=>{let n=0;t.lastIndex=0;while(t.test(e))n+=1;return e.length-n}})(),Qn=(t)=>t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510,Zn=(t)=>t===8987||t===9001||t>=12272&&t<=12287||t>=12289&&t<=12350||t>=12441&&t<=12543||t>=12549&&t<=12591||t>=12593&&t<=12686||t>=12688&&t<=12771||t>=12783&&t<=12830||t>=12832&&t<=12871||t>=12880&&t<=19903||t>=65040&&t<=65049||t>=65072&&t<=65106||t>=65108&&t<=65126||t>=65128&&t<=65131||t>=127488&&t<=127490||t>=127504&&t<=127547||t>=127552&&t<=127560||t>=131072&&t<=196605||t>=196608&&t<=262141;var js=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Ns=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,tr=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Fs=/\t{1,1000}/y,er=/[\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,Ms=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Us=/\p{M}+/gu,Vs={limit:1/0,ellipsis:""},nr=(t,e={},n={})=>{let r=e.limit??1/0,i=e.ellipsis??"",s=e?.ellipsisWidth??(i?nr(i,Vs,n).width:0),o=0,a=n.controlWidth??0,u=n.tabWidth??8,c=n.emojiWidth??2,l=2,d=n.regularWidth??1,p=n.wideWidth??2,m=[[Ms,d],[js,0],[Ns,a],[Fs,u],[er,c],[tr,p]],f=0,h=0,C=t.length,_=0,x=!1,D=C,R=Math.max(0,r-s),E=0,P=0,I=0,g=0;t:while(!0){if(P>E||h>=C&&h>f){let T=t.slice(E,P)||t.slice(f,h);_=0;for(let F of T.replaceAll(Us,"")){let M=F.codePointAt(0)||0;if(Qn(M))g=2;else if(Zn(M))g=p;else g=d;if(I+g>R)D=Math.min(D,Math.max(E,f)+_);if(I+g>r){x=!0;break t}_+=F.length,I+=g}E=P=0}if(h>=C)break t;for(let T=0,F=m.length;T<F;T++){let[M,_n]=m[T];if(M.lastIndex=h,M.test(t)){if(_=M===tr?zn(t.slice(h,M.lastIndex)):M===er?1:M.lastIndex-h,g=_*_n,I+g>R)D=Math.min(D,h+Math.floor((R-I)/_n));if(I+g>r){x=!0;break t}I+=g,E=f,P=h,h=f=M.lastIndex;continue t}}h+=1}return{width:x?R:I,index:x?D:C,truncated:x,ellipsed:x&&r>=s}},rr=nr;var Gs={limit:1/0,ellipsis:"",ellipsisWidth:0},Ws=(t,e={})=>rr(t,Gs,e).width,W=Ws;var Zt="\x1B",ur="\x9B",Bs=39,Fe="\x07",cr="[",Js="]",lr="m",Me=`${Js}8;;`,ir=new RegExp(`(?:\\${cr}(?<code>\\d+)m|\\${Me}(?<uri>.*)${Fe})`,"y"),sr=(t)=>{if(t>=30&&t<=37)return 39;if(t>=90&&t<=97)return 39;if(t>=40&&t<=47)return 49;if(t>=100&&t<=107)return 49;if(t===1||t===2)return 22;if(t===3)return 23;if(t===4)return 24;if(t===7)return 27;if(t===8)return 28;if(t===9)return 29;if(t===0)return 0;return},or=(t)=>`${Zt}${cr}${t}${lr}`,ar=(t)=>`${Zt}${Me}${t}${Fe}`,Ne=(t,e,n)=>{let r=e[Symbol.iterator](),i=!1,s=!1,o=t.at(-1),a=o===void 0?0:W(o),u=r.next(),c=r.next(),l=0;while(!u.done){let d=u.value,p=W(d);if(a+p<=n)t[t.length-1]+=d;else t.push(d),a=0;if(d===Zt||d===ur)i=!0,s=e.startsWith(Me,l+1);if(i){if(s){if(d===Fe)i=!1,s=!1}else if(d===lr)i=!1}else if(a+=p,a===n&&!c.done)t.push(""),a=0;u=c,c=r.next(),l+=d.length}if(o=t.at(-1),!a&&o!==void 0&&o.length&&t.length>1)t[t.length-2]+=t.pop()},Ks=(t)=>{let e=t.split(" "),n=e.length;while(n){if(W(e[n-1]))break;n--}if(n===e.length)return t;return e.slice(0,n).join(" ")+e.slice(n).join("")},Hs=(t,e,n={})=>{if(n.trim!==!1&&t.trim()==="")return"";let r="",i,s,o=t.split(" "),a=[""],u=0;for(let d=0;d<o.length;d++){let p=o[d];if(n.trim!==!1){let f=a.at(-1)??"",h=f.trimStart();if(f.length!==h.length)a[a.length-1]=h,u=W(h)}if(d!==0){if(u>=e&&(n.wordWrap===!1||n.trim===!1))a.push(""),u=0;if(u||n.trim===!1)a[a.length-1]+=" ",u++}let m=W(p);if(n.hard&&m>e){let f=e-u,h=1+Math.floor((m-f-1)/e);if(Math.floor((m-1)/e)<h)a.push("");Ne(a,p,e),u=W(a.at(-1)??"");continue}if(u+m>e&&u&&m){if(n.wordWrap===!1&&u<e){Ne(a,p,e),u=W(a.at(-1)??"");continue}a.push(""),u=0}if(u+m>e&&n.wordWrap===!1){Ne(a,p,e),u=W(a.at(-1)??"");continue}a[a.length-1]+=p,u+=m}if(n.trim!==!1)a=a.map((d)=>Ks(d));let c=a.join(`
|
|
7
|
+
`),l=!1;for(let d=0;d<c.length;d++){let p=c[d];if(r+=p,!l){if(l=p>="\uD800"&&p<="\uDBFF",l)continue}else l=!1;if(p===Zt||p===ur){ir.lastIndex=d+1;let f=ir.exec(c)?.groups;if(f?.code!==void 0){let h=Number.parseFloat(f.code);i=h===Bs?void 0:h}else if(f?.uri!==void 0)s=f.uri.length===0?void 0:f.uri}if(c[d+1]===`
|
|
8
|
+
`){if(s)r+=ar("");let m=i?sr(i):void 0;if(i&&m)r+=or(m)}else if(p===`
|
|
9
|
+
`){if(i&&sr(i))r+=or(i);if(s)r+=ar(s)}}return r},Xs=/\r?\n/;function $t(t,e,n){return String(t).normalize().split(Xs).map((r)=>Hs(r,e,n)).join(`
|
|
10
|
+
`)}var X={to(t,e){if(!e)return`\x1B[${t+1}G`;return`\x1B[${e+1};${t+1}H`},move(t,e){let n="";if(t<0)n+=`\x1B[${-t}D`;else if(t>0)n+=`\x1B[${t}C`;if(e<0)n+=`\x1B[${-e}A`;else if(e>0)n+=`\x1B[${e}B`;return n},up:(t=1)=>`\x1B[${t}A`,down:(t=1)=>`\x1B[${t}B`,forward:(t=1)=>`\x1B[${t}C`,backward:(t=1)=>`\x1B[${t}D`,nextLine:(t=1)=>"\x1B[E".repeat(t),prevLine:(t=1)=>"\x1B[F".repeat(t),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"};var At={screen:"\x1B[2J",up:(t=1)=>"\x1B[1J".repeat(t),down:(t=1)=>"\x1B[J".repeat(t),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(t){let e="";for(let n=0;n<t;n++)e+=this.line+(n<t-1?X.up():"");if(t)e+=X.left;return e}};function ee(t,e,n){if(!n.some((o)=>!o.disabled))return t;let r=t+e,i=Math.max(n.length-1,0),s=r<0?i:r>i?0:r;return n[s]?.disabled?ee(s,e<0?-1:1,n):s}var zs=["up","down","left","right","space","enter","cancel"],Qs=["January","February","March","April","May","June","July","August","September","October","November","December"],B={actions:new Set(zs),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,accessible:void 0,date:{monthNames:[...Qs],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(t,e)=>`There are only ${t} days in ${e}`,afterMin:(t)=>`Date must be on or after ${t.toISOString().slice(0,10)}`,beforeMax:(t)=>`Date must be on or before ${t.toISOString().slice(0,10)}`}}};function fr(t){if(t!==void 0)return t;if(B.accessible!==void 0)return B.accessible;let e=process.env.ACCESSIBLE;return e!==void 0&&e!==""&&e!=="0"&&e!=="false"}function pr(t,e){if(typeof t=="string")return B.aliases.get(t)===e;for(let n of t)if(n!==void 0&&pr(n,e))return!0;return!1}function Zs(t,e){if(t===e)return;let n=t.split(`
|
|
11
11
|
`),r=e.split(`
|
|
12
|
-
`),i=Math.max(n.length,r.length),s=[];for(let o=0;o<i;o++)n[o]!==r[o]&&s.push(o);return{lines:s,numLinesBefore:n.length,numLinesAfter:r.length,numLines:i}}var
|
|
12
|
+
`),i=Math.max(n.length,r.length),s=[];for(let o=0;o<i;o++)n[o]!==r[o]&&s.push(o);return{lines:s,numLinesBefore:n.length,numLinesAfter:r.length,numLines:i}}var Kc=globalThis.process.platform.startsWith("win"),ne=Symbol("clack:cancel");function re(t){return t===ne}function te(t,e){let n=t;n.isTTY&&n.setRawMode(e)}var Rt=(t)=>("columns"in t)&&typeof t.columns=="number"?t.columns:80,Ue=(t)=>("rows"in t)&&typeof t.rows=="number"?t.rows:20;function Pt(t,e,n,r=n,i=n,s){let o=Rt(t??dr),a=W(n);return $t(e,o-a,{hard:!0,trim:!1}).split(`
|
|
13
13
|
`).map((u,c,l)=>{let d=s?s(u,c):u;return c===0?`${r}${d}`:c===l.length-1?`${i}${d}`:`${n}${d}`}).join(`
|
|
14
|
-
`)}function
|
|
15
|
-
`),
|
|
16
|
-
`).length-1;this.output.write(X.move(-999,e*-1))}render(){let e
|
|
17
|
-
`);this.output.write(a[o]),this._prevFrame=e,this.output.write(X.move(0,a.length-o-1));return}else if(n.lines.length>1){if(i<s)o=i;else{let u=o-s;u>0&&this.output.write(X.move(0,u))}this.output.write(
|
|
14
|
+
`)}function mr(t,e){if("~standard"in t){let n=t["~standard"].validate(e);return n instanceof Promise?n.then((r)=>r.issues?.at(0)?.message):n.issues?.at(0)?.message}return t(e)}var to=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";get accessible(){return fr(this.opts.accessible)}constructor(e,n=!0){let{input:r=qs,output:i=dr,render:s,signal:o,...a}=e;this.opts=a,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=s.bind(this),this._track=n,this._abortSignal=o,this.input=r,this.output=i}unsubscribe(){this._subscribers.clear()}setSubscriber(e,n){let r=this._subscribers.get(e)??[];r.push(n),this._subscribers.set(e,r)}on(e,n){this.setSubscriber(e,{cb:n})}once(e,n){this.setSubscriber(e,{cb:n,once:!0})}emit(e,...n){let r=this._subscribers.get(e)??[],i=[];for(let s of r)s.cb(...n),s.once&&i.push(()=>r.splice(r.indexOf(s),1));for(let s of i)s()}prompt(){return new Promise((e)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),e(ne);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=Ys.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),te(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(X.show),this.output.off("resize",this.render),te(this.input,!1),e(this.value)}),this.once("cancel",()=>{this.output.write(X.show),this.output.off("resize",this.render),te(this.input,!1),e(ne)})})}_isActionKey(e,n){return e==="\t"}_shouldSubmit(e,n){return!0}_setValue(e){this.value=e,this.emit("value",this.value)}_setUserInput(e,n){this.userInput=e??"",this.emit("userInput",this.userInput),n&&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("")}async onKeypress(e,n){if(this.state!=="validating"){if(this._track&&n.name!=="return"&&(n.name&&this._isActionKey(e,n)&&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"),n?.name&&(!this._track&&B.aliases.has(n.name)&&this.emit("cursor",B.aliases.get(n.name)),B.actions.has(n.name)&&this.emit("cursor",n.name)),e&&(e.toLowerCase()==="y"||e.toLowerCase()==="n")&&this.emit("confirm",e.toLowerCase()==="y"),this.emit("key",e,n),n?.name==="return"&&this._shouldSubmit(e,n)){if(this.opts.validate){let r=mr(this.opts.validate,this.value),i;r instanceof Promise?(this.state="validating",this.render(),i=await r):i=r,i&&(this.error=i instanceof Error?i.message:i,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}pr([e,n?.name,n?.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(`
|
|
15
|
+
`),te(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=$t(this._prevFrame,Rt(this.output),{hard:!0,trim:!1}).split(`
|
|
16
|
+
`).length-1;this.output.write(X.move(-999,e*-1))}render(){let e=$t(this._render(this)??"",Rt(this.output),{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state==="initial")this.output.write(X.hide);else{let n=Zs(this._prevFrame,e),r=Ue(this.output);if(this.restoreCursor(),n){let i=Math.max(0,n.numLinesAfter-r),s=Math.max(0,n.numLinesBefore-r),o=n.lines.find((a)=>a>=i);if(o===void 0){this._prevFrame=e;return}if(n.lines.length===1){this.output.write(X.move(0,o-s)),this.output.write(At.lines(1));let a=e.split(`
|
|
17
|
+
`);this.output.write(a[o]),this._prevFrame=e,this.output.write(X.move(0,a.length-o-1));return}else if(n.lines.length>1){if(i<s)o=i;else{let u=o-s;u>0&&this.output.write(X.move(0,u))}this.output.write(At.down());let a=e.split(`
|
|
18
18
|
`).slice(o);this.output.write(a.join(`
|
|
19
|
-
`)),this._prevFrame=e;return}}this.output.write(
|
|
20
|
-
`);return n&&i.push(b("cyan",
|
|
21
|
-
`);C.push(g),_+=g.length}if(_>l){let E=0,P=0,I=_,g=t-x,T=l,F=()
|
|
19
|
+
`)),this._prevFrame=e;return}}this.output.write(At.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}};var hr=class extends to{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){let e=this._selectedValue;this.value=e===void 0?void 0:e.value}constructor(e){super(e,!1),this.options=e.options;let n=this.options.findIndex(({value:i})=>i===e.initialValue),r=n===-1?0:n;this.cursor=this.options[r]?.disabled?ee(r,1,this.options):r,this.changeValue(),this.on("cursor",(i)=>{switch(i){case"left":case"up":this.cursor=ee(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=ee(this.cursor,1,this.options);break}this.changeValue()})}};import{styleText as b,stripVTControlCharacters as al}from"util";import q from"process";function eo(){if(q.platform!=="win32")return q.env.TERM!=="linux";return Boolean(q.env.CI)||Boolean(q.env.WT_SESSION)||Boolean(q.env.TERMINUS_SUBLIME)||q.env.ConEmuTask==="{cmd::Cmder}"||q.env.TERM_PROGRAM==="Terminus-Sublime"||q.env.TERM_PROGRAM==="vscode"||q.env.TERM==="xterm-256color"||q.env.TERM==="alacritty"||q.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var br=eo();var O=(t,e)=>br?t:e,gr=O("\u25C6","*"),wr=O("\u25A0","x"),vr=O("\u25B2","x"),Ve=O("\u25C7","o"),no=O("\u250C","T"),k=O("\u2502","|"),Ge=O("\u2514","\u2014"),fl=O("\u2510","T"),pl=O("\u2518","\u2014"),ro=O("\u25CF",">"),yr=O("\u25CB"," "),ml=O("\u25FB","[\u2022]"),hl=O("\u25FC","[+]"),gl=O("\u25FB","[ ]"),yl=O("\u25AA","\u2022"),$l=O("\u2500","-"),bl=O("\u256E","+"),wl=O("\u251C","+"),vl=O("\u256F","+"),Cl=O("\u2570","+"),xl=O("\u256D","+"),io=O("\u25CF","\u2022"),so=O("\u25C6","*"),oo=O("\u25B2","!"),ao=O("\u25A0","x"),uo=(t)=>{switch(t){case"initial":case"active":return b("cyan",gr);case"cancel":return b("red",wr);case"error":return b("yellow",vr);case"submit":return b("green",Ve);case"validating":return b("dim",gr)}},co=(t)=>{switch(t){case"initial":case"active":return b("cyan",k);case"cancel":return b("red",k);case"error":return b("yellow",k);case"submit":return b("green",k)}};function lo(t,e,n){let r=n?`${b("cyan",k)} `:"",i=Pt(t,e.join(" \u2022 "),r).split(`
|
|
20
|
+
`);return n&&i.push(b("cyan",Ge)),i}var $r=(t,e,n,r,i,s=!1)=>{let o=e,a=0;if(s)for(let u=r-1;u>=n;u--){let c=t[u];if(c&&(o-=c.length),a++,o<=i)break}else for(let u=n;u<r;u++){let c=t[u];if(c&&(o-=c.length),a++,o<=i)break}return{lineCount:o,removals:a}},fo=({cursor:t,options:e,style:n,output:r=process.stdout,maxItems:i=Number.POSITIVE_INFINITY,columnPadding:s=0,rowPadding:o=4})=>{let a=Rt(r)-s,u=Ue(r),c=b("dim","..."),l=Math.max(u-o,0),d=Math.max(Math.min(i,l),5),p=0;t>=d-3&&(p=Math.max(Math.min(t-d+3,e.length-d),0));let m=d<e.length&&p>0,f=d<e.length&&p+d<e.length,h=Math.min(p+d,e.length),C=[],_=0;m&&_++,f&&_++;let x=p+(m?1:0),D=h-(f?1:0);for(let E=x;E<D;E++){let P=e[E],I=P!==void 0?n(P,E===t):"",g=$t(I,a,{hard:!0,trim:!1}).split(`
|
|
21
|
+
`);C.push(g),_+=g.length}if(_>l){let E=0,P=0,I=_,g=t-x,T=l,F=()=>$r(C,I,0,g,T),M=()=>$r(C,I,g+1,C.length,T,!0);m?({lineCount:I,removals:E}=F(),I>T&&(f||(T-=1),{lineCount:I,removals:P}=M())):(f||(T-=1),{lineCount:I,removals:P}=M(),I>T&&(T-=1,{lineCount:I,removals:E}=F())),E>0&&(m=!0,C.splice(0,E)),P>0&&(f=!0,C.splice(C.length-P,P))}let R=[];m&&R.push(c);for(let E of C)for(let P of E)R.push(P);return f&&R.push(c),R};var Sl=[`${b("dim","\u2191/\u2193")} to navigate`,`${b("dim","Space:")} select`,`${b("dim","Enter:")} confirm`];var L={message:(t=[],{symbol:e=b("gray",k),secondarySymbol:n=b("gray",k),output:r=process.stdout,spacing:i=1,withGuide:s}={})=>{let o=[],a=s??B.withGuide,u=a?n:"",c=a?`${e} `:"",l=a?`${n} `:"";for(let p=0;p<i;p++)o.push(u);let d=Array.isArray(t)?t:t.split(`
|
|
22
22
|
`);if(d.length>0){let[p,...m]=d;p.length>0?o.push(`${c}${p}`):o.push(a?e:"");for(let f of m)f.length>0?o.push(`${l}${f}`):o.push(a?n:"")}r.write(`${o.join(`
|
|
23
23
|
`)}
|
|
24
|
-
`)},info:(t,e)=>{L.message(t,{...e,symbol:b("blue",
|
|
25
|
-
`)},
|
|
26
|
-
${b("gray",
|
|
24
|
+
`)},info:(t,e)=>{L.message(t,{...e,symbol:b("blue",io)})},success:(t,e)=>{L.message(t,{...e,symbol:b("green",so)})},step:(t,e)=>{L.message(t,{...e,symbol:b("green",Ve)})},warn:(t,e)=>{L.message(t,{...e,symbol:b("yellow",oo)})},warning:(t,e)=>{L.warn(t,e)},error:(t,e)=>{L.message(t,{...e,symbol:b("red",ao)})}};var Cr=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??B.withGuide?`${b("gray",no)} `:"";n.write(`${r}${t}
|
|
25
|
+
`)},xr=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??B.withGuide?`${b("gray",k)}
|
|
26
|
+
${b("gray",Ge)} `:"";n.write(`${r}${t}
|
|
27
27
|
|
|
28
|
-
`)};var
|
|
28
|
+
`)};var El={light:O("\u2500","-"),heavy:O("\u2501","="),block:O("\u2588","#")};var po=[`${b("dim","\u2191/\u2193")} to navigate`,`${b("dim","Enter:")} confirm`],ie=(t,e)=>t.includes(`
|
|
29
29
|
`)?t.split(`
|
|
30
30
|
`).map((n)=>e(n)).join(`
|
|
31
|
-
`):e(t),
|
|
31
|
+
`):e(t),Sr=(t)=>{let e=(r,i)=>{if(r===void 0)return"";let s=r.label??String(r.value);switch(i){case"disabled":return`${b("gray",yr)} ${ie(s,(o)=>b("gray",o))}${r.hint?` ${b("dim",`(${r.hint??"disabled"})`)}`:""}`;case"selected":return`${ie(s,(o)=>b("dim",o))}`;case"active":return`${b("green",ro)} ${s}${r.hint?` ${b("dim",`(${r.hint})`)}`:""}`;case"cancelled":return`${ie(s,(o)=>b(["strikethrough","dim"],o))}`;default:return`${b("dim",yr)} ${ie(s,(o)=>b("dim",o))}`}},n=t.showInstructions??!0;return new hr({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){let r=t.withGuide??B.withGuide,i=`${uo(this.state)} `,s=`${co(this.state)} `,o=Pt(t.output,t.message,s,i),a=`${r?`${b("gray",k)}
|
|
32
32
|
`:""}${o}
|
|
33
|
-
`;switch(this.state){case"submit":{let u=r?`${b("gray",k)} `:"",c=
|
|
33
|
+
`;switch(this.state){case"submit":{let u=r?`${b("gray",k)} `:"",c=Pt(t.output,e(this.options[this.cursor],"selected"),u);return`${a}${c}`}case"cancel":{let u=r?`${b("gray",k)} `:"",c=Pt(t.output,e(this.options[this.cursor],"cancelled"),u);return`${a}${c}${r?`
|
|
34
34
|
${b("gray",k)}`:""}`}default:{let u=r?`${b("cyan",k)} `:"",c=a.split(`
|
|
35
|
-
`).length,l=n?
|
|
36
|
-
`),p=l.length+1;return`${a}${u}${
|
|
35
|
+
`).length,l=n?lo(t.output,po,r):r?[b("cyan",Ge)]:[],d=l.join(`
|
|
36
|
+
`),p=l.length+1;return`${a}${u}${fo({output:t.output,cursor:this.cursor,options:this.options,maxItems:t.maxItems,columnPadding:u.length,rowPadding:c+p,style:(m,f)=>e(m,m.disabled?"disabled":f?"active":"inactive")}).join(`
|
|
37
37
|
${u}`)}
|
|
38
38
|
${d}
|
|
39
|
-
`}}}}).prompt()};var
|
|
39
|
+
`}}}}).prompt()};var Tl=`${b("gray",k)} `;function Er(t=process.stdin){return t.readableEnded||t.destroyed}async function Tr({edits:t,input:e=process.stdin,signal:n},r){let i=new AbortController,s=()=>i.abort(),o=(u,c)=>{if(c.sequence==="\x04"&&(!t||e.isPaused()))s()},a=r(n?AbortSignal.any([i.signal,n]):i.signal);e.on("keypress",o),e.once("end",s),e.once("close",s);try{return await a}finally{e.off("keypress",o),e.off("end",s),e.off("close",s)}}var ho=new Set;function _r(){for(let t of[...ho])t.error()}var yo="Pass the value as an argument or option instead";function $o(t){if(re(t))throw new J;return t}function bo(t){if(je())return;throw new S(`Cannot prompt for ${t} without a terminal`,yo)}async function wo(t,e,{edits:n=!1,hint:r}){if(bo(e.message),Er(e.input))throw new J;return Co(r),$o(await Tr({...e,edits:n},(i)=>t({...e,signal:i})))}function vo(t){return t.map((e)=>e.key?`${y.bold(e.key)} ${y.dim(e.text)}`:y.dim(e.text)).join(y.dim(" \xB7 "))}function Co(t){L.info(vo(t))}var xo={confirm:[{key:"Enter",text:"confirm"},{key:"Esc",text:"cancel"}],multiselect:[{key:"\u2191\u2193",text:"navigate"},{key:"Space",text:"toggle"},{key:"a",text:"all"},{key:"Enter",text:"confirm"},{key:"Esc",text:"cancel"}],select:[{key:"\u2191\u2193",text:"navigate"},{key:"Enter",text:"select"},{key:"Esc",text:"cancel"}],text:[{key:"Enter",text:"submit"},{key:"Esc",text:"cancel"}]};async function We(t){return wo(Sr,{showInstructions:!1,...t},{hint:xo.select})}function se(t){return Jn()&&t.output===void 0?{...t,output:process.stderr}:t}function bt(t){return(e,n={})=>t(e,se(n))}var U={error:bt(L.error),info:bt(L.info),message:(t,e={})=>L.message(t,se(e)),step:bt(L.step),success:bt(L.success),warn:bt(L.warn),warning:bt(L.warning)};function Be(t,e={}){Cr(t,se(e))}function Je(t,e={}){xr(t,se(e))}import{inspect as So}from"util";var Eo=4;function oe(t,e=[]){if(e.length>=Eo)return[];let n=t instanceof AggregateError?t.errors:[],r=[...e,t];return[...n,...t.cause!==void 0?[t.cause]:[]].filter((s)=>!r.includes(s)).flatMap((s)=>[{hint:ue(s),message:ae(s)},...s instanceof Error?oe(s,r):[]])}function ae(t){return ce(t instanceof Error?t.message||t.name:t)}function ue(t){return t instanceof w&&t.hint!==void 0?ce(t.hint):void 0}function ce(t){return typeof t==="string"?t:So(t,{breakLength:Number.POSITIVE_INFINITY})}var To="Error",_o=27,Oo=new RegExp(`${String.fromCharCode(_o)}\\[[\\d;]*m`,"g"),Io=9,Ao=10,Ro=31,Po=127,Do=159,Lo=16,ko=4;function st(t,{json:e}){if(_r(),Fo(t),e)Q(it({error:jo(t)}));return Or(t)}function jo(t){let e=Or(t),n=Ke(ae(t));if(!(t instanceof Error))return{_tag:To,message:n,exitCode:e,causes:[]};let r=ue(t);return{_tag:No(t),message:n,hint:r===void 0?void 0:Ke(r),exitCode:e,causes:oe(t).map((i)=>Ke(i.message))}}function Or(t){if(t instanceof J)return N;if(t instanceof w)return Nt(t.exitCode)?t.exitCode:pt;return pt}function No(t){let e=Reflect.get(t,"_tag");return typeof e==="string"?e:ce(t.name)}function Fo(t){if(t instanceof J)return;let e=zt(),n=le(ae(t));if(t instanceof w){let r=ue(t);if(U.warn(y.yellow(n),{output:e}),r)U.info(y.dim(le(r)),{output:e})}else U.error(y.red(n),{output:e});if(!(t instanceof Error))return;for(let r of oe(t))if(U.info(y.dim(`caused by: ${le(r.message)}`),{output:e}),r.hint)U.info(y.dim(` ${le(r.hint)}`),{output:e})}function le(t){return Array.from(t.replace(Oo,""),(e)=>{let n=e.charCodeAt(0);return n<=Ro&&n!==Io&&n!==Ao||n>=Po&&n<=Do?`\\u${n.toString(Lo).padStart(ko,"0")}`:e}).join("")}var Mo=500,Uo="The command stopped before it finished because nothing was left for it to wait for";function Ir({json:t}){let e={ending:void 0,failed:!1,settled:!1},n=(i,s)=>(e.ending??=Vo(i,s),e.ending),r=(i)=>{if(e.failed||e.ending)return;e.failed=!0;let s=st(i,{json:t&&!Kn()});Hn(),n(s,e.settled?void 0:Mo)};return process.on("uncaughtException",r),process.on("unhandledRejection",r),process.on("beforeExit",()=>{if(!e.settled)r(Error(Uo))}),{exit:(i)=>n(i),settle(){e.settled=!0}}}async function Vo(t,e){process.exitCode=t,await Yn(e),process.exit(t)}var Z=new Uint32Array(65536),Go=(t,e)=>{let n=t.length,r=e.length,i=1<<n-1,s=-1,o=0,a=n,u=n;while(u--)Z[t.charCodeAt(u)]|=1<<u;for(u=0;u<r;u++){let c=Z[e.charCodeAt(u)],l=c|o;if(c|=(c&s)+s^s,o|=~(c|s),s&=c,o&i)a++;if(s&i)a--;o=o<<1|1,s=s<<1|~(l|o),o&=l}u=n;while(u--)Z[t.charCodeAt(u)]=0;return a},Wo=(t,e)=>{let n=e.length,r=t.length,i=[],s=[],o=Math.ceil(n/32),a=Math.ceil(r/32);for(let f=0;f<o;f++)s[f]=-1,i[f]=0;let u=0;for(;u<a-1;u++){let f=0,h=-1,C=u*32,_=Math.min(32,r)+C;for(let x=C;x<_;x++)Z[t.charCodeAt(x)]|=1<<x;for(let x=0;x<n;x++){let D=Z[e.charCodeAt(x)],R=s[x/32|0]>>>x&1,E=i[x/32|0]>>>x&1,P=D|f,I=((D|E)&h)+h^h|D|E,g=f|~(I|h),T=h&I;if(g>>>31^R)s[x/32|0]^=1<<x;if(T>>>31^E)i[x/32|0]^=1<<x;g=g<<1|R,T=T<<1|E,h=T|~(P|g),f=g&P}for(let x=C;x<_;x++)Z[t.charCodeAt(x)]=0}let c=0,l=-1,d=u*32,p=Math.min(32,r-d)+d;for(let f=d;f<p;f++)Z[t.charCodeAt(f)]|=1<<f;let m=r;for(let f=0;f<n;f++){let h=Z[e.charCodeAt(f)],C=s[f/32|0]>>>f&1,_=i[f/32|0]>>>f&1,x=h|c,D=((h|_)&l)+l^l|h|_,R=c|~(D|l),E=l&D;if(m+=R>>>r-1&1,m-=E>>>r-1&1,R>>>31^C)s[f/32|0]^=1<<f;if(E>>>31^_)i[f/32|0]^=1<<f;R=R<<1|C,E=E<<1|_,l=E|~(x|R),c=R&x}for(let f=d;f<p;f++)Z[t.charCodeAt(f)]=0;return m},Bo=(t,e)=>{if(t.length<e.length){let n=e;e=t,t=n}if(e.length===0)return t.length;if(t.length<=32)return Go(t,e);return Wo(t,e)},Ar=(t,e)=>{let n=1/0,r=0;for(let i=0;i<e.length;i++){let s=Bo(t,e[i]);if(s<n)n=s,r=i}return e[r]};function de(t,e,n){let r=e.length>0?Ar(t,[...e]):void 0,i=`Run "${n} --help" for usage.`;return new S(`Unknown command: ${t}`,r?`Did you mean "${r}"? ${i}`:i)}function Dt(t,e){if(Array.isArray(e))return[...e];if(!Rr(t)||!Rr(e))return e;return Object.fromEntries([...Object.entries(t),...Object.entries(e).map(([n,r])=>[n,Dt(Object.hasOwn(t,n)?t[n]:void 0,r)])])}function Rr(t){if(t===null||typeof t!=="object")return!1;let e=Object.getPrototypeOf(t);return e===Object.prototype||e===null}function Pr(t,e){return{name:t.name,bin:t.bin,version:t.version,description:t.description,exitCodes:{...Qt},options:Dr(G),commands:e.map((n)=>fe(n,`${t.bin} ${n.name}`))}}function fe(t,e){return{name:t.name,path:e,description:t.description,json:t.json,prompts:t.prompts,passthrough:t.passthrough,positionals:Object.entries(t.positionals).map(([n,r])=>({name:n,required:r.required??!1,variadic:r.variadic??!1,description:r.description??""})),options:Dr(t.args),examples:[...t.examples],commands:t.subcommands.map((n)=>fe(n,`${e} ${n.name}`))}}function Dr(t){return Object.entries(t).map(([e,n])=>({name:e,flag:`--${H(e)}`,...n.alias?{alias:`-${n.alias}`}:{},type:n.type,...n.default===void 0?{}:{default:n.default},...n.displayDefault===void 0?{}:{displayDefault:n.displayDefault},description:n.description??""}))}import{stripVTControlCharacters as Lr}from"util";var Jo=2,Ko="0.0.0",Ho=(t)=>t,v={arg:y.magenta,cmd:y.cyan,default:y.bold,desc:Ho,flag:y.green,header:(t)=>y.bold(y.yellow(t)),hint:y.dim,name:(t)=>y.bold(y.cyan(t)),placeholder:y.magenta};function kr(t){return`${v.name(t.name)} ${v.hint(t.version??Ko)}`}function jr(t,e){let n=`${v.name(t.name)}${t.version?` ${v.hint(`v${t.version}`)}`:""}`;return Fr([[n,...t.description?[v.desc(t.description)]:[]],Y("Usage:",[` ${v.cmd(t.bin)} ${v.placeholder("[command]")} ${v.placeholder("[options]")}`]),Y("Commands:",Mr(e)),Y("Options:",Vr(G)),Y("Exit codes:",Ur()),[`${v.hint("Run")} ${v.cmd(`${t.bin} <command> --help`)} ${v.hint("for command details.")}`]])}function Nr(t,e){let n=t.json?{...t.args,json:G.json}:t.args,r=[...t.subcommands.length>0?[` ${v.cmd(e)} ${v.placeholder("<command>")} ${v.placeholder("[options]")}`]:[],...t.run?[` ${Xo(t,e).join(" ")}`]:[],...t.prompts&&Object.keys(t.positionals).length>0?[` ${v.hint("Omit positional arguments to run interactively.")}`]:[],...t.passthrough?[` ${v.hint("Options end at the first argument; it and everything after it are passed on unchanged.")}`]:[]];return Fr([[v.name(e),v.desc(t.description)],Y("Usage:",r),Y("Commands:",Mr(t.subcommands)),Y("Arguments:",Yo(t.positionals)),Y("Options:",Vr(n)),Y("Examples:",t.examples.map((i)=>` ${v.cmd(i)}`)),Y("Exit codes:",Ur())])}function Xo(t,e){let n=qo(t.positionals);return t.passthrough?[v.cmd(e),v.placeholder("[options]"),v.placeholder("[--]"),...n]:[v.cmd(e),...n,v.placeholder("[options]")]}function Y(t,e){return e.length>0?[v.header(t),...e]:[]}function Fr(t){return t.filter((e)=>e.length>0).map((e)=>e.join(`
|
|
40
40
|
`)).join(`
|
|
41
41
|
|
|
42
|
-
`)}function
|
|
43
|
-
`:void 0}function
|
|
44
|
-
`}function
|
|
45
|
-
`}function
|
|
46
|
-
`}function
|
|
42
|
+
`)}function Mr(t){return pe(t.map((e)=>[` ${v.cmd(e.name)}`,v.desc(e.description)]))}function Ur(){return pe(Object.entries(Qt).map(([t,e])=>[` ${t}`,e]))}function He(t,e){return e.variadic?`${t}...`:t}function qo(t){return Object.entries(t).map(([e,n])=>n.required?v.arg(`<${He(e,n)}>`):v.arg(`[${He(e,n)}]`))}function Yo(t){return pe(Object.entries(t).map(([e,n])=>[` ${v.arg(He(e,n))}`,`${v.desc(n.description??"")}${n.required?"":v.hint(" (optional)")}`]))}function Vr(t){return pe(Object.entries(t).map(([e,n])=>{let r=n.alias?`${v.flag(`-${n.alias}`)}, `:" ",i=n.type==="boolean"?"":` ${v.placeholder(`<${n.type==="number"?"number":"value"}>`)}`,s=zo(n),o=s===void 0?"":` (default: ${v.default(s)})`;return[` ${r}${v.flag(`--${H(e)}`)}${i}`,`${v.desc(n.description??"")}${o}`]}))}function zo(t){if(typeof t.displayDefault==="string")return t.displayDefault;if(t.default===void 0)return;if(t.type==="boolean"&&t.default===!1)return;if(t.type==="string")return`"${t.default}"`;return String(t.default)}function pe(t){let e=Math.max(0,...t.map(([n])=>Lr(n).length));return t.map(([n,r])=>`${n}${" ".repeat(e-Lr(n).length+Jo)}${r}`)}function me(t){let e=!1;return{emitted:()=>e,json:t,result(n,r){if(e)throw Error("ctx.output.result was called more than once; a command emits one result");let i=Qo(t,n,r);if(e=!0,i!==void 0)Q(i)}}}function Qo(t,e,n){if(t)return it(e);return n?`${n(e)}
|
|
43
|
+
`:void 0}function he(t,e,n){return{args:e.args,cli:t.info,config:t.config,interactive:e.interactive,json:e.json,output:n,positionals:e.positionals}}async function ge(t,e,n,r){let i=await qn(n.json,async()=>{let s=await t.run?.(n);return typeof s==="number"?Zo(e,s):N});if(n.json&&!r.emitted())throw Error(`${e} finished in JSON mode without calling ctx.output.result`);return i}function Zo(t,e){if(Nt(e))return e;throw Error(`${t} returned ${e}, which is not an exit code from ${N} to ${In}`)}var Xe="__exit__",Gr="__run__",ta="Back",ea="Return to previous menu";async function Wr(t,e){if(e)throw new S("Interactive mode cannot be combined with --json","Pass a command and its arguments instead");if(!It())throw new S("Interactive mode requires a terminal","Pass a command and its arguments to run non-interactively");if(t.interactive.clearOnStart)console.clear();let n=t.info.version?` v${t.info.version}`:"";Be(y.bgCyan(y.black(` ${t.info.name}${n} `)));let r={commands:t.commands,message:t.interactive.promptMessage,path:t.info.bin,root:!0};return await Br(t,new Map,r),Je(t.interactive.goodbyeMessage),N}async function Br(t,e,n){while(!0){let r=await na(t,e,n);if(r===void 0)return;if(e.set(n.path,r),r===Gr&&n.owner){await Jr(t,n.owner,n.path);continue}let i=n.commands.find((s)=>s.name===r);if(i)await ra(t,e,i,`${n.path} ${r}`)}}async function na(t,e,n){let r=n.root?{hint:t.interactive.exitHint,label:t.interactive.exitLabel,value:Xe}:{hint:ea,label:ta,value:Xe};try{let i=await We({initialValue:e.get(n.path),message:n.message,options:[...n.owner?[{hint:n.owner.description,label:n.owner.name,value:Gr}]:[],...n.commands.map((s)=>({hint:s.description,label:s.name,value:s.name})),r]});return i===Xe?void 0:i}catch(i){if(i instanceof J)return;throw i}}async function ra(t,e,n,r){if(n.subcommands.length===0)return Jr(t,n,r);return Br(t,e,{commands:n.subcommands,message:`${n.name}:`,path:r,root:!1,...n.run?{owner:n}:{}})}async function Jr(t,e,n){try{await ia(t,e,n)}catch(r){if(r instanceof J)return;if(!(r instanceof w))throw r;st(r,{json:!1})}}async function ia(t,e,n){let{args:r}=Ot([],e.args),i=Bt([],e.positionals),s=e.prompts?null:Jt(i,e.positionals);if(s)throw new S(s,`Run "${n} --help" for usage.`);let o=me(!1),a={args:Gt(r,e.args),interactive:e.prompts,json:!1,positionals:i};await ge(e,n,he(t,a,o),o)}var sa="--",oa=/^(?:--json(?:=true)?|-[^-=]*j[^-=]*(?:=true)?)$/,aa=/^(?:--no-(?:help|json)|(?:--(?:help|json)|-[hj]+)(?:=(?:true|false))?)$/;async function qe(t,e){try{return await ua(t,e)}catch(n){return{code:st(n,{json:ze(e)}),menu:!1}}}function Ye(t,e){let{command:n,restArgs:r}=Vt(e,G),i=n===void 0||n===at?void 0:Xr(t,n,r);if(!i||i instanceof S||!i.command.passthrough)return{operands:[],options:[...e]};let s=kn(i.tokens,{...i.command.args,...yt}),o=s<0?[]:i.tokens.slice(s);return{operands:o,options:e.slice(0,e.length-o.length)}}async function ua(t,{options:e,operands:n}){let{command:r,flags:i,restArgs:s}=De(e,G,yt),o=i.json===!0,a={code:N,menu:!1};if(r===void 0){if(i.interactive&&!i.help&&!i.version)return{code:await Wr(t,o),menu:!0};return Q(i.version&&!i.help?la(t,o):Kr(t,o)),a}let u=i.interactive?"--interactive":i.version?"--version":void 0;if(u)throw new S(`${u} cannot be combined with a command`,`Run "${t.info.bin} ${u}" on its own.`);if(r===at)return Q(da(t,s,o)),a;let c=fa(t,r,s);if(i.help)return Q(Qe(c.command,c.path,o)),a;return{code:await pa(t,c,n,o),menu:!1}}function ze({options:t}){let{before:e,restArgs:n}=Vt(t,G);return[e,n].some((r)=>ca(r).some((i)=>oa.test(i)))}function ca(t){let e=t.indexOf(sa);return e<0?t:t.slice(0,e)}function la({info:t},e){return e?it({name:t.name,bin:t.bin,version:t.version}):`${kr(t)}
|
|
44
|
+
`}function Kr(t,e){return e?it(Pr(t.info,t.commands)):`${jr(t.info,t.commands)}
|
|
45
|
+
`}function Qe(t,e,n){return n?it(fe(t,e)):`${Nr(t,e)}
|
|
46
|
+
`}function da(t,e,n){let{args:r,rawPositionals:i}=Ot(e,yt);if(Ut(r,yt,`Run "${t.info.bin} ${at} [command]" for usage.`,e),i.length===0)return Kr(t,n);let{command:s,path:o}=Hr(t.commands,i,t.info.bin);return Qe(s,o,n)}function Hr(t,e,n){let[r="",...i]=e,s=t.find((a)=>a.name===r);if(!s)throw de(r,Ze(t),n);let o=`${n} ${r}`;return i.length===0?{command:s,path:o}:Hr(s.subcommands,i,o)}function Ze(t){return t.map((e)=>e.name)}function fa(t,e,n){let r=Xr(t,e,n);if(r instanceof S)throw r;return r}function Xr(t,e,n){let r=t.commands.find((i)=>i.name===e);if(!r)return de(e,Ze(t.commands),t.info.bin);return qr({command:r,path:`${t.info.bin} ${e}`,tokens:n})}function qr(t){let{command:e,path:n,tokens:r}=t;if(e.subcommands.length===0)return t;let i=r.findIndex((a)=>!aa.test(a)),s=r[i];if(s===void 0||s.startsWith("-"))return t;let o=e.subcommands.find((a)=>a.name===s);if(o)return qr({command:o,path:`${n} ${s}`,tokens:r.toSpliced(i,1)});if(e.run&&Object.keys(e.positionals).length>0)return t;return de(s,Ze(e.subcommands),n)}async function pa(t,{command:e,path:n,tokens:r},i,s){let o=`Run "${n} --help" for usage.`,a={...e.args,...yt},u=Ot(r,a),{args:c}=u,l=[...u.rawPositionals,...i];if(e.strict)Ut(c,a,o,r);if(s&&!e.json)throw new S(`${n} does not support --json`,o);let d=e.strict?Nn(l,e.positionals):void 0;if(d!==void 0)throw new S(`Unexpected argument: ${d}`,o);if(!e.run)return Q(Qe(e,n,s)),N;let p=Bt(l,e.positionals),m=Jt(p,e.positionals);if(m)throw new S(m,o);let f=e.prompts&&l.length===0&&It()&&!s,h={args:Gt(c,e.args),interactive:f,json:s,positionals:p},C=me(s);try{return await ge(e,n,he(t,h,C),C)}catch(_){return st(_,{json:s&&!C.emitted()})}}var ma={clearOnStart:!0,exitHint:"Close the CLI",exitLabel:"Exit",goodbyeMessage:"Goodbye!",promptMessage:"What would you like to do?"};function tn(t){let e=`CLI "${t.name}"`;if(Ht(e,t.commands),t.commands.some((r)=>r.name===at))throw Error(`${e} cannot define a command named "${at}": the framework provides it`);let n={commands:t.commands,config:t.config,info:{bin:t.bin??t.name,description:t.description,name:t.name,version:t.version},interactive:{...ma,...t.interactive}};return{async main(r=process.argv.slice(2)){Xn();let i=Ye(n,r),s=Ir({json:ze(i)}),o=await qe(n,i);if(s.settle(),o.code===N&&!o.menu)return;await s.exit(o.code)},async run(r=process.argv.slice(2)){return(await qe(n,Ye(n,r))).code}}}import Ct from"fs";import dn from"path";var ye=(t)=>(t.map=(e)=>ye((n)=>e(t(n))),t.or=(e)=>ye((n)=>{try{return t(n)}catch(r){return e(n)}}),t),Yr=()=>"bad banditype"();var en=(t)=>ye((e)=>typeof e===typeof t?e:Yr()),nn=()=>en("");var zr=()=>en(!0);var rn=()=>en();var sn=(t)=>ye((e)=>e instanceof t?e:Yr());var Lt=(t)=>sn(Object).map((e)=>{let n={};for(let r in t){let i=t[r](e[r]);i!==void 0&&(n[r]=i)}return n});import{randomUUID as ha}from"crypto";import{closeSync as Qr,fchmodSync as ga,fsyncSync as Zr,openSync as ti,renameSync as ya,rmSync as $a,writeFileSync as ba}from"fs";import{dirname as wa,join as va}from"path";function on(t,e,{durable:n=!1,mode:r}={}){let i=wa(t),s=va(i,`.${process.pid}.${ha()}.tmp`);try{let o=ti(s,"wx",r);try{if(typeof e==="function")e(o);else ba(o,e);if(r!==void 0)ga(o,r);if(n)Zr(o)}finally{Qr(o)}if(ya(s,t),n)Ca(i)}finally{$a(s,{force:!0})}}function Ca(t){let e=ti(t,"r");try{Zr(e)}finally{Qr(e)}}function $e(t){return t instanceof Error?t.message:String(t)}function ut(t){if(typeof t!=="object"||t===null)return;let e=Reflect.get(t,"code");return typeof e==="string"?e:void 0}function wt(t,e){return ut(t)===e}import vt from"fs";var xa=".lock",Sa=".break",ei=10,Ea=1e4,Ta=5000;function ni(t,e){let n=`${t}${xa}`,r=crypto.randomUUID();_a(n,r);try{return e()}finally{ri(n,r)}}function _a(t,e){let n=Date.now()+Ea;while(!ii(t,e)){if(Date.now()>n)throw Error(`timed out waiting for ${t}, which another process holds`);if(an(t))Oa(t,e);else Bun.sleepSync(ei)}}function ri(t,e){if(Ia(t)===e)vt.rmSync(t,{force:!0})}function Oa(t,e){let n=`${t}${Sa}`;if(!ii(n,e)){if(an(n))vt.rmSync(n,{force:!0});else Bun.sleepSync(ei);return}try{if(an(t))vt.rmSync(t,{force:!0})}finally{ri(n,e)}}function ii(t,e){try{return vt.writeFileSync(t,e,{flag:"wx"}),!0}catch(n){if(ut(n)==="EEXIST")return!1;throw n}}function an(t){let e=vt.statSync(t,{throwIfNoEntry:!1})?.mtimeMs;return e!==void 0&&Date.now()-e>Ta}function Ia(t){try{return vt.readFileSync(t,"utf8")}catch(e){if(ut(e)==="ENOENT")return;throw e}}import un from"fs";import ct from"path";var Aa="..",Ra=40;function oi(t){let{root:e}=ct.parse(ct.resolve(t)),n=si(ct.resolve(t)),r=e,i=0;for(let s=n.shift();s!==void 0;s=n.shift()){if(s===Aa){r=ct.dirname(un.realpathSync(r));continue}let o=ct.join(r,s);if(!un.lstatSync(o,{throwIfNoEntry:!1})?.isSymbolicLink()){r=o;continue}if(i+=1,i>Ra)throw Error(`too many symbolic links in ${t}`);let a=un.readlinkSync(o);if(ct.isAbsolute(a))r=e;n.unshift(...si(a))}return r}function si(t){return t.split(ct.sep).filter((e)=>e!==""&&e!==".")}function ln(t,e){JSON.parse(t);let n=JSON.parse(JSON.stringify(e)),r=Pa(t),i=t.match(/^[\t ]+(?=\S)/m)?.[0]??" ",s=t.includes(`\r
|
|
47
47
|
`)?`\r
|
|
48
48
|
`:`
|
|
49
49
|
`,o=/\s/.test(t[r.start+1]??"")||r.entries.some((c)=>/:\s+$/.test(t.slice(c.start,c.node.start)))?" ":"";function a(c,l){let d=t.slice(c.start,c.end);if(JSON.stringify(c.value)===JSON.stringify(l))return d;let p=Array.isArray(l);if(l===null||typeof l!=="object"||c.value===null||typeof c.value!=="object"||Array.isArray(c.value)!==p)return u(l,c.start,d.includes(`
|
|
50
50
|
`));let m=p?l.map((g,T)=>String(T)):[...new Set([...c.entries.map((g)=>g.key).filter((g)=>Object.hasOwn(l,g)),...Object.keys(l)])];if(m.length===0)return p?"[]":"{}";let f=c.entries[0],h=c.entries.at(-1);if(!f||!h)return u(l,c.start,d.includes(`
|
|
51
51
|
`));let C=(g)=>p?l[Number(g)]:l[g];if(m.length===c.entries.length&&m.every((g,T)=>g===c.entries[T]?.key)){let g=c.start,T="";for(let F of c.entries)T+=t.slice(g,F.node.start)+a(F.node,C(F.key)),g=F.node.end;return T+t.slice(g,c.end)}let _=t.slice(c.start+1,f.start),x=t.slice(h.node.end,c.end-1),D=c.entries[1],R=D?t.slice(f.node.end,D.start):`,${_.includes(`
|
|
52
52
|
`)?_:o}`,E=p?"":t.slice(f.start,f.node.start).match(/:\s*$/)?.[0]??": ",P=new Map(c.entries.map((g)=>[g.key,g])),I=m.map((g)=>{let T=P.get(g);if(T)return t.slice(T.start,T.node.start)+a(T.node,C(g));return(p?"":JSON.stringify(g)+E)+u(C(g),f.start,_.includes(`
|
|
53
|
-
`))});return`${p?"[":"{"}${_}${I.join(R)}${x}${p?"]":"}"}`}function u(c,l,d){if(!d)return
|
|
53
|
+
`))});return`${p?"[":"{"}${_}${I.join(R)}${x}${p?"]":"}"}`}function u(c,l,d){if(!d)return cn(c,o);let p=t.lastIndexOf(`
|
|
54
54
|
`,l-1)+1,m=t.slice(p,l).match(/^[\t ]*/)?.[0]??"";return JSON.stringify(c,null,i).replaceAll(`
|
|
55
|
-
`,s+m)}return t.slice(0,r.start)+a(r,n)+t.slice(r.end)}function
|
|
56
|
-
`;
|
|
55
|
+
`,s+m)}return t.slice(0,r.start)+a(r,n)+t.slice(r.end)}function cn(t,e){if(Array.isArray(t))return`[${t.map((i)=>cn(i,e)).join(`,${e}`)}]`;if(t===null||typeof t!=="object")return JSON.stringify(t);let n=Object.entries(t);if(n.length===0)return"{}";let r=n.map(([i,s])=>`${JSON.stringify(i)}:${e}${cn(s,e)}`);return`{${e}${r.join(`,${e}`)}${e}}`}function Pa(t){let e=t.matchAll(/"(?:[^"\\]|\\.)*"|[^\s{}[\],:]+|[{}[\],:]/g),n=e.next().value;function r(){if(!n)throw Error("Unexpected end of JSON");let s=n;return n=e.next().value,s}function i(){let s=r(),o=[],a=s[0]==="{";if(!a&&s[0]!=="[")return{end:s.index+s[0].length,entries:o,start:s.index,value:JSON.parse(s[0])};let u=a?"}":"]";while(n&&n[0]!==u){let l=n.index,d=a?JSON.parse(r()[0]):String(o.length);if(a)r();if(o.push({key:d,node:i(),start:l}),n?.[0]===",")r()}let c=r().index+1;return{end:c,entries:o,start:s.index,value:JSON.parse(t.slice(s.index,c))}}return i()}var Da=2,fn="ConfigError",La=sn(Object);class pn{loaded;configPath;defaultConfig;options;constructor(t,e,n={}){this.configPath=dn.resolve(t),this.defaultConfig=e,this.options=n}get path(){return this.configPath}get failure(){return this.state().failure}get(t){return this.current()[t]}set(t,e){let n=this.writable();this.update((r)=>({...r,[t]:e})),n.config={...n.config,[t]:e}}delete(t){let e=this.writable();this.update((n)=>(delete n[t],n)),delete e.config[t]}exists(){return Ct.existsSync(this.configPath)}getAll(){return structuredClone(this.current())}save(t){let e=this.writable();if(t)e.config={...t};this.update(()=>e.config)}state(){return this.loaded??=this.load(),this.loaded}current(){let{config:t,failure:e}=this.state();if(e)throw e;return t}writable(){let t=this.state();if(t.failure)throw t.failure;if(t.error)throw this.unreadable(t.error);return t}unreadable(t){return new w(`Cannot overwrite unreadable config at ${this.configPath}`,"Repair the file and try again",void 0,{cause:t,tag:fn})}readStored(){try{let t=this.readConfigFile();if(t===void 0)return structuredClone(this.defaultConfig);return Dt(structuredClone(this.defaultConfig),ai(t))}catch(t){throw this.unreadable(t)}}update(t){try{let e=this.savePath();ni(e,()=>this.write(e,t(this.readStored())))}catch(e){throw e instanceof w?e:this.saveFailure(e)}}savePath(){let t=this.exists()?Ct.realpathSync(this.configPath):oi(this.configPath);return Ct.mkdirSync(dn.dirname(t),{recursive:!0}),t}write(t,e){let n=this.exists()?Ct.statSync(this.configPath).mode:void 0,r=this.exists()?ln(Ct.readFileSync(this.configPath,"utf-8"),e):`${JSON.stringify(e,null,Da)}
|
|
56
|
+
`;on(t,r,{mode:n})}saveFailure(t){return new w(`Cannot save config at ${this.configPath}: ${$e(t)}`,`Check that ${dn.dirname(this.configPath)} is writable and that no other process is saving the file`,void 0,{cause:t,tag:fn})}load(){let{parse:t,strict:e}=this.options;try{let n=this.readConfigFile();if(n===void 0)return{config:structuredClone(this.defaultConfig)};let r=Dt(structuredClone(this.defaultConfig),ai(n));return{config:t?t(r):r}}catch(n){if(e)return{config:structuredClone(this.defaultConfig),failure:this.loadFailure(n)};return U.warn(y.yellow(`Config file corrupted at ${this.configPath}. Using defaults.`),{output:zt()}),{config:structuredClone(this.defaultConfig),error:n}}}loadFailure(t){return new w(`Cannot read config at ${this.configPath}: ${$e(t)}`,"Repair the file and try again",void 0,{cause:t,tag:fn})}readConfigFile(){try{return Ct.readFileSync(this.configPath,"utf-8")}catch(t){if(wt(t,"ENOENT"))return;throw t}}}function ai(t){let e=JSON.parse(t);if(Array.isArray(e))throw Error("Config must be an object");return La(e)}var ui="0.7.4";import{mkdir as Fu}from"fs/promises";import{dirname as Mu}from"path";var z=Kt();import{existsSync as Di,readFileSync as lu}from"fs";var ci="ATLAS",li="atlas",di="Profile-based env composition for apps and environments",tt=".atlas",kt="config.json",fi="cli-state.json",pi=".env",mn="ATLAS_TRUSTED_DIRS",mi="*",hi={defaults:{profiles:[],exportFile:".env"},profiles:{}};import{realpathSync as ja,statSync as Na}from"fs";import{homedir as Fa}from"os";import{isAbsolute as Ma,resolve as hn}from"path";function gn(t,e,n){if(t!==void 0&&t.trim().length===0)throw new S(`--${e} must not be empty`,n)}function lt(t,e){gn(t,"cwd",e);let n=t===void 0?process.cwd():et(t);if(!Ua(n))throw new S(`Working directory is not a directory: ${n}`,e);return n}function ot(){return process.env.HOME||Fa()}function et(t,e=process.cwd()){if(t==="~")return ot();if(t.startsWith("~/"))return hn(ot(),t.slice(2));if(Ma(t))return t;return hn(e,t)}function jt(t){try{return ja(t)}catch{return hn(t)}}function be(t,e){if(t===void 0)return;let n=Va(t);if(n.length===0)throw new S("--profile must include at least one profile",e);return n}function Ua(t){try{return Na(t,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function Va(t){return t.split(",").map((e)=>e.trim()).filter(Boolean)}import{existsSync as wi,lstatSync as Ga,statSync as gi}from"fs";import{delimiter as Wa,dirname as $n,join as bn,parse as Ba,resolve as yi}from"path";var $i=0,Ja=2,vi="AtlasUntrustedConfig",Ka=/^\d+$/;function Ci(t={}){let e=yi(t.cwd??process.cwd()),n=yi(t.home??ot()),r=bn(n,tt,kt),i=wi(r)?r:void 0,s=Ha(e,n,Xa(t)),o=s?$n($n(s)):void 0;return{cwd:e,globalPath:i,home:n,projectPath:s,projectRoot:o}}function Ha(t,e,n){let r=Ba(t).root,i,s=t;while(!0){let o=bn(s,tt,kt);if(wi(o)){if(i??=jt(e),!(s===e||jt(s)===i))return za(s,o,n),o}if(s===r)return;s=$n(s)}}function Xa(t){let e=t.uid??process.getuid?.();if(e===void 0)return;let n=t.env??process.env,r=e===$i?qa(n.SUDO_UID):void 0;return{owners:new Set([e,$i,...r===void 0?[]:[r]]),trustedDirectories:Ya(n[mn])}}function qa(t){return t!==void 0&&Ka.test(t)?Number(t):void 0}function Ya(t){return(t??"").split(Wa).map((e)=>e.trim()).filter(Boolean)}function za(t,e,n){if(!n||Qa(t,n.trustedDirectories))return;let r=bn(t,tt),i=yn(r,e,Ga),s=yn(r,e,gi),o=yn(e,e,gi),a=[[r,s],[e,o]];for(let[u,c]of[[r,i],...a])if(!n.owners.has(c.uid))throw bi(e,t,`${u} is owned by uid ${c.uid}`);for(let[u,c]of a)if((c.mode&Ja)!==0)throw bi(e,t,`${u} is writable by every user`)}function Qa(t,e){if(e.includes(mi))return!0;if(e.length===0)return!1;let n=jt(t);return e.some((r)=>jt(et(r))===n)}function yn(t,e,n){try{return n(t)}catch(r){throw new w(`Failed to inspect Atlas config ${e}`,`Check that ${t} is readable`,void 0,{cause:r,tag:vi})}}function bi(t,e,n){return new w(`Refusing to use Atlas config ${t}: ${n}`,`Remove it if you did not create it, or trust it with ${mn}=${e}`,void 0,{tag:vi})}var ve=/^[A-Za-z_][A-Za-z0-9_]*$/;class xt extends Error{key;_tag="DotenvUnrepresentableValue";constructor(t){super(`Unrepresentable dotenv value for key ${t}`);this.key=t}}var Za=2,j=1,we=-1,tu=['"',"'","`"],eu=/^\s+#/;function xi(t){let e=Object.create(null),n=t.split(/\r?\n/);for(let r=0;r<n.length;r+=1){let i=r+j,s=n[r]??"",o=s.trim();if(!o||o.startsWith("#"))continue;let a=o.startsWith("export ")?o.slice(7).trimStart():o,u=a.indexOf("=");if(u<0)throw Error(`Invalid dotenv syntax at line ${i}: expected KEY=VALUE`);let c=a.slice(0,u).trim();if(!ve.test(c))throw Error(`Invalid dotenv key at line ${i}`);let l=a.slice(u+1);if(eu.test(l)){e[c]="";continue}let d=l.trim(),p=nu(d,s,n,r);if(p){e[c]=p.value,r=p.endIndex;continue}e[c]=Ei(d)}return e}function Si(t){return Object.keys(t).sort().map((e,n)=>{let r=n+j;if(!ve.test(e))throw Error(`Invalid dotenv key at entry ${r}`);let i=t[e]??"",s=au(i,e);if(Ei(s)!==i)throw new xt(e);return`${e}=${s}`}).join(`
|
|
57
57
|
`).concat(`
|
|
58
|
-
`)}function
|
|
59
|
-
`),i)}}return}function
|
|
60
|
-
`;if(t==="r")return"\r";if(t==="t")return"\t";if(t==='"')return'"';if(t==="\\")return"\\";if(t==="$")return"$";return}function
|
|
61
|
-
`)||t.includes("\r"))&&!t.includes("'")&&!
|
|
62
|
-
`)||t.includes("\r")||t.includes("#"))return!1;if(t.trim()!==t)return!1;return
|
|
63
|
-
`,t.args.force,"Atlas config"),U.success(`Created ${y.green(n)}`),t.output.result({path:n})}});var
|
|
64
|
-
`)}function
|
|
65
|
-
`)}function
|
|
58
|
+
`)}function nu(t,e,n,r){let i=vn(t[0]);if(i===void 0)return;if(wn(t,i,j)!==we)return;let s=e.indexOf(i),o=[e.slice(s+j)];for(let a=r+1;a<n.length;a+=1){let u=n[a]??"",c=wn(u,i,0);if(c===we){o.push(u);continue}if(!_i(u,c+j))return;return o.push(u.slice(0,c)),{endIndex:a,value:Ti(o.join(`
|
|
59
|
+
`),i)}}return}function Ei(t){let e=vn(t[0]);if(e!==void 0){let n=ru(t,e);if(n!==void 0)return Ti(n,e)}return Ii(iu(t).trimEnd())}function vn(t){return tu.find((e)=>e===t)}function Ti(t,e){return e==='"'?su(t):Ii(t)}function ru(t,e){let n=wn(t,e,j);if(n===we)return;if(!_i(t,n+j))return;return t.slice(j,n)}function _i(t,e){let n=t.slice(e).trimStart();return!n||n.startsWith("#")}function wn(t,e,n){for(let r=n;r<t.length;r+=1)if(t[r]===e&&!Oi(t,r))return r;return we}function Oi(t,e){let n=0;for(let r=e-j;t[r]==="\\";r-=1)n+=1;return n%Za===j}function iu(t){let e=t.search(/\s#/);return e<0?t:t.slice(0,e)}function su(t){let e="";for(let n=0;n<t.length;n+=1){let r=t[n];if(r!=="\\"||n+j>=t.length){e+=r;continue}let i=t[n+j],s=ou(i);if(s===void 0){e+=r;continue}e+=s,n+=j}return e}function ou(t){if(t==="n")return`
|
|
60
|
+
`;if(t==="r")return"\r";if(t==="t")return"\t";if(t==='"')return'"';if(t==="\\")return"\\";if(t==="$")return"$";return}function Ii(t){let e="";for(let n=0;n<t.length;n+=1){if(t[n]==="\\"&&t[n+j]==="$"){e+="$",n+=j;continue}e+=t[n]}return e}function au(t,e){if(t.includes("\x00"))throw new xt(e);if(t==="")return"";let n=Ai(t);if(uu(t))return n;if(!(t.includes(`
|
|
61
|
+
`)||t.includes("\r"))&&!t.includes("'")&&!Oi(t,t.length))return`'${n}'`;if(!t.includes('"')&&!t.includes("\\"))return`"${cu(t)}"`;throw new xt(e)}function uu(t){if(t.includes(`
|
|
62
|
+
`)||t.includes("\r")||t.includes("#"))return!1;if(t.trim()!==t)return!1;return vn(t[0])===void 0}function Ai(t){return t.replace(/\$(?!$)/g,"\\$&")}function cu(t){return Ai(t).replace(/\n/g,"\\n").replace(/\r/g,"\\r")}var du="must be a valid environment variable name matching [A-Za-z_][A-Za-z0-9_]*",fu=new Set(Object.getOwnPropertyNames(Object.prototype)),pu=zr().or(rn()),mu=nn().or(rn()),Li=nn(),hu=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),gu="\x00",yu="AtlasNulValue",$u="AtlasInvalidEncoding";class V extends Error{_tag="AtlasConfigValidationError"}function ft(t={}){let e=Ci(t),n=Ri(e.globalPath,e.home,"global"),r=Ri(e.projectPath,e.projectRoot,"project"),i=dt(),s=dt();for(let a of[n,r]){if(!a)continue;for(let[u,c]of Object.entries(a.config.profiles)){let l=Object.hasOwn(i,u)?i[u]?.path:void 0;s[u]=c,i[u]={layer:a.layer,path:a.path,rootDir:a.rootDir,shadows:l}}}return{config:{defaults:{...n?.config.defaults,...r?.config.defaults,profiles:[...n?.config.defaults?.profiles??[],...r?.config.defaults?.profiles??[]]},profiles:s},cwd:e.cwd,globalPath:e.globalPath,home:e.home,profileSources:i,projectPath:e.projectPath,projectRoot:e.projectRoot}}function Ce(t,e={}){let n=[...t.config.defaults?.profiles??[],...e.profiles??[]],r=dt(),i=[],s=new Set,o=e.env??process.env;function a(u,c){if(s.has(u))return;let l=Object.hasOwn(t.config.profiles,u)?t.config.profiles[u]:void 0;if(!l)throw new w(`Unknown Atlas profile: ${u}`,"Run 'atlas profiles list'");if(c.includes(u))throw new w(`Profile inheritance cycle: ${[...c,u].join(" -> ")}`);for(let m of l.extends??[])a(m,[...c,u]);let p=(Object.hasOwn(t.profileSources,u)?t.profileSources[u]:void 0)?.rootDir??t.projectRoot??t.cwd;for(let m of l.envFiles??[]){let f=et(m,p);Cn(r,_u(f),`env file ${f}`)}Cn(r,l.vars??{},`the vars of profile ${u}`);for(let[m,f]of Object.entries(l.secrets??{})){let h=Ou(m,f,p,o);if(h!==void 0)Cn(r,{[m]:h},`the secrets of profile ${u}`)}s.add(u),i.push(u)}for(let u of n)a(u,[]);return{env:r,exportFile:Sn(t),profiles:i}}function Sn(t){return et(t.config.defaults?.exportFile??pi,t.projectRoot??t.cwd)}function Cn(t,e,n){for(let[r,i]of Object.entries(e)){if(i.includes(gu))throw new w(`Value of ${r} from ${n} contains a NUL byte`,"Environment values cannot hold NUL bytes; remove it from the source",void 0,{tag:yu});t[r]=i}}function Ri(t,e,n){if(!t||!e)return;let r,i=Iu(t,`Atlas config ${t}`);try{r=JSON.parse(i)}catch(s){if(s instanceof SyntaxError)throw new w(`Invalid JSON in Atlas config ${t}`,"Fix the JSON syntax in the config file");throw s}try{return{config:bu(r),layer:n,path:t,rootDir:e}}catch(s){let o=s instanceof V?s.message:"config failed validation";throw new w(`Invalid Atlas config at ${t}: ${o}`)}}function bu(t){let e=Ee(t,"config",["$schema","defaults","profiles"]);return Lt({$schema:(n)=>xe(n,"$schema"),defaults:(n)=>wu(n,"defaults"),profiles:(n)=>vu(n,"profiles")})(e)}function wu(t,e){if(t===void 0)return;let n=Ee(t,e,["exportFile","profiles"]);return Lt({exportFile:(r)=>ki(r,`${e}.exportFile`),profiles:(r)=>xn(r,`${e}.profiles`)})(n)}function vu(t,e){if(t===void 0)return dt();let n=Se(t,e),r=dt();for(let i of Object.keys(n)){let s=Tn(e,i);if(fu.has(i))throw new V(`${s} must not use a prototype-sensitive profile name`);r[i]=Cu(n[i],s)}return r}function Cu(t,e){let n=Ee(t,e,["description","envFiles","extends","secrets","vars"]);return Lt({description:(r)=>xe(r,`${e}.description`),envFiles:(r)=>xn(r,`${e}.envFiles`),extends:(r)=>xn(r,`${e}.extends`),secrets:(r)=>Su(r,`${e}.secrets`),vars:(r)=>xu(r,`${e}.vars`)})(n)}function xu(t,e){if(t===void 0)return;let n=Se(t,e),r=dt();for(let i of Object.keys(n)){let s=Tn(e,i);En(i,s),r[i]=Te(Li,n[i],s,"must be a string")}return r}function Su(t,e){if(t===void 0)return;let n=Se(t,e),r=dt();for(let i of Object.keys(n)){let s=Tn(e,i);En(i,s),r[i]=Eu(n[i],s)}return r}function Eu(t,e){let n=Ee(t,e,["env","file","optional","trim"]),r=Lt({env:(i)=>Tu(i,`${e}.env`),file:(i)=>ki(i,`${e}.file`),optional:(i)=>Pi(i,`${e}.optional`),trim:(i)=>Pi(i,`${e}.trim`)})(n);if(r.env===void 0&&r.file===void 0)throw new V(`${e} must define env or file`);if(r.env!==void 0&&r.file!==void 0)throw new V(`${e} must define only one of env or file`);if(r.env!==void 0&&r.trim!==void 0)throw new V(`${e}.trim only applies to file secrets`);return r}function xn(t,e){if(t===void 0)return;if(!Array.isArray(t))throw new V(`${e} must be an array`);return t.map((n,r)=>{let i=`${e}[${r}]`,s=Te(Li,n,i,"must be a string");return ji(s,i)})}function ki(t,e){let n=xe(t,e);return n===void 0?void 0:ji(n,e)}function ji(t,e){if(t.trim().length===0)throw new V(`${e} must be a non-empty string`);return t}function xe(t,e){return Te(mu,t,e,"must be a string")}function Tu(t,e){let n=xe(t,e);if(n===void 0)return;return En(n,e),n}function Pi(t,e){return Te(pu,t,e,"must be a boolean")}function Se(t,e){if(typeof t!=="object"||t===null||Array.isArray(t))throw new V(`${e} must be an object`);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n!==null)throw new V(`${e} must be an object`);return t}function Ee(t,e,n){let r=Se(t,e);for(let i of Object.keys(r))if(!n.includes(i))throw new V(`${e} has unknown key ${JSON.stringify(i)}`);return r}function En(t,e){if(!ve.test(t))throw new V(`${e} ${du}`)}function Te(t,e,n,r){try{return t(e)}catch{throw new V(`${n} ${r}`)}}function Tn(t,e){return`${t}[${JSON.stringify(e)}]`}function dt(){return Object.create(null)}function _u(t){if(!Di(t))throw new w(`Atlas env file not found: ${t}`,"Create the file or remove it from the profile's envFiles");let e=Ni(t,`Atlas env file ${t}`);try{return xi(e)}catch(n){let r=n instanceof Error?n.message:"env file failed to parse";throw new w(`Invalid dotenv file ${t}: ${r}`,"Fix the reported line in the env file")}}function Ou(t,e,n,r){if(e.env){let i=Object.hasOwn(r,e.env)?r[e.env]:void 0;if(i!==void 0)return i;if(e.optional)return;throw new w(`Missing required secret ${t}: env ${e.env} is not set`,`Set ${e.env} or mark the secret optional`)}if(e.file){let i=et(e.file,n);if(!Di(i)){if(e.optional)return;throw new w(`Missing required secret ${t}: file ${i} does not exist`,"Create the file or mark the secret optional")}let s=Ni(i,`secret file ${i} for ${t}`);return e.trim===!1?s:s.trim()}if(e.optional)return;throw new w(`Missing required secret ${t}: secret ref must define env or file`)}function Ni(t,e){let n=Fi(t,e);try{return hu.decode(n)}catch{throw new w(`Failed to read ${e}: it is not valid UTF-8`,"Save the file as UTF-8 text",void 0,{tag:$u})}}function Iu(t,e){return Fi(t,e).toString("utf8")}function Fi(t,e){try{return lu(t)}catch(n){throw new w(`Failed to read ${e}`,"Check that the path is a readable file",void 0,{cause:n})}}import{randomUUID as Au}from"crypto";import{link as Ru,lstat as Pu,open as Du,rename as Lu,rm as Mi}from"fs/promises";import{basename as ku,dirname as ju,join as Nu}from"path";var Ui=384;async function _e(t,e,n,r="Output file"){let i=await Pu(t).catch((a)=>{if(wt(a,"ENOENT"))return null;throw a});if(i&&!i.isFile()&&!i.isSymbolicLink())throw new w(`Output path is not a regular file: ${t}`);let s=Nu(ju(t),`.${ku(t)}.${Au()}.tmp`),o=null;try{if(o=await Du(s,"wx",Ui),await o.chmod(Ui),await o.writeFile(e,"utf8"),await o.sync(),await o.close(),o=null,n)await Lu(s,t);else await Ru(s,t).catch((a)=>{if(wt(a,"EEXIST"))throw new w(`${r} already exists: ${t}`,"Use --force to overwrite it");throw a}),await Mi(s)}catch(a){throw await o?.close().catch(()=>{return}),await Mi(s,{force:!0}).catch(()=>{return}),a}}var Uu="Usage: atlas export --profile <name,...>",Vu="Usage: atlas export --cwd <dir>",Gu="Usage: atlas export --out <path>",Vi=z({args:K({cwd:{description:"Working directory override",type:"string"},force:{alias:"f",default:!1,description:"Overwrite an existing file",type:"boolean"},out:{alias:"o",description:"Output .env path",type:"string"},profile:{alias:"p",description:"Comma-separated profiles to apply",type:"string"},stdout:{default:!1,description:"Print to stdout instead of writing a file",type:"boolean"}}),description:"Export resolved Atlas env to a dotenv file",examples:["atlas export --profile app:web,env:dev --out .env.local","atlas export --profile env:dev --stdout","atlas export --profile env:dev --json"],json:!0,name:"export",run:async(t)=>{if(t.args.stdout&&t.args.out!==void 0)throw new S("--stdout cannot be combined with --out","Use --stdout to print, or --out <path> to write a file");if(t.args.stdout&&t.json)throw new S("--stdout cannot be combined with --json","Use --stdout for the dotenv body, or --json for a summary of the written file");gn(t.args.out,"out",Gu);let e=lt(t.args.cwd,Vu),n=be(t.args.profile,Uu),r=ft({cwd:e}),i=Ce(r,{profiles:n}),s=Wu(i.env);if(t.args.stdout){process.stdout.write(s);return}let o=t.args.out!==void 0?et(t.args.out,r.cwd):i.exportFile;await Fu(Mu(o),{recursive:!0}),await _e(o,s,t.args.force);let a=i.profiles.length>0?i.profiles.join(", "):"no profiles";U.success(`Wrote ${y.green(o)} using ${a}`),t.output.result({keys:Object.keys(i.env).sort(),path:o,profiles:i.profiles})}});function Wu(t){try{return Si(t)}catch(e){if(!(e instanceof xt))throw e;throw new w(e.message,`Change the value of ${e.key}, or pass it with 'atlas run', which needs no dotenv file`,void 0,{tag:e._tag})}}import{mkdir as Bu}from"fs/promises";import{join as Gi}from"path";var Ju=2,Wi=z({args:K({force:{alias:"f",default:!1,description:"Overwrite an existing config",type:"boolean"},global:{alias:"g",default:!1,description:"Write ~/.atlas/config.json",type:"boolean"}}),description:"Create an Atlas config",examples:["atlas init","atlas init --global --json"],json:!0,name:"init",run:async(t)=>{let e=t.args.global?ot():process.cwd(),n=Gi(e,tt,kt);await Bu(Gi(e,tt),{recursive:!0}),await _e(n,`${JSON.stringify(hi,null,Ju)}
|
|
63
|
+
`,t.args.force,"Atlas config"),U.success(`Created ${y.green(n)}`),t.output.result({path:n})}});var Ku=2;function Bi(t){let e=Object.keys(t.config.profiles).sort();return{defaults:{exportFile:Sn(t),profiles:t.config.defaults?.profiles??[]},globalPath:t.globalPath??null,profiles:e.flatMap((n)=>{let r=Xi(t,n);return r?[r]:[]}),projectPath:t.projectPath??null}}function Ji(t,e){let n=Xi(t,e),r=Object.hasOwn(t.config.profiles,e)?t.config.profiles[e]:void 0;if(!n||!r)return;let{description:i,...s}=n;return{...s,profile:r}}function Ki(t){return[...t.profiles.length===0?["No Atlas profiles configured"]:t.profiles.map((n)=>{let r=n.description?y.dim(` - ${n.description}`):"";return`${y.cyan(n.name)}${r}${y.dim(` (${n.layer})`)}`}),"",...Hu(t)].join(`
|
|
64
|
+
`)}function Hi(t){let e=t.shadows?`, overrides ${t.shadows}`:"";return[`${y.bold(t.name)} ${y.dim(`(${t.layer}: ${t.path}${e})`)}`,JSON.stringify(t.profile,null,Ku)].join(`
|
|
65
|
+
`)}function Hu(t){let e=t.defaults.profiles.length>0?t.defaults.profiles.join(", "):"none";return[y.dim(`Global config: ${t.globalPath??"none"}`),y.dim(`Project config: ${t.projectPath??"none"}`),y.dim(`Default profiles: ${e}`),y.dim(`Export file: ${t.defaults.exportFile}`)]}function Xi(t,e){let n=Object.hasOwn(t.config.profiles,e)?t.config.profiles[e]:void 0,r=Object.hasOwn(t.profileSources,e)?t.profileSources[e]:void 0;if(!n||!r)return;return{description:n.description??null,layer:r.layer,name:e,path:r.path,shadows:r.shadows??null}}var qi="Usage: atlas profiles <list|show> --cwd <dir>",Xu=z({args:K({cwd:{description:"Working directory override",type:"string"}}),description:"List available profiles and the configs they come from",examples:["atlas profiles list","atlas profiles list --cwd apps/web --json"],json:!0,name:"list",run:async(t)=>{let e=ft({cwd:lt(t.args.cwd,qi)});t.output.result(Bi(e),Ki)}}),qu=z({args:K({cwd:{description:"Working directory override",type:"string"}}),description:"Show one Atlas profile and its source",examples:["atlas profiles show app:web","atlas profiles show app:web --json"],json:!0,name:"show",positionals:gt({profile:{description:"Profile name",required:!0}}),run:async(t)=>{let e=ft({cwd:lt(t.args.cwd,qi)}),n=Ji(e,t.positionals.profile);if(!n)throw new w(`Unknown Atlas profile: ${t.positionals.profile}`,"Run 'atlas profiles list'");t.output.result(n,Hi)}}),Yi=z({description:"Inspect Atlas profiles",name:"profiles",subcommands:[Xu,qu]});var Yu=127,zu=126,Qu="Usage: atlas run --profile <name,...> <command...>",Zu="Usage: atlas run --cwd <dir> <command...>",tc="AtlasSpawnFailed",ec=["SIGTERM","SIGHUP","SIGUSR1","SIGUSR2"],zi=["SIGINT","SIGQUIT"],Qi=z({args:K({cwd:{description:"Working directory override",type:"string"},profile:{alias:"p",description:"Comma-separated profiles to apply",type:"string"}}),description:"Run a command with resolved Atlas env; Atlas options go before the command",examples:["atlas run --profile app:web,env:dev bun dev --hot","atlas run --cwd apps/web -- make test"],name:"run",passthrough:!0,positionals:gt({command:{description:"Command and its arguments, passed on unchanged",required:!0,variadic:!0}}),run:async(t)=>{let e=lt(t.args.cwd,Zu),n=be(t.args.profile,Qu),r=nc(e,n);return await sc(rc(t.positionals.command,e,r))}});function nc(t,e){let n=Ce(ft({cwd:t}),{profiles:e});return{...Object.fromEntries(Object.entries(process.env).filter((i)=>i[1]!==void 0)),...n.env}}function rc(t,e,n){try{return Bun.spawn(t,{cwd:e,env:n,stderr:"inherit",stdin:"inherit",stdout:"inherit"})}catch(r){throw ic(t[0]??"",r)}}function ic(t,e){let n=ut(e);if(n==="ENOENT")return new w(`Command not found: ${t}`,"Check that it is installed and on PATH",Yu);if(n==="EACCES")return new w(`Command is not executable: ${t}`,"Check the executable permissions",zu);return new w(`Failed to start command: ${t}${n?` (${n})`:""}`,"Check the command, its arguments and the resolved environment",void 0,{tag:tc})}async function sc(t){let e=oc(),n=[...ec,...zi].map((r)=>{let s=e&&zi.includes(r)?()=>{return}:()=>t.kill(r);return process.on(r,s),{handler:s,signal:r}});try{return await t.exited}finally{for(let{handler:r,signal:i}of n)process.off(i,r)}}function oc(){return process.stdin.isTTY===!0||process.stdout.isTTY===!0||process.stderr.isTTY===!0}function Zi(t=new pn(ac(ot(),tt,fi),{})){return tn({bin:li,commands:[Wi,Yi,Qi,Vi],config:t,description:di,interactive:{clearOnStart:!1},name:ci,version:ui})}Zi().main();
|
package/package.json
CHANGED