@visulima/cerebro 1.1.25 → 1.1.27

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/CHANGELOG.md CHANGED
@@ -1,3 +1,40 @@
1
+ ## @visulima/cerebro [1.1.27](https://github.com/visulima/visulima/compare/@visulima/cerebro@1.1.26...@visulima/cerebro@1.1.27) (2024-12-27)
2
+
3
+ ### Miscellaneous Chores
4
+
5
+ * updated dev dependencies ([9de2eab](https://github.com/visulima/visulima/commit/9de2eab91e95c8b9289d12f863a5167218770650))
6
+
7
+
8
+ ### Dependencies
9
+
10
+ * **@visulima/find-cache-dir:** upgraded to 1.0.17
11
+
12
+ ## @visulima/cerebro [1.1.26](https://github.com/visulima/visulima/compare/@visulima/cerebro@1.1.25...@visulima/cerebro@1.1.26) (2024-12-12)
13
+
14
+ ### Bug Fixes
15
+
16
+ * allow node v23 ([8ca929a](https://github.com/visulima/visulima/commit/8ca929af311ce8036cbbfde68b6db05381b860a5))
17
+ * allowed node 23, updated dev dependencies ([f99d34e](https://github.com/visulima/visulima/commit/f99d34e01f6b13be8586a1b5d37dc8b8df0a5817))
18
+ * updated packem to v1.8.2 ([23f869b](https://github.com/visulima/visulima/commit/23f869b4120856cc97e2bffa6d508e2ae30420ea))
19
+ * updated packem to v1.9.2 ([47bdc2d](https://github.com/visulima/visulima/commit/47bdc2dfaeca4e7014dbe7772eae2fdf8c8b35bb))
20
+
21
+ ### Styles
22
+
23
+ * cs fixes ([46d31e0](https://github.com/visulima/visulima/commit/46d31e082e1865262bf380859c14fabd28ff456d))
24
+
25
+ ### Miscellaneous Chores
26
+
27
+ * updated dev dependencies ([a916944](https://github.com/visulima/visulima/commit/a916944b888bb34c34b0c54328b38d29e4399857))
28
+
29
+
30
+ ### Dependencies
31
+
32
+ * **@visulima/boxen:** upgraded to 1.0.22
33
+ * **@visulima/colorize:** upgraded to 1.4.13
34
+ * **@visulima/find-cache-dir:** upgraded to 1.0.16
35
+ * **@visulima/pail:** upgraded to 2.1.12
36
+ * **@visulima/path:** upgraded to 1.1.2
37
+
1
38
  ## @visulima/cerebro [1.1.25](https://github.com/visulima/visulima/compare/@visulima/cerebro@1.1.24...@visulima/cerebro@1.1.25) (2024-10-25)
2
39
 
3
40
 
package/README.md CHANGED
@@ -87,18 +87,18 @@ If you would like to help take a look at the [list of issues](https://github.com
87
87
 
88
88
  ## Credits
89
89
 
90
- - [Daniel Bannert](https://github.com/prisis)
91
- - [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
90
+ - [Daniel Bannert](https://github.com/prisis)
91
+ - [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
92
92
 
93
93
  ## About
94
94
 
95
95
  ### Related Projects
96
96
 
97
- - [oclif](https://oclif.io) - The Open CLI Framework
98
- - [gluegun](https://infinitered.github.io/gluegun/#/) - A delightful toolkit for building TypeScript-powered command-line apps.
99
- - [meow](https://www.npmjs.com/package/meow) - CLI app helper
100
- - [commander.js](https://github.com/tj/commander.js) - node.js command-line interfaces made easy
101
- - [yargs](https://www.npmjs.com/package/yargs) - yargs the modern, pirate-themed successor to optimist.
97
+ - [oclif](https://oclif.io) - The Open CLI Framework
98
+ - [gluegun](https://infinitered.github.io/gluegun/#/) - A delightful toolkit for building TypeScript-powered command-line apps.
99
+ - [meow](https://www.npmjs.com/package/meow) - CLI app helper
100
+ - [commander.js](https://github.com/tj/commander.js) - node.js command-line interfaces made easy
101
+ - [yargs](https://www.npmjs.com/package/yargs) - yargs the modern, pirate-themed successor to optimist.
102
102
 
103
103
  ## License
104
104
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const e=require("./packem_shared/default-B6yh48Ox.cjs");module.exports=e.Cli;
1
+ "use strict";const e=require("./packem_shared/default-B6w1KajL.cjs");module.exports=e.Cli;
package/dist/index.d.cts CHANGED
@@ -99,6 +99,13 @@ interface Cli$1 {
99
99
  setDefaultCommand: (commandName: string) => this;
100
100
  }
101
101
 
102
+ declare global {
103
+ namespace Cerebro {
104
+ interface ExtensionOverrides {
105
+ }
106
+ }
107
+ }
108
+
102
109
  type CliOptions = {
103
110
  argv?: string[];
104
111
  cwd?: string;
package/dist/index.d.mts CHANGED
@@ -99,6 +99,13 @@ interface Cli$1 {
99
99
  setDefaultCommand: (commandName: string) => this;
100
100
  }
101
101
 
102
+ declare global {
103
+ namespace Cerebro {
104
+ interface ExtensionOverrides {
105
+ }
106
+ }
107
+ }
108
+
102
109
  type CliOptions = {
103
110
  argv?: string[];
104
111
  cwd?: string;
package/dist/index.d.ts CHANGED
@@ -99,6 +99,13 @@ interface Cli$1 {
99
99
  setDefaultCommand: (commandName: string) => this;
100
100
  }
101
101
 
102
+ declare global {
103
+ namespace Cerebro {
104
+ interface ExtensionOverrides {
105
+ }
106
+ }
107
+ }
108
+
102
109
  type CliOptions = {
103
110
  argv?: string[];
104
111
  cwd?: string;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{Cli as f}from"./packem_shared/default-CsGtOwTl.mjs";export{f as default};
1
+ import{Cli as f}from"./packem_shared/default-DNNnCan-.mjs";export{f as default};
@@ -1 +1 @@
1
- "use strict";var j=Object.defineProperty;var f=(e,n)=>j(e,"name",{value:n,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("node:fs"),O=require("@visulima/find-cache-dir"),S=require("node:https");var k=Object.defineProperty,P=f((e,n)=>k(e,"name",{value:n,configurable:!0}),"o$1");const A=P((e,n)=>{const r=e.split(".").map(Number),t=n.split(".").map(Number);for(const[o,s]of r.entries()){if(s>t[o])return!0;if(s<t[o])return!1}return!1},"semverGt");var x=Object.defineProperty,v=f((e,n)=>x(e,"name",{value:n,configurable:!0}),"u$1"),N=Object.defineProperty,_=v((e,n)=>N(e,"name",{value:n,configurable:!0}),"t");const C=/^[A-Z]:\//i,l=_((e="")=>e&&e.replaceAll("\\","/").replace(C,n=>n.toUpperCase()),"normalizeWindowsPath");var U=Object.defineProperty,c=v((e,n)=>U(e,"name",{value:n,configurable:!0}),"r");const D=/^[/\\]{2}/,E=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,b=/^[A-Z]:$/i,m=/^\/([A-Z]:)?$/i,L=/.(\.[^./]+)$/,Z=c(()=>typeof process.cwd=="function"?process.cwd().replaceAll("\\","/"):"/","cwd");/^win/i.test(globalThis.process?.platform);const y=c((e,n)=>{let r="",t=0,o=-1,s=0,a=null;for(let i=0;i<=e.length;++i){if(i<e.length)a=e[i];else{if(a==="/")break;a="/"}if(a==="/"){if(!(o===i-1||s===1))if(s===2){if(r.length<2||t!==2||!r.endsWith(".")||r.at(-2)!=="."){if(r.length>2){const u=r.lastIndexOf("/");u===-1?(r="",t=0):(r=r.slice(0,u),t=r.length-1-r.lastIndexOf("/")),o=i,s=0;continue}else if(r.length>0){r="",t=0,o=i,s=0;continue}}n&&(r+=r.length>0?"/..":"..",t=2)}else r.length>0?r+=`/${e.slice(o+1,i)}`:r=e.slice(o+1,i),t=i-o-1;o=i,s=0}else a==="."&&s!==-1?++s:s=-1}return r},"normalizeString"),d=c(e=>E.test(e),"isAbsolute"),z=c(function(e){if(e.length===0)return".";e=l(e);const n=D.exec(e),r=d(e),t=e.at(-1)==="/";return e=y(e,!r),e.length===0?r?"/":t?"./":".":(t&&(e+="/"),b.test(e)&&(e+="/"),n?r?`//${e}`:`//./${e}`:r&&!d(e)?`/${e}`:e)},"normalize"),T=c(function(...e){if(e.length===0)return".";let n;for(const r of e)r&&r.length>0&&(n===void 0?n=r:n+=`/${r}`);return n===void 0?".":z(n.replaceAll(/\/{2,}/g,"/"))},"join"),g=c(function(...e){e=e.map(t=>l(t));let n="",r=!1;for(let t=e.length-1;t>=-1&&!r;t--){const o=t>=0?e[t]:Z();!o||o.length===0||(n=`${o}/${n}`,r=d(o))}return n=y(n,!r),r&&!d(n)?`/${n}`:n.length>0?n:"."},"resolve");c(function(e){return l(e)},"toNamespacedPath");const q=c(function(e){return L.exec(l(e))?.[1]??""},"extname");c(function(e,n){const r=g(e).replace(m,"$1").split("/"),t=g(n).replace(m,"$1").split("/");if(t[0][1]===":"&&r[0][1]===":"&&r[0]!==t[0])return t.join("/");const o=[...r];for(const s of o){if(t[0]!==s)break;r.shift(),t.shift()}return[...r.map(()=>".."),...t].join("/")},"relative");const $=c(e=>{const n=l(e).replace(/\/$/,"").split("/").slice(0,-1);return n.length===1&&b.test(n[0])&&(n[0]+="/"),n.join("/")||(d(e)?"/":".")},"dirname");c(function(e){const n=[e.root,e.dir,e.base??e.name+e.ext].filter(Boolean);return l(e.root?g(...n):n.join("/"))},"format");const F=c((e,n)=>{const r=l(e).split("/").pop();return n&&r.endsWith(n)?r.slice(0,-n.length):r},"basename");c(function(e){let n=l(e).split("/").shift();n===""?n="/":n+="/";const r=F(e),t=q(r);return{base:r,dir:$(e),ext:t,name:r.slice(0,r.length-t.length),root:n}},"parse");var I=Object.defineProperty,h=f((e,n)=>I(e,"name",{value:n,configurable:!0}),"r");const J="last-update-check.json",w=h(e=>{const n=O.findCacheDirSync(e);if(n===void 0)throw new Error("Could not find cache directory");return T(n,J)},"getConfigFile"),M=h(e=>{const n=w(e);try{if(!p.existsSync(n))return;const{lastUpdateCheck:r}=JSON.parse(p.readFileSync(n,"utf8"));return r}catch{return}},"getLastUpdate"),W=h(e=>{const n=w(e),r=$(n);p.existsSync(r)||p.mkdirSync(r,{recursive:!0}),p.writeFileSync(n,JSON.stringify({lastUpdateCheck:Date.now()}))},"saveLastUpdate");var V=Object.defineProperty,B=f((e,n)=>V(e,"name",{value:n,configurable:!0}),"g");const G=B(async(e,n,r)=>{const t=r.replace("__NAME__",e);return await new Promise((o,s)=>{S.get(t,a=>{let i="";a.on("data",u=>i+=u),a.on("end",()=>{try{const u=JSON.parse(i)[n];u||s(new Error("Error getting version")),o(u)}catch{s(new Error("Could not parse version response"))}})}).on("error",a=>s(a))})},"getDistributionVersion");var R=Object.defineProperty,H=f((e,n)=>R(e,"name",{value:n,configurable:!0}),"i");const K=H(async({alwaysRun:e,debug:n,distTag:r="latest",pkg:t,registryUrl:o="https://registry.npmjs.org/-/package/__NAME__/dist-tags",updateCheckInterval:s=1e3*60*60*24})=>{const a=M(t.name);if(e||!a||a<Date.now()-s){const i=await G(t.name,r,o);if(W(t.name),A(i,t.version))return i;n&&console.error(`Latest version (${i}) not newer than current version (${t.version})`)}else n&&console.error(`Too recent to check for a new update. simpleUpdateNotifier() interval set to ${s}ms but only ${Date.now()-a}ms since last check.`);return null},"hasNewVersion");exports.default=K;
1
+ "use strict";var j=Object.defineProperty;var f=(e,t)=>j(e,"name",{value:t,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("node:fs"),O=require("@visulima/find-cache-dir"),k=require("node:https");var P=Object.defineProperty,S=f((e,t)=>P(e,"name",{value:t,configurable:!0}),"o$1");const N=S((e,t)=>{const n=e.split(".").map(Number),r=t.split(".").map(Number);for(const[o,i]of n.entries()){if(i>r[o])return!0;if(i<r[o])return!1}return!1},"semverGt");var _=Object.defineProperty,x=f((e,t)=>_(e,"name",{value:t,configurable:!0}),"v"),A=Object.defineProperty,m=x((e,t)=>A(e,"name",{value:t,configurable:!0}),"u"),C=Object.defineProperty,U=m((e,t)=>C(e,"name",{value:t,configurable:!0}),"t");const D=/^[A-Z]:\//i,l=U((e="")=>e&&e.replaceAll("\\","/").replace(D,t=>t.toUpperCase()),"normalizeWindowsPath");var E=Object.defineProperty,c=m((e,t)=>E(e,"name",{value:t,configurable:!0}),"r");const L=/^[/\\]{2}/,Z=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,b=/^[A-Z]:$/i,v=/^\/([A-Z]:)?$/i,I=/.(\.[^./]+)$/,M=c(()=>typeof process.cwd=="function"?process.cwd().replaceAll("\\","/"):"/","cwd"),y=c((e,t)=>{let n="",r=0,o=-1,i=0,s=null;for(let a=0;a<=e.length;++a){if(a<e.length)s=e[a];else{if(s==="/")break;s="/"}if(s==="/"){if(!(o===a-1||i===1))if(i===2){if(n.length<2||r!==2||!n.endsWith(".")||n.at(-2)!=="."){if(n.length>2){const u=n.lastIndexOf("/");u===-1?(n="",r=0):(n=n.slice(0,u),r=n.length-1-n.lastIndexOf("/")),o=a,i=0;continue}else if(n.length>0){n="",r=0,o=a,i=0;continue}}t&&(n+=n.length>0?"/..":"..",r=2)}else n.length>0?n+=`/${e.slice(o+1,a)}`:n=e.slice(o+1,a),r=a-o-1;o=a,i=0}else s==="."&&i!==-1?++i:i=-1}return n},"normalizeString"),d=c(e=>Z.test(e),"isAbsolute"),T=c(function(e){if(e.length===0)return".";e=l(e);const t=L.exec(e),n=d(e),r=e.at(-1)==="/";return e=y(e,!n),e.length===0?n?"/":r?"./":".":(r&&(e+="/"),b.test(e)&&(e+="/"),t?n?`//${e}`:`//./${e}`:n&&!d(e)?`/${e}`:e)},"normalize"),W=c(function(...e){if(e.length===0)return".";let t;for(const n of e)n&&n.length>0&&(t===void 0?t=n:t+=`/${n}`);return t===void 0?".":T(t.replaceAll(/\/{2,}/g,"/"))},"join"),g=c(function(...e){e=e.map(r=>l(r));let t="",n=!1;for(let r=e.length-1;r>=-1&&!n;r--){const o=r>=0?e[r]:M();!o||o.length===0||(t=`${o}/${t}`,n=d(o))}return t=y(t,!n),n&&!d(t)?`/${t}`:t.length>0?t:"."},"resolve");c(function(e){return l(e)},"toNamespacedPath");const q=c(function(e){return I.exec(l(e))?.[1]??""},"extname");c(function(e,t){const n=g(e).replace(v,"$1").split("/"),r=g(t).replace(v,"$1").split("/");if(r[0][1]===":"&&n[0][1]===":"&&n[0]!==r[0])return r.join("/");const o=[...n];for(const i of o){if(r[0]!==i)break;n.shift(),r.shift()}return[...n.map(()=>".."),...r].join("/")},"relative");const $=c(e=>{const t=l(e).replace(/\/$/,"").split("/").slice(0,-1);return t.length===1&&b.test(t[0])&&(t[0]+="/"),t.join("/")||(d(e)?"/":".")},"dirname");c(function(e){const t=[e.root,e.dir,e.base??e.name+e.ext].filter(Boolean);return l(e.root?g(...t):t.join("/"))},"format");const z=c((e,t)=>{const n=l(e).split("/").pop();return t&&n.endsWith(t)?n.slice(0,-t.length):n},"basename");c(function(e){let t=l(e).split("/").shift();t===""?t="/":t+="/";const n=z(e),r=q(n);return{base:n,dir:$(e),ext:r,name:n.slice(0,n.length-r.length),root:t}},"parse");var F=Object.defineProperty,h=f((e,t)=>F(e,"name",{value:t,configurable:!0}),"r");const J="last-update-check.json",w=h(e=>{const t=O.findCacheDirSync(e);if(t===void 0)throw new Error("Could not find cache directory");return W(t,J)},"getConfigFile"),B=h(e=>{const t=w(e);try{if(!p.existsSync(t))return;const{lastUpdateCheck:n}=JSON.parse(p.readFileSync(t,"utf8"));return n}catch{return}},"getLastUpdate"),V=h(e=>{const t=w(e),n=$(t);p.existsSync(n)||p.mkdirSync(n,{recursive:!0}),p.writeFileSync(t,JSON.stringify({lastUpdateCheck:Date.now()}))},"saveLastUpdate");var G=Object.defineProperty,R=f((e,t)=>G(e,"name",{value:t,configurable:!0}),"g");const H=R(async(e,t,n)=>{const r=n.replace("__NAME__",e);return await new Promise((o,i)=>{k.get(r,s=>{let a="";s.on("data",u=>a+=u),s.on("end",()=>{try{const u=JSON.parse(a)[t];u||i(new Error("Error getting version")),o(u)}catch{i(new Error("Could not parse version response"))}})}).on("error",s=>i(s))})},"getDistributionVersion");var K=Object.defineProperty,Q=f((e,t)=>K(e,"name",{value:t,configurable:!0}),"i");const X=Q(async({alwaysRun:e,debug:t,distTag:n="latest",pkg:r,registryUrl:o="https://registry.npmjs.org/-/package/__NAME__/dist-tags",updateCheckInterval:i=1e3*60*60*24})=>{const s=B(r.name);if(e||!s||s<Date.now()-i){const a=await H(r.name,n,o);if(V(r.name),N(a,r.version))return a;t&&console.error(`Latest version (${a}) not newer than current version (${r.version})`)}else t&&console.error(`Too recent to check for a new update. simpleUpdateNotifier() interval set to ${i}ms but only ${Date.now()-s}ms since last check.`);return null},"hasNewVersion");exports.default=X;
@@ -1 +1 @@
1
- var j=Object.defineProperty;var u=(e,n)=>j(e,"name",{value:n,configurable:!0});import{existsSync as h,readFileSync as O,mkdirSync as k,writeFileSync as A}from"node:fs";import{findCacheDirSync as P}from"@visulima/find-cache-dir";import{get as x}from"node:https";var N=Object.defineProperty,S=u((e,n)=>N(e,"name",{value:n,configurable:!0}),"o$1");const U=S((e,n)=>{const r=e.split(".").map(Number),t=n.split(".").map(Number);for(const[o,i]of r.entries()){if(i>t[o])return!0;if(i<t[o])return!1}return!1},"semverGt");var C=Object.defineProperty,v=u((e,n)=>C(e,"name",{value:n,configurable:!0}),"u$1"),_=Object.defineProperty,E=v((e,n)=>_(e,"name",{value:n,configurable:!0}),"t");const D=/^[A-Z]:\//i,l=E((e="")=>e&&e.replaceAll("\\","/").replace(D,n=>n.toUpperCase()),"normalizeWindowsPath");var L=Object.defineProperty,c=v((e,n)=>L(e,"name",{value:n,configurable:!0}),"r");const Z=/^[/\\]{2}/,z=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,b=/^[A-Z]:$/i,m=/^\/([A-Z]:)?$/i,F=/.(\.[^./]+)$/,I=c(()=>typeof process.cwd=="function"?process.cwd().replaceAll("\\","/"):"/","cwd");/^win/i.test(globalThis.process?.platform);const $=c((e,n)=>{let r="",t=0,o=-1,i=0,s=null;for(let a=0;a<=e.length;++a){if(a<e.length)s=e[a];else{if(s==="/")break;s="/"}if(s==="/"){if(!(o===a-1||i===1))if(i===2){if(r.length<2||t!==2||!r.endsWith(".")||r.at(-2)!=="."){if(r.length>2){const f=r.lastIndexOf("/");f===-1?(r="",t=0):(r=r.slice(0,f),t=r.length-1-r.lastIndexOf("/")),o=a,i=0;continue}else if(r.length>0){r="",t=0,o=a,i=0;continue}}n&&(r+=r.length>0?"/..":"..",t=2)}else r.length>0?r+=`/${e.slice(o+1,a)}`:r=e.slice(o+1,a),t=a-o-1;o=a,i=0}else s==="."&&i!==-1?++i:i=-1}return r},"normalizeString"),p=c(e=>z.test(e),"isAbsolute"),J=c(function(e){if(e.length===0)return".";e=l(e);const n=Z.exec(e),r=p(e),t=e.at(-1)==="/";return e=$(e,!r),e.length===0?r?"/":t?"./":".":(t&&(e+="/"),b.test(e)&&(e+="/"),n?r?`//${e}`:`//./${e}`:r&&!p(e)?`/${e}`:e)},"normalize"),T=c(function(...e){if(e.length===0)return".";let n;for(const r of e)r&&r.length>0&&(n===void 0?n=r:n+=`/${r}`);return n===void 0?".":J(n.replaceAll(/\/{2,}/g,"/"))},"join"),g=c(function(...e){e=e.map(t=>l(t));let n="",r=!1;for(let t=e.length-1;t>=-1&&!r;t--){const o=t>=0?e[t]:I();!o||o.length===0||(n=`${o}/${n}`,r=p(o))}return n=$(n,!r),r&&!p(n)?`/${n}`:n.length>0?n:"."},"resolve");c(function(e){return l(e)},"toNamespacedPath");const W=c(function(e){return F.exec(l(e))?.[1]??""},"extname");c(function(e,n){const r=g(e).replace(m,"$1").split("/"),t=g(n).replace(m,"$1").split("/");if(t[0][1]===":"&&r[0][1]===":"&&r[0]!==t[0])return t.join("/");const o=[...r];for(const i of o){if(t[0]!==i)break;r.shift(),t.shift()}return[...r.map(()=>".."),...t].join("/")},"relative");const y=c(e=>{const n=l(e).replace(/\/$/,"").split("/").slice(0,-1);return n.length===1&&b.test(n[0])&&(n[0]+="/"),n.join("/")||(p(e)?"/":".")},"dirname");c(function(e){const n=[e.root,e.dir,e.base??e.name+e.ext].filter(Boolean);return l(e.root?g(...n):n.join("/"))},"format");const M=c((e,n)=>{const r=l(e).split("/").pop();return n&&r.endsWith(n)?r.slice(0,-n.length):r},"basename");c(function(e){let n=l(e).split("/").shift();n===""?n="/":n+="/";const r=M(e),t=W(r);return{base:r,dir:y(e),ext:t,name:r.slice(0,r.length-t.length),root:n}},"parse");var V=Object.defineProperty,d=u((e,n)=>V(e,"name",{value:n,configurable:!0}),"r");const B="last-update-check.json",w=d(e=>{const n=P(e);if(n===void 0)throw new Error("Could not find cache directory");return T(n,B)},"getConfigFile"),G=d(e=>{const n=w(e);try{if(!h(n))return;const{lastUpdateCheck:r}=JSON.parse(O(n,"utf8"));return r}catch{return}},"getLastUpdate"),R=d(e=>{const n=w(e),r=y(n);h(r)||k(r,{recursive:!0}),A(n,JSON.stringify({lastUpdateCheck:Date.now()}))},"saveLastUpdate");var q=Object.defineProperty,H=u((e,n)=>q(e,"name",{value:n,configurable:!0}),"g");const K=H(async(e,n,r)=>{const t=r.replace("__NAME__",e);return await new Promise((o,i)=>{x(t,s=>{let a="";s.on("data",f=>a+=f),s.on("end",()=>{try{const f=JSON.parse(a)[n];f||i(new Error("Error getting version")),o(f)}catch{i(new Error("Could not parse version response"))}})}).on("error",s=>i(s))})},"getDistributionVersion");var Q=Object.defineProperty,X=u((e,n)=>Q(e,"name",{value:n,configurable:!0}),"i");const te=X(async({alwaysRun:e,debug:n,distTag:r="latest",pkg:t,registryUrl:o="https://registry.npmjs.org/-/package/__NAME__/dist-tags",updateCheckInterval:i=1e3*60*60*24})=>{const s=G(t.name);if(e||!s||s<Date.now()-i){const a=await K(t.name,r,o);if(R(t.name),U(a,t.version))return a;n&&console.error(`Latest version (${a}) not newer than current version (${t.version})`)}else n&&console.error(`Too recent to check for a new update. simpleUpdateNotifier() interval set to ${i}ms but only ${Date.now()-s}ms since last check.`);return null},"hasNewVersion");export{te as default};
1
+ var j=Object.defineProperty;var f=(e,t)=>j(e,"name",{value:t,configurable:!0});import{existsSync as h,readFileSync as O,mkdirSync as k,writeFileSync as N}from"node:fs";import{findCacheDirSync as P}from"@visulima/find-cache-dir";import{get as x}from"node:https";var A=Object.defineProperty,C=f((e,t)=>A(e,"name",{value:t,configurable:!0}),"o$1");const S=C((e,t)=>{const n=e.split(".").map(Number),r=t.split(".").map(Number);for(const[o,a]of n.entries()){if(a>r[o])return!0;if(a<r[o])return!1}return!1},"semverGt");var U=Object.defineProperty,_=f((e,t)=>U(e,"name",{value:t,configurable:!0}),"v"),E=Object.defineProperty,v=_((e,t)=>E(e,"name",{value:t,configurable:!0}),"u"),D=Object.defineProperty,L=v((e,t)=>D(e,"name",{value:t,configurable:!0}),"t");const Z=/^[A-Z]:\//i,l=L((e="")=>e&&e.replaceAll("\\","/").replace(Z,t=>t.toUpperCase()),"normalizeWindowsPath");var I=Object.defineProperty,c=v((e,t)=>I(e,"name",{value:t,configurable:!0}),"r");const W=/^[/\\]{2}/,z=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,b=/^[A-Z]:$/i,m=/^\/([A-Z]:)?$/i,F=/.(\.[^./]+)$/,J=c(()=>typeof process.cwd=="function"?process.cwd().replaceAll("\\","/"):"/","cwd"),$=c((e,t)=>{let n="",r=0,o=-1,a=0,s=null;for(let i=0;i<=e.length;++i){if(i<e.length)s=e[i];else{if(s==="/")break;s="/"}if(s==="/"){if(!(o===i-1||a===1))if(a===2){if(n.length<2||r!==2||!n.endsWith(".")||n.at(-2)!=="."){if(n.length>2){const u=n.lastIndexOf("/");u===-1?(n="",r=0):(n=n.slice(0,u),r=n.length-1-n.lastIndexOf("/")),o=i,a=0;continue}else if(n.length>0){n="",r=0,o=i,a=0;continue}}t&&(n+=n.length>0?"/..":"..",r=2)}else n.length>0?n+=`/${e.slice(o+1,i)}`:n=e.slice(o+1,i),r=i-o-1;o=i,a=0}else s==="."&&a!==-1?++a:a=-1}return n},"normalizeString"),p=c(e=>z.test(e),"isAbsolute"),M=c(function(e){if(e.length===0)return".";e=l(e);const t=W.exec(e),n=p(e),r=e.at(-1)==="/";return e=$(e,!n),e.length===0?n?"/":r?"./":".":(r&&(e+="/"),b.test(e)&&(e+="/"),t?n?`//${e}`:`//./${e}`:n&&!p(e)?`/${e}`:e)},"normalize"),T=c(function(...e){if(e.length===0)return".";let t;for(const n of e)n&&n.length>0&&(t===void 0?t=n:t+=`/${n}`);return t===void 0?".":M(t.replaceAll(/\/{2,}/g,"/"))},"join"),g=c(function(...e){e=e.map(r=>l(r));let t="",n=!1;for(let r=e.length-1;r>=-1&&!n;r--){const o=r>=0?e[r]:J();!o||o.length===0||(t=`${o}/${t}`,n=p(o))}return t=$(t,!n),n&&!p(t)?`/${t}`:t.length>0?t:"."},"resolve");c(function(e){return l(e)},"toNamespacedPath");const B=c(function(e){return F.exec(l(e))?.[1]??""},"extname");c(function(e,t){const n=g(e).replace(m,"$1").split("/"),r=g(t).replace(m,"$1").split("/");if(r[0][1]===":"&&n[0][1]===":"&&n[0]!==r[0])return r.join("/");const o=[...n];for(const a of o){if(r[0]!==a)break;n.shift(),r.shift()}return[...n.map(()=>".."),...r].join("/")},"relative");const y=c(e=>{const t=l(e).replace(/\/$/,"").split("/").slice(0,-1);return t.length===1&&b.test(t[0])&&(t[0]+="/"),t.join("/")||(p(e)?"/":".")},"dirname");c(function(e){const t=[e.root,e.dir,e.base??e.name+e.ext].filter(Boolean);return l(e.root?g(...t):t.join("/"))},"format");const V=c((e,t)=>{const n=l(e).split("/").pop();return t&&n.endsWith(t)?n.slice(0,-t.length):n},"basename");c(function(e){let t=l(e).split("/").shift();t===""?t="/":t+="/";const n=V(e),r=B(n);return{base:n,dir:y(e),ext:r,name:n.slice(0,n.length-r.length),root:t}},"parse");var G=Object.defineProperty,d=f((e,t)=>G(e,"name",{value:t,configurable:!0}),"r");const R="last-update-check.json",w=d(e=>{const t=P(e);if(t===void 0)throw new Error("Could not find cache directory");return T(t,R)},"getConfigFile"),q=d(e=>{const t=w(e);try{if(!h(t))return;const{lastUpdateCheck:n}=JSON.parse(O(t,"utf8"));return n}catch{return}},"getLastUpdate"),H=d(e=>{const t=w(e),n=y(t);h(n)||k(n,{recursive:!0}),N(t,JSON.stringify({lastUpdateCheck:Date.now()}))},"saveLastUpdate");var K=Object.defineProperty,Q=f((e,t)=>K(e,"name",{value:t,configurable:!0}),"g");const X=Q(async(e,t,n)=>{const r=n.replace("__NAME__",e);return await new Promise((o,a)=>{x(r,s=>{let i="";s.on("data",u=>i+=u),s.on("end",()=>{try{const u=JSON.parse(i)[t];u||a(new Error("Error getting version")),o(u)}catch{a(new Error("Could not parse version response"))}})}).on("error",s=>a(s))})},"getDistributionVersion");var Y=Object.defineProperty,ee=f((e,t)=>Y(e,"name",{value:t,configurable:!0}),"i");const ae=ee(async({alwaysRun:e,debug:t,distTag:n="latest",pkg:r,registryUrl:o="https://registry.npmjs.org/-/package/__NAME__/dist-tags",updateCheckInterval:a=1e3*60*60*24})=>{const s=q(r.name);if(e||!s||s<Date.now()-a){const i=await X(r.name,n,o);if(H(r.name),S(i,r.version))return i;t&&console.error(`Latest version (${i}) not newer than current version (${r.version})`)}else t&&console.error(`Too recent to check for a new update. simpleUpdateNotifier() interval set to ${a}ms but only ${Date.now()-s}ms since last check.`);return null},"hasNewVersion");export{ae as default};
@@ -0,0 +1,10 @@
1
+ "use strict";var ne=Object.create;var P=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ae=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var c=(t,e)=>P(t,"name",{value:e,configurable:!0});var se=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of re(e))!ie.call(t,r)&&r!==n&&P(t,r,{get:()=>e[r],enumerable:!(o=oe(e,r))||o.enumerable});return t};var le=(t,e,n)=>(n=t!=null?ne(ae(t)):{},se(e||!t||!t.__esModule?P(n,"default",{value:t,enumerable:!0}):n,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("node:process"),ce=require("@visulima/boxen"),v=require("@visulima/colorize"),B=require("@visulima/pail/processor"),pe=require("@visulima/pail/server"),de=require("command-line-args"),me=require("cli-table3"),ue=require("@visulima/colorize/template"),ge=require("node:os"),he=require("fastest-levenshtein"),_=c(t=>t&&typeof t=="object"&&"default"in t?t.default:t,"_interopDefaultCompat"),fe=_(de),O=_(me),ve=_(ue),ye=_(ge);var be=Object.defineProperty,A=c((t,e)=>be(t,"name",{value:e,configurable:!0}),"f$3");const $e=/[\p{Lu}]/u,we=/[\p{Ll}]/u,k=/^[\p{Lu}](?![\p{Lu}])/gu,W=/([\p{Alpha}\p{N}_]|$)/u,R=/[_.\- ]+/,Ee=new RegExp("^"+R.source),U=new RegExp(R.source+W.source,"gu"),I=new RegExp("\\d+"+W.source,"gu"),Oe=A((t,e,n,o)=>{let r=!1,i=!1,a=!1,s=!1;for(let l=0;l<t.length;l++){const d=t[l];s=l>2?t[l-3]==="-":!0,r&&$e.test(d)?(t=t.slice(0,l)+"-"+t.slice(l),r=!1,a=i,i=!0,l++):i&&a&&we.test(d)&&(!s||o)?(t=t.slice(0,l-1)+"-"+t.slice(l-1),a=i,i=!1,r=!0):(r=e(d)===d&&n(d)!==d,a=i,i=n(d)===d&&e(d)!==d)}return t},"preserveCamelCase"),Ce=A((t,e)=>(k.lastIndex=0,t.replaceAll(k,n=>e(n))),"preserveConsecutiveUppercase"),_e=A((t,e)=>(U.lastIndex=0,I.lastIndex=0,t.replaceAll(I,(n,o,r)=>["_","-"].includes(t.charAt(r+n.length))?n:e(n)).replaceAll(U,(n,o)=>e(o))),"postProcess");function H(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(r=>r.trim()).filter(r=>r.length).join("-"):t=t.trim(),t.length===0)return"";const n=e.locale===!1?r=>r.toLowerCase():r=>r.toLocaleLowerCase(e.locale),o=e.locale===!1?r=>r.toUpperCase():r=>r.toLocaleUpperCase(e.locale);return t.length===1?R.test(t)?"":e.pascalCase?o(t):n(t):(t!==n(t)&&(t=Oe(t,n,o,e.preserveConsecutiveUppercase)),t=t.replace(Ee,""),t=e.preserveConsecutiveUppercase?Ce(t,n):n(t),e.pascalCase&&(t=o(t.charAt(0))+t.slice(1)),_e(t,o))}c(H,"S");A(H,"camelCase");const C=[{description:"Turn on verbose output",group:"global",name:"verbose",type:Boolean},{description:"Turn on debugging output",group:"global",name:"debug",type:Boolean},{alias:"h",description:"Print out helpful usage information",group:"global",name:"help",type:Boolean},{alias:"q",description:"Silence output",group:"global",name:"quiet",type:Boolean},{alias:"V",description:"Print version info",group:"global",name:"version",type:Boolean},{description:"Turn off colored output",group:"global",name:"no-color",type:Boolean},{description:"Force colored output",group:"global",name:"color",type:Boolean}];var Ae=Object.defineProperty,Ne=c((t,e)=>Ae(t,"name",{value:e,configurable:!0}),"e$4");const m=Ne(t=>t?ve(Object.assign([],{raw:[t.replaceAll("`","\\`")]})):"","templateFormat");var Le=Object.defineProperty,xe=c((t,e)=>Le(t,"name",{value:e,configurable:!0}),"t$6");let J=class{static{c(this,"n")}static{xe(this,"BaseSection")}lines;constructor(){this.lines=[]}add(e){this.lines.push(e)}toString(){return this.lines.join(ye.EOL)}header(e){this.add(v.bold(e)),this.lines.push("")}};var Pe=Object.defineProperty,Se=c((t,e)=>Pe(t,"name",{value:e,configurable:!0}),"p$4");const w={chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,60],style:{border:[],compact:!0,head:[],"padding-left":2,"padding-right":1},wordWrap:!0};let je=class extends J{static{c(this,"y")}static{Se(this,"ContentSection")}constructor(e){if(super(),e.header&&this.header(m(e.header)),e.content){if(e.raw)if(Array.isArray(e.content)&&e.content.every(n=>typeof n=="string"))e.content.forEach(n=>{Array.isArray(n)?n.forEach(o=>this.add(m(o))):this.add(m(n))});else if(typeof e.content=="string")this.add(m(e.content));else throw new TypeError("Invalid raw content, must be a string or array of strings.");else this.add(this.getContentLines(e.content));this.add("")}}getContentLines(e){if(typeof e=="string"){const n=new O({...w,colWidths:[80]});return n.push([m(e)]),n.toString()}if(Array.isArray(e)&&e.every(n=>typeof n=="string"||Array.isArray(n)&&n.every(o=>typeof o=="string"))){const n=new O({...w});return e.forEach(o=>{Array.isArray(o)?n.push(o.map(r=>m(r))):n.push([m(o)])}),n.toString()}if(typeof e=="object"){const n=e;if(!n.options||!n.data)throw new Error(`Must have an "options" or "data" property
2
+ ${JSON.stringify(e)}`);const o=new O({...w,...n.options,style:{...w.style,...n.options.style}});return n.data.forEach(r=>{Array.isArray(r)?o.push(r.map(i=>m(i))):o.push([m(r)])}),o.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
3
+
4
+ ${JSON.stringify(e)}`)}};var Re=Object.defineProperty,Te=c((t,e)=>Re(t,"name",{value:e,configurable:!0}),"a$1");let Ve=class extends J{static{c(this,"c")}static{Te(this,"OptionListSection")}constructor(e){super();let n=e.optionList??[];const o=Array.isArray(e.hide)?e.hide:[e.hide].filter(Boolean),r=Array.isArray(e.group)?e.group:[e.group].filter(Boolean);o.length>0&&(n=n.filter(a=>!o.includes(a.name))),e.header&&this.header(m(e.header)),r.length>0&&(n=n.filter(a=>{const s=r.includes("_none")&&!a.group,l=this.intersect(Array.isArray(a.group)?a.group:[a.group],r);return s||l?a:void 0}));const i=new O({chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,40],style:{"padding-left":2,"padding-right":1},wordWrap:!0});n.forEach(a=>i.push([this.getOptionNames(a,e.reverseNameOrder??!1,e.isArgument??!1),m(a.description)])),this.add(i.toString()),this.lines.push("")}getOptionNames(e,n,o){if(!e.name)throw new TypeError("Invalid option definition, name is required.");let r=e.type?e.type.name.toLowerCase():"string";const i=e.multiple||e.lazyMultiple?"[]":"";r=m(e.typeLabel??`{underline ${r}${i}}`);let a;if(e.alias)if(e.name){const s=o?e.name:`{yellow --${e.name}}`;a=m(n?`{bold ${s}}, {bold -${e.alias}} ${r}`:`{bold -${e.alias}}, {bold ${s}} ${r}`)}else n?a=m(`{bold -${e.alias}} ${r}`):a=m(`{bold -${e.alias}} ${r}`);else a=m(`{bold ${o?e.name:`{yellow --${e.name}}`}} ${r}`);return a}intersect(e,n){return e.some(o=>n.includes(o))}};var Be=Object.defineProperty,ke=c((t,e)=>Be(t,"name",{value:e,configurable:!0}),"o$3");const z=ke(t=>(Array.isArray(t)?t:[t]).length===0?"":`
5
+ ${t.map(e=>e.optionList?new Ve(e).toString():new je(e).toString()).join(`
6
+ `)}`,"commandLineUsage");var Ue=Object.defineProperty,N=c((t,e)=>Ue(t,"name",{value:e,configurable:!0}),"l$5");const D="__Other",q=N(t=>t.charAt(0).toUpperCase()+t.slice(1),"upperFirstChar"),Ie=N((t,e,n,o)=>{t.debug("no command given, printing general help...");let r=[...new Set(n.values())].filter(a=>!a.hidden);o&&(r=r.filter(a=>a.group===o));const i=r.reduce((a,s)=>{const l=s.group??D;return a[l]||(a[l]=[]),a[l].push(s),a},{});t.raw(z([{content:`{cyan ${e.getCliName()}} {green <command>} [positional arguments] {yellow [options]}`,header:"{inverse.cyan Usage }"},...Object.keys(i).map(a=>({content:i[a].map(s=>{let l="";return typeof s.alias=="string"?l=s.alias:Array.isArray(s.alias)&&(l=s.alias.join(", ")),l!==""&&(l=` [${l}]`),[`{green ${s.name}} ${l}`,s.description??""]}),header:a===D||o?`{inverse.green Available${o?` ${q(o)}`:""} Commands }`:` {inverse.green ${q(a)} }`})),n.has("help")?{header:"{inverse.yellow Command Options }",optionList:n.get("help").options?.filter(a=>!a.hidden)}:void 0,{header:"{inverse.yellow Global Options }",optionList:C},{content:`Run "{cyan ${e.getCliName()}} {green help <command>}" or "{cyan ${e.getCliName()}} {green <command>} {yellow --help}" for help with a specific command.`,raw:!0}].filter(Boolean)))},"printGeneralHelp"),De=N((t,e,n,o)=>{const r=n.get(o),i=[];if(i.push({content:`{cyan ${e.getCliName()}} {green ${r.name}}${r.argument?" [positional arguments]":""}${r.options?" [options]":""}`,header:"{inverse.cyan Usage }"}),r.description&&i.push({content:r.description,header:"{inverse.green Description }"}),r.argument&&i.push({header:"Command Positional Arguments",isArgument:!0,optionList:[r.argument]}),Array.isArray(r.options)&&r.options.length>0&&i.push({header:"{inverse.yellow Command Options }",optionList:r.options.filter(a=>!a.hidden)}),i.push({header:"{inverse.yellow Global Options }",optionList:C}),r.alias!==void 0&&r.alias.length>0){let a=r.alias;typeof r.alias=="string"&&(a=[r.alias]),i.splice(1,0,{content:a,header:"Alias(es)"})}Array.isArray(r.examples)&&r.examples.length>0&&i.push({content:r.examples,header:"Examples"}),t.raw(z(i))},"printCommandHelp");class qe{static{c(this,"C")}static{N(this,"HelpCommand")}name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(e){this.commands=e}execute(e){const{commandName:n,logger:o,options:r,runtime:i}=e,{footer:a,header:s}=i.getCommandSection();s&&o.raw(m(s)),n==="help"?Ie(o,i,this.commands,r?.group):De(o,i,this.commands,n),a&&o.raw(m(a))}}var Me=Object.defineProperty,Fe=c((t,e)=>Me(t,"name",{value:e,configurable:!0}),"s$7");const Ye={alias:["v","V"],description:"Output the version number",execute:Fe(({logger:t,runtime:e})=>{const n=e.getPackageVersion();n===void 0?(t.warn("Unknown version"),t.debug("The version number was not provided by the cli constructor.")):t.info(n)},"execute"),name:"version",options:[],usage:[]},M=16,Ge=32,We=64,S=128,E="positionals";var He=Object.defineProperty,Je=c((t,e)=>He(t,"name",{value:e,configurable:!0}),"m$2");let ze=class{static{c(this,"c")}static{Je(this,"EmptyToolbox")}result;argv;options;argument;command;commandName;runtime;logger;constructor(e,n){this.commandName=e,this.command=n}};var Ke=Object.defineProperty,Qe=c((t,e)=>Ke(t,"name",{value:e,configurable:!0}),"s$6");const Xe=Qe(()=>{const t=process.env.CEREBRO_MIN_NODE_VERSION?Number(process.env.CEREBRO_MIN_NODE_VERSION):18,e=process.version.replace("v","");Number(/v([^.]+)/.exec(process.version)[1])<t&&(console.log(`cerebro supports a minimum Node version of ${t}. You have ${e}. Read our version support policy: https://github.com/visulima/visulima#supported-nodejs-versions`),process.exit(1))},"checkNodeVersion");var Ze=Object.defineProperty,et=c((t,e)=>Ze(t,"name",{value:e,configurable:!0}),"r$4");const tt=/^-{1,2}(\w+)(=(\w+))?$/,K=et((t,e)=>{const n=tt.exec(t);if(n==null)return{};const o=n[1],r=e.find(i=>i.name===o||i.alias===o);return r!==void 0?{argName:r.name,argValue:n[3],option:r}:{}},"getParameterOption");var nt=Object.defineProperty,ot=c((t,e)=>nt(t,"name",{value:e,configurable:!0}),"i$3");const b=ot(t=>t.type?.name==="Boolean","isBoolean");var rt=Object.defineProperty,j=c((t,e)=>rt(t,"name",{value:e,configurable:!0}),"n$2");const F=j((t,e)=>{if(e.type===void 0)return t;if(e.type.name==="Boolean"){if(t==="true"||t==="1")return e.type(!0);if(t==="false"||t==="0")return e.type(!1)}return e.type(t)},"convertType"),at=new Set(["1","0","true","false"]),it=j((t,e)=>{const n=j((o,r)=>{const{argName:i,argValue:a,option:s}=K(r,e),{lastOption:l}=o;return s&&b(s)&&a&&i?o.partial[i]=F(a,s):o.lastName&&l&&b(l)&&at.has(r)&&(o.partial[o.lastName]=F(r,l)),{lastName:i,lastOption:s,partial:o.partial}},"getBooleanValue");return t.reduce(n,{partial:{}}).partial},"getBooleanValues");var st=Object.defineProperty,Q=c((t,e)=>st(t,"name",{value:e,configurable:!0}),"p$1");const lt=Q(t=>{let e=t.type?t.type.name.toLowerCase():"string";const n=t.multiple??t.lazyMultiple?"[]":"";return e&&(e=e==="boolean"?"":`{underline ${e}${n}}`),e},"getTypeLabel"),ct=Q(t=>(b(t)||(t.typeLabel=t.typeLabel??lt(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var pt=Object.defineProperty,Y=c((t,e)=>pt(t,"name",{value:e,configurable:!0}),"s$3");const dt=new Set(["1","0","true","false"]),mt=Y((t,e)=>{const n=Y((o,r)=>{const{argValue:i,option:a}=K(r,e),{lastOption:s}=o;if(s&&b(s)&&dt.has(r)){const l=[...o.args];return l.pop(),{args:l}}return a&&b(a)&&i?{args:o.args}:{args:[...o.args,r],lastOption:a}},"removeBooleanArguments");return t.reduce(n,{args:[]}).args},"removeBooleanValues");var ut=Object.defineProperty,X=c((t,e)=>ut(t,"name",{value:e,configurable:!0}),"e$2");const gt=new RegExp(/^-([^\d-])$/),ht=new RegExp(/^--(\S+)/),ft=new RegExp(/^-([^\d-]{2,})$/),vt=X(t=>gt.test(t)||ht.test(t)||ft.test(t),"isOption"),yt=X((t,e)=>{const n=e[0]&&vt(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(n)){const o=new Error(`Command not recognised: ${n}`);throw o.command=n,o.name="INVALID_COMMAND",o}return{argv:e,command:n}},"commandLineCommands");var bt=Object.defineProperty,Z=c((t,e)=>bt(t,"name",{value:e,configurable:!0}),"i$1");const $t=Z((t,e)=>he.distance(t,e)<=t.length/3||e.includes(t),"isSimilar"),G=Z((t,e)=>{const n=t.toLowerCase();return e.filter(o=>$t(o.toLowerCase(),n))},"findAlternatives");var wt=Object.defineProperty,Et=c((t,e)=>wt(t,"name",{value:e,configurable:!0}),"t$3");const Ot=Et((t,e)=>t.filter(n=>n.required&&e[n.name]==null).filter(n=>n.type?.name==="Boolean"?(e[n.name]=!1,!1):!0),"listMissingArguments");var Ct=Object.defineProperty,_t=c((t,e)=>Ct(t,"name",{value:e,configurable:!0}),"t$2");const At=_t(t=>{const e=new Map;return t.forEach(n=>{e.set(n.name,{...e.get(n.name),...n})}),[...e.values()]},"mergeArguments");var Nt=Object.defineProperty,L=c((t,e)=>Nt(t,"name",{value:e,configurable:!0}),"e$1");const Lt=L(()=>!!process.versions.electron,"isElectronApp"),xt=L(()=>Lt()&&!process.defaultApp,"isBundledElectronApp"),Pt=L(()=>xt()?0:1,"getProcessArgvBinIndex"),St=L(t=>t.slice(Pt()+1),"hideBin");var jt=Object.defineProperty,ee=c((t,e)=>jt(t,"name",{value:e,configurable:!0}),"i");const Rt=" ",Tt=ee((t,e)=>t.length===e.length&&t.every((n,o)=>n===e[o]),"equals"),Vt=ee(t=>typeof t=="string"?t.split(Rt):Tt(t,process.argv)?St(t):t,"parseRawCommand");var Bt=Object.defineProperty,kt=c((t,e)=>Bt(t,"name",{value:e,configurable:!0}),"t");const Ut=kt(t=>{process.on("uncaughtException",e=>{t.error(`Uncaught exception: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)}),process.on("unhandledRejection",e=>{t.error(`Promise rejection: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)})},"registerExceptionHandler");var It=Object.defineProperty,y=c((t,e)=>It(t,"name",{value:e,configurable:!0}),"g");const Dt="CI"in p.env&&("GITHUB_ACTIONS"in p.env||"GITLAB_CI"in p.env||"CIRCLECI"in p.env),qt=y(t=>t.charAt(0).toLowerCase()+t.slice(1),"lowerFirstChar");class Mt{static{c(this,"Cli")}static{y(this,"Cli")}logger;argv;cwd;cliName;packageVersion;packageName;extensions=[];commands;defaultCommand;updateNotifierOptions;commandSection;constructor(e,n={}){const{argv:o,cwd:r,packageName:i,packageVersion:a}={argv:p.argv,cwd:p.cwd(),...n};this.argv=Vt(o),this.argv.includes("--quiet")||this.argv.includes("-q")?p.env.CEREBRO_OUTPUT_LEVEL=String(M):this.argv.includes("--verbose")||this.argv.includes("-v")?p.env.CEREBRO_OUTPUT_LEVEL=String(We):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in p.env?p.env.CEREBRO_OUTPUT_LEVEL=String(S):p.env.CEREBRO_OUTPUT_LEVEL=String(Ge);const s={32:"informational",64:"trace",128:"debug"},l=[new B.MessageFormatterProcessor];p.env.CEREBRO_OUTPUT_LEVEL===String(S)&&l.push(new B.CallerProcessor),this.logger=pe.createPail({logLevel:p.env.CEREBRO_OUTPUT_LEVEL?s[p.env.CEREBRO_OUTPUT_LEVEL]??"informational":"informational",processors:l,...n.logger}),p.env.CEREBRO_OUTPUT_LEVEL===String(M)&&this.logger.disable(),Xe(),Ut(this.logger),this.cliName=e,this.packageVersion=a,this.packageName=i,this.cwd=r,this.defaultCommand="help",this.commandSection={header:`${this.cliName}${this.packageVersion?` v${this.packageVersion}`:""}`},this.commands=new Map,this.addCoreExtensions(),this.addCommand(Ye),this.addCommand(new qe(this.commands))}setCommandSection(e){return this.commandSection=e,this}getCommandSection(){return this.commandSection}setDefaultCommand(e){return this.defaultCommand=e,this}addCommand(e){if(this.commands.has(e.name))throw new Error(`Ignored command with name "${e.name}", it was found in the command list.`);if(e.options?.map(n=>ct(n)),this.validateDoubleOptions(e),this.addNegatableOption(e),e.options?.forEach(n=>{n.__camelCaseName__=H(n.name)}),this.commands.set(e.name,e),e.alias!==void 0){let n=e.alias;typeof e.alias=="string"&&(n=[e.alias]),n.forEach(o=>{if(this.logger.debug("adding alias",o),this.commands.has(o))throw new Error(`Ignoring command alias "${o}, command with the same name was found."`);this.commands.set(o,e)})}return this}addExtension(e){return this.extensions.push(e),this}enableUpdateNotifier(e={}){if(!this.packageName||!this.packageVersion)throw new Error("Cannot enable update notifier without package name and version.");const n=Object.keys(e);if(n.length>0&&!n.includes("alwaysRun")&&!n.includes("distTag")&&!n.includes("updateCheckInterval"))throw new Error("Invalid update notifier options, please check the documentation.");return this.updateNotifierOptions={alwaysRun:!1,debug:p.env.CEREBRO_OUTPUT_LEVEL===String(S),distTag:"latest",pkg:{name:this.packageName,version:this.packageVersion},updateCheckInterval:1e3*60*60*24,...e},this}getCliName(){return this.cliName}getPackageVersion(){return this.packageVersion}getPackageName(){return this.packageName}getCommands(){return this.commands}getCwd(){return this.cwd}async run(e={}){const{shouldExitProcess:n=!0,...o}=e,r=[...this.commands.keys()];let i;this.logger.debug(`process.execPath: ${p.execPath}`),this.logger.debug(`process.execArgv: ${p.execArgv.join(" ")}`),this.logger.debug(`process.argv: ${p.argv.join(" ")}`);try{i=yt([null,...r],this.argv)}catch(h){if(h.name==="INVALID_COMMAND"&&h.command){let T="";const V=G(h.command,[...this.commands.keys()]);V.length>0&&(T=` Did you mean: \r
7
+ - ${V.join(` \r
8
+ - `)}`),this.logger.error(`"${h.command}" is not an available command.${T}`)}else this.logger.error(h);return n?p.exit(1):void 0}const a=i.command??this.defaultCommand,s=this.commands.get(a);if(typeof s.execute!="function")return this.logger.error(`Command "${s.name}" has no function to execute.`),n?p.exit(1):void 0;const l=i.argv;this.logger.debug(`command '${a}' found, parsing command args: ${l.join(", ")}`);let d=At([...s.options??[],...C]);d.forEach(h=>{if(h.multiple&&h.lazyMultiple)throw new Error(`Argument "${h.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}),s.argument&&(this.logger.debug("command has positional argument, parsing them..."),d=[{defaultOption:!0,description:s.argument?.description,group:"positionals",multiple:!0,name:E,type:s.argument?.type,typeLabel:s.argument?.typeLabel},...d]);const g=fe(d,{argv:mt(l,s.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),$=it(l,s.options??[]),f={...g,_all:{...g._all,...$}};this.validateCommandOptions(d,f,s);const u=new ze(s.name,s);u.runtime=this,await this.registerExtensions(u),await this.updateNotifier(u);const{_all:x,positionals:te}=f;return x[E]&&delete x[E],u.argument=te?.[E]??[],u.argv=this.argv,u.options={...x,...o},this.mapNegatableOptions(u,s),this.mapImpliesOptions(u,s),this.validateCommandArgsForConflicts(d,u.options,s),this.logger.debug("command options parsed from options:"),this.logger.debug(JSON.stringify(u.options,null,2)),this.logger.debug("command argument parsed from argument:"),this.logger.debug(JSON.stringify(u.argument,null,2)),await this.prepareToolboxResult(f,u,s),n?p.exit(0):void 0}validateDoubleOptions(e){if(Array.isArray(e.options)){const n=e.options.reduce((i,a)=>{const s=`${a.name}-${a.alias}`;return i[s]||(i[s]=[]),i[s].push(a),i},{}),o=Object.values(n).filter(i=>i.length>1);let r="";if(o.forEach(i=>{const a=i[0],s=i[1];let l="alias";a.name===s.name&&(l="name",a.alias===s.alias&&(l+=" and alias")),r+=`Cannot add option ${l} "${JSON.stringify(s)}" to command "${e.name}" due to conflicting option ${JSON.stringify(a)}
9
+ `}),r.length>0)throw new Error(r)}}addCoreExtensions(){this.addExtension({execute:y(e=>{e.logger=this.logger},"execute"),name:"logger"})}async prepareToolboxResult(e,n,o){if(e.global?.help){this.logger.debug("'--help' option found, running 'help' for given command...");const r=this.commands.get("help");if(!r)throw new Error("Help command not found.");await r.execute(n);return}if(e.global?.version||e.global?.V){this.logger.debug("'--version' option found, running 'version' for given command...");const r=this.commands.get("version");if(!r)throw new Error("Version command not found.");await r.execute(n);return}await o.execute(n)}async updateNotifier({logger:e}){if(this.updateNotifierOptions?.alwaysRun||!(p.env.NO_UPDATE_NOTIFIER||p.env.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||Dt)&&this.updateNotifierOptions){e.raw("Checking for updates...");const n=await(await import("../packem_chunks/has-new-version.cjs").then(o=>o.default))(this.updateNotifierOptions);if(n){const o="Update available "+v.dim(this.packageVersion+"")+v.reset(" → ")+v.green(n);this.logger.error(ce.boxen(o,{borderColor:y(r=>v.yellow(r),"borderColor"),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}))}}}validateCommandOptions(e,n,o){const r=Ot(e,n);if(r.length>0)throw new Error(`You called the command "${o.name}" without the required options: ${r.map(i=>i.name).join(", ")}`);if(n._unknown&&n._unknown.length>0){const i=[];if(n._unknown.forEach(a=>{const s=a.startsWith("--");let l=`Found unknown ${s?"option":"argument"} "${a}"`;if(s){const d=G(a.replace("--",""),[...(o.options??[]).map(g=>g.name),...C.map(g=>g.name)]);if(d.length>0){const[g,...$]=d.map(f=>`--${f}`);l+=$.length>0?`, did you mean ${g} or ${$.join(", ")}?`:`, did you mean ${g}?`}}i.push(l)}),i.length>0)throw new Error(i.join(`
10
+ `))}}validateCommandArgsForConflicts(e,n,o){const r=e.filter(i=>i.conflicts!==void 0);if(r.length>0){const i=r.find(a=>Array.isArray(a.conflicts)?a.conflicts.some(s=>n[s]!==void 0)&&n[a.name]!==void 0:n[a.conflicts]!==void 0&&n[a.name]!==void 0);if(i)throw new Error(`You called the command "${o.name}" with conflicting options: ${i.name} and ${typeof i.conflicts=="string"?i.conflicts:i.conflicts?.join(", ")}`)}}addNegatableOption(e){Array.isArray(e.options)&&e.options.forEach(n=>{if(n.name.startsWith("no-")&&!e.options.some(o=>o.name===n.name.replace("no-",""))){if(n.type!==Boolean){this.logger.debug(`Cannot add negated option "${n.name}" to command "${e.name}" because it is not a boolean.`);return}const o={...n,defaultValue:n.defaultValue===void 0?!0:!n.defaultValue,name:`${n.name.replace("no-","")}`};e.options.push(o)}})}async registerExtensions(e){const n=y(async o=>typeof o.execute!="function"?(this.logger.warn(`Skipped ${o.name} because execute is not a function.`),null):(await o.execute(e),null),"callback");for(const o of this.extensions)await n(o)}mapNegatableOptions(e,n){Object.entries(e.options).forEach(([o,r])=>{if(/^no\w+/.test(o)){const i=qt(o.replace("no",""));this.logger.debug(`mapping negated option "${o}" to "${i}"`),e.options[i]=!r,n.options?.forEach(a=>{a.name===i&&(a.__negated__=!0)})}})}mapImpliesOptions(e,n){Object.keys(e.options).forEach(o=>{const r=n.options?.find(i=>i.__camelCaseName__===o&&i.__negated__===void 0&&i.implies!==void 0);if(r?.implies){const i=r.implies;Object.entries(i).forEach(([a,s])=>{if(e.options[a]===void 0)e.options[a]=s;else{const l=n.options?.find(d=>d.name===a);(l?.defaultValue===void 0||e.options[a]===l.defaultValue)&&(e.options[a]=s)}})}})}}exports.Cli=Mt;
@@ -0,0 +1,10 @@
1
+ var ee=Object.defineProperty;var c=(t,e)=>ee(t,"name",{value:e,configurable:!0});import{argv as V,cwd as te,env as d,execPath as oe,execArgv as ne,exit as L}from"node:process";import{boxen as re}from"@visulima/boxen";import{bold as ae,dim as ie,reset as se,green as le,yellow as ce}from"@visulima/colorize";import{MessageFormatterProcessor as pe,CallerProcessor as me}from"@visulima/pail/processor";import{createPail as de}from"@visulima/pail/server";import ue from"command-line-args";import E from"cli-table3";import ge from"@visulima/colorize/template";import he from"node:os";import{distance as fe}from"fastest-levenshtein";var ve=Object.defineProperty,C=c((t,e)=>ve(t,"name",{value:e,configurable:!0}),"f$3");const ye=/[\p{Lu}]/u,be=/[\p{Ll}]/u,T=/^[\p{Lu}](?![\p{Lu}])/gu,Y=/([\p{Alpha}\p{N}_]|$)/u,S=/[_.\- ]+/,$e=new RegExp("^"+S.source),B=new RegExp(S.source+Y.source,"gu"),k=new RegExp("\\d+"+Y.source,"gu"),we=C((t,e,o,n)=>{let r=!1,i=!1,a=!1,s=!1;for(let l=0;l<t.length;l++){const p=t[l];s=l>2?t[l-3]==="-":!0,r&&ye.test(p)?(t=t.slice(0,l)+"-"+t.slice(l),r=!1,a=i,i=!0,l++):i&&a&&be.test(p)&&(!s||n)?(t=t.slice(0,l-1)+"-"+t.slice(l-1),a=i,i=!1,r=!0):(r=e(p)===p&&o(p)!==p,a=i,i=o(p)===p&&e(p)!==p)}return t},"preserveCamelCase"),Ee=C((t,e)=>(T.lastIndex=0,t.replaceAll(T,o=>e(o))),"preserveConsecutiveUppercase"),Oe=C((t,e)=>(B.lastIndex=0,k.lastIndex=0,t.replaceAll(k,(o,n,r)=>["_","-"].includes(t.charAt(r+o.length))?o:e(o)).replaceAll(B,(o,n)=>e(n))),"postProcess");function G(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(r=>r.trim()).filter(r=>r.length).join("-"):t=t.trim(),t.length===0)return"";const o=e.locale===!1?r=>r.toLowerCase():r=>r.toLocaleLowerCase(e.locale),n=e.locale===!1?r=>r.toUpperCase():r=>r.toLocaleUpperCase(e.locale);return t.length===1?S.test(t)?"":e.pascalCase?n(t):o(t):(t!==o(t)&&(t=we(t,o,n,e.preserveConsecutiveUppercase)),t=t.replace($e,""),t=e.preserveConsecutiveUppercase?Ee(t,o):o(t),e.pascalCase&&(t=n(t.charAt(0))+t.slice(1)),Oe(t,n))}c(G,"S");C(G,"camelCase");const O=[{description:"Turn on verbose output",group:"global",name:"verbose",type:Boolean},{description:"Turn on debugging output",group:"global",name:"debug",type:Boolean},{alias:"h",description:"Print out helpful usage information",group:"global",name:"help",type:Boolean},{alias:"q",description:"Silence output",group:"global",name:"quiet",type:Boolean},{alias:"V",description:"Print version info",group:"global",name:"version",type:Boolean},{description:"Turn off colored output",group:"global",name:"no-color",type:Boolean},{description:"Force colored output",group:"global",name:"color",type:Boolean}];var Ce=Object.defineProperty,Ae=c((t,e)=>Ce(t,"name",{value:e,configurable:!0}),"e$4");const m=Ae(t=>t?ge(Object.assign([],{raw:[t.replaceAll("`","\\`")]})):"","templateFormat");var Ne=Object.defineProperty,_e=c((t,e)=>Ne(t,"name",{value:e,configurable:!0}),"t$6");let W=class{static{c(this,"n")}static{_e(this,"BaseSection")}lines;constructor(){this.lines=[]}add(e){this.lines.push(e)}toString(){return this.lines.join(he.EOL)}header(e){this.add(ae(e)),this.lines.push("")}};var Le=Object.defineProperty,xe=c((t,e)=>Le(t,"name",{value:e,configurable:!0}),"p$4");const $={chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,60],style:{border:[],compact:!0,head:[],"padding-left":2,"padding-right":1},wordWrap:!0};let Pe=class extends W{static{c(this,"y")}static{xe(this,"ContentSection")}constructor(e){if(super(),e.header&&this.header(m(e.header)),e.content){if(e.raw)if(Array.isArray(e.content)&&e.content.every(o=>typeof o=="string"))e.content.forEach(o=>{Array.isArray(o)?o.forEach(n=>this.add(m(n))):this.add(m(o))});else if(typeof e.content=="string")this.add(m(e.content));else throw new TypeError("Invalid raw content, must be a string or array of strings.");else this.add(this.getContentLines(e.content));this.add("")}}getContentLines(e){if(typeof e=="string"){const o=new E({...$,colWidths:[80]});return o.push([m(e)]),o.toString()}if(Array.isArray(e)&&e.every(o=>typeof o=="string"||Array.isArray(o)&&o.every(n=>typeof n=="string"))){const o=new E({...$});return e.forEach(n=>{Array.isArray(n)?o.push(n.map(r=>m(r))):o.push([m(n)])}),o.toString()}if(typeof e=="object"){const o=e;if(!o.options||!o.data)throw new Error(`Must have an "options" or "data" property
2
+ ${JSON.stringify(e)}`);const n=new E({...$,...o.options,style:{...$.style,...o.options.style}});return o.data.forEach(r=>{Array.isArray(r)?n.push(r.map(i=>m(i))):n.push([m(r)])}),n.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
3
+
4
+ ${JSON.stringify(e)}`)}};var Se=Object.defineProperty,Re=c((t,e)=>Se(t,"name",{value:e,configurable:!0}),"a$1");let je=class extends W{static{c(this,"c")}static{Re(this,"OptionListSection")}constructor(e){super();let o=e.optionList??[];const n=Array.isArray(e.hide)?e.hide:[e.hide].filter(Boolean),r=Array.isArray(e.group)?e.group:[e.group].filter(Boolean);n.length>0&&(o=o.filter(a=>!n.includes(a.name))),e.header&&this.header(m(e.header)),r.length>0&&(o=o.filter(a=>{const s=r.includes("_none")&&!a.group,l=this.intersect(Array.isArray(a.group)?a.group:[a.group],r);return s||l?a:void 0}));const i=new E({chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,40],style:{"padding-left":2,"padding-right":1},wordWrap:!0});o.forEach(a=>i.push([this.getOptionNames(a,e.reverseNameOrder??!1,e.isArgument??!1),m(a.description)])),this.add(i.toString()),this.lines.push("")}getOptionNames(e,o,n){if(!e.name)throw new TypeError("Invalid option definition, name is required.");let r=e.type?e.type.name.toLowerCase():"string";const i=e.multiple||e.lazyMultiple?"[]":"";r=m(e.typeLabel??`{underline ${r}${i}}`);let a;if(e.alias)if(e.name){const s=n?e.name:`{yellow --${e.name}}`;a=m(o?`{bold ${s}}, {bold -${e.alias}} ${r}`:`{bold -${e.alias}}, {bold ${s}} ${r}`)}else o?a=m(`{bold -${e.alias}} ${r}`):a=m(`{bold -${e.alias}} ${r}`);else a=m(`{bold ${n?e.name:`{yellow --${e.name}}`}} ${r}`);return a}intersect(e,o){return e.some(n=>o.includes(n))}};var Ve=Object.defineProperty,Te=c((t,e)=>Ve(t,"name",{value:e,configurable:!0}),"o$3");const H=Te(t=>(Array.isArray(t)?t:[t]).length===0?"":`
5
+ ${t.map(e=>e.optionList?new je(e).toString():new Pe(e).toString()).join(`
6
+ `)}`,"commandLineUsage");var Be=Object.defineProperty,A=c((t,e)=>Be(t,"name",{value:e,configurable:!0}),"l$5");const U="__Other",I=A(t=>t.charAt(0).toUpperCase()+t.slice(1),"upperFirstChar"),ke=A((t,e,o,n)=>{t.debug("no command given, printing general help...");let r=[...new Set(o.values())].filter(a=>!a.hidden);n&&(r=r.filter(a=>a.group===n));const i=r.reduce((a,s)=>{const l=s.group??U;return a[l]||(a[l]=[]),a[l].push(s),a},{});t.raw(H([{content:`{cyan ${e.getCliName()}} {green <command>} [positional arguments] {yellow [options]}`,header:"{inverse.cyan Usage }"},...Object.keys(i).map(a=>({content:i[a].map(s=>{let l="";return typeof s.alias=="string"?l=s.alias:Array.isArray(s.alias)&&(l=s.alias.join(", ")),l!==""&&(l=` [${l}]`),[`{green ${s.name}} ${l}`,s.description??""]}),header:a===U||n?`{inverse.green Available${n?` ${I(n)}`:""} Commands }`:` {inverse.green ${I(a)} }`})),o.has("help")?{header:"{inverse.yellow Command Options }",optionList:o.get("help").options?.filter(a=>!a.hidden)}:void 0,{header:"{inverse.yellow Global Options }",optionList:O},{content:`Run "{cyan ${e.getCliName()}} {green help <command>}" or "{cyan ${e.getCliName()}} {green <command>} {yellow --help}" for help with a specific command.`,raw:!0}].filter(Boolean)))},"printGeneralHelp"),Ue=A((t,e,o,n)=>{const r=o.get(n),i=[];if(i.push({content:`{cyan ${e.getCliName()}} {green ${r.name}}${r.argument?" [positional arguments]":""}${r.options?" [options]":""}`,header:"{inverse.cyan Usage }"}),r.description&&i.push({content:r.description,header:"{inverse.green Description }"}),r.argument&&i.push({header:"Command Positional Arguments",isArgument:!0,optionList:[r.argument]}),Array.isArray(r.options)&&r.options.length>0&&i.push({header:"{inverse.yellow Command Options }",optionList:r.options.filter(a=>!a.hidden)}),i.push({header:"{inverse.yellow Global Options }",optionList:O}),r.alias!==void 0&&r.alias.length>0){let a=r.alias;typeof r.alias=="string"&&(a=[r.alias]),i.splice(1,0,{content:a,header:"Alias(es)"})}Array.isArray(r.examples)&&r.examples.length>0&&i.push({content:r.examples,header:"Examples"}),t.raw(H(i))},"printCommandHelp");class Ie{static{c(this,"C")}static{A(this,"HelpCommand")}name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(e){this.commands=e}execute(e){const{commandName:o,logger:n,options:r,runtime:i}=e,{footer:a,header:s}=i.getCommandSection();s&&n.raw(m(s)),o==="help"?ke(n,i,this.commands,r?.group):Ue(n,i,this.commands,o),a&&n.raw(m(a))}}var De=Object.defineProperty,Me=c((t,e)=>De(t,"name",{value:e,configurable:!0}),"s$7");const Fe={alias:["v","V"],description:"Output the version number",execute:Me(({logger:t,runtime:e})=>{const o=e.getPackageVersion();o===void 0?(t.warn("Unknown version"),t.debug("The version number was not provided by the cli constructor.")):t.info(o)},"execute"),name:"version",options:[],usage:[]},D=16,qe=32,Ye=64,x=128,w="positionals";var Ge=Object.defineProperty,We=c((t,e)=>Ge(t,"name",{value:e,configurable:!0}),"m$2");let He=class{static{c(this,"c")}static{We(this,"EmptyToolbox")}result;argv;options;argument;command;commandName;runtime;logger;constructor(e,o){this.commandName=e,this.command=o}};var Je=Object.defineProperty,ze=c((t,e)=>Je(t,"name",{value:e,configurable:!0}),"s$6");const Ke=ze(()=>{const t=process.env.CEREBRO_MIN_NODE_VERSION?Number(process.env.CEREBRO_MIN_NODE_VERSION):18,e=process.version.replace("v","");Number(/v([^.]+)/.exec(process.version)[1])<t&&(console.log(`cerebro supports a minimum Node version of ${t}. You have ${e}. Read our version support policy: https://github.com/visulima/visulima#supported-nodejs-versions`),process.exit(1))},"checkNodeVersion");var Qe=Object.defineProperty,Xe=c((t,e)=>Qe(t,"name",{value:e,configurable:!0}),"r$4");const Ze=/^-{1,2}(\w+)(=(\w+))?$/,J=Xe((t,e)=>{const o=Ze.exec(t);if(o==null)return{};const n=o[1],r=e.find(i=>i.name===n||i.alias===n);return r!==void 0?{argName:r.name,argValue:o[3],option:r}:{}},"getParameterOption");var et=Object.defineProperty,tt=c((t,e)=>et(t,"name",{value:e,configurable:!0}),"i$3");const y=tt(t=>t.type?.name==="Boolean","isBoolean");var ot=Object.defineProperty,P=c((t,e)=>ot(t,"name",{value:e,configurable:!0}),"n$2");const M=P((t,e)=>{if(e.type===void 0)return t;if(e.type.name==="Boolean"){if(t==="true"||t==="1")return e.type(!0);if(t==="false"||t==="0")return e.type(!1)}return e.type(t)},"convertType"),nt=new Set(["1","0","true","false"]),rt=P((t,e)=>{const o=P((n,r)=>{const{argName:i,argValue:a,option:s}=J(r,e),{lastOption:l}=n;return s&&y(s)&&a&&i?n.partial[i]=M(a,s):n.lastName&&l&&y(l)&&nt.has(r)&&(n.partial[n.lastName]=M(r,l)),{lastName:i,lastOption:s,partial:n.partial}},"getBooleanValue");return t.reduce(o,{partial:{}}).partial},"getBooleanValues");var at=Object.defineProperty,z=c((t,e)=>at(t,"name",{value:e,configurable:!0}),"p$1");const it=z(t=>{let e=t.type?t.type.name.toLowerCase():"string";const o=t.multiple??t.lazyMultiple?"[]":"";return e&&(e=e==="boolean"?"":`{underline ${e}${o}}`),e},"getTypeLabel"),st=z(t=>(y(t)||(t.typeLabel=t.typeLabel??it(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var lt=Object.defineProperty,F=c((t,e)=>lt(t,"name",{value:e,configurable:!0}),"s$3");const ct=new Set(["1","0","true","false"]),pt=F((t,e)=>{const o=F((n,r)=>{const{argValue:i,option:a}=J(r,e),{lastOption:s}=n;if(s&&y(s)&&ct.has(r)){const l=[...n.args];return l.pop(),{args:l}}return a&&y(a)&&i?{args:n.args}:{args:[...n.args,r],lastOption:a}},"removeBooleanArguments");return t.reduce(o,{args:[]}).args},"removeBooleanValues");var mt=Object.defineProperty,K=c((t,e)=>mt(t,"name",{value:e,configurable:!0}),"e$2");const dt=new RegExp(/^-([^\d-])$/),ut=new RegExp(/^--(\S+)/),gt=new RegExp(/^-([^\d-]{2,})$/),ht=K(t=>dt.test(t)||ut.test(t)||gt.test(t),"isOption"),ft=K((t,e)=>{const o=e[0]&&ht(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(o)){const n=new Error(`Command not recognised: ${o}`);throw n.command=o,n.name="INVALID_COMMAND",n}return{argv:e,command:o}},"commandLineCommands");var vt=Object.defineProperty,Q=c((t,e)=>vt(t,"name",{value:e,configurable:!0}),"i$1");const yt=Q((t,e)=>fe(t,e)<=t.length/3||e.includes(t),"isSimilar"),q=Q((t,e)=>{const o=t.toLowerCase();return e.filter(n=>yt(n.toLowerCase(),o))},"findAlternatives");var bt=Object.defineProperty,$t=c((t,e)=>bt(t,"name",{value:e,configurable:!0}),"t$3");const wt=$t((t,e)=>t.filter(o=>o.required&&e[o.name]==null).filter(o=>o.type?.name==="Boolean"?(e[o.name]=!1,!1):!0),"listMissingArguments");var Et=Object.defineProperty,Ot=c((t,e)=>Et(t,"name",{value:e,configurable:!0}),"t$2");const Ct=Ot(t=>{const e=new Map;return t.forEach(o=>{e.set(o.name,{...e.get(o.name),...o})}),[...e.values()]},"mergeArguments");var At=Object.defineProperty,N=c((t,e)=>At(t,"name",{value:e,configurable:!0}),"e$1");const Nt=N(()=>!!process.versions.electron,"isElectronApp"),_t=N(()=>Nt()&&!process.defaultApp,"isBundledElectronApp"),Lt=N(()=>_t()?0:1,"getProcessArgvBinIndex"),xt=N(t=>t.slice(Lt()+1),"hideBin");var Pt=Object.defineProperty,X=c((t,e)=>Pt(t,"name",{value:e,configurable:!0}),"i");const St=" ",Rt=X((t,e)=>t.length===e.length&&t.every((o,n)=>o===e[n]),"equals"),jt=X(t=>typeof t=="string"?t.split(St):Rt(t,process.argv)?xt(t):t,"parseRawCommand");var Vt=Object.defineProperty,Tt=c((t,e)=>Vt(t,"name",{value:e,configurable:!0}),"t");const Bt=Tt(t=>{process.on("uncaughtException",e=>{t.error(`Uncaught exception: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)}),process.on("unhandledRejection",e=>{t.error(`Promise rejection: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)})},"registerExceptionHandler");var kt=Object.defineProperty,v=c((t,e)=>kt(t,"name",{value:e,configurable:!0}),"g");const Ut="CI"in d&&("GITHUB_ACTIONS"in d||"GITLAB_CI"in d||"CIRCLECI"in d),It=v(t=>t.charAt(0).toLowerCase()+t.slice(1),"lowerFirstChar");class to{static{c(this,"Cli")}static{v(this,"Cli")}logger;argv;cwd;cliName;packageVersion;packageName;extensions=[];commands;defaultCommand;updateNotifierOptions;commandSection;constructor(e,o={}){const{argv:n,cwd:r,packageName:i,packageVersion:a}={argv:V,cwd:te(),...o};this.argv=jt(n),this.argv.includes("--quiet")||this.argv.includes("-q")?d.CEREBRO_OUTPUT_LEVEL=String(D):this.argv.includes("--verbose")||this.argv.includes("-v")?d.CEREBRO_OUTPUT_LEVEL=String(Ye):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in d?d.CEREBRO_OUTPUT_LEVEL=String(x):d.CEREBRO_OUTPUT_LEVEL=String(qe);const s={32:"informational",64:"trace",128:"debug"},l=[new pe];d.CEREBRO_OUTPUT_LEVEL===String(x)&&l.push(new me),this.logger=de({logLevel:d.CEREBRO_OUTPUT_LEVEL?s[d.CEREBRO_OUTPUT_LEVEL]??"informational":"informational",processors:l,...o.logger}),d.CEREBRO_OUTPUT_LEVEL===String(D)&&this.logger.disable(),Ke(),Bt(this.logger),this.cliName=e,this.packageVersion=a,this.packageName=i,this.cwd=r,this.defaultCommand="help",this.commandSection={header:`${this.cliName}${this.packageVersion?` v${this.packageVersion}`:""}`},this.commands=new Map,this.addCoreExtensions(),this.addCommand(Fe),this.addCommand(new Ie(this.commands))}setCommandSection(e){return this.commandSection=e,this}getCommandSection(){return this.commandSection}setDefaultCommand(e){return this.defaultCommand=e,this}addCommand(e){if(this.commands.has(e.name))throw new Error(`Ignored command with name "${e.name}", it was found in the command list.`);if(e.options?.map(o=>st(o)),this.validateDoubleOptions(e),this.addNegatableOption(e),e.options?.forEach(o=>{o.__camelCaseName__=G(o.name)}),this.commands.set(e.name,e),e.alias!==void 0){let o=e.alias;typeof e.alias=="string"&&(o=[e.alias]),o.forEach(n=>{if(this.logger.debug("adding alias",n),this.commands.has(n))throw new Error(`Ignoring command alias "${n}, command with the same name was found."`);this.commands.set(n,e)})}return this}addExtension(e){return this.extensions.push(e),this}enableUpdateNotifier(e={}){if(!this.packageName||!this.packageVersion)throw new Error("Cannot enable update notifier without package name and version.");const o=Object.keys(e);if(o.length>0&&!o.includes("alwaysRun")&&!o.includes("distTag")&&!o.includes("updateCheckInterval"))throw new Error("Invalid update notifier options, please check the documentation.");return this.updateNotifierOptions={alwaysRun:!1,debug:d.CEREBRO_OUTPUT_LEVEL===String(x),distTag:"latest",pkg:{name:this.packageName,version:this.packageVersion},updateCheckInterval:1e3*60*60*24,...e},this}getCliName(){return this.cliName}getPackageVersion(){return this.packageVersion}getPackageName(){return this.packageName}getCommands(){return this.commands}getCwd(){return this.cwd}async run(e={}){const{shouldExitProcess:o=!0,...n}=e,r=[...this.commands.keys()];let i;this.logger.debug(`process.execPath: ${oe}`),this.logger.debug(`process.execArgv: ${ne.join(" ")}`),this.logger.debug(`process.argv: ${V.join(" ")}`);try{i=ft([null,...r],this.argv)}catch(h){if(h.name==="INVALID_COMMAND"&&h.command){let R="";const j=q(h.command,[...this.commands.keys()]);j.length>0&&(R=` Did you mean: \r
7
+ - ${j.join(` \r
8
+ - `)}`),this.logger.error(`"${h.command}" is not an available command.${R}`)}else this.logger.error(h);return o?L(1):void 0}const a=i.command??this.defaultCommand,s=this.commands.get(a);if(typeof s.execute!="function")return this.logger.error(`Command "${s.name}" has no function to execute.`),o?L(1):void 0;const l=i.argv;this.logger.debug(`command '${a}' found, parsing command args: ${l.join(", ")}`);let p=Ct([...s.options??[],...O]);p.forEach(h=>{if(h.multiple&&h.lazyMultiple)throw new Error(`Argument "${h.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}),s.argument&&(this.logger.debug("command has positional argument, parsing them..."),p=[{defaultOption:!0,description:s.argument?.description,group:"positionals",multiple:!0,name:w,type:s.argument?.type,typeLabel:s.argument?.typeLabel},...p]);const g=ue(p,{argv:pt(l,s.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),b=rt(l,s.options??[]),f={...g,_all:{...g._all,...b}};this.validateCommandOptions(p,f,s);const u=new He(s.name,s);u.runtime=this,await this.registerExtensions(u),await this.updateNotifier(u);const{_all:_,positionals:Z}=f;return _[w]&&delete _[w],u.argument=Z?.[w]??[],u.argv=this.argv,u.options={..._,...n},this.mapNegatableOptions(u,s),this.mapImpliesOptions(u,s),this.validateCommandArgsForConflicts(p,u.options,s),this.logger.debug("command options parsed from options:"),this.logger.debug(JSON.stringify(u.options,null,2)),this.logger.debug("command argument parsed from argument:"),this.logger.debug(JSON.stringify(u.argument,null,2)),await this.prepareToolboxResult(f,u,s),o?L(0):void 0}validateDoubleOptions(e){if(Array.isArray(e.options)){const o=e.options.reduce((i,a)=>{const s=`${a.name}-${a.alias}`;return i[s]||(i[s]=[]),i[s].push(a),i},{}),n=Object.values(o).filter(i=>i.length>1);let r="";if(n.forEach(i=>{const a=i[0],s=i[1];let l="alias";a.name===s.name&&(l="name",a.alias===s.alias&&(l+=" and alias")),r+=`Cannot add option ${l} "${JSON.stringify(s)}" to command "${e.name}" due to conflicting option ${JSON.stringify(a)}
9
+ `}),r.length>0)throw new Error(r)}}addCoreExtensions(){this.addExtension({execute:v(e=>{e.logger=this.logger},"execute"),name:"logger"})}async prepareToolboxResult(e,o,n){if(e.global?.help){this.logger.debug("'--help' option found, running 'help' for given command...");const r=this.commands.get("help");if(!r)throw new Error("Help command not found.");await r.execute(o);return}if(e.global?.version||e.global?.V){this.logger.debug("'--version' option found, running 'version' for given command...");const r=this.commands.get("version");if(!r)throw new Error("Version command not found.");await r.execute(o);return}await n.execute(o)}async updateNotifier({logger:e}){if(this.updateNotifierOptions?.alwaysRun||!(d.NO_UPDATE_NOTIFIER||d.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||Ut)&&this.updateNotifierOptions){e.raw("Checking for updates...");const o=await(await import("../packem_chunks/has-new-version.mjs").then(n=>n.default))(this.updateNotifierOptions);if(o){const n="Update available "+ie(this.packageVersion+"")+se(" → ")+le(o);this.logger.error(re(n,{borderColor:v(r=>ce(r),"borderColor"),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}))}}}validateCommandOptions(e,o,n){const r=wt(e,o);if(r.length>0)throw new Error(`You called the command "${n.name}" without the required options: ${r.map(i=>i.name).join(", ")}`);if(o._unknown&&o._unknown.length>0){const i=[];if(o._unknown.forEach(a=>{const s=a.startsWith("--");let l=`Found unknown ${s?"option":"argument"} "${a}"`;if(s){const p=q(a.replace("--",""),[...(n.options??[]).map(g=>g.name),...O.map(g=>g.name)]);if(p.length>0){const[g,...b]=p.map(f=>`--${f}`);l+=b.length>0?`, did you mean ${g} or ${b.join(", ")}?`:`, did you mean ${g}?`}}i.push(l)}),i.length>0)throw new Error(i.join(`
10
+ `))}}validateCommandArgsForConflicts(e,o,n){const r=e.filter(i=>i.conflicts!==void 0);if(r.length>0){const i=r.find(a=>Array.isArray(a.conflicts)?a.conflicts.some(s=>o[s]!==void 0)&&o[a.name]!==void 0:o[a.conflicts]!==void 0&&o[a.name]!==void 0);if(i)throw new Error(`You called the command "${n.name}" with conflicting options: ${i.name} and ${typeof i.conflicts=="string"?i.conflicts:i.conflicts?.join(", ")}`)}}addNegatableOption(e){Array.isArray(e.options)&&e.options.forEach(o=>{if(o.name.startsWith("no-")&&!e.options.some(n=>n.name===o.name.replace("no-",""))){if(o.type!==Boolean){this.logger.debug(`Cannot add negated option "${o.name}" to command "${e.name}" because it is not a boolean.`);return}const n={...o,defaultValue:o.defaultValue===void 0?!0:!o.defaultValue,name:`${o.name.replace("no-","")}`};e.options.push(n)}})}async registerExtensions(e){const o=v(async n=>typeof n.execute!="function"?(this.logger.warn(`Skipped ${n.name} because execute is not a function.`),null):(await n.execute(e),null),"callback");for(const n of this.extensions)await o(n)}mapNegatableOptions(e,o){Object.entries(e.options).forEach(([n,r])=>{if(/^no\w+/.test(n)){const i=It(n.replace("no",""));this.logger.debug(`mapping negated option "${n}" to "${i}"`),e.options[i]=!r,o.options?.forEach(a=>{a.name===i&&(a.__negated__=!0)})}})}mapImpliesOptions(e,o){Object.keys(e.options).forEach(n=>{const r=o.options?.find(i=>i.__camelCaseName__===n&&i.__negated__===void 0&&i.implies!==void 0);if(r?.implies){const i=r.implies;Object.entries(i).forEach(([a,s])=>{if(e.options[a]===void 0)e.options[a]=s;else{const l=o.options?.find(p=>p.name===a);(l?.defaultValue===void 0||e.options[a]===l.defaultValue)&&(e.options[a]=s)}})}})}}export{to as Cli};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/cerebro",
3
- "version": "1.1.25",
3
+ "version": "1.1.27",
4
4
  "description": "A delightful toolkit for building Node-powered CLIs.",
5
5
  "keywords": [
6
6
  "command",
@@ -86,10 +86,10 @@
86
86
  "LICENSE.md"
87
87
  ],
88
88
  "dependencies": {
89
- "@visulima/boxen": "1.0.21",
90
- "@visulima/colorize": "1.4.12",
91
- "@visulima/find-cache-dir": "1.0.15",
92
- "@visulima/pail": "2.1.11",
89
+ "@visulima/boxen": "1.0.22",
90
+ "@visulima/colorize": "1.4.13",
91
+ "@visulima/find-cache-dir": "1.0.17",
92
+ "@visulima/pail": "2.1.12",
93
93
  "cli-table3": "^0.6.5",
94
94
  "command-line-args": "^6.0.0",
95
95
  "fastest-levenshtein": "^1.0.16"
@@ -97,10 +97,10 @@
97
97
  "devDependencies": {
98
98
  "@anolilab/eslint-config": "^15.0.3",
99
99
  "@anolilab/prettier-config": "^5.0.14",
100
- "@anolilab/semantic-release-pnpm": "^1.1.3",
101
- "@anolilab/semantic-release-preset": "^9.0.0",
102
- "@arethetypeswrong/cli": "^0.16.4",
103
- "@babel/core": "^7.25.7",
100
+ "@anolilab/semantic-release-pnpm": "^1.1.6",
101
+ "@anolilab/semantic-release-preset": "^9.0.3",
102
+ "@arethetypeswrong/cli": "^0.17.2",
103
+ "@babel/core": "^7.26.0",
104
104
  "@eslint-types/deprecation": "^2.0.0",
105
105
  "@eslint-types/import": "^2.29.1",
106
106
  "@eslint-types/jsdoc": "^48.2.2",
@@ -111,9 +111,9 @@
111
111
  "@types/command-line-args": "^5.2.3",
112
112
  "@types/node": "18.19.15",
113
113
  "@visulima/nextra-theme-docs": "4.0.26",
114
- "@visulima/packem": "1.0.7",
115
- "@visulima/path": "1.1.1",
116
- "@vitest/coverage-v8": "^2.1.2",
114
+ "@visulima/packem": "1.9.2",
115
+ "@visulima/path": "1.1.2",
116
+ "@vitest/coverage-v8": "^2.1.8",
117
117
  "camelcase": "8.0.0",
118
118
  "conventional-changelog-conventionalcommits": "8.0.0",
119
119
  "cross-env": "^7.0.3",
@@ -124,14 +124,14 @@
124
124
  "eslint-plugin-mdx": "^3.1.5",
125
125
  "eslint-plugin-vitest": "^0.4.1",
126
126
  "eslint-plugin-vitest-globals": "^1.5.0",
127
- "prettier": "^3.3.3",
127
+ "prettier": "^3.4.2",
128
128
  "rimraf": "5.0.9",
129
129
  "semantic-release": "24.0.0",
130
130
  "typescript": "5.4.5",
131
- "vitest": "^2.1.2"
131
+ "vitest": "^2.1.8"
132
132
  },
133
133
  "engines": {
134
- "node": ">=18.* <=22.*"
134
+ "node": ">=18.* <=23.*"
135
135
  },
136
136
  "os": [
137
137
  "darwin",
@@ -1,10 +0,0 @@
1
- "use strict";var ee=Object.create;var x=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var c=(t,e)=>x(t,"name",{value:e,configurable:!0});var ae=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of oe(e))!re.call(t,r)&&r!==o&&x(t,r,{get:()=>e[r],enumerable:!(n=te(e,r))||n.enumerable});return t};var se=(t,e,o)=>(o=t!=null?ee(ne(t)):{},ae(e||!t||!t.__esModule?x(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("node:process"),ie=require("@visulima/boxen"),v=require("@visulima/colorize"),j=require("@visulima/pail/processor"),le=require("@visulima/pail/server"),ce=require("command-line-args"),pe=require("cli-table3"),de=require("@visulima/colorize/template"),me=require("node:os"),ue=require("fastest-levenshtein"),A=c(t=>t&&typeof t=="object"&&"default"in t?t.default:t,"_interopDefaultCompat"),ge=A(ce),O=A(pe),he=A(de),fe=A(me),ve=/[\p{Lu}]/u,ye=/[\p{Ll}]/u,V=/^[\p{Lu}](?![\p{Lu}])/gu,Y=/([\p{Alpha}\p{N}_]|$)/u,P=/[_.\- ]+/,be=new RegExp("^"+P.source),B=new RegExp(P.source+Y.source,"gu"),U=new RegExp("\\d+"+Y.source,"gu"),$e=c((t,e,o,n)=>{let r=!1,a=!1,s=!1,i=!1;for(let l=0;l<t.length;l++){const d=t[l];i=l>2?t[l-3]==="-":!0,r&&ve.test(d)?(t=t.slice(0,l)+"-"+t.slice(l),r=!1,s=a,a=!0,l++):a&&s&&ye.test(d)&&(!i||n)?(t=t.slice(0,l-1)+"-"+t.slice(l-1),s=a,a=!1,r=!0):(r=e(d)===d&&o(d)!==d,s=a,a=o(d)===d&&e(d)!==d)}return t},"preserveCamelCase"),Ee=c((t,e)=>(V.lastIndex=0,t.replaceAll(V,o=>e(o))),"preserveConsecutiveUppercase"),we=c((t,e)=>(B.lastIndex=0,U.lastIndex=0,t.replaceAll(U,(o,n,r)=>["_","-"].includes(t.charAt(r+o.length))?o:e(o)).replaceAll(B,(o,n)=>e(n))),"postProcess");function Oe(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(a=>a.trim()).filter(a=>a.length).join("-"):t=t.trim(),t.length===0)return"";const o=e.locale===!1?a=>a.toLowerCase():a=>a.toLocaleLowerCase(e.locale),n=e.locale===!1?a=>a.toUpperCase():a=>a.toLocaleUpperCase(e.locale);return t.length===1?P.test(t)?"":e.pascalCase?n(t):o(t):(t!==o(t)&&(t=$e(t,o,n,e.preserveConsecutiveUppercase)),t=t.replace(be,""),t=e.preserveConsecutiveUppercase?Ee(t,o):o(t),e.pascalCase&&(t=n(t.charAt(0))+t.slice(1)),we(t,n))}c(Oe,"camelCase");const C=[{description:"Turn on verbose output",group:"global",name:"verbose",type:Boolean},{description:"Turn on debugging output",group:"global",name:"debug",type:Boolean},{alias:"h",description:"Print out helpful usage information",group:"global",name:"help",type:Boolean},{alias:"q",description:"Silence output",group:"global",name:"quiet",type:Boolean},{alias:"V",description:"Print version info",group:"global",name:"version",type:Boolean},{description:"Turn off colored output",group:"global",name:"no-color",type:Boolean},{description:"Force colored output",group:"global",name:"color",type:Boolean}];var Ce=Object.defineProperty,Ae=c((t,e)=>Ce(t,"name",{value:e,configurable:!0}),"e$4");const m=Ae(t=>t?he(Object.assign([],{raw:[t.replaceAll("`","\\`")]})):"","templateFormat");var _e=Object.defineProperty,Ne=c((t,e)=>_e(t,"name",{value:e,configurable:!0}),"t$6");let W=class{static{c(this,"n")}static{Ne(this,"BaseSection")}lines;constructor(){this.lines=[]}add(e){this.lines.push(e)}toString(){return this.lines.join(fe.EOL)}header(e){this.add(v.bold(e)),this.lines.push("")}};var Le=Object.defineProperty,xe=c((t,e)=>Le(t,"name",{value:e,configurable:!0}),"p$4");const E={chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,60],style:{border:[],compact:!0,head:[],"padding-left":2,"padding-right":1},wordWrap:!0};let Re=class extends W{static{c(this,"y")}static{xe(this,"ContentSection")}constructor(e){if(super(),e.header&&this.header(m(e.header)),e.content){if(e.raw)if(Array.isArray(e.content)&&e.content.every(o=>typeof o=="string"))e.content.forEach(o=>{Array.isArray(o)?o.forEach(n=>this.add(m(n))):this.add(m(o))});else if(typeof e.content=="string")this.add(m(e.content));else throw new TypeError("Invalid raw content, must be a string or array of strings.");else this.add(this.getContentLines(e.content));this.add("")}}getContentLines(e){if(typeof e=="string"){const o=new O({...E,colWidths:[80]});return o.push([m(e)]),o.toString()}if(Array.isArray(e)&&e.every(o=>typeof o=="string"||Array.isArray(o)&&o.every(n=>typeof n=="string"))){const o=new O({...E});return e.forEach(n=>{Array.isArray(n)?o.push(n.map(r=>m(r))):o.push([m(n)])}),o.toString()}if(typeof e=="object"){const o=e;if(!o.options||!o.data)throw new Error(`Must have an "options" or "data" property
2
- ${JSON.stringify(e)}`);const n=new O({...E,...o.options,style:{...E.style,...o.options.style}});return o.data.forEach(r=>{Array.isArray(r)?n.push(r.map(a=>m(a))):n.push([m(r)])}),n.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
3
-
4
- ${JSON.stringify(e)}`)}};var Se=Object.defineProperty,Pe=c((t,e)=>Se(t,"name",{value:e,configurable:!0}),"a$1");let Te=class extends W{static{c(this,"c")}static{Pe(this,"OptionListSection")}constructor(e){super();let o=e.optionList??[];const n=Array.isArray(e.hide)?e.hide:[e.hide].filter(Boolean),r=Array.isArray(e.group)?e.group:[e.group].filter(Boolean);n.length>0&&(o=o.filter(s=>!n.includes(s.name))),e.header&&this.header(m(e.header)),r.length>0&&(o=o.filter(s=>{const i=r.includes("_none")&&!s.group,l=this.intersect(Array.isArray(s.group)?s.group:[s.group],r);return i||l?s:void 0}));const a=new O({chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,40],style:{"padding-left":2,"padding-right":1},wordWrap:!0});o.forEach(s=>a.push([this.getOptionNames(s,e.reverseNameOrder??!1,e.isArgument??!1),m(s.description)])),this.add(a.toString()),this.lines.push("")}getOptionNames(e,o,n){if(!e.name)throw new TypeError("Invalid option definition, name is required.");let r=e.type?e.type.name.toLowerCase():"string";const a=e.multiple||e.lazyMultiple?"[]":"";r=m(e.typeLabel??`{underline ${r}${a}}`);let s;if(e.alias)if(e.name){const i=n?e.name:`{yellow --${e.name}}`;s=m(o?`{bold ${i}}, {bold -${e.alias}} ${r}`:`{bold -${e.alias}}, {bold ${i}} ${r}`)}else o?s=m(`{bold -${e.alias}} ${r}`):s=m(`{bold -${e.alias}} ${r}`);else s=m(`{bold ${n?e.name:`{yellow --${e.name}}`}} ${r}`);return s}intersect(e,o){return e.some(n=>o.includes(n))}};var Ie=Object.defineProperty,je=c((t,e)=>Ie(t,"name",{value:e,configurable:!0}),"o$3");const H=je(t=>(Array.isArray(t)?t:[t]).length===0?"":`
5
- ${t.map(e=>e.optionList?new Te(e).toString():new Re(e).toString()).join(`
6
- `)}`,"commandLineUsage");var Ve=Object.defineProperty,_=c((t,e)=>Ve(t,"name",{value:e,configurable:!0}),"l$5");const k="__Other",D=_(t=>t.charAt(0).toUpperCase()+t.slice(1),"upperFirstChar"),Be=_((t,e,o,n)=>{t.debug("no command given, printing general help...");let r=[...new Set(o.values())].filter(s=>!s.hidden);n&&(r=r.filter(s=>s.group===n));const a=r.reduce((s,i)=>{const l=i.group??k;return s[l]||(s[l]=[]),s[l].push(i),s},{});t.raw(H([{content:`{cyan ${e.getCliName()}} {green <command>} [positional arguments] {yellow [options]}`,header:"{inverse.cyan Usage }"},...Object.keys(a).map(s=>({content:a[s].map(i=>{let l="";return typeof i.alias=="string"?l=i.alias:Array.isArray(i.alias)&&(l=i.alias.join(", ")),l!==""&&(l=` [${l}]`),[`{green ${i.name}} ${l}`,i.description??""]}),header:s===k||n?`{inverse.green Available${n?` ${D(n)}`:""} Commands }`:` {inverse.green ${D(s)} }`})),o.has("help")?{header:"{inverse.yellow Command Options }",optionList:o.get("help").options?.filter(s=>!s.hidden)}:void 0,{header:"{inverse.yellow Global Options }",optionList:C},{content:`Run "{cyan ${e.getCliName()}} {green help <command>}" or "{cyan ${e.getCliName()}} {green <command>} {yellow --help}" for help with a specific command.`,raw:!0}].filter(Boolean)))},"printGeneralHelp"),Ue=_((t,e,o,n)=>{const r=o.get(n),a=[];if(a.push({content:`{cyan ${e.getCliName()}} {green ${r.name}}${r.argument?" [positional arguments]":""}${r.options?" [options]":""}`,header:"{inverse.cyan Usage }"}),r.description&&a.push({content:r.description,header:"{inverse.green Description }"}),r.argument&&a.push({header:"Command Positional Arguments",isArgument:!0,optionList:[r.argument]}),Array.isArray(r.options)&&r.options.length>0&&a.push({header:"{inverse.yellow Command Options }",optionList:r.options.filter(s=>!s.hidden)}),a.push({header:"{inverse.yellow Global Options }",optionList:C}),r.alias!==void 0&&r.alias.length>0){let s=r.alias;typeof r.alias=="string"&&(s=[r.alias]),a.splice(1,0,{content:s,header:"Alias(es)"})}Array.isArray(r.examples)&&r.examples.length>0&&a.push({content:r.examples,header:"Examples"}),t.raw(H(a))},"printCommandHelp");class ke{static{c(this,"C")}static{_(this,"HelpCommand")}name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(e){this.commands=e}execute(e){const{commandName:o,logger:n,options:r,runtime:a}=e,{footer:s,header:i}=a.getCommandSection();i&&n.raw(m(i)),o==="help"?Be(n,a,this.commands,r?.group):Ue(n,a,this.commands,o),s&&n.raw(m(s))}}var De=Object.defineProperty,Me=c((t,e)=>De(t,"name",{value:e,configurable:!0}),"s$7");const qe={alias:["v","V"],description:"Output the version number",execute:Me(({logger:t,runtime:e})=>{const o=e.getPackageVersion();o===void 0?(t.warn("Unknown version"),t.debug("The version number was not provided by the cli constructor.")):t.info(o)},"execute"),name:"version",options:[],usage:[]},M=16,Fe=32,Ge=64,R=128,w="positionals";var Ye=Object.defineProperty,We=c((t,e)=>Ye(t,"name",{value:e,configurable:!0}),"m$2");let He=class{static{c(this,"c")}static{We(this,"EmptyToolbox")}result;argv;options;argument;command;commandName;runtime;logger;constructor(e,o){this.commandName=e,this.command=o}};var Je=Object.defineProperty,ze=c((t,e)=>Je(t,"name",{value:e,configurable:!0}),"s$6");const Ke=ze(()=>{const t=process.env.CEREBRO_MIN_NODE_VERSION?Number(process.env.CEREBRO_MIN_NODE_VERSION):18,e=process.version.replace("v","");Number(/v([^.]+)/.exec(process.version)[1])<t&&(console.log(`cerebro supports a minimum Node version of ${t}. You have ${e}. Read our version support policy: https://github.com/visulima/visulima#supported-nodejs-versions`),process.exit(1))},"checkNodeVersion");var Qe=Object.defineProperty,Xe=c((t,e)=>Qe(t,"name",{value:e,configurable:!0}),"r$4");const Ze=/^-{1,2}(\w+)(=(\w+))?$/,J=Xe((t,e)=>{const o=Ze.exec(t);if(o==null)return{};const n=o[1],r=e.find(a=>a.name===n||a.alias===n);return r!==void 0?{argName:r.name,argValue:o[3],option:r}:{}},"getParameterOption");var et=Object.defineProperty,tt=c((t,e)=>et(t,"name",{value:e,configurable:!0}),"i$3");const b=tt(t=>t.type?.name==="Boolean","isBoolean");var ot=Object.defineProperty,S=c((t,e)=>ot(t,"name",{value:e,configurable:!0}),"n$2");const q=S((t,e)=>{if(e.type===void 0)return t;if(e.type.name==="Boolean"){if(t==="true"||t==="1")return e.type(!0);if(t==="false"||t==="0")return e.type(!1)}return e.type(t)},"convertType"),nt=new Set(["1","0","true","false"]),rt=S((t,e)=>{const o=S((n,r)=>{const{argName:a,argValue:s,option:i}=J(r,e),{lastOption:l}=n;return i&&b(i)&&s&&a?n.partial[a]=q(s,i):n.lastName&&l&&b(l)&&nt.has(r)&&(n.partial[n.lastName]=q(r,l)),{lastName:a,lastOption:i,partial:n.partial}},"getBooleanValue");return t.reduce(o,{partial:{}}).partial},"getBooleanValues");var at=Object.defineProperty,z=c((t,e)=>at(t,"name",{value:e,configurable:!0}),"p$1");const st=z(t=>{let e=t.type?t.type.name.toLowerCase():"string";const o=t.multiple??t.lazyMultiple?"[]":"";return e&&(e=e==="boolean"?"":`{underline ${e}${o}}`),e},"getTypeLabel"),it=z(t=>(b(t)||(t.typeLabel=t.typeLabel??st(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var lt=Object.defineProperty,F=c((t,e)=>lt(t,"name",{value:e,configurable:!0}),"s$3");const ct=new Set(["1","0","true","false"]),pt=F((t,e)=>{const o=F((n,r)=>{const{argValue:a,option:s}=J(r,e),{lastOption:i}=n;if(i&&b(i)&&ct.has(r)){const l=[...n.args];return l.pop(),{args:l}}return s&&b(s)&&a?{args:n.args}:{args:[...n.args,r],lastOption:s}},"removeBooleanArguments");return t.reduce(o,{args:[]}).args},"removeBooleanValues");var dt=Object.defineProperty,K=c((t,e)=>dt(t,"name",{value:e,configurable:!0}),"e$2");const mt=new RegExp(/^-([^\d-])$/),ut=new RegExp(/^--(\S+)/),gt=new RegExp(/^-([^\d-]{2,})$/),ht=K(t=>mt.test(t)||ut.test(t)||gt.test(t),"isOption"),ft=K((t,e)=>{const o=e[0]&&ht(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(o)){const n=new Error(`Command not recognised: ${o}`);throw n.command=o,n.name="INVALID_COMMAND",n}return{argv:e,command:o}},"commandLineCommands");var vt=Object.defineProperty,Q=c((t,e)=>vt(t,"name",{value:e,configurable:!0}),"i$1");const yt=Q((t,e)=>ue.distance(t,e)<=t.length/3||e.includes(t),"isSimilar"),G=Q((t,e)=>{const o=t.toLowerCase();return e.filter(n=>yt(n.toLowerCase(),o))},"findAlternatives");var bt=Object.defineProperty,$t=c((t,e)=>bt(t,"name",{value:e,configurable:!0}),"t$3");const Et=$t((t,e)=>t.filter(o=>o.required&&e[o.name]==null).filter(o=>o.type?.name==="Boolean"?(e[o.name]=!1,!1):!0),"listMissingArguments");var wt=Object.defineProperty,Ot=c((t,e)=>wt(t,"name",{value:e,configurable:!0}),"t$2");const Ct=Ot(t=>{const e=new Map;return t.forEach(o=>{e.set(o.name,{...e.get(o.name),...o})}),[...e.values()]},"mergeArguments");var At=Object.defineProperty,N=c((t,e)=>At(t,"name",{value:e,configurable:!0}),"e$1");const _t=N(()=>!!process.versions.electron,"isElectronApp"),Nt=N(()=>_t()&&!process.defaultApp,"isBundledElectronApp"),Lt=N(()=>Nt()?0:1,"getProcessArgvBinIndex"),xt=N(t=>t.slice(Lt()+1),"hideBin");var Rt=Object.defineProperty,X=c((t,e)=>Rt(t,"name",{value:e,configurable:!0}),"i");const St=" ",Pt=X((t,e)=>t.length===e.length&&t.every((o,n)=>o===e[n]),"equals"),Tt=X(t=>typeof t=="string"?t.split(St):Pt(t,process.argv)?xt(t):t,"parseRawCommand");var It=Object.defineProperty,jt=c((t,e)=>It(t,"name",{value:e,configurable:!0}),"t");const Vt=jt(t=>{process.on("uncaughtException",e=>{t.error(`Uncaught exception: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)}),process.on("unhandledRejection",e=>{t.error(`Promise rejection: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)})},"registerExceptionHandler");var Bt=Object.defineProperty,y=c((t,e)=>Bt(t,"name",{value:e,configurable:!0}),"g");const Ut="CI"in p.env&&("GITHUB_ACTIONS"in p.env||"GITLAB_CI"in p.env||"CIRCLECI"in p.env),kt=y(t=>t.charAt(0).toLowerCase()+t.slice(1),"lowerFirstChar");class Dt{static{c(this,"Cli")}static{y(this,"Cli")}logger;argv;cwd;cliName;packageVersion;packageName;extensions=[];commands;defaultCommand;updateNotifierOptions;commandSection;constructor(e,o={}){const{argv:n,cwd:r,packageName:a,packageVersion:s}={argv:p.argv,cwd:p.cwd(),...o};this.argv=Tt(n),this.argv.includes("--quiet")||this.argv.includes("-q")?p.env.CEREBRO_OUTPUT_LEVEL=String(M):this.argv.includes("--verbose")||this.argv.includes("-v")?p.env.CEREBRO_OUTPUT_LEVEL=String(Ge):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in p.env?p.env.CEREBRO_OUTPUT_LEVEL=String(R):p.env.CEREBRO_OUTPUT_LEVEL=String(Fe);const i={32:"informational",64:"trace",128:"debug"},l=[new j.MessageFormatterProcessor];p.env.CEREBRO_OUTPUT_LEVEL===String(R)&&l.push(new j.CallerProcessor),this.logger=le.createPail({logLevel:p.env.CEREBRO_OUTPUT_LEVEL?i[p.env.CEREBRO_OUTPUT_LEVEL]??"informational":"informational",processors:l,...o.logger}),p.env.CEREBRO_OUTPUT_LEVEL===String(M)&&this.logger.disable(),Ke(),Vt(this.logger),this.cliName=e,this.packageVersion=s,this.packageName=a,this.cwd=r,this.defaultCommand="help",this.commandSection={header:`${this.cliName}${this.packageVersion?` v${this.packageVersion}`:""}`},this.commands=new Map,this.addCoreExtensions(),this.addCommand(qe),this.addCommand(new ke(this.commands))}setCommandSection(e){return this.commandSection=e,this}getCommandSection(){return this.commandSection}setDefaultCommand(e){return this.defaultCommand=e,this}addCommand(e){if(this.commands.has(e.name))throw new Error(`Ignored command with name "${e.name}", it was found in the command list.`);if(e.options?.map(o=>it(o)),this.validateDoubleOptions(e),this.addNegatableOption(e),e.options?.forEach(o=>{o.__camelCaseName__=Oe(o.name)}),this.commands.set(e.name,e),e.alias!==void 0){let o=e.alias;typeof e.alias=="string"&&(o=[e.alias]),o.forEach(n=>{if(this.logger.debug("adding alias",n),this.commands.has(n))throw new Error(`Ignoring command alias "${n}, command with the same name was found."`);this.commands.set(n,e)})}return this}addExtension(e){return this.extensions.push(e),this}enableUpdateNotifier(e={}){if(!this.packageName||!this.packageVersion)throw new Error("Cannot enable update notifier without package name and version.");const o=Object.keys(e);if(o.length>0&&!o.includes("alwaysRun")&&!o.includes("distTag")&&!o.includes("updateCheckInterval"))throw new Error("Invalid update notifier options, please check the documentation.");return this.updateNotifierOptions={alwaysRun:!1,debug:p.env.CEREBRO_OUTPUT_LEVEL===String(R),distTag:"latest",pkg:{name:this.packageName,version:this.packageVersion},updateCheckInterval:1e3*60*60*24,...e},this}getCliName(){return this.cliName}getPackageVersion(){return this.packageVersion}getPackageName(){return this.packageName}getCommands(){return this.commands}getCwd(){return this.cwd}async run(e={}){const{shouldExitProcess:o=!0,...n}=e,r=[...this.commands.keys()];let a;this.logger.debug(`process.execPath: ${p.execPath}`),this.logger.debug(`process.execArgv: ${p.execArgv.join(" ")}`),this.logger.debug(`process.argv: ${p.argv.join(" ")}`);try{a=ft([null,...r],this.argv)}catch(h){if(h.name==="INVALID_COMMAND"&&h.command){let T="";const I=G(h.command,[...this.commands.keys()]);I.length>0&&(T=` Did you mean: \r
7
- - ${I.join(` \r
8
- - `)}`),this.logger.error(`"${h.command}" is not an available command.${T}`)}else this.logger.error(h);return o?p.exit(1):void 0}const s=a.command??this.defaultCommand,i=this.commands.get(s);if(typeof i.execute!="function")return this.logger.error(`Command "${i.name}" has no function to execute.`),o?p.exit(1):void 0;const l=a.argv;this.logger.debug(`command '${s}' found, parsing command args: ${l.join(", ")}`);let d=Ct([...i.options??[],...C]);d.forEach(h=>{if(h.multiple&&h.lazyMultiple)throw new Error(`Argument "${h.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}),i.argument&&(this.logger.debug("command has positional argument, parsing them..."),d=[{defaultOption:!0,description:i.argument?.description,group:"positionals",multiple:!0,name:w,type:i.argument?.type,typeLabel:i.argument?.typeLabel},...d]);const g=ge(d,{argv:pt(l,i.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),$=rt(l,i.options??[]),f={...g,_all:{...g._all,...$}};this.validateCommandOptions(d,f,i);const u=new He(i.name,i);u.runtime=this,await this.registerExtensions(u),await this.updateNotifier(u);const{_all:L,positionals:Z}=f;return L[w]&&delete L[w],u.argument=Z?.[w]??[],u.argv=this.argv,u.options={...L,...n},this.mapNegatableOptions(u,i),this.mapImpliesOptions(u,i),this.validateCommandArgsForConflicts(d,u.options,i),this.logger.debug("command options parsed from options:"),this.logger.debug(JSON.stringify(u.options,null,2)),this.logger.debug("command argument parsed from argument:"),this.logger.debug(JSON.stringify(u.argument,null,2)),await this.prepareToolboxResult(f,u,i),o?p.exit(0):void 0}validateDoubleOptions(e){if(Array.isArray(e.options)){const o=e.options.reduce((a,s)=>{const i=`${s.name}-${s.alias}`;return a[i]||(a[i]=[]),a[i].push(s),a},{}),n=Object.values(o).filter(a=>a.length>1);let r="";if(n.forEach(a=>{const s=a[0],i=a[1];let l="alias";s.name===i.name&&(l="name",s.alias===i.alias&&(l+=" and alias")),r+=`Cannot add option ${l} "${JSON.stringify(i)}" to command "${e.name}" due to conflicting option ${JSON.stringify(s)}
9
- `}),r.length>0)throw new Error(r)}}addCoreExtensions(){this.addExtension({execute:y(e=>{e.logger=this.logger},"execute"),name:"logger"})}async prepareToolboxResult(e,o,n){if(e.global?.help){this.logger.debug("'--help' option found, running 'help' for given command...");const r=this.commands.get("help");if(!r)throw new Error("Help command not found.");await r.execute(o);return}if(e.global?.version||e.global?.V){this.logger.debug("'--version' option found, running 'version' for given command...");const r=this.commands.get("version");if(!r)throw new Error("Version command not found.");await r.execute(o);return}await n.execute(o)}async updateNotifier({logger:e}){if(this.updateNotifierOptions?.alwaysRun||!(p.env.NO_UPDATE_NOTIFIER||p.env.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||Ut)&&this.updateNotifierOptions){e.raw("Checking for updates...");const o=await(await import("../packem_chunks/has-new-version.cjs").then(n=>n.default))(this.updateNotifierOptions);if(o){const n="Update available "+v.dim(this.packageVersion+"")+v.reset(" → ")+v.green(o);this.logger.error(ie.boxen(n,{borderColor:y(r=>v.yellow(r),"borderColor"),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}))}}}validateCommandOptions(e,o,n){const r=Et(e,o);if(r.length>0)throw new Error(`You called the command "${n.name}" without the required options: ${r.map(a=>a.name).join(", ")}`);if(o._unknown&&o._unknown.length>0){const a=[];if(o._unknown.forEach(s=>{const i=s.startsWith("--");let l=`Found unknown ${i?"option":"argument"} "${s}"`;if(i){const d=G(s.replace("--",""),[...(n.options??[]).map(g=>g.name),...C.map(g=>g.name)]);if(d.length>0){const[g,...$]=d.map(f=>`--${f}`);l+=$.length>0?`, did you mean ${g} or ${$.join(", ")}?`:`, did you mean ${g}?`}}a.push(l)}),a.length>0)throw new Error(a.join(`
10
- `))}}validateCommandArgsForConflicts(e,o,n){const r=e.filter(a=>a.conflicts!==void 0);if(r.length>0){const a=r.find(s=>Array.isArray(s.conflicts)?s.conflicts.some(i=>o[i]!==void 0)&&o[s.name]!==void 0:o[s.conflicts]!==void 0&&o[s.name]!==void 0);if(a)throw new Error(`You called the command "${n.name}" with conflicting options: ${a.name} and ${typeof a.conflicts=="string"?a.conflicts:a.conflicts?.join(", ")}`)}}addNegatableOption(e){Array.isArray(e.options)&&e.options.forEach(o=>{if(o.name.startsWith("no-")&&!e.options.some(n=>n.name===o.name.replace("no-",""))){if(o.type!==Boolean){this.logger.debug(`Cannot add negated option "${o.name}" to command "${e.name}" because it is not a boolean.`);return}const n={...o,defaultValue:o.defaultValue===void 0?!0:!o.defaultValue,name:`${o.name.replace("no-","")}`};e.options.push(n)}})}async registerExtensions(e){const o=y(async n=>typeof n.execute!="function"?(this.logger.warn(`Skipped ${n.name} because execute is not a function.`),null):(await n.execute(e),null),"callback");for(const n of this.extensions)await o(n)}mapNegatableOptions(e,o){Object.entries(e.options).forEach(([n,r])=>{if(/^no\w+/.test(n)){const a=kt(n.replace("no",""));this.logger.debug(`mapping negated option "${n}" to "${a}"`),e.options[a]=!r,o.options?.forEach(s=>{s.name===a&&(s.__negated__=!0)})}})}mapImpliesOptions(e,o){Object.keys(e.options).forEach(n=>{const r=o.options?.find(a=>a.__camelCaseName__===n&&a.__negated__===void 0&&a.implies!==void 0);if(r?.implies){const a=r.implies;Object.entries(a).forEach(([s,i])=>{if(e.options[s]===void 0)e.options[s]=i;else{const l=o.options?.find(d=>d.name===s);(l?.defaultValue===void 0||e.options[s]===l.defaultValue)&&(e.options[s]=i)}})}})}}exports.Cli=Dt;
@@ -1,10 +0,0 @@
1
- var X=Object.defineProperty;var c=(t,e)=>X(t,"name",{value:e,configurable:!0});import{argv as T,cwd as Z,env as d,execPath as ee,execArgv as te,exit as L}from"node:process";import{boxen as oe}from"@visulima/boxen";import{bold as ne,dim as re,reset as ae,green as se,yellow as ie}from"@visulima/colorize";import{MessageFormatterProcessor as le,CallerProcessor as ce}from"@visulima/pail/processor";import{createPail as pe}from"@visulima/pail/server";import me from"command-line-args";import w from"cli-table3";import de from"@visulima/colorize/template";import ge from"node:os";import{distance as ue}from"fastest-levenshtein";const he=/[\p{Lu}]/u,fe=/[\p{Ll}]/u,I=/^[\p{Lu}](?![\p{Lu}])/gu,q=/([\p{Alpha}\p{N}_]|$)/u,R=/[_.\- ]+/,ve=new RegExp("^"+R.source),j=new RegExp(R.source+q.source,"gu"),V=new RegExp("\\d+"+q.source,"gu"),ye=c((t,e,o,n)=>{let a=!1,r=!1,s=!1,i=!1;for(let l=0;l<t.length;l++){const p=t[l];i=l>2?t[l-3]==="-":!0,a&&he.test(p)?(t=t.slice(0,l)+"-"+t.slice(l),a=!1,s=r,r=!0,l++):r&&s&&fe.test(p)&&(!i||n)?(t=t.slice(0,l-1)+"-"+t.slice(l-1),s=r,r=!1,a=!0):(a=e(p)===p&&o(p)!==p,s=r,r=o(p)===p&&e(p)!==p)}return t},"preserveCamelCase"),be=c((t,e)=>(I.lastIndex=0,t.replaceAll(I,o=>e(o))),"preserveConsecutiveUppercase"),$e=c((t,e)=>(j.lastIndex=0,V.lastIndex=0,t.replaceAll(V,(o,n,a)=>["_","-"].includes(t.charAt(a+o.length))?o:e(o)).replaceAll(j,(o,n)=>e(n))),"postProcess");function Ee(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(r=>r.trim()).filter(r=>r.length).join("-"):t=t.trim(),t.length===0)return"";const o=e.locale===!1?r=>r.toLowerCase():r=>r.toLocaleLowerCase(e.locale),n=e.locale===!1?r=>r.toUpperCase():r=>r.toLocaleUpperCase(e.locale);return t.length===1?R.test(t)?"":e.pascalCase?n(t):o(t):(t!==o(t)&&(t=ye(t,o,n,e.preserveConsecutiveUppercase)),t=t.replace(ve,""),t=e.preserveConsecutiveUppercase?be(t,o):o(t),e.pascalCase&&(t=n(t.charAt(0))+t.slice(1)),$e(t,n))}c(Ee,"camelCase");const O=[{description:"Turn on verbose output",group:"global",name:"verbose",type:Boolean},{description:"Turn on debugging output",group:"global",name:"debug",type:Boolean},{alias:"h",description:"Print out helpful usage information",group:"global",name:"help",type:Boolean},{alias:"q",description:"Silence output",group:"global",name:"quiet",type:Boolean},{alias:"V",description:"Print version info",group:"global",name:"version",type:Boolean},{description:"Turn off colored output",group:"global",name:"no-color",type:Boolean},{description:"Force colored output",group:"global",name:"color",type:Boolean}];var we=Object.defineProperty,Oe=c((t,e)=>we(t,"name",{value:e,configurable:!0}),"e$4");const m=Oe(t=>t?de(Object.assign([],{raw:[t.replaceAll("`","\\`")]})):"","templateFormat");var Ce=Object.defineProperty,Ae=c((t,e)=>Ce(t,"name",{value:e,configurable:!0}),"t$6");let G=class{static{c(this,"n")}static{Ae(this,"BaseSection")}lines;constructor(){this.lines=[]}add(e){this.lines.push(e)}toString(){return this.lines.join(ge.EOL)}header(e){this.add(ne(e)),this.lines.push("")}};var Ne=Object.defineProperty,Le=c((t,e)=>Ne(t,"name",{value:e,configurable:!0}),"p$4");const $={chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,60],style:{border:[],compact:!0,head:[],"padding-left":2,"padding-right":1},wordWrap:!0};let _e=class extends G{static{c(this,"y")}static{Le(this,"ContentSection")}constructor(e){if(super(),e.header&&this.header(m(e.header)),e.content){if(e.raw)if(Array.isArray(e.content)&&e.content.every(o=>typeof o=="string"))e.content.forEach(o=>{Array.isArray(o)?o.forEach(n=>this.add(m(n))):this.add(m(o))});else if(typeof e.content=="string")this.add(m(e.content));else throw new TypeError("Invalid raw content, must be a string or array of strings.");else this.add(this.getContentLines(e.content));this.add("")}}getContentLines(e){if(typeof e=="string"){const o=new w({...$,colWidths:[80]});return o.push([m(e)]),o.toString()}if(Array.isArray(e)&&e.every(o=>typeof o=="string"||Array.isArray(o)&&o.every(n=>typeof n=="string"))){const o=new w({...$});return e.forEach(n=>{Array.isArray(n)?o.push(n.map(a=>m(a))):o.push([m(n)])}),o.toString()}if(typeof e=="object"){const o=e;if(!o.options||!o.data)throw new Error(`Must have an "options" or "data" property
2
- ${JSON.stringify(e)}`);const n=new w({...$,...o.options,style:{...$.style,...o.options.style}});return o.data.forEach(a=>{Array.isArray(a)?n.push(a.map(r=>m(r))):n.push([m(a)])}),n.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
3
-
4
- ${JSON.stringify(e)}`)}};var xe=Object.defineProperty,Re=c((t,e)=>xe(t,"name",{value:e,configurable:!0}),"a$1");let Se=class extends G{static{c(this,"c")}static{Re(this,"OptionListSection")}constructor(e){super();let o=e.optionList??[];const n=Array.isArray(e.hide)?e.hide:[e.hide].filter(Boolean),a=Array.isArray(e.group)?e.group:[e.group].filter(Boolean);n.length>0&&(o=o.filter(s=>!n.includes(s.name))),e.header&&this.header(m(e.header)),a.length>0&&(o=o.filter(s=>{const i=a.includes("_none")&&!s.group,l=this.intersect(Array.isArray(s.group)?s.group:[s.group],a);return i||l?s:void 0}));const r=new w({chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,40],style:{"padding-left":2,"padding-right":1},wordWrap:!0});o.forEach(s=>r.push([this.getOptionNames(s,e.reverseNameOrder??!1,e.isArgument??!1),m(s.description)])),this.add(r.toString()),this.lines.push("")}getOptionNames(e,o,n){if(!e.name)throw new TypeError("Invalid option definition, name is required.");let a=e.type?e.type.name.toLowerCase():"string";const r=e.multiple||e.lazyMultiple?"[]":"";a=m(e.typeLabel??`{underline ${a}${r}}`);let s;if(e.alias)if(e.name){const i=n?e.name:`{yellow --${e.name}}`;s=m(o?`{bold ${i}}, {bold -${e.alias}} ${a}`:`{bold -${e.alias}}, {bold ${i}} ${a}`)}else o?s=m(`{bold -${e.alias}} ${a}`):s=m(`{bold -${e.alias}} ${a}`);else s=m(`{bold ${n?e.name:`{yellow --${e.name}}`}} ${a}`);return s}intersect(e,o){return e.some(n=>o.includes(n))}};var Pe=Object.defineProperty,Te=c((t,e)=>Pe(t,"name",{value:e,configurable:!0}),"o$3");const Y=Te(t=>(Array.isArray(t)?t:[t]).length===0?"":`
5
- ${t.map(e=>e.optionList?new Se(e).toString():new _e(e).toString()).join(`
6
- `)}`,"commandLineUsage");var Ie=Object.defineProperty,C=c((t,e)=>Ie(t,"name",{value:e,configurable:!0}),"l$5");const B="__Other",U=C(t=>t.charAt(0).toUpperCase()+t.slice(1),"upperFirstChar"),je=C((t,e,o,n)=>{t.debug("no command given, printing general help...");let a=[...new Set(o.values())].filter(s=>!s.hidden);n&&(a=a.filter(s=>s.group===n));const r=a.reduce((s,i)=>{const l=i.group??B;return s[l]||(s[l]=[]),s[l].push(i),s},{});t.raw(Y([{content:`{cyan ${e.getCliName()}} {green <command>} [positional arguments] {yellow [options]}`,header:"{inverse.cyan Usage }"},...Object.keys(r).map(s=>({content:r[s].map(i=>{let l="";return typeof i.alias=="string"?l=i.alias:Array.isArray(i.alias)&&(l=i.alias.join(", ")),l!==""&&(l=` [${l}]`),[`{green ${i.name}} ${l}`,i.description??""]}),header:s===B||n?`{inverse.green Available${n?` ${U(n)}`:""} Commands }`:` {inverse.green ${U(s)} }`})),o.has("help")?{header:"{inverse.yellow Command Options }",optionList:o.get("help").options?.filter(s=>!s.hidden)}:void 0,{header:"{inverse.yellow Global Options }",optionList:O},{content:`Run "{cyan ${e.getCliName()}} {green help <command>}" or "{cyan ${e.getCliName()}} {green <command>} {yellow --help}" for help with a specific command.`,raw:!0}].filter(Boolean)))},"printGeneralHelp"),Ve=C((t,e,o,n)=>{const a=o.get(n),r=[];if(r.push({content:`{cyan ${e.getCliName()}} {green ${a.name}}${a.argument?" [positional arguments]":""}${a.options?" [options]":""}`,header:"{inverse.cyan Usage }"}),a.description&&r.push({content:a.description,header:"{inverse.green Description }"}),a.argument&&r.push({header:"Command Positional Arguments",isArgument:!0,optionList:[a.argument]}),Array.isArray(a.options)&&a.options.length>0&&r.push({header:"{inverse.yellow Command Options }",optionList:a.options.filter(s=>!s.hidden)}),r.push({header:"{inverse.yellow Global Options }",optionList:O}),a.alias!==void 0&&a.alias.length>0){let s=a.alias;typeof a.alias=="string"&&(s=[a.alias]),r.splice(1,0,{content:s,header:"Alias(es)"})}Array.isArray(a.examples)&&a.examples.length>0&&r.push({content:a.examples,header:"Examples"}),t.raw(Y(r))},"printCommandHelp");class Be{static{c(this,"C")}static{C(this,"HelpCommand")}name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(e){this.commands=e}execute(e){const{commandName:o,logger:n,options:a,runtime:r}=e,{footer:s,header:i}=r.getCommandSection();i&&n.raw(m(i)),o==="help"?je(n,r,this.commands,a?.group):Ve(n,r,this.commands,o),s&&n.raw(m(s))}}var Ue=Object.defineProperty,ke=c((t,e)=>Ue(t,"name",{value:e,configurable:!0}),"s$7");const De={alias:["v","V"],description:"Output the version number",execute:ke(({logger:t,runtime:e})=>{const o=e.getPackageVersion();o===void 0?(t.warn("Unknown version"),t.debug("The version number was not provided by the cli constructor.")):t.info(o)},"execute"),name:"version",options:[],usage:[]},k=16,Me=32,Fe=64,_=128,E="positionals";var qe=Object.defineProperty,Ge=c((t,e)=>qe(t,"name",{value:e,configurable:!0}),"m$2");let Ye=class{static{c(this,"c")}static{Ge(this,"EmptyToolbox")}result;argv;options;argument;command;commandName;runtime;logger;constructor(e,o){this.commandName=e,this.command=o}};var We=Object.defineProperty,He=c((t,e)=>We(t,"name",{value:e,configurable:!0}),"s$6");const Je=He(()=>{const t=process.env.CEREBRO_MIN_NODE_VERSION?Number(process.env.CEREBRO_MIN_NODE_VERSION):18,e=process.version.replace("v","");Number(/v([^.]+)/.exec(process.version)[1])<t&&(console.log(`cerebro supports a minimum Node version of ${t}. You have ${e}. Read our version support policy: https://github.com/visulima/visulima#supported-nodejs-versions`),process.exit(1))},"checkNodeVersion");var ze=Object.defineProperty,Ke=c((t,e)=>ze(t,"name",{value:e,configurable:!0}),"r$4");const Qe=/^-{1,2}(\w+)(=(\w+))?$/,W=Ke((t,e)=>{const o=Qe.exec(t);if(o==null)return{};const n=o[1],a=e.find(r=>r.name===n||r.alias===n);return a!==void 0?{argName:a.name,argValue:o[3],option:a}:{}},"getParameterOption");var Xe=Object.defineProperty,Ze=c((t,e)=>Xe(t,"name",{value:e,configurable:!0}),"i$3");const y=Ze(t=>t.type?.name==="Boolean","isBoolean");var et=Object.defineProperty,x=c((t,e)=>et(t,"name",{value:e,configurable:!0}),"n$2");const D=x((t,e)=>{if(e.type===void 0)return t;if(e.type.name==="Boolean"){if(t==="true"||t==="1")return e.type(!0);if(t==="false"||t==="0")return e.type(!1)}return e.type(t)},"convertType"),tt=new Set(["1","0","true","false"]),ot=x((t,e)=>{const o=x((n,a)=>{const{argName:r,argValue:s,option:i}=W(a,e),{lastOption:l}=n;return i&&y(i)&&s&&r?n.partial[r]=D(s,i):n.lastName&&l&&y(l)&&tt.has(a)&&(n.partial[n.lastName]=D(a,l)),{lastName:r,lastOption:i,partial:n.partial}},"getBooleanValue");return t.reduce(o,{partial:{}}).partial},"getBooleanValues");var nt=Object.defineProperty,H=c((t,e)=>nt(t,"name",{value:e,configurable:!0}),"p$1");const rt=H(t=>{let e=t.type?t.type.name.toLowerCase():"string";const o=t.multiple??t.lazyMultiple?"[]":"";return e&&(e=e==="boolean"?"":`{underline ${e}${o}}`),e},"getTypeLabel"),at=H(t=>(y(t)||(t.typeLabel=t.typeLabel??rt(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var st=Object.defineProperty,M=c((t,e)=>st(t,"name",{value:e,configurable:!0}),"s$3");const it=new Set(["1","0","true","false"]),lt=M((t,e)=>{const o=M((n,a)=>{const{argValue:r,option:s}=W(a,e),{lastOption:i}=n;if(i&&y(i)&&it.has(a)){const l=[...n.args];return l.pop(),{args:l}}return s&&y(s)&&r?{args:n.args}:{args:[...n.args,a],lastOption:s}},"removeBooleanArguments");return t.reduce(o,{args:[]}).args},"removeBooleanValues");var ct=Object.defineProperty,J=c((t,e)=>ct(t,"name",{value:e,configurable:!0}),"e$2");const pt=new RegExp(/^-([^\d-])$/),mt=new RegExp(/^--(\S+)/),dt=new RegExp(/^-([^\d-]{2,})$/),gt=J(t=>pt.test(t)||mt.test(t)||dt.test(t),"isOption"),ut=J((t,e)=>{const o=e[0]&&gt(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(o)){const n=new Error(`Command not recognised: ${o}`);throw n.command=o,n.name="INVALID_COMMAND",n}return{argv:e,command:o}},"commandLineCommands");var ht=Object.defineProperty,z=c((t,e)=>ht(t,"name",{value:e,configurable:!0}),"i$1");const ft=z((t,e)=>ue(t,e)<=t.length/3||e.includes(t),"isSimilar"),F=z((t,e)=>{const o=t.toLowerCase();return e.filter(n=>ft(n.toLowerCase(),o))},"findAlternatives");var vt=Object.defineProperty,yt=c((t,e)=>vt(t,"name",{value:e,configurable:!0}),"t$3");const bt=yt((t,e)=>t.filter(o=>o.required&&e[o.name]==null).filter(o=>o.type?.name==="Boolean"?(e[o.name]=!1,!1):!0),"listMissingArguments");var $t=Object.defineProperty,Et=c((t,e)=>$t(t,"name",{value:e,configurable:!0}),"t$2");const wt=Et(t=>{const e=new Map;return t.forEach(o=>{e.set(o.name,{...e.get(o.name),...o})}),[...e.values()]},"mergeArguments");var Ot=Object.defineProperty,A=c((t,e)=>Ot(t,"name",{value:e,configurable:!0}),"e$1");const Ct=A(()=>!!process.versions.electron,"isElectronApp"),At=A(()=>Ct()&&!process.defaultApp,"isBundledElectronApp"),Nt=A(()=>At()?0:1,"getProcessArgvBinIndex"),Lt=A(t=>t.slice(Nt()+1),"hideBin");var _t=Object.defineProperty,K=c((t,e)=>_t(t,"name",{value:e,configurable:!0}),"i");const xt=" ",Rt=K((t,e)=>t.length===e.length&&t.every((o,n)=>o===e[n]),"equals"),St=K(t=>typeof t=="string"?t.split(xt):Rt(t,process.argv)?Lt(t):t,"parseRawCommand");var Pt=Object.defineProperty,Tt=c((t,e)=>Pt(t,"name",{value:e,configurable:!0}),"t");const It=Tt(t=>{process.on("uncaughtException",e=>{t.error(`Uncaught exception: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)}),process.on("unhandledRejection",e=>{t.error(`Promise rejection: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)})},"registerExceptionHandler");var jt=Object.defineProperty,v=c((t,e)=>jt(t,"name",{value:e,configurable:!0}),"g");const Vt="CI"in d&&("GITHUB_ACTIONS"in d||"GITLAB_CI"in d||"CIRCLECI"in d),Bt=v(t=>t.charAt(0).toLowerCase()+t.slice(1),"lowerFirstChar");class Zt{static{c(this,"Cli")}static{v(this,"Cli")}logger;argv;cwd;cliName;packageVersion;packageName;extensions=[];commands;defaultCommand;updateNotifierOptions;commandSection;constructor(e,o={}){const{argv:n,cwd:a,packageName:r,packageVersion:s}={argv:T,cwd:Z(),...o};this.argv=St(n),this.argv.includes("--quiet")||this.argv.includes("-q")?d.CEREBRO_OUTPUT_LEVEL=String(k):this.argv.includes("--verbose")||this.argv.includes("-v")?d.CEREBRO_OUTPUT_LEVEL=String(Fe):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in d?d.CEREBRO_OUTPUT_LEVEL=String(_):d.CEREBRO_OUTPUT_LEVEL=String(Me);const i={32:"informational",64:"trace",128:"debug"},l=[new le];d.CEREBRO_OUTPUT_LEVEL===String(_)&&l.push(new ce),this.logger=pe({logLevel:d.CEREBRO_OUTPUT_LEVEL?i[d.CEREBRO_OUTPUT_LEVEL]??"informational":"informational",processors:l,...o.logger}),d.CEREBRO_OUTPUT_LEVEL===String(k)&&this.logger.disable(),Je(),It(this.logger),this.cliName=e,this.packageVersion=s,this.packageName=r,this.cwd=a,this.defaultCommand="help",this.commandSection={header:`${this.cliName}${this.packageVersion?` v${this.packageVersion}`:""}`},this.commands=new Map,this.addCoreExtensions(),this.addCommand(De),this.addCommand(new Be(this.commands))}setCommandSection(e){return this.commandSection=e,this}getCommandSection(){return this.commandSection}setDefaultCommand(e){return this.defaultCommand=e,this}addCommand(e){if(this.commands.has(e.name))throw new Error(`Ignored command with name "${e.name}", it was found in the command list.`);if(e.options?.map(o=>at(o)),this.validateDoubleOptions(e),this.addNegatableOption(e),e.options?.forEach(o=>{o.__camelCaseName__=Ee(o.name)}),this.commands.set(e.name,e),e.alias!==void 0){let o=e.alias;typeof e.alias=="string"&&(o=[e.alias]),o.forEach(n=>{if(this.logger.debug("adding alias",n),this.commands.has(n))throw new Error(`Ignoring command alias "${n}, command with the same name was found."`);this.commands.set(n,e)})}return this}addExtension(e){return this.extensions.push(e),this}enableUpdateNotifier(e={}){if(!this.packageName||!this.packageVersion)throw new Error("Cannot enable update notifier without package name and version.");const o=Object.keys(e);if(o.length>0&&!o.includes("alwaysRun")&&!o.includes("distTag")&&!o.includes("updateCheckInterval"))throw new Error("Invalid update notifier options, please check the documentation.");return this.updateNotifierOptions={alwaysRun:!1,debug:d.CEREBRO_OUTPUT_LEVEL===String(_),distTag:"latest",pkg:{name:this.packageName,version:this.packageVersion},updateCheckInterval:1e3*60*60*24,...e},this}getCliName(){return this.cliName}getPackageVersion(){return this.packageVersion}getPackageName(){return this.packageName}getCommands(){return this.commands}getCwd(){return this.cwd}async run(e={}){const{shouldExitProcess:o=!0,...n}=e,a=[...this.commands.keys()];let r;this.logger.debug(`process.execPath: ${ee}`),this.logger.debug(`process.execArgv: ${te.join(" ")}`),this.logger.debug(`process.argv: ${T.join(" ")}`);try{r=ut([null,...a],this.argv)}catch(h){if(h.name==="INVALID_COMMAND"&&h.command){let S="";const P=F(h.command,[...this.commands.keys()]);P.length>0&&(S=` Did you mean: \r
7
- - ${P.join(` \r
8
- - `)}`),this.logger.error(`"${h.command}" is not an available command.${S}`)}else this.logger.error(h);return o?L(1):void 0}const s=r.command??this.defaultCommand,i=this.commands.get(s);if(typeof i.execute!="function")return this.logger.error(`Command "${i.name}" has no function to execute.`),o?L(1):void 0;const l=r.argv;this.logger.debug(`command '${s}' found, parsing command args: ${l.join(", ")}`);let p=wt([...i.options??[],...O]);p.forEach(h=>{if(h.multiple&&h.lazyMultiple)throw new Error(`Argument "${h.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}),i.argument&&(this.logger.debug("command has positional argument, parsing them..."),p=[{defaultOption:!0,description:i.argument?.description,group:"positionals",multiple:!0,name:E,type:i.argument?.type,typeLabel:i.argument?.typeLabel},...p]);const u=me(p,{argv:lt(l,i.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),b=ot(l,i.options??[]),f={...u,_all:{...u._all,...b}};this.validateCommandOptions(p,f,i);const g=new Ye(i.name,i);g.runtime=this,await this.registerExtensions(g),await this.updateNotifier(g);const{_all:N,positionals:Q}=f;return N[E]&&delete N[E],g.argument=Q?.[E]??[],g.argv=this.argv,g.options={...N,...n},this.mapNegatableOptions(g,i),this.mapImpliesOptions(g,i),this.validateCommandArgsForConflicts(p,g.options,i),this.logger.debug("command options parsed from options:"),this.logger.debug(JSON.stringify(g.options,null,2)),this.logger.debug("command argument parsed from argument:"),this.logger.debug(JSON.stringify(g.argument,null,2)),await this.prepareToolboxResult(f,g,i),o?L(0):void 0}validateDoubleOptions(e){if(Array.isArray(e.options)){const o=e.options.reduce((r,s)=>{const i=`${s.name}-${s.alias}`;return r[i]||(r[i]=[]),r[i].push(s),r},{}),n=Object.values(o).filter(r=>r.length>1);let a="";if(n.forEach(r=>{const s=r[0],i=r[1];let l="alias";s.name===i.name&&(l="name",s.alias===i.alias&&(l+=" and alias")),a+=`Cannot add option ${l} "${JSON.stringify(i)}" to command "${e.name}" due to conflicting option ${JSON.stringify(s)}
9
- `}),a.length>0)throw new Error(a)}}addCoreExtensions(){this.addExtension({execute:v(e=>{e.logger=this.logger},"execute"),name:"logger"})}async prepareToolboxResult(e,o,n){if(e.global?.help){this.logger.debug("'--help' option found, running 'help' for given command...");const a=this.commands.get("help");if(!a)throw new Error("Help command not found.");await a.execute(o);return}if(e.global?.version||e.global?.V){this.logger.debug("'--version' option found, running 'version' for given command...");const a=this.commands.get("version");if(!a)throw new Error("Version command not found.");await a.execute(o);return}await n.execute(o)}async updateNotifier({logger:e}){if(this.updateNotifierOptions?.alwaysRun||!(d.NO_UPDATE_NOTIFIER||d.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||Vt)&&this.updateNotifierOptions){e.raw("Checking for updates...");const o=await(await import("../packem_chunks/has-new-version.mjs").then(n=>n.default))(this.updateNotifierOptions);if(o){const n="Update available "+re(this.packageVersion+"")+ae(" → ")+se(o);this.logger.error(oe(n,{borderColor:v(a=>ie(a),"borderColor"),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}))}}}validateCommandOptions(e,o,n){const a=bt(e,o);if(a.length>0)throw new Error(`You called the command "${n.name}" without the required options: ${a.map(r=>r.name).join(", ")}`);if(o._unknown&&o._unknown.length>0){const r=[];if(o._unknown.forEach(s=>{const i=s.startsWith("--");let l=`Found unknown ${i?"option":"argument"} "${s}"`;if(i){const p=F(s.replace("--",""),[...(n.options??[]).map(u=>u.name),...O.map(u=>u.name)]);if(p.length>0){const[u,...b]=p.map(f=>`--${f}`);l+=b.length>0?`, did you mean ${u} or ${b.join(", ")}?`:`, did you mean ${u}?`}}r.push(l)}),r.length>0)throw new Error(r.join(`
10
- `))}}validateCommandArgsForConflicts(e,o,n){const a=e.filter(r=>r.conflicts!==void 0);if(a.length>0){const r=a.find(s=>Array.isArray(s.conflicts)?s.conflicts.some(i=>o[i]!==void 0)&&o[s.name]!==void 0:o[s.conflicts]!==void 0&&o[s.name]!==void 0);if(r)throw new Error(`You called the command "${n.name}" with conflicting options: ${r.name} and ${typeof r.conflicts=="string"?r.conflicts:r.conflicts?.join(", ")}`)}}addNegatableOption(e){Array.isArray(e.options)&&e.options.forEach(o=>{if(o.name.startsWith("no-")&&!e.options.some(n=>n.name===o.name.replace("no-",""))){if(o.type!==Boolean){this.logger.debug(`Cannot add negated option "${o.name}" to command "${e.name}" because it is not a boolean.`);return}const n={...o,defaultValue:o.defaultValue===void 0?!0:!o.defaultValue,name:`${o.name.replace("no-","")}`};e.options.push(n)}})}async registerExtensions(e){const o=v(async n=>typeof n.execute!="function"?(this.logger.warn(`Skipped ${n.name} because execute is not a function.`),null):(await n.execute(e),null),"callback");for(const n of this.extensions)await o(n)}mapNegatableOptions(e,o){Object.entries(e.options).forEach(([n,a])=>{if(/^no\w+/.test(n)){const r=Bt(n.replace("no",""));this.logger.debug(`mapping negated option "${n}" to "${r}"`),e.options[r]=!a,o.options?.forEach(s=>{s.name===r&&(s.__negated__=!0)})}})}mapImpliesOptions(e,o){Object.keys(e.options).forEach(n=>{const a=o.options?.find(r=>r.__camelCaseName__===n&&r.__negated__===void 0&&r.implies!==void 0);if(a?.implies){const r=a.implies;Object.entries(r).forEach(([s,i])=>{if(e.options[s]===void 0)e.options[s]=i;else{const l=o.options?.find(p=>p.name===s);(l?.defaultValue===void 0||e.options[s]===l.defaultValue)&&(e.options[s]=i)}})}})}}export{Zt as Cli};