@r5n/atlas 0.6.6 → 0.7.1
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/README.md +16 -3
- package/dist/cli.js +56 -51
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ atlas run --profile env:dev -- bun --version
|
|
|
40
40
|
atlas export --profile env:dev
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
Put
|
|
43
|
+
Put Atlas options before the command. Everything from the first word of the command on goes to the child unchanged, so the child's own flags never change Atlas options; `--` before the command is optional. The export uses `.env.generated` from the defaults; add `--out <path>` to choose another file.
|
|
44
44
|
|
|
45
45
|
## Everyday commands
|
|
46
46
|
|
|
@@ -49,9 +49,22 @@ Put child-command flags after `--`. The export uses `.env.generated` from the de
|
|
|
49
49
|
| Initialise project or global config | `atlas init [--global]` |
|
|
50
50
|
| List available profiles | `atlas profiles list` |
|
|
51
51
|
| Inspect a profile | `atlas profiles show <profile>` |
|
|
52
|
-
| Combine profiles for a process | `atlas run --profile app:web,env:dev
|
|
52
|
+
| Combine profiles for a process | `atlas run --profile app:web,env:dev <command...>` |
|
|
53
53
|
| Export a dotenv file | `atlas export --profile app:web,env:dev --out <path>` |
|
|
54
54
|
| Print dotenv to stdout | `atlas export --profile env:dev --stdout` |
|
|
55
|
+
| Describe every command as JSON | `atlas --help --json` |
|
|
56
|
+
|
|
57
|
+
## Scripts and agents
|
|
58
|
+
|
|
59
|
+
`--json` (or `-j`) is a global flag: `init`, `export`, `profiles list` and `profiles show` then write exactly one JSON document to stdout, and every log line goes to stderr. A failure writes `{ "error": { "_tag", "message", "hint", "exitCode", "causes" } }` to stdout instead. `run` does not accept `--json`, because the child owns stdout.
|
|
60
|
+
|
|
61
|
+
| Exit code | Meaning |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| 0 | Success |
|
|
64
|
+
| 1 | Failure, such as an unknown profile, a missing secret or an untrusted config |
|
|
65
|
+
| 2 | Usage error: unknown or repeated option, blank value, missing `--cwd` directory |
|
|
66
|
+
| 126, 127 | `atlas run` could not execute the command, or did not find it |
|
|
67
|
+
| other | `atlas run` returns the child's exit code, or 128 plus the signal number when a signal ended it |
|
|
55
68
|
|
|
56
69
|
## How profiles combine
|
|
57
70
|
|
|
@@ -59,7 +72,7 @@ Atlas merges global `~/.atlas/config.json` with the nearest project `.atlas/conf
|
|
|
59
72
|
|
|
60
73
|
The [configuration reference](https://github.com/r5n-labs/clis/blob/develop/packages/atlas/docs/reference.md) explains precedence, inheritance, secret references, dotenv parsing and export limits. Atlas preserves literal `$` references rather than expanding them.
|
|
61
74
|
|
|
62
|
-
Project configuration is applied automatically, and secret file references may point outside the project. Review a repository's `.atlas/config.json` before using Atlas inside it.
|
|
75
|
+
Project configuration is applied automatically, and secret file references may point outside the project. Review a repository's `.atlas/config.json` before using Atlas inside it. Atlas refuses a discovered project config owned by another user or writable by every user; set `ATLAS_TRUSTED_DIRS` to trust a specific project root. The installed `atlas` binary does not load the caller's `.env` files. See the [trust model](https://github.com/r5n-labs/clis/blob/develop/packages/atlas/docs/reference.md#trust-model).
|
|
63
76
|
|
|
64
77
|
For source commands, builds and checks, see the [development guide](https://github.com/r5n-labs/clis/blob/develop/packages/atlas/docs/development.md).
|
|
65
78
|
|
package/dist/cli.js
CHANGED
|
@@ -1,60 +1,65 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
1
|
+
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
-
var Nn=Object.create;var{getPrototypeOf:Mn,defineProperty:$e,getOwnPropertyNames:Ln}=Object;var ye=Object.prototype.hasOwnProperty;function jn(t){return this[t]}var Vn,Un,be=(t,e,n)=>{var s=t!=null&&typeof t==="object";if(s){var i=e?Vn??=new WeakMap:Un??=new WeakMap,r=i.get(t);if(r)return r}n=t!=null?Nn(Mn(t)):{};let o=e||!t||!t.__esModule||!ye.call(t,"default")?$e(n,"default",{value:t,enumerable:!0}):n;if(t&&typeof t==="object"||typeof t==="function"){for(let a of Ln(t))if(!ye.call(o,a))$e(o,a,{get:jn.bind(t,a),enumerable:!0})}if(s)i.set(t,o);return o};var Gn=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Vt=Gn(function(pr,De){var jt={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"},ns={up:(t=1)=>"\x1B[S".repeat(t),down:(t=1)=>"\x1B[T".repeat(t)},ss={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?jt.up():"");if(t)e+=jt.left;return e}};De.exports={cursor:jt,scroll:ns,erase:ss,beep:"\x07"}});import{join as sr}from"path";class W extends Error{constructor(t="Operation cancelled"){super(t)}}class g extends Error{hint;exitCode;constructor(t,e,n=1){super(t);this.hint=e;this.exitCode=n}}import{stdout as Fe,stdin as is}from"process";import rs from"readline";var ve=(()=>{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}})(),we=(t)=>t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510,xe=(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 Hn=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Bn=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Ce=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Wn=/\t{1,1000}/y,Se=/[\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,Jn=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Kn=/\p{M}+/gu,qn={limit:1/0,ellipsis:""},Ae=(t,e={},n={})=>{let s=e.limit??1/0,i=e.ellipsis??"",r=e?.ellipsisWidth??(i?Ae(i,qn,n).width:0),o=0,a=n.controlWidth??0,l=n.tabWidth??8,c=n.emojiWidth??2,u=2,h=n.regularWidth??1,f=n.wideWidth??2,m=[[Jn,h],[Hn,0],[Bn,a],[Wn,l],[Se,c],[Ce,f]],d=0,b=0,E=t.length,_=0,x=!1,P=E,R=Math.max(0,s-r),C=0,O=0,T=0,p=0;t:while(!0){if(O>C||b>=E&&b>d){let S=t.slice(C,O)||t.slice(d,b);_=0;for(let D of S.replaceAll(Kn,"")){let F=D.codePointAt(0)||0;if(we(F))p=2;else if(xe(F))p=f;else p=h;if(T+p>R)P=Math.min(P,Math.max(C,d)+_);if(T+p>s){x=!0;break t}_+=D.length,T+=p}C=O=0}if(b>=E)break t;for(let S=0,D=m.length;S<D;S++){let[F,ge]=m[S];if(F.lastIndex=b,F.test(t)){if(_=F===Ce?ve(t.slice(b,F.lastIndex)):F===Se?1:F.lastIndex-b,p=_*ge,T+p>R)P=Math.min(P,b+Math.floor((R-T)/ge));if(T+p>s){x=!0;break t}T+=p,C=d,O=b,b=d=F.lastIndex;continue t}}b+=1}return{width:x?R:T,index:x?P:E,truncated:x,ellipsed:x&&s>=r}},Ee=Ae;var Xn={limit:1/0,ellipsis:"",ellipsisWidth:0},zn=(t,e={})=>Ee(t,Xn,e).width,U=zn;var lt="\x1B",Oe="\x9B",Yn=39,Mt="\x07",Pe="[",Qn="]",ke="m",Lt=`${Qn}8;;`,Ie=new RegExp(`(?:\\${Pe}(?<code>\\d+)m|\\${Lt}(?<uri>.*)${Mt})`,"y"),_e=(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},Te=(t)=>`${lt}${Pe}${t}${ke}`,Re=(t)=>`${lt}${Lt}${t}${Mt}`,Nt=(t,e,n)=>{let s=e[Symbol.iterator](),i=!1,r=!1,o=t.at(-1),a=o===void 0?0:U(o),l=s.next(),c=s.next(),u=0;while(!l.done){let h=l.value,f=U(h);if(a+f<=n)t[t.length-1]+=h;else t.push(h),a=0;if(h===lt||h===Oe)i=!0,r=e.startsWith(Lt,u+1);if(i){if(r){if(h===Mt)i=!1,r=!1}else if(h===ke)i=!1}else if(a+=f,a===n&&!c.done)t.push(""),a=0;l=c,c=s.next(),u+=h.length}if(o=t.at(-1),!a&&o!==void 0&&o.length&&t.length>1)t[t.length-2]+=t.pop()},Zn=(t)=>{let e=t.split(" "),n=e.length;while(n){if(U(e[n-1]))break;n--}if(n===e.length)return t;return e.slice(0,n).join(" ")+e.slice(n).join("")},ts=(t,e,n={})=>{if(n.trim!==!1&&t.trim()==="")return"";let s="",i,r,o=t.split(" "),a=[""],l=0;for(let h=0;h<o.length;h++){let f=o[h];if(n.trim!==!1){let d=a.at(-1)??"",b=d.trimStart();if(d.length!==b.length)a[a.length-1]=b,l=U(b)}if(h!==0){if(l>=e&&(n.wordWrap===!1||n.trim===!1))a.push(""),l=0;if(l||n.trim===!1)a[a.length-1]+=" ",l++}let m=U(f);if(n.hard&&m>e){let d=e-l,b=1+Math.floor((m-d-1)/e);if(Math.floor((m-1)/e)<b)a.push("");Nt(a,f,e),l=U(a.at(-1)??"");continue}if(l+m>e&&l&&m){if(n.wordWrap===!1&&l<e){Nt(a,f,e),l=U(a.at(-1)??"");continue}a.push(""),l=0}if(l+m>e&&n.wordWrap===!1){Nt(a,f,e),l=U(a.at(-1)??"");continue}a[a.length-1]+=f,l+=m}if(n.trim!==!1)a=a.map((h)=>Zn(h));let c=a.join(`
|
|
4
|
-
`),
|
|
5
|
-
`)
|
|
6
|
-
`){if(i&&
|
|
7
|
-
`)
|
|
8
|
-
`)
|
|
9
|
-
`)
|
|
10
|
-
`).
|
|
11
|
-
`)
|
|
12
|
-
`),
|
|
13
|
-
`).
|
|
14
|
-
`);this.output.
|
|
15
|
-
`).
|
|
16
|
-
`)
|
|
17
|
-
`);
|
|
18
|
-
`)
|
|
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 Bn(){return A.documentWritten}function Jn(){A.sealed=!0}function Z(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(!Xt(n,process.stdout))throw n;A.stdoutClosed=!0}}function Kn(){if(A.outputGuarded)return;A.outputGuarded=!0,process.stdout.write=Un(process.stdout.write,!0),console.write=Un(console.write,0),process.stdout.on("error",(t)=>{if(!Xt(t,process.stdout))throw t;A.stdoutClosed=!0}),process.stderr.on("error",(t)=>{if(!Xt(t,process.stderr))throw t});for(let t of[process.stdout,process.stderr])t.once("close",()=>A.closedStreams.add(t))}function Un(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(!Xt(s,process.stdout))throw s;return A.stdoutClosed=!0,n(i)}}}function Xt(t,e){if(!(t instanceof Error))return!1;let n=Reflect.get(t,"code");return n===_s||n===Os&&e.isTTY===!0}function qt(){let t=Ht(process.stderr);return new vs({decodeStrings:!1,write(e,n,r){process.stderr.write(t?e:xs(e)),r()}})}async function Hn(t,e){if(!t)return e();A.jsonRuns+=1,A.restoreStdout??=Is(),it.active=!0;try{return await e()}finally{if(A.jsonRuns-=1,it.active=A.jsonRuns>0,!it.active&&!A.outputGuarded)A.restoreStdout?.(),A.restoreStdout=void 0}}async function Xn(t){let e=Promise.all([A.stdoutClosed?void 0:Vn(process.stdout),Vn(process.stderr)]);await(t===void 0?e:Promise.race([e,Bun.sleep(t)]))}function Vn(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 Is(){let t=process.stdout.write,e=new ws({stderr:process.stderr,stdout:process.stderr}),n=Object.fromEntries(Es.map((i)=>[i,console[i]])),r=Object.fromEntries(Gn.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:As(e),write:Rs}),()=>{process.stdout.write=t,Object.assign(console,n),A.stdoutWrite=void 0}}function As(t){let e=(...n)=>{let r={};Error.captureStackTrace(r,e);let i=r.stack?.split(`
|
|
5
|
+
`).slice(Ts)??[];t.error([`Trace: ${Cs(...n)}`,...i].join(`
|
|
6
|
+
`))};return e}function Rs(...t){let e=Buffer.concat(t.map(Ps));return process.stderr.write(e),e.byteLength}function Ps(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"}},gt={help:G.help,json:G.json},ut="help",Yt={[j]:"success",[vt]:"failure",[Tn]:"usage error"};import{stripVTControlCharacters as We}from"util";import{stdout as cr,stdin as Ks}from"process";import Hs from"readline";var qn=(()=>{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}})(),Yn=(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 Ds=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Ls=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Qn=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,ks=/\t{1,1000}/y,Zn=/[\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,Ns=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,js=/\p{M}+/gu,Fs={limit:1/0,ellipsis:""},tr=(t,e={},n={})=>{let r=e.limit??1/0,i=e.ellipsis??"",s=e?.ellipsisWidth??(i?tr(i,Fs,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=[[Ns,d],[Ds,0],[Ls,a],[ks,u],[Zn,c],[Qn,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(js,"")){let M=F.codePointAt(0)||0;if(Yn(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,En]=m[T];if(M.lastIndex=h,M.test(t)){if(_=M===Qn?qn(t.slice(h,M.lastIndex)):M===Zn?1:M.lastIndex-h,g=_*En,I+g>R)D=Math.min(D,h+Math.floor((R-I)/En));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}},er=tr;var Ms={limit:1/0,ellipsis:"",ellipsisWidth:0},Us=(t,e={})=>er(t,Ms,e).width,W=Us;var zt="\x1B",or="\x9B",Vs=39,ke="\x07",ar="[",Gs="]",ur="m",Ne=`${Gs}8;;`,nr=new RegExp(`(?:\\${ar}(?<code>\\d+)m|\\${Ne}(?<uri>.*)${ke})`,"y"),rr=(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},ir=(t)=>`${zt}${ar}${t}${ur}`,sr=(t)=>`${zt}${Ne}${t}${ke}`,Le=(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===or)i=!0,s=e.startsWith(Ne,l+1);if(i){if(s){if(d===ke)i=!1,s=!1}else if(d===ur)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()},Ws=(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("")},Bs=(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("");Le(a,p,e),u=W(a.at(-1)??"");continue}if(u+m>e&&u&&m){if(n.wordWrap===!1&&u<e){Le(a,p,e),u=W(a.at(-1)??"");continue}a.push(""),u=0}if(u+m>e&&n.wordWrap===!1){Le(a,p,e),u=W(a.at(-1)??"");continue}a[a.length-1]+=p,u+=m}if(n.trim!==!1)a=a.map((d)=>Ws(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===or){nr.lastIndex=d+1;let f=nr.exec(c)?.groups;if(f?.code!==void 0){let h=Number.parseFloat(f.code);i=h===Vs?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+=sr("");let m=i?rr(i):void 0;if(i&&m)r+=ir(m)}else if(p===`
|
|
9
|
+
`){if(i&&rr(i))r+=ir(i);if(s)r+=sr(s)}}return r},Js=/\r?\n/;function yt(t,e,n){return String(t).normalize().split(Js).map((r)=>Bs(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 Ot={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 Zt(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?Zt(s,e<0?-1:1,n):s}var Xs=["up","down","left","right","space","enter","cancel"],qs=["January","February","March","April","May","June","July","August","September","October","November","December"],B={actions:new Set(Xs),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 lr(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 dr(t,e){if(typeof t=="string")return B.aliases.get(t)===e;for(let n of t)if(n!==void 0&&dr(n,e))return!0;return!1}function Ys(t,e){if(t===e)return;let n=t.split(`
|
|
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 kc=globalThis.process.platform.startsWith("win"),te=Symbol("clack:cancel");function ee(t){return t===te}function Qt(t,e){let n=t;n.isTTY&&n.setRawMode(e)}var It=(t)=>("columns"in t)&&typeof t.columns=="number"?t.columns:80,je=(t)=>("rows"in t)&&typeof t.rows=="number"?t.rows:20;function At(t,e,n,r=n,i=n,s){let o=It(t??cr),a=W(n);return yt(e,o-a,{hard:!0,trim:!1}).split(`
|
|
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 fr(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 zs=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";get accessible(){return lr(this.opts.accessible)}constructor(e,n=!0){let{input:r=Ks,output:i=cr,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(te);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=Hs.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),Qt(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),Qt(this.input,!1),e(this.value)}),this.once("cancel",()=>{this.output.write(X.show),this.output.off("resize",this.render),Qt(this.input,!1),e(te)})})}_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=fr(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")}dr([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
|
+
`),Qt(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=yt(this._prevFrame,It(this.output),{hard:!0,trim:!1}).split(`
|
|
16
|
+
`).length-1;this.output.write(X.move(-999,e*-1))}render(){let e=yt(this._render(this)??"",It(this.output),{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state==="initial")this.output.write(X.hide);else{let n=Ys(this._prevFrame,e),r=je(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(Ot.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(Ot.down());let a=e.split(`
|
|
18
|
+
`).slice(o);this.output.write(a.join(`
|
|
19
|
+
`)),this._prevFrame=e;return}}this.output.write(Ot.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}};var pr=class extends zs{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?Zt(r,1,this.options):r,this.changeValue(),this.on("cursor",(i)=>{switch(i){case"left":case"up":this.cursor=Zt(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=Zt(this.cursor,1,this.options);break}this.changeValue()})}};import{styleText as b,stripVTControlCharacters as Yc}from"util";import q from"process";function Qs(){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 yr=Qs();var O=(t,e)=>yr?t:e,mr=O("\u25C6","*"),$r=O("\u25A0","x"),br=O("\u25B2","x"),Fe=O("\u25C7","o"),Zs=O("\u250C","T"),k=O("\u2502","|"),Me=O("\u2514","\u2014"),el=O("\u2510","T"),nl=O("\u2518","\u2014"),to=O("\u25CF",">"),hr=O("\u25CB"," "),rl=O("\u25FB","[\u2022]"),il=O("\u25FC","[+]"),sl=O("\u25FB","[ ]"),ol=O("\u25AA","\u2022"),al=O("\u2500","-"),ul=O("\u256E","+"),cl=O("\u251C","+"),ll=O("\u256F","+"),dl=O("\u2570","+"),fl=O("\u256D","+"),eo=O("\u25CF","\u2022"),no=O("\u25C6","*"),ro=O("\u25B2","!"),io=O("\u25A0","x"),so=(t)=>{switch(t){case"initial":case"active":return b("cyan",mr);case"cancel":return b("red",$r);case"error":return b("yellow",br);case"submit":return b("green",Fe);case"validating":return b("dim",mr)}},oo=(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 ao(t,e,n){let r=n?`${b("cyan",k)} `:"",i=At(t,e.join(" \u2022 "),r).split(`
|
|
20
|
+
`);return n&&i.push(b("cyan",Me)),i}var gr=(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}},uo=({cursor:t,options:e,style:n,output:r=process.stdout,maxItems:i=Number.POSITIVE_INFINITY,columnPadding:s=0,rowPadding:o=4})=>{let a=It(r)-s,u=je(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=yt(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=()=>gr(C,I,0,g,T),M=()=>gr(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 pl=[`${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
|
+
`);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(`
|
|
19
23
|
`)}
|
|
20
|
-
`)},info:(t,e)=>{
|
|
21
|
-
`)},
|
|
22
|
-
${
|
|
24
|
+
`)},info:(t,e)=>{L.message(t,{...e,symbol:b("blue",eo)})},success:(t,e)=>{L.message(t,{...e,symbol:b("green",no)})},step:(t,e)=>{L.message(t,{...e,symbol:b("green",Fe)})},warn:(t,e)=>{L.message(t,{...e,symbol:b("yellow",ro)})},warning:(t,e)=>{L.warn(t,e)},error:(t,e)=>{L.message(t,{...e,symbol:b("red",io)})}};var wr=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??B.withGuide?`${b("gray",Zs)} `:"";n.write(`${r}${t}
|
|
25
|
+
`)},vr=(t="",e)=>{let n=e?.output??process.stdout,r=e?.withGuide??B.withGuide?`${b("gray",k)}
|
|
26
|
+
${b("gray",Me)} `:"";n.write(`${r}${t}
|
|
23
27
|
|
|
24
|
-
`)};var
|
|
28
|
+
`)};var ml={light:O("\u2500","-"),heavy:O("\u2501","="),block:O("\u2588","#")};var co=[`${b("dim","\u2191/\u2193")} to navigate`,`${b("dim","Enter:")} confirm`],ne=(t,e)=>t.includes(`
|
|
25
29
|
`)?t.split(`
|
|
26
30
|
`).map((n)=>e(n)).join(`
|
|
27
|
-
`):e(t),
|
|
31
|
+
`):e(t),Cr=(t)=>{let e=(r,i)=>{if(r===void 0)return"";let s=r.label??String(r.value);switch(i){case"disabled":return`${b("gray",hr)} ${ne(s,(o)=>b("gray",o))}${r.hint?` ${b("dim",`(${r.hint??"disabled"})`)}`:""}`;case"selected":return`${ne(s,(o)=>b("dim",o))}`;case"active":return`${b("green",to)} ${s}${r.hint?` ${b("dim",`(${r.hint})`)}`:""}`;case"cancelled":return`${ne(s,(o)=>b(["strikethrough","dim"],o))}`;default:return`${b("dim",hr)} ${ne(s,(o)=>b("dim",o))}`}},n=t.showInstructions??!0;return new pr({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){let r=t.withGuide??B.withGuide,i=`${so(this.state)} `,s=`${oo(this.state)} `,o=At(t.output,t.message,s,i),a=`${r?`${b("gray",k)}
|
|
28
32
|
`:""}${o}
|
|
29
|
-
`;switch(this.state){case"submit":{let
|
|
30
|
-
${
|
|
31
|
-
`).length,
|
|
32
|
-
`),
|
|
33
|
-
${
|
|
34
|
-
${
|
|
35
|
-
`}}}}).prompt()};var
|
|
36
|
-
`)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
`;switch(this.state){case"submit":{let u=r?`${b("gray",k)} `:"",c=At(t.output,e(this.options[this.cursor],"selected"),u);return`${a}${c}`}case"cancel":{let u=r?`${b("gray",k)} `:"",c=At(t.output,e(this.options[this.cursor],"cancelled"),u);return`${a}${c}${r?`
|
|
34
|
+
${b("gray",k)}`:""}`}default:{let u=r?`${b("cyan",k)} `:"",c=a.split(`
|
|
35
|
+
`).length,l=n?ao(t.output,co,r):r?[b("cyan",Me)]:[],d=l.join(`
|
|
36
|
+
`),p=l.length+1;return`${a}${u}${uo({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
|
+
${u}`)}
|
|
38
|
+
${d}
|
|
39
|
+
`}}}}).prompt()};var hl=`${b("gray",k)} `;function xr(t=process.stdin){return t.readableEnded||t.destroyed}async function Sr({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 fo=new Set;function Er(){for(let t of[...fo])t.error()}var mo="Pass the value as an argument or option instead";function ho(t){if(ee(t))throw new J;return t}function go(t){if(De())return;throw new S(`Cannot prompt for ${t} without a terminal`,mo)}async function yo(t,e,{edits:n=!1,hint:r}){if(go(e.message),xr(e.input))throw new J;return bo(r),ho(await Sr({...e,edits:n},(i)=>t({...e,signal:i})))}function $o(t){return t.map((e)=>e.key?`${y.bold(e.key)} ${y.dim(e.text)}`:y.dim(e.text)).join(y.dim(" \xB7 "))}function bo(t){L.info($o(t))}var wo={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 Ue(t){return yo(Cr,{showInstructions:!1,...t},{hint:wo.select})}function re(t){return Wn()&&t.output===void 0?{...t,output:process.stderr}:t}function $t(t){return(e,n={})=>t(e,re(n))}var U={error:$t(L.error),info:$t(L.info),message:(t,e={})=>L.message(t,re(e)),step:$t(L.step),success:$t(L.success),warn:$t(L.warn),warning:$t(L.warning)};function Ve(t,e={}){wr(t,re(e))}function Ge(t,e={}){vr(t,re(e))}import{inspect as vo}from"util";var Co=4;function ie(t,e=[]){if(e.length>=Co)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:oe(s),message:se(s)},...s instanceof Error?ie(s,r):[]])}function se(t){return ae(t instanceof Error?t.message||t.name:t)}function oe(t){return t instanceof w&&t.hint!==void 0?ae(t.hint):void 0}function ae(t){return typeof t==="string"?t:vo(t,{breakLength:Number.POSITIVE_INFINITY})}var xo="Error",So=27,Eo=new RegExp(`${String.fromCharCode(So)}\\[[\\d;]*m`,"g"),To=9,_o=10,Oo=31,Io=127,Ao=159,Ro=16,Po=4;function ot(t,{json:e}){if(Er(),ko(t),e)Z(st({error:Do(t)}));return Tr(t)}function Do(t){let e=Tr(t),n=We(se(t));if(!(t instanceof Error))return{_tag:xo,message:n,exitCode:e,causes:[]};let r=oe(t);return{_tag:Lo(t),message:n,hint:r===void 0?void 0:We(r),exitCode:e,causes:ie(t).map((i)=>We(i.message))}}function Tr(t){if(t instanceof J)return j;if(t instanceof w)return kt(t.exitCode)?t.exitCode:vt;return vt}function Lo(t){let e=Reflect.get(t,"_tag");return typeof e==="string"?e:ae(t.name)}function ko(t){if(t instanceof J)return;let e=qt(),n=ue(se(t));if(t instanceof w){let r=oe(t);if(U.warn(y.yellow(n),{output:e}),r)U.info(y.dim(ue(r)),{output:e})}else U.error(y.red(n),{output:e});if(!(t instanceof Error))return;for(let r of ie(t))if(U.info(y.dim(`caused by: ${ue(r.message)}`),{output:e}),r.hint)U.info(y.dim(` ${ue(r.hint)}`),{output:e})}function ue(t){return Array.from(t.replace(Eo,""),(e)=>{let n=e.charCodeAt(0);return n<=Oo&&n!==To&&n!==_o||n>=Io&&n<=Ao?`\\u${n.toString(Ro).padStart(Po,"0")}`:e}).join("")}var No=500,jo="The command stopped before it finished because nothing was left for it to wait for";function _r({json:t}){let e={ending:void 0,failed:!1,settled:!1},n=(i,s)=>(e.ending??=Fo(i,s),e.ending),r=(i)=>{if(e.failed||e.ending)return;e.failed=!0;let s=ot(i,{json:t&&!Bn()});Jn(),n(s,e.settled?void 0:No)};return process.on("uncaughtException",r),process.on("unhandledRejection",r),process.on("beforeExit",()=>{if(!e.settled)r(Error(jo))}),{exit:(i)=>n(i),settle(){e.settled=!0}}}async function Fo(t,e){process.exitCode=t,await Xn(e),process.exit(t)}var tt=new Uint32Array(65536),Mo=(t,e)=>{let n=t.length,r=e.length,i=1<<n-1,s=-1,o=0,a=n,u=n;while(u--)tt[t.charCodeAt(u)]|=1<<u;for(u=0;u<r;u++){let c=tt[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--)tt[t.charCodeAt(u)]=0;return a},Uo=(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++)tt[t.charCodeAt(x)]|=1<<x;for(let x=0;x<n;x++){let D=tt[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++)tt[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++)tt[t.charCodeAt(f)]|=1<<f;let m=r;for(let f=0;f<n;f++){let h=tt[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++)tt[t.charCodeAt(f)]=0;return m},Vo=(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 Mo(t,e);return Uo(t,e)},Or=(t,e)=>{let n=1/0,r=0;for(let i=0;i<e.length;i++){let s=Vo(t,e[i]);if(s<n)n=s,r=i}return e[r]};function ce(t,e,n){let r=e.length>0?Or(t,[...e]):void 0,i=`Run "${n} --help" for usage.`;return new S(`Unknown command: ${t}`,r?`Did you mean "${r}"? ${i}`:i)}function Rt(t,e){if(Array.isArray(e))return[...e];if(!Ir(t)||!Ir(e))return e;return Object.fromEntries([...Object.entries(t),...Object.entries(e).map(([n,r])=>[n,Rt(Object.hasOwn(t,n)?t[n]:void 0,r)])])}function Ir(t){if(t===null||typeof t!=="object")return!1;let e=Object.getPrototypeOf(t);return e===Object.prototype||e===null}function Ar(t,e){return{name:t.name,bin:t.bin,version:t.version,description:t.description,exitCodes:{...Yt},options:Rr(G),commands:e.map((n)=>le(n,`${t.bin} ${n.name}`))}}function le(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:Rr(t.args),examples:[...t.examples],commands:t.subcommands.map((n)=>le(n,`${e} ${n.name}`))}}function Rr(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 Pr}from"util";var Go=2,Wo="0.0.0",Bo=(t)=>t,v={arg:y.magenta,cmd:y.cyan,default:y.bold,desc:Bo,flag:y.green,header:(t)=>y.bold(y.yellow(t)),hint:y.dim,name:(t)=>y.bold(y.cyan(t)),placeholder:y.magenta};function Dr(t){return`${v.name(t.name)} ${v.hint(t.version??Wo)}`}function Lr(t,e){let n=`${v.name(t.name)}${t.version?` ${v.hint(`v${t.version}`)}`:""}`;return Nr([[n,...t.description?[v.desc(t.description)]:[]],Y("Usage:",[` ${v.cmd(t.bin)} ${v.placeholder("[command]")} ${v.placeholder("[options]")}`]),Y("Commands:",jr(e)),Y("Options:",Mr(G)),Y("Exit codes:",Fr()),[`${v.hint("Run")} ${v.cmd(`${t.bin} <command> --help`)} ${v.hint("for command details.")}`]])}function kr(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?[` ${Jo(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 Nr([[v.name(e),v.desc(t.description)],Y("Usage:",r),Y("Commands:",jr(t.subcommands)),Y("Arguments:",Ho(t.positionals)),Y("Options:",Mr(n)),Y("Examples:",t.examples.map((i)=>` ${v.cmd(i)}`)),Y("Exit codes:",Fr())])}function Jo(t,e){let n=Ko(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 Nr(t){return t.filter((e)=>e.length>0).map((e)=>e.join(`
|
|
40
|
+
`)).join(`
|
|
41
|
+
|
|
42
|
+
`)}function jr(t){return de(t.map((e)=>[` ${v.cmd(e.name)}`,v.desc(e.description)]))}function Fr(){return de(Object.entries(Yt).map(([t,e])=>[` ${t}`,e]))}function Be(t,e){return e.variadic?`${t}...`:t}function Ko(t){return Object.entries(t).map(([e,n])=>n.required?v.arg(`<${Be(e,n)}>`):v.arg(`[${Be(e,n)}]`))}function Ho(t){return de(Object.entries(t).map(([e,n])=>[` ${v.arg(Be(e,n))}`,`${v.desc(n.description??"")}${n.required?"":v.hint(" (optional)")}`]))}function Mr(t){return de(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=Xo(n),o=s===void 0?"":` (default: ${v.default(s)})`;return[` ${r}${v.flag(`--${H(e)}`)}${i}`,`${v.desc(n.description??"")}${o}`]}))}function Xo(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 de(t){let e=Math.max(0,...t.map(([n])=>Pr(n).length));return t.map(([n,r])=>`${n}${" ".repeat(e-Pr(n).length+Go)}${r}`)}function fe(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)Z(i)}}}function qo(t,e,n){if(t)return st(e);return n?`${n(e)}
|
|
43
|
+
`:void 0}function pe(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 me(t,e,n,r){let i=await Hn(n.json,async()=>{let s=await t.run?.(n);return typeof s==="number"?Yo(e,s):j});if(n.json&&!r.emitted())throw Error(`${e} finished in JSON mode without calling ctx.output.result`);return i}function Yo(t,e){if(kt(e))return e;throw Error(`${t} returned ${e}, which is not an exit code from ${j} to ${_n}`)}var Je="__exit__",Ur="__run__",zo="Back",Qo="Return to previous menu";async function Vr(t,e){if(e)throw new S("Interactive mode cannot be combined with --json","Pass a command and its arguments instead");if(!_t())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}`:"";Ve(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 Gr(t,new Map,r),Ge(t.interactive.goodbyeMessage),j}async function Gr(t,e,n){while(!0){let r=await Zo(t,e,n);if(r===void 0)return;if(e.set(n.path,r),r===Ur&&n.owner){await Wr(t,n.owner,n.path);continue}let i=n.commands.find((s)=>s.name===r);if(i)await ta(t,e,i,`${n.path} ${r}`)}}async function Zo(t,e,n){let r=n.root?{hint:t.interactive.exitHint,label:t.interactive.exitLabel,value:Je}:{hint:Qo,label:zo,value:Je};try{let i=await Ue({initialValue:e.get(n.path),message:n.message,options:[...n.owner?[{hint:n.owner.description,label:n.owner.name,value:Ur}]:[],...n.commands.map((s)=>({hint:s.description,label:s.name,value:s.name})),r]});return i===Je?void 0:i}catch(i){if(i instanceof J)return;throw i}}async function ta(t,e,n,r){if(n.subcommands.length===0)return Wr(t,n,r);return Gr(t,e,{commands:n.subcommands,message:`${n.name}:`,path:r,root:!1,...n.run?{owner:n}:{}})}async function Wr(t,e,n){try{await ea(t,e,n)}catch(r){if(r instanceof J)return;if(!(r instanceof w))throw r;ot(r,{json:!1})}}async function ea(t,e,n){let{args:r}=Tt([],e.args),i=Gt([],e.positionals),s=e.prompts?null:Wt(i,e.positionals);if(s)throw new S(s,`Run "${n} --help" for usage.`);let o=fe(!1),a={args:Ut(r,e.args),interactive:e.prompts,json:!1,positionals:i};await me(e,n,pe(t,a,o),o)}var na="--",ra=/^(?:--json(?:=true)?|-[^-=]*j[^-=]*(?:=true)?)$/,ia=/^(?:--no-(?:help|json)|(?:--(?:help|json)|-[hj]+)(?:=(?:true|false))?)$/;async function Ke(t,e){try{return await sa(t,e)}catch(n){return{code:ot(n,{json:Xe(e)}),menu:!1}}}function He(t,e){let{command:n,restArgs:r}=Mt(e,G),i=n===void 0||n===ut?void 0:Kr(t,n,r);if(!i||i instanceof S||!i.command.passthrough)return{operands:[],options:[...e]};let s=Dn(i.tokens,{...i.command.args,...gt}),o=s<0?[]:i.tokens.slice(s);return{operands:o,options:e.slice(0,e.length-o.length)}}async function sa(t,{options:e,operands:n}){let{command:r,flags:i,restArgs:s}=Ae(e,G,gt),o=i.json===!0,a={code:j,menu:!1};if(r===void 0){if(i.interactive&&!i.help&&!i.version)return{code:await Vr(t,o),menu:!0};return Z(i.version&&!i.help?aa(t,o):Br(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===ut)return Z(ua(t,s,o)),a;let c=ca(t,r,s);if(i.help)return Z(qe(c.command,c.path,o)),a;return{code:await la(t,c,n,o),menu:!1}}function Xe({options:t}){let{before:e,restArgs:n}=Mt(t,G);return[e,n].some((r)=>oa(r).some((i)=>ra.test(i)))}function oa(t){let e=t.indexOf(na);return e<0?t:t.slice(0,e)}function aa({info:t},e){return e?st({name:t.name,bin:t.bin,version:t.version}):`${Dr(t)}
|
|
44
|
+
`}function Br(t,e){return e?st(Ar(t.info,t.commands)):`${Lr(t.info,t.commands)}
|
|
45
|
+
`}function qe(t,e,n){return n?st(le(t,e)):`${kr(t,e)}
|
|
46
|
+
`}function ua(t,e,n){let{args:r,rawPositionals:i}=Tt(e,gt);if(Ft(r,gt,`Run "${t.info.bin} ${ut} [command]" for usage.`,e),i.length===0)return Br(t,n);let{command:s,path:o}=Jr(t.commands,i,t.info.bin);return qe(s,o,n)}function Jr(t,e,n){let[r="",...i]=e,s=t.find((a)=>a.name===r);if(!s)throw ce(r,Ye(t),n);let o=`${n} ${r}`;return i.length===0?{command:s,path:o}:Jr(s.subcommands,i,o)}function Ye(t){return t.map((e)=>e.name)}function ca(t,e,n){let r=Kr(t,e,n);if(r instanceof S)throw r;return r}function Kr(t,e,n){let r=t.commands.find((i)=>i.name===e);if(!r)return ce(e,Ye(t.commands),t.info.bin);return Hr({command:r,path:`${t.info.bin} ${e}`,tokens:n})}function Hr(t){let{command:e,path:n,tokens:r}=t;if(e.subcommands.length===0)return t;let i=r.findIndex((a)=>!ia.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 Hr({command:o,path:`${n} ${s}`,tokens:r.toSpliced(i,1)});if(e.run&&Object.keys(e.positionals).length>0)return t;return ce(s,Ye(e.subcommands),n)}async function la(t,{command:e,path:n,tokens:r},i,s){let o=`Run "${n} --help" for usage.`,a={...e.args,...gt},u=Tt(r,a),{args:c}=u,l=[...u.rawPositionals,...i];if(e.strict)Ft(c,a,o,r);if(s&&!e.json)throw new S(`${n} does not support --json`,o);let d=e.strict?kn(l,e.positionals):void 0;if(d!==void 0)throw new S(`Unexpected argument: ${d}`,o);if(!e.run)return Z(qe(e,n,s)),j;let p=Gt(l,e.positionals),m=Wt(p,e.positionals);if(m)throw new S(m,o);let f=e.prompts&&l.length===0&&_t()&&!s,h={args:Ut(c,e.args),interactive:f,json:s,positionals:p},C=fe(s);try{return await me(e,n,pe(t,h,C),C)}catch(_){return ot(_,{json:s&&!C.emitted()})}}var da={clearOnStart:!0,exitHint:"Close the CLI",exitLabel:"Exit",goodbyeMessage:"Goodbye!",promptMessage:"What would you like to do?"};function ze(t){let e=`CLI "${t.name}"`;if(Jt(e,t.commands),t.commands.some((r)=>r.name===ut))throw Error(`${e} cannot define a command named "${ut}": 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:{...da,...t.interactive}};return{async main(r=process.argv.slice(2)){Kn();let i=He(n,r),s=_r({json:Xe(i)}),o=await Ke(n,i);if(s.settle(),o.code===j&&!o.menu)return;await s.exit(o.code)},async run(r=process.argv.slice(2)){return(await Ke(n,He(n,r))).code}}}import z from"fs";import an from"path";var he=(t)=>(t.map=(e)=>he((n)=>e(t(n))),t.or=(e)=>he((n)=>{try{return t(n)}catch(r){return e(n)}}),t),Xr=()=>"bad banditype"();var Qe=(t)=>he((e)=>typeof e===typeof t?e:Xr()),Ze=()=>Qe("");var qr=()=>Qe(!0);var tn=()=>Qe();var en=(t)=>he((e)=>e instanceof t?e:Xr());var Pt=(t)=>en(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 bt from"fs";var fa=".lock",pa=".break",Yr=10,ma=1e4,ha=5000;function zr(t,e){let n=`${t}${fa}`,r=crypto.randomUUID();ga(n,r);try{return e()}finally{Qr(n,r)}}function ga(t,e){let n=Date.now()+ma;while(!Zr(t,e)){if(Date.now()>n)throw Error(`timed out waiting for ${t}, which another process holds`);if(nn(t))ya(t,e);else Bun.sleepSync(Yr)}}function Qr(t,e){if($a(t)===e)bt.rmSync(t,{force:!0})}function ya(t,e){let n=`${t}${pa}`;if(!Zr(n,e)){if(nn(n))bt.rmSync(n,{force:!0});else Bun.sleepSync(Yr);return}try{if(nn(t))bt.rmSync(t,{force:!0})}finally{Qr(n,e)}}function Zr(t,e){try{return bt.writeFileSync(t,e,{flag:"wx"}),!0}catch(n){if(ti(n)==="EEXIST")return!1;throw n}}function nn(t){let e=bt.statSync(t,{throwIfNoEntry:!1})?.mtimeMs;return e!==void 0&&Date.now()-e>ha}function $a(t){try{return bt.readFileSync(t,"utf8")}catch(e){if(ti(e)==="ENOENT")return;throw e}}function ti(t){return t instanceof Error?Reflect.get(t,"code"):void 0}import rn from"fs";import ct from"path";var ba="..",wa=40;function ni(t){let{root:e}=ct.parse(ct.resolve(t)),n=ei(ct.resolve(t)),r=e,i=0;for(let s=n.shift();s!==void 0;s=n.shift()){if(s===ba){r=ct.dirname(rn.realpathSync(r));continue}let o=ct.join(r,s);if(!rn.lstatSync(o,{throwIfNoEntry:!1})?.isSymbolicLink()){r=o;continue}if(i+=1,i>wa)throw Error(`too many symbolic links in ${t}`);let a=rn.readlinkSync(o);if(ct.isAbsolute(a))r=e;n.unshift(...ei(a))}return r}function ei(t){return t.split(ct.sep).filter((e)=>e!==""&&e!==".")}function on(t,e){JSON.parse(t);let n=JSON.parse(JSON.stringify(e)),r=va(t),i=t.match(/^[\t ]+(?=\S)/m)?.[0]??" ",s=t.includes(`\r
|
|
40
47
|
`)?`\r
|
|
41
48
|
`:`
|
|
42
|
-
`,o=/\s/.test(t[
|
|
43
|
-
`));let m=
|
|
44
|
-
`));let
|
|
45
|
-
`)?_:o}`,
|
|
46
|
-
`))});return`${
|
|
47
|
-
`,
|
|
48
|
-
`,
|
|
49
|
-
`;if(
|
|
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
|
+
`));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
|
+
`));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
|
+
`)?_: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 sn(c,o);let p=t.lastIndexOf(`
|
|
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 sn(t,e){if(Array.isArray(t))return`[${t.map((i)=>sn(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}${sn(s,e)}`);return`{${e}${r.join(`,${e}`)}${e}}`}function va(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 Ca=2,un="ConfigError",xa=en(Object);class cn{loaded;configPath;defaultConfig;options;constructor(t,e,n={}){this.configPath=an.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 z.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:un})}readStored(){try{let t=this.readConfigFile();if(t===void 0)return structuredClone(this.defaultConfig);return Rt(structuredClone(this.defaultConfig),ri(t))}catch(t){throw this.unreadable(t)}}update(t){try{let e=this.savePath();zr(e,()=>this.write(e,t(this.readStored())))}catch(e){throw e instanceof w?e:this.saveFailure(e)}}savePath(){let t=this.exists()?z.realpathSync(this.configPath):ni(this.configPath);return z.mkdirSync(an.dirname(t),{recursive:!0}),t}write(t,e){let n=`${t}.${crypto.randomUUID()}.tmp`;try{let r=this.exists()?z.statSync(this.configPath).mode:void 0,i=this.exists()?on(z.readFileSync(this.configPath,"utf-8"),e):`${JSON.stringify(e,null,Ca)}
|
|
56
|
+
`;if(z.writeFileSync(n,i,{flag:"wx",mode:r}),r!==void 0)z.chmodSync(n,r);z.renameSync(n,t)}finally{z.rmSync(n,{force:!0})}}saveFailure(t){return new w(`Cannot save config at ${this.configPath}: ${ii(t)}`,`Check that ${an.dirname(this.configPath)} is writable and that no other process is saving the file`,void 0,{cause:t,tag:un})}load(){let{parse:t,strict:e}=this.options;try{let n=this.readConfigFile();if(n===void 0)return{config:structuredClone(this.defaultConfig)};let r=Rt(structuredClone(this.defaultConfig),ri(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:qt()}),{config:structuredClone(this.defaultConfig),error:n}}}loadFailure(t){return new w(`Cannot read config at ${this.configPath}: ${ii(t)}`,"Repair the file and try again",void 0,{cause:t,tag:un})}readConfigFile(){try{return z.readFileSync(this.configPath,"utf-8")}catch(t){if(t.code==="ENOENT")return;throw t}}}function ri(t){let e=JSON.parse(t);if(Array.isArray(e))throw Error("Config must be an object");return xa(e)}function ii(t){return t instanceof Error?t.message:String(t)}var si="0.7.1";import{mkdir as _u}from"fs/promises";import{dirname as Ou}from"path";var Q=Bt();import{existsSync as Ai,readFileSync as Za}from"fs";var oi="ATLAS",ai="atlas",ui="Profile-based env composition for apps and environments",et=".atlas",Dt="config.json",ci="cli-state.json",li=".env",ln="ATLAS_TRUSTED_DIRS",di="*",fi={defaults:{profiles:[],exportFile:".env"},profiles:{}};import{realpathSync as Ea,statSync as Ta}from"fs";import{homedir as _a}from"os";import{isAbsolute as Oa,resolve as dn}from"path";function fn(t,e,n){if(t!==void 0&&t.trim().length===0)throw new S(`--${e} must not be empty`,n)}function lt(t,e){fn(t,"cwd",e);let n=t===void 0?process.cwd():nt(t);if(!Ia(n))throw new S(`Working directory is not a directory: ${n}`,e);return n}function pn(t,e){return mn(t)===e}function mn(t){if(!(t instanceof Error)||!("code"in t))return;return typeof t.code==="string"?t.code:void 0}function at(){return process.env.HOME||_a()}function nt(t,e=process.cwd()){if(t==="~")return at();if(t.startsWith("~/"))return dn(at(),t.slice(2));if(Oa(t))return t;return dn(e,t)}function Lt(t){try{return Ea(t)}catch{return dn(t)}}function ge(t,e){if(t===void 0)return;let n=Aa(t);if(n.length===0)throw new S("--profile must include at least one profile",e);return n}function Ia(t){try{return Ta(t,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function Aa(t){return t.split(",").map((e)=>e.trim()).filter(Boolean)}import{existsSync as yi,lstatSync as Ra,statSync as pi}from"fs";import{delimiter as Pa,dirname as gn,join as yn,parse as Da,resolve as mi}from"path";var hi=0,La=2,$i="AtlasUntrustedConfig",ka=/^\d+$/;function bi(t={}){let e=mi(t.cwd??process.cwd()),n=mi(t.home??at()),r=yn(n,et,Dt),i=yi(r)?r:void 0,s=Na(e,n,ja(t)),o=s?gn(gn(s)):void 0;return{cwd:e,globalPath:i,home:n,projectPath:s,projectRoot:o}}function Na(t,e,n){let r=Da(t).root,i,s=t;while(!0){let o=yn(s,et,Dt);if(yi(o)){if(i??=Lt(e),!(s===e||Lt(s)===i))return Ua(s,o,n),o}if(s===r)return;s=gn(s)}}function ja(t){let e=t.uid??process.getuid?.();if(e===void 0)return;let n=t.env??process.env,r=e===hi?Fa(n.SUDO_UID):void 0;return{owners:new Set([e,hi,...r===void 0?[]:[r]]),trustedDirectories:Ma(n[ln])}}function Fa(t){return t!==void 0&&ka.test(t)?Number(t):void 0}function Ma(t){return(t??"").split(Pa).map((e)=>e.trim()).filter(Boolean)}function Ua(t,e,n){if(!n||Va(t,n.trustedDirectories))return;let r=yn(t,et),i=hn(r,e,Ra),s=hn(r,e,pi),o=hn(e,e,pi),a=[[r,s],[e,o]];for(let[u,c]of[[r,i],...a])if(!n.owners.has(c.uid))throw gi(e,t,`${u} is owned by uid ${c.uid}`);for(let[u,c]of a)if((c.mode&La)!==0)throw gi(e,t,`${u} is writable by every user`)}function Va(t,e){if(e.includes(di))return!0;if(e.length===0)return!1;let n=Lt(t);return e.some((r)=>Lt(nt(r))===n)}function hn(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:$i})}}function gi(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 ${ln}=${e}`,void 0,{tag:$i})}var $e=/^[A-Za-z_][A-Za-z0-9_]*$/;class wt extends Error{key;_tag="DotenvUnrepresentableValue";constructor(t){super(`Unrepresentable dotenv value for key ${t}`);this.key=t}}var Ga=2,N=1,ye=-1,Wa=['"',"'","`"],Ba=/^\s+#/;function wi(t){let e=Object.create(null),n=t.split(/\r?\n/);for(let r=0;r<n.length;r+=1){let i=r+N,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(!$e.test(c))throw Error(`Invalid dotenv key at line ${i}`);let l=a.slice(u+1);if(Ba.test(l)){e[c]="";continue}let d=l.trim(),p=Ja(d,s,n,r);if(p){e[c]=p.value,r=p.endIndex;continue}e[c]=Ci(d)}return e}function vi(t){return Object.keys(t).sort().map((e,n)=>{let r=n+N;if(!$e.test(e))throw Error(`Invalid dotenv key at entry ${r}`);let i=t[e]??"",s=Ya(i,e);if(Ci(s)!==i)throw new wt(e);return`${e}=${s}`}).join(`
|
|
50
57
|
`).concat(`
|
|
51
|
-
`)}function
|
|
52
|
-
`),i)}}return}function
|
|
53
|
-
`;if(t==="r")return"\r";if(t==="t")return"\t";if(t==='"')return'"';if(t==="\\")return"\\";if(t==="$")return"$";return}function
|
|
54
|
-
`)||t.includes("\r"))&&!t.includes("'")&&!
|
|
55
|
-
`)||t.includes("\r")||t.includes("#"))return!1;if(t.trim()!==t)return!1;return
|
|
56
|
-
`,t.args.force,"Atlas config"),
|
|
57
|
-
`)
|
|
58
|
-
`);return}
|
|
59
|
-
${JSON.stringify(i,null,2)}`)})}}function Pn(t){H(t,pe,"Run 'atlas profiles --help' for supported commands"),X(t.cwd,"cwd","Usage: atlas profiles <list|show> --cwd <dir>")}function kn(t,e){try{e()}catch(n){if(!t||!(n instanceof g))throw n;process.stderr.write(`${JSON.stringify({error:n.message})}
|
|
60
|
-
`),process.exitCode=n.exitCode}}import{statSync as qi}from"fs";import{resolve as Xi}from"path";var Dn=B({cwd:{description:"Working directory override",type:"string"},profile:{alias:"p",description:"Comma-separated profiles to apply",type:"string"}}),zi=127,Yi=126,Qi="Put child command flags after --: atlas run -p app -- <cmd> --flags",Zi="Usage: atlas run --profile <name,...> -- <command...>",tr=nt({command:{description:"Command to run",required:!0,variadic:!0}});class Ft extends V{name="run";description="Run a command with resolved Atlas env";args=Dn;positionals=tr;async execute(t){H(t.args,Dn,Qi);let e=t.positionals.command;if(e.length===0)throw new g("Command is required","Usage: atlas run --profile app:web -- <command...>");X(t.args.cwd,"cwd","Usage: atlas run --cwd <dir> -- <command...>");let n=Ct(t.args.profile,Zi),s=Xi(t.args.cwd??process.cwd());if(!qi(s,{throwIfNoEntry:!1})?.isDirectory())throw new g(`Working directory is not a directory: ${s}`,"Usage: atlas run --cwd <dir> -- <command...>");let i=nr(s,n),r=er(e,s,i),o=()=>r.kill("SIGINT"),a=()=>r.kill("SIGTERM");process.on("SIGINT",o),process.on("SIGTERM",a);let l;try{l=await r.exited}finally{process.off("SIGINT",o),process.off("SIGTERM",a)}if(l!==0)process.exit(l)}}function er(t,e,n){try{return Bun.spawn(t,{cwd:e,env:n,stderr:"inherit",stdin:"inherit",stdout:"inherit"})}catch(s){if(st(s,"ENOENT"))throw new g(`Command not found: ${t[0]}`,"Check that it is installed and on PATH",zi);if(st(s,"EACCES"))throw new g(`Command is not executable: ${t[0]}`,"Check the executable permissions",Yi);throw s}}function nr(t,e){let n=Y({cwd:t}),s=Et(n,{profiles:e});return{...Object.fromEntries(Object.entries(process.env).filter((r)=>r[1]!==void 0)),...s.env}}class Fn extends Zt{constructor(){super(new oe(sr(q(),K,"cli-state.json"),xt),{bin:cn,clearOnStart:!1,description:"Profile-based env composition for apps and environments",name:an,version:on})}init(){this.registerCommands([new kt,new Dt,new Ft,new Pt])}}var ir=new Fn;ir.run();
|
|
58
|
+
`)}function Ja(t,e,n,r){let i=bn(t[0]);if(i===void 0)return;if($n(t,i,N)!==ye)return;let s=e.indexOf(i),o=[e.slice(s+N)];for(let a=r+1;a<n.length;a+=1){let u=n[a]??"",c=$n(u,i,0);if(c===ye){o.push(u);continue}if(!Si(u,c+N))return;return o.push(u.slice(0,c)),{endIndex:a,value:xi(o.join(`
|
|
59
|
+
`),i)}}return}function Ci(t){let e=bn(t[0]);if(e!==void 0){let n=Ka(t,e);if(n!==void 0)return xi(n,e)}return Ti(Ha(t).trimEnd())}function bn(t){return Wa.find((e)=>e===t)}function xi(t,e){return e==='"'?Xa(t):Ti(t)}function Ka(t,e){let n=$n(t,e,N);if(n===ye)return;if(!Si(t,n+N))return;return t.slice(N,n)}function Si(t,e){let n=t.slice(e).trimStart();return!n||n.startsWith("#")}function $n(t,e,n){for(let r=n;r<t.length;r+=1)if(t[r]===e&&!Ei(t,r))return r;return ye}function Ei(t,e){let n=0;for(let r=e-N;t[r]==="\\";r-=1)n+=1;return n%Ga===N}function Ha(t){let e=t.search(/\s#/);return e<0?t:t.slice(0,e)}function Xa(t){let e="";for(let n=0;n<t.length;n+=1){let r=t[n];if(r!=="\\"||n+N>=t.length){e+=r;continue}let i=t[n+N],s=qa(i);if(s===void 0){e+=r;continue}e+=s,n+=N}return e}function qa(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 Ti(t){let e="";for(let n=0;n<t.length;n+=1){if(t[n]==="\\"&&t[n+N]==="$"){e+="$",n+=N;continue}e+=t[n]}return e}function Ya(t,e){if(t.includes("\x00"))throw new wt(e);if(t==="")return"";let n=_i(t);if(za(t))return n;if(!(t.includes(`
|
|
61
|
+
`)||t.includes("\r"))&&!t.includes("'")&&!Ei(t,t.length))return`'${n}'`;if(!t.includes('"')&&!t.includes("\\"))return`"${Qa(t)}"`;throw new wt(e)}function za(t){if(t.includes(`
|
|
62
|
+
`)||t.includes("\r")||t.includes("#"))return!1;if(t.trim()!==t)return!1;return bn(t[0])===void 0}function _i(t){return t.replace(/\$(?!$)/g,"\\$&")}function Qa(t){return _i(t).replace(/\n/g,"\\n").replace(/\r/g,"\\r")}var tu="must be a valid environment variable name matching [A-Za-z_][A-Za-z0-9_]*",eu=new Set(Object.getOwnPropertyNames(Object.prototype)),nu=qr().or(tn()),ru=Ze().or(tn()),Ri=Ze(),iu=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),su="\x00",ou="AtlasNulValue",au="AtlasInvalidEncoding";class V extends Error{_tag="AtlasConfigValidationError"}function ft(t={}){let e=bi(t),n=Oi(e.globalPath,e.home,"global"),r=Oi(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 be(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=nt(m,p);wn(r,gu(f),`env file ${f}`)}wn(r,l.vars??{},`the vars of profile ${u}`);for(let[m,f]of Object.entries(l.secrets??{})){let h=yu(m,f,p,o);if(h!==void 0)wn(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:Cn(t),profiles:i}}function Cn(t){return nt(t.config.defaults?.exportFile??li,t.projectRoot??t.cwd)}function wn(t,e,n){for(let[r,i]of Object.entries(e)){if(i.includes(su))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:ou});t[r]=i}}function Oi(t,e,n){if(!t||!e)return;let r,i=$u(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:uu(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 uu(t){let e=Ce(t,"config",["$schema","defaults","profiles"]);return Pt({$schema:(n)=>we(n,"$schema"),defaults:(n)=>cu(n,"defaults"),profiles:(n)=>lu(n,"profiles")})(e)}function cu(t,e){if(t===void 0)return;let n=Ce(t,e,["exportFile","profiles"]);return Pt({exportFile:(r)=>Pi(r,`${e}.exportFile`),profiles:(r)=>vn(r,`${e}.profiles`)})(n)}function lu(t,e){if(t===void 0)return dt();let n=ve(t,e),r=dt();for(let i of Object.keys(n)){let s=Sn(e,i);if(eu.has(i))throw new V(`${s} must not use a prototype-sensitive profile name`);r[i]=du(n[i],s)}return r}function du(t,e){let n=Ce(t,e,["description","envFiles","extends","secrets","vars"]);return Pt({description:(r)=>we(r,`${e}.description`),envFiles:(r)=>vn(r,`${e}.envFiles`),extends:(r)=>vn(r,`${e}.extends`),secrets:(r)=>pu(r,`${e}.secrets`),vars:(r)=>fu(r,`${e}.vars`)})(n)}function fu(t,e){if(t===void 0)return;let n=ve(t,e),r=dt();for(let i of Object.keys(n)){let s=Sn(e,i);xn(i,s),r[i]=xe(Ri,n[i],s,"must be a string")}return r}function pu(t,e){if(t===void 0)return;let n=ve(t,e),r=dt();for(let i of Object.keys(n)){let s=Sn(e,i);xn(i,s),r[i]=mu(n[i],s)}return r}function mu(t,e){let n=Ce(t,e,["env","file","optional","trim"]),r=Pt({env:(i)=>hu(i,`${e}.env`),file:(i)=>Pi(i,`${e}.file`),optional:(i)=>Ii(i,`${e}.optional`),trim:(i)=>Ii(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 vn(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=xe(Ri,n,i,"must be a string");return Di(s,i)})}function Pi(t,e){let n=we(t,e);return n===void 0?void 0:Di(n,e)}function Di(t,e){if(t.trim().length===0)throw new V(`${e} must be a non-empty string`);return t}function we(t,e){return xe(ru,t,e,"must be a string")}function hu(t,e){let n=we(t,e);if(n===void 0)return;return xn(n,e),n}function Ii(t,e){return xe(nu,t,e,"must be a boolean")}function ve(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 Ce(t,e,n){let r=ve(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 xn(t,e){if(!$e.test(t))throw new V(`${e} ${tu}`)}function xe(t,e,n,r){try{return t(e)}catch{throw new V(`${n} ${r}`)}}function Sn(t,e){return`${t}[${JSON.stringify(e)}]`}function dt(){return Object.create(null)}function gu(t){if(!Ai(t))throw new w(`Atlas env file not found: ${t}`,"Create the file or remove it from the profile's envFiles");let e=Li(t,`Atlas env file ${t}`);try{return wi(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 yu(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=nt(e.file,n);if(!Ai(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=Li(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 Li(t,e){let n=ki(t,e);try{return iu.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:au})}}function $u(t,e){return ki(t,e).toString("utf8")}function ki(t,e){try{return Za(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 bu}from"crypto";import{link as wu,lstat as vu,open as Cu,rename as xu,rm as Ni}from"fs/promises";import{basename as Su,dirname as Eu,join as Tu}from"path";var ji=384;async function Se(t,e,n,r="Output file"){let i=await vu(t).catch((a)=>{if(pn(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=Tu(Eu(t),`.${Su(t)}.${bu()}.tmp`),o=null;try{if(o=await Cu(s,"wx",ji),await o.chmod(ji),await o.writeFile(e,"utf8"),await o.sync(),await o.close(),o=null,n)await xu(s,t);else await wu(s,t).catch((a)=>{if(pn(a,"EEXIST"))throw new w(`${r} already exists: ${t}`,"Use --force to overwrite it");throw a}),await Ni(s)}catch(a){throw await o?.close().catch(()=>{return}),await Ni(s,{force:!0}).catch(()=>{return}),a}}var Iu="Usage: atlas export --profile <name,...>",Au="Usage: atlas export --cwd <dir>",Ru="Usage: atlas export --out <path>",Fi=Q({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");fn(t.args.out,"out",Ru);let e=lt(t.args.cwd,Au),n=ge(t.args.profile,Iu),r=ft({cwd:e}),i=be(r,{profiles:n}),s=Pu(i.env);if(t.args.stdout){process.stdout.write(s);return}let o=t.args.out!==void 0?nt(t.args.out,r.cwd):i.exportFile;await _u(Ou(o),{recursive:!0}),await Se(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 Pu(t){try{return vi(t)}catch(e){if(!(e instanceof wt))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 Du}from"fs/promises";import{join as Mi}from"path";var Lu=2,Ui=Q({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?at():process.cwd(),n=Mi(e,et,Dt);await Du(Mi(e,et),{recursive:!0}),await Se(n,`${JSON.stringify(fi,null,Lu)}
|
|
63
|
+
`,t.args.force,"Atlas config"),U.success(`Created ${y.green(n)}`),t.output.result({path:n})}});var ku=2;function Vi(t){let e=Object.keys(t.config.profiles).sort();return{defaults:{exportFile:Cn(t),profiles:t.config.defaults?.profiles??[]},globalPath:t.globalPath??null,profiles:e.flatMap((n)=>{let r=Ji(t,n);return r?[r]:[]}),projectPath:t.projectPath??null}}function Gi(t,e){let n=Ji(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 Wi(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})`)}`}),"",...Nu(t)].join(`
|
|
64
|
+
`)}function Bi(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 Nu(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 Ji(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 Ki="Usage: atlas profiles <list|show> --cwd <dir>",ju=Q({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,Ki)});t.output.result(Vi(e),Wi)}}),Fu=Q({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:ht({profile:{description:"Profile name",required:!0}}),run:async(t)=>{let e=ft({cwd:lt(t.args.cwd,Ki)}),n=Gi(e,t.positionals.profile);if(!n)throw new w(`Unknown Atlas profile: ${t.positionals.profile}`,"Run 'atlas profiles list'");t.output.result(n,Bi)}}),Hi=Q({description:"Inspect Atlas profiles",name:"profiles",subcommands:[ju,Fu]});var Mu=127,Uu=126,Vu="Usage: atlas run --profile <name,...> <command...>",Gu="Usage: atlas run --cwd <dir> <command...>",Wu="AtlasSpawnFailed",Bu=["SIGTERM","SIGHUP","SIGUSR1","SIGUSR2"],Xi=["SIGINT","SIGQUIT"],qi=Q({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:ht({command:{description:"Command and its arguments, passed on unchanged",required:!0,variadic:!0}}),run:async(t)=>{let e=lt(t.args.cwd,Gu),n=ge(t.args.profile,Vu),r=Ju(e,n);return await Xu(Ku(t.positionals.command,e,r))}});function Ju(t,e){let n=be(ft({cwd:t}),{profiles:e});return{...Object.fromEntries(Object.entries(process.env).filter((i)=>i[1]!==void 0)),...n.env}}function Ku(t,e,n){try{return Bun.spawn(t,{cwd:e,env:n,stderr:"inherit",stdin:"inherit",stdout:"inherit"})}catch(r){throw Hu(t[0]??"",r)}}function Hu(t,e){let n=mn(e);if(n==="ENOENT")return new w(`Command not found: ${t}`,"Check that it is installed and on PATH",Mu);if(n==="EACCES")return new w(`Command is not executable: ${t}`,"Check the executable permissions",Uu);return new w(`Failed to start command: ${t}${n?` (${n})`:""}`,"Check the command, its arguments and the resolved environment",void 0,{tag:Wu})}async function Xu(t){let e=qu(),n=[...Bu,...Xi].map((r)=>{let s=e&&Xi.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 qu(){return process.stdin.isTTY===!0||process.stdout.isTTY===!0||process.stderr.isTTY===!0}function Yi(t=new cn(Yu(at(),et,ci),{})){return ze({bin:ai,commands:[Ui,Hi,qi,Fi],config:t,description:ui,interactive:{clearOnStart:!1},name:oi,version:si})}Yi().main();
|
package/package.json
CHANGED
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "rm -rf dist && bun build.ts",
|
|
31
31
|
"clean": "rm -rf dist node_modules",
|
|
32
|
-
"dev": "bun --bun src/cli.ts",
|
|
32
|
+
"dev": "bun --bun --no-env-file src/cli.ts",
|
|
33
33
|
"package:dryRun": "bun ../../tools/scripts/publish-package.ts . --dry-run",
|
|
34
34
|
"package:prepare": "NODE_ENV=production bun run build && bun ../../tools/scripts/prepare-publish.ts .",
|
|
35
35
|
"package:publish": "bun ../../tools/scripts/publish-package.ts ."
|
|
36
36
|
},
|
|
37
37
|
"type": "module",
|
|
38
|
-
"version": "0.
|
|
38
|
+
"version": "0.7.1"
|
|
39
39
|
}
|