@visulima/cerebro 1.1.0 → 1.1.2
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 +13 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +6 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## @visulima/cerebro [1.1.2](https://github.com/visulima/visulima/compare/@visulima/cerebro@1.1.1...@visulima/cerebro@1.1.2) (2024-07-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Dependencies
|
|
5
|
+
|
|
6
|
+
* **@visulima/find-cache-dir:** upgraded to 1.0.1
|
|
7
|
+
|
|
8
|
+
## @visulima/cerebro [1.1.1](https://github.com/visulima/visulima/compare/@visulima/cerebro@1.1.0...@visulima/cerebro@1.1.1) (2024-06-26)
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **cerebro:** fixed typing of command options ([6eca24b](https://github.com/visulima/visulima/commit/6eca24b95528842d898a69415c86abfbf2fab871))
|
|
13
|
+
|
|
1
14
|
## @visulima/cerebro [1.1.0](https://github.com/visulima/visulima/compare/@visulima/cerebro@1.0.51...@visulima/cerebro@1.1.0) (2024-06-25)
|
|
2
15
|
|
|
3
16
|
### Features
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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));const p=require("node:process"),ie=require("@visulima/boxen"),v=require("@visulima/colorize"),R=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,W=/([\p{Alpha}\p{N}_]|$)/u,T=/[_.\- ]+/,be=new RegExp("^"+T.source),B=new RegExp(T.source+W.source,"gu"),U=new RegExp("\\d+"+W.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?T.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$
|
|
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));const p=require("node:process"),ie=require("@visulima/boxen"),v=require("@visulima/colorize"),R=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,W=/([\p{Alpha}\p{N}_]|$)/u,T=/[_.\- ]+/,be=new RegExp("^"+T.source),B=new RegExp(T.source+W.source,"gu"),U=new RegExp("\\d+"+W.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?T.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 Y=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 Y{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
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
3
|
|
|
4
|
-
${JSON.stringify(e)}`)}};var
|
|
4
|
+
${JSON.stringify(e)}`)}};var Pe=Object.defineProperty,Se=c((t,e)=>Pe(t,"name",{value:e,configurable:!0}),"a$1");let Te=class extends Y{static{c(this,"c")}static{Se(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
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}),"p$2");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,"y")}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,qe=c((t,e)=>De(t,"name",{value:e,configurable:!0}),"s$5");const Me={alias:["v","V"],description:"Output the version number",execute:qe(({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:[]},q=16,Fe=32,Ge=64,S=128,w="positionals";var We=Object.defineProperty,Ye=c((t,e)=>We(t,"name",{value:e,configurable:!0}),"m$4");let He=class{static{c(this,"c")}static{Ye(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$4");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}),"a$2");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}),"e$4");const b=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:a,argValue:s,option:i}=J(r,e),{lastOption:l}=n;return i&&b(i)&&s&&a?n.partial[a]=M(s,i):n.lastName&&l&&b(l)&&nt.has(r)&&(n.partial[n.lastName]=M(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}),"e$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}),"o");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}),"c");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(q):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(S):p.env.CEREBRO_OUTPUT_LEVEL=String(Fe);const i={32:"informational",64:"trace",128:"debug"},l=[new R.MessageFormatterProcessor,new R.ErrorProcessor];p.env.CEREBRO_OUTPUT_LEVEL===String(S)&&l.push(new R.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(q)&&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(Me),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(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: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 I="";const j=G(h.command,[...this.commands.keys()]);j.length>0&&(I=` Did you mean: \r
|
|
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,qe=c((t,e)=>De(t,"name",{value:e,configurable:!0}),"s$7");const Me={alias:["v","V"],description:"Output the version number",execute:qe(({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:[]},q=16,Fe=32,Ge=64,P=128,w="positionals";var We=Object.defineProperty,Ye=c((t,e)=>We(t,"name",{value:e,configurable:!0}),"m$2");let He=class{static{c(this,"c")}static{Ye(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 M=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]=M(s,i):n.lastName&&l&&b(l)&&nt.has(r)&&(n.partial[n.lastName]=M(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 Pt=" ",St=X((t,e)=>t.length===e.length&&t.every((o,n)=>o===e[n]),"equals"),Tt=X(t=>typeof t=="string"?t.split(Pt):St(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}),"c");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(q):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(P):p.env.CEREBRO_OUTPUT_LEVEL=String(Fe);const i={32:"informational",64:"trace",128:"debug"},l=[new R.MessageFormatterProcessor,new R.ErrorProcessor];p.env.CEREBRO_OUTPUT_LEVEL===String(P)&&l.push(new R.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(q)&&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(Me),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(P),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 I="";const j=G(h.command,[...this.commands.keys()]);j.length>0&&(I=` Did you mean: \r
|
|
7
7
|
- ${j.join(` \r
|
|
8
8
|
- `)}`),this.logger.error(`"${h.command}" is not an available command.${I}`)}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
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&&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("./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(`
|
package/dist/index.d.cts
CHANGED
|
@@ -53,7 +53,7 @@ type OptionDefinition<T> = MultiplePropertyOptions<T> & Omit<OptionDefinition$1,
|
|
|
53
53
|
typeLabel?: string | undefined;
|
|
54
54
|
};
|
|
55
55
|
type ArgumentDefinition<T = any> = Omit<OptionDefinition<T>, "multiple|lazyMultiple|defaultOption|alias|group|defaultValue">;
|
|
56
|
-
interface Command<O = any, TContext extends Toolbox = Toolbox> {
|
|
56
|
+
interface Command<O extends OptionDefinition<any> = any, TContext extends Toolbox = Toolbox> {
|
|
57
57
|
alias?: string[] | string;
|
|
58
58
|
argument?: ArgumentDefinition;
|
|
59
59
|
commandPath?: string[];
|
|
@@ -64,7 +64,7 @@ interface Command<O = any, TContext extends Toolbox = Toolbox> {
|
|
|
64
64
|
group?: string;
|
|
65
65
|
hidden?: boolean;
|
|
66
66
|
name: string;
|
|
67
|
-
options?: (OptionDefinition<boolean[]> | OptionDefinition<boolean> | OptionDefinition<number[]> | OptionDefinition<number> | OptionDefinition<
|
|
67
|
+
options?: (O | OptionDefinition<boolean[]> | OptionDefinition<boolean> | OptionDefinition<number[]> | OptionDefinition<number> | OptionDefinition<string[]> | OptionDefinition<string>)[];
|
|
68
68
|
usage?: Content[];
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -85,7 +85,7 @@ type CliRunOptions = {
|
|
|
85
85
|
shouldExitProcess?: boolean;
|
|
86
86
|
};
|
|
87
87
|
interface Cli$1 {
|
|
88
|
-
addCommand: <
|
|
88
|
+
addCommand: <OD extends OptionDefinition<any> = any>(command: Command<OD>) => this;
|
|
89
89
|
addExtension: (extension: Extension) => this;
|
|
90
90
|
enableUpdateNotifier: ({ alwaysRun, distTag, updateCheckInterval }: Partial<Omit<UpdateNotifierOptions, "debug | pkg">>) => this;
|
|
91
91
|
getCliName: () => string;
|
|
@@ -122,7 +122,7 @@ declare class Cli implements Cli$1 {
|
|
|
122
122
|
setCommandSection(commandSection: CommandSection): this;
|
|
123
123
|
getCommandSection(): CommandSection;
|
|
124
124
|
setDefaultCommand(commandName: string): this;
|
|
125
|
-
addCommand<
|
|
125
|
+
addCommand<OD extends OptionDefinition<any> = any>(command: Command<OD>): this;
|
|
126
126
|
addExtension(extension: Extension): this;
|
|
127
127
|
enableUpdateNotifier(options?: Partial<Omit<UpdateNotifierOptions, "debug | pkg">>): this;
|
|
128
128
|
getCliName(): string;
|
package/dist/index.d.mts
CHANGED
|
@@ -53,7 +53,7 @@ type OptionDefinition<T> = MultiplePropertyOptions<T> & Omit<OptionDefinition$1,
|
|
|
53
53
|
typeLabel?: string | undefined;
|
|
54
54
|
};
|
|
55
55
|
type ArgumentDefinition<T = any> = Omit<OptionDefinition<T>, "multiple|lazyMultiple|defaultOption|alias|group|defaultValue">;
|
|
56
|
-
interface Command<O = any, TContext extends Toolbox = Toolbox> {
|
|
56
|
+
interface Command<O extends OptionDefinition<any> = any, TContext extends Toolbox = Toolbox> {
|
|
57
57
|
alias?: string[] | string;
|
|
58
58
|
argument?: ArgumentDefinition;
|
|
59
59
|
commandPath?: string[];
|
|
@@ -64,7 +64,7 @@ interface Command<O = any, TContext extends Toolbox = Toolbox> {
|
|
|
64
64
|
group?: string;
|
|
65
65
|
hidden?: boolean;
|
|
66
66
|
name: string;
|
|
67
|
-
options?: (OptionDefinition<boolean[]> | OptionDefinition<boolean> | OptionDefinition<number[]> | OptionDefinition<number> | OptionDefinition<
|
|
67
|
+
options?: (O | OptionDefinition<boolean[]> | OptionDefinition<boolean> | OptionDefinition<number[]> | OptionDefinition<number> | OptionDefinition<string[]> | OptionDefinition<string>)[];
|
|
68
68
|
usage?: Content[];
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -85,7 +85,7 @@ type CliRunOptions = {
|
|
|
85
85
|
shouldExitProcess?: boolean;
|
|
86
86
|
};
|
|
87
87
|
interface Cli$1 {
|
|
88
|
-
addCommand: <
|
|
88
|
+
addCommand: <OD extends OptionDefinition<any> = any>(command: Command<OD>) => this;
|
|
89
89
|
addExtension: (extension: Extension) => this;
|
|
90
90
|
enableUpdateNotifier: ({ alwaysRun, distTag, updateCheckInterval }: Partial<Omit<UpdateNotifierOptions, "debug | pkg">>) => this;
|
|
91
91
|
getCliName: () => string;
|
|
@@ -122,7 +122,7 @@ declare class Cli implements Cli$1 {
|
|
|
122
122
|
setCommandSection(commandSection: CommandSection): this;
|
|
123
123
|
getCommandSection(): CommandSection;
|
|
124
124
|
setDefaultCommand(commandName: string): this;
|
|
125
|
-
addCommand<
|
|
125
|
+
addCommand<OD extends OptionDefinition<any> = any>(command: Command<OD>): this;
|
|
126
126
|
addExtension(extension: Extension): this;
|
|
127
127
|
enableUpdateNotifier(options?: Partial<Omit<UpdateNotifierOptions, "debug | pkg">>): this;
|
|
128
128
|
getCliName(): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ type OptionDefinition<T> = MultiplePropertyOptions<T> & Omit<OptionDefinition$1,
|
|
|
53
53
|
typeLabel?: string | undefined;
|
|
54
54
|
};
|
|
55
55
|
type ArgumentDefinition<T = any> = Omit<OptionDefinition<T>, "multiple|lazyMultiple|defaultOption|alias|group|defaultValue">;
|
|
56
|
-
interface Command<O = any, TContext extends Toolbox = Toolbox> {
|
|
56
|
+
interface Command<O extends OptionDefinition<any> = any, TContext extends Toolbox = Toolbox> {
|
|
57
57
|
alias?: string[] | string;
|
|
58
58
|
argument?: ArgumentDefinition;
|
|
59
59
|
commandPath?: string[];
|
|
@@ -64,7 +64,7 @@ interface Command<O = any, TContext extends Toolbox = Toolbox> {
|
|
|
64
64
|
group?: string;
|
|
65
65
|
hidden?: boolean;
|
|
66
66
|
name: string;
|
|
67
|
-
options?: (OptionDefinition<boolean[]> | OptionDefinition<boolean> | OptionDefinition<number[]> | OptionDefinition<number> | OptionDefinition<
|
|
67
|
+
options?: (O | OptionDefinition<boolean[]> | OptionDefinition<boolean> | OptionDefinition<number[]> | OptionDefinition<number> | OptionDefinition<string[]> | OptionDefinition<string>)[];
|
|
68
68
|
usage?: Content[];
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -85,7 +85,7 @@ type CliRunOptions = {
|
|
|
85
85
|
shouldExitProcess?: boolean;
|
|
86
86
|
};
|
|
87
87
|
interface Cli$1 {
|
|
88
|
-
addCommand: <
|
|
88
|
+
addCommand: <OD extends OptionDefinition<any> = any>(command: Command<OD>) => this;
|
|
89
89
|
addExtension: (extension: Extension) => this;
|
|
90
90
|
enableUpdateNotifier: ({ alwaysRun, distTag, updateCheckInterval }: Partial<Omit<UpdateNotifierOptions, "debug | pkg">>) => this;
|
|
91
91
|
getCliName: () => string;
|
|
@@ -122,7 +122,7 @@ declare class Cli implements Cli$1 {
|
|
|
122
122
|
setCommandSection(commandSection: CommandSection): this;
|
|
123
123
|
getCommandSection(): CommandSection;
|
|
124
124
|
setDefaultCommand(commandName: string): this;
|
|
125
|
-
addCommand<
|
|
125
|
+
addCommand<OD extends OptionDefinition<any> = any>(command: Command<OD>): this;
|
|
126
126
|
addExtension(extension: Extension): this;
|
|
127
127
|
enableUpdateNotifier(options?: Partial<Omit<UpdateNotifierOptions, "debug | pkg">>): this;
|
|
128
128
|
getCliName(): string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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,ErrorProcessor as ce,CallerProcessor as pe}from"@visulima/pail/processor";import{createPail as me}from"@visulima/pail/server";import de from"command-line-args";import w from"cli-table3";import ge from"@visulima/colorize/template";import ue from"node:os";import{distance as he}from"fastest-levenshtein";const fe=/[\p{Lu}]/u,ve=/[\p{Ll}]/u,I=/^[\p{Lu}](?![\p{Lu}])/gu,G=/([\p{Alpha}\p{N}_]|$)/u,R=/[_.\- ]+/,ye=new RegExp("^"+R.source),j=new RegExp(R.source+G.source,"gu"),V=new RegExp("\\d+"+G.source,"gu"),be=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&&fe.test(p)?(t=t.slice(0,l)+"-"+t.slice(l),a=!1,s=r,r=!0,l++):r&&s&&ve.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"),$e=c((t,e)=>(I.lastIndex=0,t.replaceAll(I,o=>e(o))),"preserveConsecutiveUppercase"),Ee=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 we(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=be(t,o,n,e.preserveConsecutiveUppercase)),t=t.replace(ye,""),t=e.preserveConsecutiveUppercase?$e(t,o):o(t),e.pascalCase&&(t=n(t.charAt(0))+t.slice(1)),Ee(t,n))}c(we,"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 Oe=Object.defineProperty,Ce=c((t,e)=>Oe(t,"name",{value:e,configurable:!0}),"e$
|
|
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,ErrorProcessor as ce,CallerProcessor as pe}from"@visulima/pail/processor";import{createPail as me}from"@visulima/pail/server";import de from"command-line-args";import w from"cli-table3";import ge from"@visulima/colorize/template";import ue from"node:os";import{distance as he}from"fastest-levenshtein";const fe=/[\p{Lu}]/u,ve=/[\p{Ll}]/u,I=/^[\p{Lu}](?![\p{Lu}])/gu,G=/([\p{Alpha}\p{N}_]|$)/u,R=/[_.\- ]+/,ye=new RegExp("^"+R.source),j=new RegExp(R.source+G.source,"gu"),V=new RegExp("\\d+"+G.source,"gu"),be=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&&fe.test(p)?(t=t.slice(0,l)+"-"+t.slice(l),a=!1,s=r,r=!0,l++):r&&s&&ve.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"),$e=c((t,e)=>(I.lastIndex=0,t.replaceAll(I,o=>e(o))),"preserveConsecutiveUppercase"),Ee=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 we(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=be(t,o,n,e.preserveConsecutiveUppercase)),t=t.replace(ye,""),t=e.preserveConsecutiveUppercase?$e(t,o):o(t),e.pascalCase&&(t=n(t.charAt(0))+t.slice(1)),Ee(t,n))}c(we,"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 Oe=Object.defineProperty,Ce=c((t,e)=>Oe(t,"name",{value:e,configurable:!0}),"e$4");const m=Ce(t=>t?ge(Object.assign([],{raw:[t.replaceAll("`","\\`")]})):"","templateFormat");var Ae=Object.defineProperty,Ne=c((t,e)=>Ae(t,"name",{value:e,configurable:!0}),"t$6");let q=class{static{c(this,"n")}static{Ne(this,"BaseSection")}lines;constructor(){this.lines=[]}add(e){this.lines.push(e)}toString(){return this.lines.join(ue.EOL)}header(e){this.add(ne(e)),this.lines.push("")}};var Le=Object.defineProperty,_e=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 xe=class extends q{static{c(this,"y")}static{_e(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
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
3
|
|
|
4
|
-
${JSON.stringify(e)}`)}};var Re=Object.defineProperty,
|
|
5
|
-
${t.map(e=>e.optionList?new
|
|
6
|
-
`)}`,"commandLineUsage");var je=Object.defineProperty,C=c((t,e)=>je(t,"name",{value:e,configurable:!0}),"p$2");const B="__Other",U=C(t=>t.charAt(0).toUpperCase()+t.slice(1),"upperFirstChar"),Ve=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(W([{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"),Be=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(W(r))},"printCommandHelp");class Ue{static{c(this,"y")}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"?Ve(n,r,this.commands,a?.group):Be(n,r,this.commands,o),s&&n.raw(m(s))}}var ke=Object.defineProperty,De=c((t,e)=>ke(t,"name",{value:e,configurable:!0}),"s$5");const Me={alias:["v","V"],description:"Output the version number",execute:De(({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,Fe=32,Ge=64,_=128,E="positionals";var qe=Object.defineProperty,We=c((t,e)=>qe(t,"name",{value:e,configurable:!0}),"m$4");let Ye=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 He=Object.defineProperty,Je=c((t,e)=>He(t,"name",{value:e,configurable:!0}),"s$4");const ze=Je(()=>{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 Ke=Object.defineProperty,Qe=c((t,e)=>Ke(t,"name",{value:e,configurable:!0}),"a$2");const Xe=/^-{1,2}(\w+)(=(\w+))?$/,Y=Qe((t,e)=>{const o=Xe.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 Ze=Object.defineProperty,et=c((t,e)=>Ze(t,"name",{value:e,configurable:!0}),"e$4");const y=et(t=>t.type?.name==="Boolean","isBoolean");var tt=Object.defineProperty,x=c((t,e)=>tt(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"),ot=new Set(["1","0","true","false"]),nt=x((t,e)=>{const o=x((n,a)=>{const{argName:r,argValue:s,option:i}=Y(a,e),{lastOption:l}=n;return i&&y(i)&&s&&r?n.partial[r]=D(s,i):n.lastName&&l&&y(l)&&ot.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 rt=Object.defineProperty,H=c((t,e)=>rt(t,"name",{value:e,configurable:!0}),"p$1");const at=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"),st=H(t=>(y(t)||(t.typeLabel=t.typeLabel??at(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var it=Object.defineProperty,M=c((t,e)=>it(t,"name",{value:e,configurable:!0}),"e$3");const lt=new Set(["1","0","true","false"]),ct=M((t,e)=>{const o=M((n,a)=>{const{argValue:r,option:s}=Y(a,e),{lastOption:i}=n;if(i&&y(i)&<.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 pt=Object.defineProperty,J=c((t,e)=>pt(t,"name",{value:e,configurable:!0}),"e$2");const mt=new RegExp(/^-([^\d-])$/),dt=new RegExp(/^--(\S+)/),gt=new RegExp(/^-([^\d-]{2,})$/),ut=J(t=>mt.test(t)||dt.test(t)||gt.test(t),"isOption"),ht=J((t,e)=>{const o=e[0]&&ut(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 ft=Object.defineProperty,z=c((t,e)=>ft(t,"name",{value:e,configurable:!0}),"i$1");const vt=z((t,e)=>he(t,e)<=t.length/3||e.includes(t),"isSimilar"),F=z((t,e)=>{const o=t.toLowerCase();return e.filter(n=>vt(n.toLowerCase(),o))},"findAlternatives");var yt=Object.defineProperty,bt=c((t,e)=>yt(t,"name",{value:e,configurable:!0}),"t$3");const $t=bt((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,wt=c((t,e)=>Et(t,"name",{value:e,configurable:!0}),"o");const Ot=wt(t=>{const e=new Map;return t.forEach(o=>{e.set(o.name,{...e.get(o.name),...o})}),[...e.values()]},"mergeArguments");var Ct=Object.defineProperty,A=c((t,e)=>Ct(t,"name",{value:e,configurable:!0}),"e$1");const At=A(()=>!!process.versions.electron,"isElectronApp"),Nt=A(()=>At()&&!process.defaultApp,"isBundledElectronApp"),Lt=A(()=>Nt()?0:1,"getProcessArgvBinIndex"),_t=A(t=>t.slice(Lt()+1),"hideBin");var xt=Object.defineProperty,K=c((t,e)=>xt(t,"name",{value:e,configurable:!0}),"i");const Rt=" ",St=K((t,e)=>t.length===e.length&&t.every((o,n)=>o===e[n]),"equals"),Pt=K(t=>typeof t=="string"?t.split(Rt):St(t,process.argv)?_t(t):t,"parseRawCommand");var Tt=Object.defineProperty,It=c((t,e)=>Tt(t,"name",{value:e,configurable:!0}),"t");const jt=It(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 Vt=Object.defineProperty,v=c((t,e)=>Vt(t,"name",{value:e,configurable:!0}),"c");const Bt="CI"in d&&("GITHUB_ACTIONS"in d||"GITLAB_CI"in d||"CIRCLECI"in d),Ut=v(t=>t.charAt(0).toLowerCase()+t.slice(1),"lowerFirstChar");class eo{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=Pt(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(Ge):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in d?d.CEREBRO_OUTPUT_LEVEL=String(_):d.CEREBRO_OUTPUT_LEVEL=String(Fe);const i={32:"informational",64:"trace",128:"debug"},l=[new le,new ce];d.CEREBRO_OUTPUT_LEVEL===String(_)&&l.push(new pe),this.logger=me({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(),ze(),jt(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(Me),this.addCommand(new Ue(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__=we(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=ht([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
|
-
- ${
|
|
8
|
-
- `)}`),this.logger.error(`"${h.command}" is not an available command.${
|
|
4
|
+
${JSON.stringify(e)}`)}};var Re=Object.defineProperty,Pe=c((t,e)=>Re(t,"name",{value:e,configurable:!0}),"a$1");let Se=class extends q{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),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 Te=Object.defineProperty,Ie=c((t,e)=>Te(t,"name",{value:e,configurable:!0}),"o$3");const W=Ie(t=>(Array.isArray(t)?t:[t]).length===0?"":`
|
|
5
|
+
${t.map(e=>e.optionList?new Se(e).toString():new xe(e).toString()).join(`
|
|
6
|
+
`)}`,"commandLineUsage");var je=Object.defineProperty,C=c((t,e)=>je(t,"name",{value:e,configurable:!0}),"l$5");const B="__Other",U=C(t=>t.charAt(0).toUpperCase()+t.slice(1),"upperFirstChar"),Ve=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(W([{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"),Be=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(W(r))},"printCommandHelp");class Ue{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"?Ve(n,r,this.commands,a?.group):Be(n,r,this.commands,o),s&&n.raw(m(s))}}var ke=Object.defineProperty,De=c((t,e)=>ke(t,"name",{value:e,configurable:!0}),"s$7");const Me={alias:["v","V"],description:"Output the version number",execute:De(({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,Fe=32,Ge=64,_=128,E="positionals";var qe=Object.defineProperty,We=c((t,e)=>qe(t,"name",{value:e,configurable:!0}),"m$2");let Ye=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 He=Object.defineProperty,Je=c((t,e)=>He(t,"name",{value:e,configurable:!0}),"s$6");const ze=Je(()=>{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 Ke=Object.defineProperty,Qe=c((t,e)=>Ke(t,"name",{value:e,configurable:!0}),"r$4");const Xe=/^-{1,2}(\w+)(=(\w+))?$/,Y=Qe((t,e)=>{const o=Xe.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 Ze=Object.defineProperty,et=c((t,e)=>Ze(t,"name",{value:e,configurable:!0}),"i$3");const y=et(t=>t.type?.name==="Boolean","isBoolean");var tt=Object.defineProperty,x=c((t,e)=>tt(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"),ot=new Set(["1","0","true","false"]),nt=x((t,e)=>{const o=x((n,a)=>{const{argName:r,argValue:s,option:i}=Y(a,e),{lastOption:l}=n;return i&&y(i)&&s&&r?n.partial[r]=D(s,i):n.lastName&&l&&y(l)&&ot.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 rt=Object.defineProperty,H=c((t,e)=>rt(t,"name",{value:e,configurable:!0}),"p$1");const at=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"),st=H(t=>(y(t)||(t.typeLabel=t.typeLabel??at(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var it=Object.defineProperty,M=c((t,e)=>it(t,"name",{value:e,configurable:!0}),"s$3");const lt=new Set(["1","0","true","false"]),ct=M((t,e)=>{const o=M((n,a)=>{const{argValue:r,option:s}=Y(a,e),{lastOption:i}=n;if(i&&y(i)&<.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 pt=Object.defineProperty,J=c((t,e)=>pt(t,"name",{value:e,configurable:!0}),"e$2");const mt=new RegExp(/^-([^\d-])$/),dt=new RegExp(/^--(\S+)/),gt=new RegExp(/^-([^\d-]{2,})$/),ut=J(t=>mt.test(t)||dt.test(t)||gt.test(t),"isOption"),ht=J((t,e)=>{const o=e[0]&&ut(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 ft=Object.defineProperty,z=c((t,e)=>ft(t,"name",{value:e,configurable:!0}),"i$1");const vt=z((t,e)=>he(t,e)<=t.length/3||e.includes(t),"isSimilar"),F=z((t,e)=>{const o=t.toLowerCase();return e.filter(n=>vt(n.toLowerCase(),o))},"findAlternatives");var yt=Object.defineProperty,bt=c((t,e)=>yt(t,"name",{value:e,configurable:!0}),"t$3");const $t=bt((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,wt=c((t,e)=>Et(t,"name",{value:e,configurable:!0}),"t$2");const Ot=wt(t=>{const e=new Map;return t.forEach(o=>{e.set(o.name,{...e.get(o.name),...o})}),[...e.values()]},"mergeArguments");var Ct=Object.defineProperty,A=c((t,e)=>Ct(t,"name",{value:e,configurable:!0}),"e$1");const At=A(()=>!!process.versions.electron,"isElectronApp"),Nt=A(()=>At()&&!process.defaultApp,"isBundledElectronApp"),Lt=A(()=>Nt()?0:1,"getProcessArgvBinIndex"),_t=A(t=>t.slice(Lt()+1),"hideBin");var xt=Object.defineProperty,K=c((t,e)=>xt(t,"name",{value:e,configurable:!0}),"i");const Rt=" ",Pt=K((t,e)=>t.length===e.length&&t.every((o,n)=>o===e[n]),"equals"),St=K(t=>typeof t=="string"?t.split(Rt):Pt(t,process.argv)?_t(t):t,"parseRawCommand");var Tt=Object.defineProperty,It=c((t,e)=>Tt(t,"name",{value:e,configurable:!0}),"t");const jt=It(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 Vt=Object.defineProperty,v=c((t,e)=>Vt(t,"name",{value:e,configurable:!0}),"c");const Bt="CI"in d&&("GITHUB_ACTIONS"in d||"GITLAB_CI"in d||"CIRCLECI"in d),Ut=v(t=>t.charAt(0).toLowerCase()+t.slice(1),"lowerFirstChar");class eo{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(Ge):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in d?d.CEREBRO_OUTPUT_LEVEL=String(_):d.CEREBRO_OUTPUT_LEVEL=String(Fe);const i={32:"informational",64:"trace",128:"debug"},l=[new le,new ce];d.CEREBRO_OUTPUT_LEVEL===String(_)&&l.push(new pe),this.logger=me({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(),ze(),jt(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(Me),this.addCommand(new Ue(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__=we(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=ht([null,...a],this.argv)}catch(h){if(h.name==="INVALID_COMMAND"&&h.command){let P="";const S=F(h.command,[...this.commands.keys()]);S.length>0&&(P=` Did you mean: \r
|
|
7
|
+
- ${S.join(` \r
|
|
8
|
+
- `)}`),this.logger.error(`"${h.command}" is not an available command.${P}`)}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=Ot([...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=de(p,{argv:ct(l,i.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),b=nt(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
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&&this.updateNotifierOptions.alwaysRun||!(d.NO_UPDATE_NOTIFIER||d.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||Bt)&&this.updateNotifierOptions){e.raw("Checking for updates...");const o=await(await import("./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=$t(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
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.conflicts]!==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=Ut(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{eo as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/cerebro",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A delightful toolkit for building Node-powered CLIs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"command",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@visulima/boxen": "1.0.10",
|
|
80
80
|
"@visulima/colorize": "1.4.3",
|
|
81
|
-
"@visulima/find-cache-dir": "1.0.
|
|
81
|
+
"@visulima/find-cache-dir": "1.0.1",
|
|
82
82
|
"@visulima/pail": "1.4.3",
|
|
83
83
|
"cli-table3": "^0.6.5",
|
|
84
84
|
"command-line-args": "^5.2.1",
|