@visulima/cerebro 1.0.38 → 1.0.39

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,14 @@
1
+ ## @visulima/cerebro [1.0.39](https://github.com/visulima/visulima/compare/@visulima/cerebro@1.0.38...@visulima/cerebro@1.0.39) (2024-06-14)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **cerebro:** fixed wrong typing of error log ([2aee6e4](https://github.com/visulima/visulima/commit/2aee6e4b8aa8d20f252aba52c7d73d83e4979163))
6
+
7
+
8
+ ### Dependencies
9
+
10
+ * **@visulima/pail:** upgraded to 1.2.2
11
+
1
12
  ## @visulima/cerebro [1.0.38](https://github.com/visulima/visulima/compare/@visulima/cerebro@1.0.37...@visulima/cerebro@1.0.38) (2024-06-13)
2
13
 
3
14
 
package/dist/index.cjs CHANGED
@@ -8,7 +8,7 @@ var server = require('@visulima/pail/server');
8
8
  var dt = require('command-line-args');
9
9
  var L = require('cli-table3');
10
10
  var Oe = require('@visulima/colorize/template');
11
- var Te = require('os');
11
+ var Ee = require('os');
12
12
  var fastestLevenshtein = require('fastest-levenshtein');
13
13
 
14
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -16,17 +16,17 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
16
  var dt__default = /*#__PURE__*/_interopDefault(dt);
17
17
  var L__default = /*#__PURE__*/_interopDefault(L);
18
18
  var Oe__default = /*#__PURE__*/_interopDefault(Oe);
19
- var Te__default = /*#__PURE__*/_interopDefault(Te);
19
+ var Ee__default = /*#__PURE__*/_interopDefault(Ee);
20
20
 
21
- chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();var de=/[\p{Lu}]/u,ge=/[\p{Ll}]/u,M=/^[\p{Lu}](?![\p{Lu}])/gu,F=/([\p{Alpha}\p{N}_]|$)/u,w=/[_.\- ]+/,ue=new RegExp("^"+w.source),j=new RegExp(w.source+F.source,"gu"),Y=new RegExp("\\d+"+F.source,"gu"),fe=(o,e,t,n)=>{let r=!1,i=!1,s=!1,a=!1;for(let p=0;p<o.length;p++){let c=o[p];a=p>2?o[p-3]==="-":!0,r&&de.test(c)?(o=o.slice(0,p)+"-"+o.slice(p),r=!1,s=i,i=!0,p++):i&&s&&ge.test(c)&&(!a||n)?(o=o.slice(0,p-1)+"-"+o.slice(p-1),s=i,i=!1,r=!0):(r=e(c)===c&&t(c)!==c,s=i,i=t(c)===c&&e(c)!==c);}return o},he=(o,e)=>(M.lastIndex=0,o.replaceAll(M,t=>e(t))),ye=(o,e)=>(j.lastIndex=0,Y.lastIndex=0,o.replaceAll(Y,(t,n,r)=>["_","-"].includes(o.charAt(r+t.length))?t:e(t)).replaceAll(j,(t,n)=>e(n)));function A(o,e){if(!(typeof o=="string"||Array.isArray(o)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(o)?o=o.map(i=>i.trim()).filter(i=>i.length).join("-"):o=o.trim(),o.length===0)return "";let t=e.locale===!1?i=>i.toLowerCase():i=>i.toLocaleLowerCase(e.locale),n=e.locale===!1?i=>i.toUpperCase():i=>i.toLocaleUpperCase(e.locale);return o.length===1?w.test(o)?"":e.pascalCase?n(o):t(o):(o!==t(o)&&(o=fe(o,t,n,e.preserveConsecutiveUppercase)),o=o.replace(ue,""),o=e.preserveConsecutiveUppercase?he(o,t):t(o),e.pascalCase&&(o=n(o.charAt(0))+o.slice(1)),ye(o,n))}chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();var be=[{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}],b=be;chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();var Ce=o=>o?Oe__default.default(Object.assign([],{raw:[o.replaceAll("`","\\`")]})):"",d=Ce;chunk764E7XDY_cjs.c();var N=class{lines;constructor(){this.lines=[];}add(e){this.lines.push(e);}toString(){return this.lines.join(Te__default.default.EOL)}header(e){this.add(colorize.bold(e)),this.lines.push("");}},E=N;var v={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},P=class extends E{constructor(e){if(super(),e.header&&this.header(d(e.header)),e.content){if(e.raw)if(Array.isArray(e.content)&&e.content.every(t=>typeof t=="string"))e.content.forEach(t=>{Array.isArray(t)?t.forEach(n=>this.add(d(n))):this.add(d(t));});else if(typeof e.content=="string")this.add(d(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"){let t=new L__default.default({...v,colWidths:[80]});return t.push([d(e)]),t.toString()}if(Array.isArray(e)&&e.every(t=>typeof t=="string"||Array.isArray(t)&&t.every(n=>typeof n=="string"))){let t=new L__default.default({...v});return e.forEach(n=>{Array.isArray(n)?t.push(n.map(r=>d(r))):t.push([d(n)]);}),t.toString()}if(typeof e=="object"){let t=e;if(!t.options||!t.data)throw new Error(`Must have an "options" or "data" property
21
+ chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();var de=/[\p{Lu}]/u,ge=/[\p{Ll}]/u,M=/^[\p{Lu}](?![\p{Lu}])/gu,F=/([\p{Alpha}\p{N}_]|$)/u,w=/[_.\- ]+/,ue=new RegExp("^"+w.source),j=new RegExp(w.source+F.source,"gu"),Y=new RegExp("\\d+"+F.source,"gu"),fe=(o,e,t,n)=>{let r=!1,i=!1,s=!1,a=!1;for(let p=0;p<o.length;p++){let c=o[p];a=p>2?o[p-3]==="-":!0,r&&de.test(c)?(o=o.slice(0,p)+"-"+o.slice(p),r=!1,s=i,i=!0,p++):i&&s&&ge.test(c)&&(!a||n)?(o=o.slice(0,p-1)+"-"+o.slice(p-1),s=i,i=!1,r=!0):(r=e(c)===c&&t(c)!==c,s=i,i=t(c)===c&&e(c)!==c);}return o},he=(o,e)=>(M.lastIndex=0,o.replaceAll(M,t=>e(t))),ye=(o,e)=>(j.lastIndex=0,Y.lastIndex=0,o.replaceAll(Y,(t,n,r)=>["_","-"].includes(o.charAt(r+t.length))?t:e(t)).replaceAll(j,(t,n)=>e(n)));function A(o,e){if(!(typeof o=="string"||Array.isArray(o)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(o)?o=o.map(i=>i.trim()).filter(i=>i.length).join("-"):o=o.trim(),o.length===0)return "";let t=e.locale===!1?i=>i.toLowerCase():i=>i.toLocaleLowerCase(e.locale),n=e.locale===!1?i=>i.toUpperCase():i=>i.toLocaleUpperCase(e.locale);return o.length===1?w.test(o)?"":e.pascalCase?n(o):t(o):(o!==t(o)&&(o=fe(o,t,n,e.preserveConsecutiveUppercase)),o=o.replace(ue,""),o=e.preserveConsecutiveUppercase?he(o,t):t(o),e.pascalCase&&(o=n(o.charAt(0))+o.slice(1)),ye(o,n))}chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();var be=[{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}],b=be;chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();var Ce=o=>o?Oe__default.default(Object.assign([],{raw:[o.replaceAll("`","\\`")]})):"",d=Ce;chunk764E7XDY_cjs.c();var N=class{lines;constructor(){this.lines=[];}add(e){this.lines.push(e);}toString(){return this.lines.join(Ee__default.default.EOL)}header(e){this.add(colorize.bold(e)),this.lines.push("");}},T=N;var v={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},P=class extends T{constructor(e){if(super(),e.header&&this.header(d(e.header)),e.content){if(e.raw)if(Array.isArray(e.content)&&e.content.every(t=>typeof t=="string"))e.content.forEach(t=>{Array.isArray(t)?t.forEach(n=>this.add(d(n))):this.add(d(t));});else if(typeof e.content=="string")this.add(d(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"){let t=new L__default.default({...v,colWidths:[80]});return t.push([d(e)]),t.toString()}if(Array.isArray(e)&&e.every(t=>typeof t=="string"||Array.isArray(t)&&t.every(n=>typeof n=="string"))){let t=new L__default.default({...v});return e.forEach(n=>{Array.isArray(n)?t.push(n.map(r=>d(r))):t.push([d(n)]);}),t.toString()}if(typeof e=="object"){let t=e;if(!t.options||!t.data)throw new Error(`Must have an "options" or "data" property
22
22
  ${JSON.stringify(e)}`);let n=new L__default.default({...v,...t.options,style:{...v.style,...t.options.style}});return t.data.forEach(r=>{Array.isArray(r)?n.push(r.map(i=>d(i))):n.push([d(r)]);}),n.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
23
23
 
24
- ${JSON.stringify(e)}`)}},G=P;chunk764E7XDY_cjs.c();var _=class extends E{constructor(e){super();let t=e.optionList??[],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&&(t=t.filter(s=>!n.includes(s.name))),e.header&&this.header(d(e.header)),r.length>0&&(t=t.filter(s=>{let a=r.includes("_none")&&!s.group,p=this.intersect(Array.isArray(s.group)?s.group:[s.group],r);return a||p?s:void 0}));let i=new L__default.default({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});t.forEach(s=>i.push([this.getOptionNames(s,e.reverseNameOrder??!1,e.isArgument??!1),d(s.description)])),this.add(i.toString()),this.lines.push("");}getOptionNames(e,t,n){if(!e.name)throw new TypeError("Invalid option definition, name is required.");let r=e.type?e.type.name.toLowerCase():"string",i=e.multiple||e.lazyMultiple?"[]":"";r=d(e.typeLabel??`{underline ${r}${i}}`);let s;if(e.alias)if(e.name){let a=n?e.name:`{yellow --${e.name}}`;s=t?d(`{bold ${a}}, {bold -${e.alias}} ${r}`):d(`{bold -${e.alias}}, {bold ${a}} ${r}`);}else t?s=d(`{bold -${e.alias}} ${r}`):s=d(`{bold -${e.alias}} ${r}`);else s=d(`{bold ${n?e.name:`{yellow --${e.name}}`}} ${r}`);return s}intersect(e,t){return e.some(n=>t.includes(n))}},q=_;var Ie=o=>(Array.isArray(o)?o:[o]).length===0?"":`
24
+ ${JSON.stringify(e)}`)}},G=P;chunk764E7XDY_cjs.c();var _=class extends T{constructor(e){super();let t=e.optionList??[],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&&(t=t.filter(s=>!n.includes(s.name))),e.header&&this.header(d(e.header)),r.length>0&&(t=t.filter(s=>{let a=r.includes("_none")&&!s.group,p=this.intersect(Array.isArray(s.group)?s.group:[s.group],r);return a||p?s:void 0}));let i=new L__default.default({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});t.forEach(s=>i.push([this.getOptionNames(s,e.reverseNameOrder??!1,e.isArgument??!1),d(s.description)])),this.add(i.toString()),this.lines.push("");}getOptionNames(e,t,n){if(!e.name)throw new TypeError("Invalid option definition, name is required.");let r=e.type?e.type.name.toLowerCase():"string",i=e.multiple||e.lazyMultiple?"[]":"";r=d(e.typeLabel??`{underline ${r}${i}}`);let s;if(e.alias)if(e.name){let a=n?e.name:`{yellow --${e.name}}`;s=t?d(`{bold ${a}}, {bold -${e.alias}} ${r}`):d(`{bold -${e.alias}}, {bold ${a}} ${r}`);}else t?s=d(`{bold -${e.alias}} ${r}`):s=d(`{bold -${e.alias}} ${r}`);else s=d(`{bold ${n?e.name:`{yellow --${e.name}}`}} ${r}`);return s}intersect(e,t){return e.some(n=>t.includes(n))}},q=_;var Ie=o=>(Array.isArray(o)?o:[o]).length===0?"":`
25
25
  ${o.map(t=>t.optionList?new q(t).toString():new G(t).toString()).join(`
26
26
  `)}`,R=Ie;var J="__Other",W=o=>o.charAt(0).toUpperCase()+o.slice(1),xe=(o,e,t,n)=>{o.debug("no command given, printing general help...");let r=[...new Set(t.values())].filter(s=>!s.hidden);n&&(r=r.filter(s=>s.group===n));let i=r.reduce((s,a)=>{let p=a.group??J;return s[p]||(s[p]=[]),s[p].push(a),s},{});o.raw(R([{content:`{cyan ${e.getCliName()}} {green <command>} [positional arguments] {yellow [options]}`,header:"{inverse.cyan Usage }"},...Object.keys(i).map(s=>({content:i[s].map(a=>{let p="";return typeof a.alias=="string"?p=a.alias:Array.isArray(a.alias)&&(p=a.alias.join(", ")),p!==""&&(p=` [${p}]`),[`{green ${a.name}} ${p}`,a.description??""]}),header:s===J||n?`{inverse.green Available${n?` ${W(n)}`:""} Commands }`:` {inverse.green ${W(s)} }`})),t.has("help")?{header:"{inverse.yellow Command Options }",optionList:t.get("help").options?.filter(s=>!s.hidden)}:void 0,{header:"{inverse.yellow Global Options }",optionList:b},{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)));},we=(o,e,t,n)=>{let r=t.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(s=>!s.hidden)}),i.push({header:"{inverse.yellow Global Options }",optionList:b}),r.alias!==void 0&&r.alias.length>0){let s=r.alias;typeof r.alias=="string"&&(s=[r.alias]),i.splice(1,0,{content:s,header:"Alias(es)"});}Array.isArray(r.examples)&&r.examples.length>0&&i.push({content:r.examples,header:"Examples"}),o.raw(R(i));},$=class{name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(e){this.commands=e;}execute(e){let{commandName:t,logger:n,options:r,runtime:i}=e,{footer:s,header:a}=i.getCommandSection();a&&n.raw(d(a)),t==="help"?xe(n,i,this.commands,r?.group):we(n,i,this.commands,t),s&&n.raw(d(s));}},H=$;chunk764E7XDY_cjs.c();var K={alias:["v","V"],description:"Output the version number",execute:({logger:o,runtime:e})=>{let t=e.getPackageVersion();t===void 0?(o.warn("Unknown version"),o.debug("The version number was not provided by the cli constructor.")):o.info(t);},name:"version",options:[],usage:[]};chunk764E7XDY_cjs.c();var C="positionals";chunk764E7XDY_cjs.c();var S=class{result;argv;options;argument;command;commandName;runtime;logger;constructor(e,t){this.commandName=e,this.command=t;}},z=S;chunk764E7XDY_cjs.c();var Ae=()=>{let o=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])<o&&(console.log(`cerebro supports a minimum Node version of ${o}. You have ${e}. Read our version support policy: https://github.com/visulima/visulima#supported-nodejs-versions`),process.exit(1));},Q=Ae;chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();var Ne=/^-{1,2}(\w+)(=(\w+))?$/,Le=(o,e)=>{let t=Ne.exec(o);if(t==null)return {};let n=t[1],r=e.find(i=>i.name===n||i.alias===n);return r!==void 0?{argName:r.name,argValue:t[3],option:r}:{}},I=Le;chunk764E7XDY_cjs.c();var Pe=o=>o.type?.name==="Boolean",y=Pe;var X=(o,e)=>{if(e.type===void 0)return o;if(e.type.name==="Boolean"){if(o==="true"||o==="1")return e.type(!0);if(o==="false"||o==="0")return e.type(!1)}return e.type(o)},_e=new Set(["1","0","true","false"]),Re=(o,e)=>{let t=(n,r)=>{let{argName:i,argValue:s,option:a}=I(r,e),{lastOption:p}=n;return a&&y(a)&&s&&i?n.partial[i]=X(s,a):n.lastName&&p&&y(p)&&_e.has(r)&&(n.partial[n.lastName]=X(r,p)),{lastName:i,lastOption:a,partial:n.partial}};return o.reduce(t,{partial:{}}).partial},Z=Re;chunk764E7XDY_cjs.c();var $e=o=>{let e=o.type?o.type.name.toLowerCase():"string",t=o.multiple??o.lazyMultiple?"[]":"";return e&&(e=e==="boolean"?"":`{underline ${e}${t}}`),e},Se=o=>(y(o)||(o.typeLabel=o.typeLabel??$e(o),o.defaultOption&&(o.typeLabel=`${o.typeLabel} (D)`),o.required&&(o.typeLabel=`${o.typeLabel} (R)`)),o),ee=Se;chunk764E7XDY_cjs.c();var De=new Set(["1","0","true","false"]),Ve=(o,e)=>{let t=(n,r)=>{let{argValue:i,option:s}=I(r,e),{lastOption:a}=n;if(a&&y(a)&&De.has(r)){let p=[...n.args];return p.pop(),{args:p}}return s&&y(s)&&i?{args:n.args}:{args:[...n.args,r],lastOption:s}};return o.reduce(t,{args:[]}).args},te=Ve;chunk764E7XDY_cjs.c();var Be=new RegExp(/^-([^\d-])$/),Ue=new RegExp(/^--(\S+)/),ke=new RegExp(/^-([^\d-]{2,})$/),Me=o=>Be.test(o)||Ue.test(o)||ke.test(o),je=(o,e)=>{let t=e[0]&&Me(e[0])||e.length===0?null:e.shift()??null;if(!o.includes(t)){let n=new Error(`Command not recognised: ${t}`);throw n.command=t,n.name="INVALID_COMMAND",n}return {argv:e,command:t}},oe=je;chunk764E7XDY_cjs.c();var Fe=(o,e)=>fastestLevenshtein.distance(o,e)<=o.length/3||e.includes(o),Ge=(o,e)=>{let t=o.toLowerCase();return e.filter(n=>Fe(n.toLowerCase(),t))},D=Ge;chunk764E7XDY_cjs.c();var qe=(o,e)=>o.filter(t=>t.required&&e[t.name]==null).filter(t=>t.type?.name==="Boolean"?(e[t.name]=!1,!1):!0),ne=qe;chunk764E7XDY_cjs.c();var Je=o=>{let e=new Map;return o.forEach(t=>{e.set(t.name,{...e.get(t.name),...t});}),[...e.values()]},ie=Je;chunk764E7XDY_cjs.c();chunk764E7XDY_cjs.c();var We=()=>!!process.versions.electron,He=()=>We()&&!process.defaultApp,Ke=()=>He()?0:1,ze=o=>o.slice(Ke()+1),re=ze;var Qe=" ",Xe=(o,e)=>o.length===e.length&&o.every((t,n)=>t===e[n]),Ze=o=>typeof o=="string"?o.split(Qe):Xe(o,process.argv)?re(o):o,se=Ze;chunk764E7XDY_cjs.c();var et=o=>{process.on("uncaughtException",e=>{o.error(`Uncaught exception: ${e}`),e?.stack&&o.error(e.stack),process.exit(1);}),process.on("unhandledRejection",e=>{o.error(`Promise rejection: ${e}`),e?.stack&&o.error(e.stack),process.exit(1);});},ae=et;var gt="CI"in process$1.env&&("GITHUB_ACTIONS"in process$1.env||"GITLAB_CI"in process$1.env||"CIRCLECI"in process$1.env),ut=o=>o.charAt(0).toLowerCase()+o.slice(1),B=class{logger;argv;cwd;cliName;packageVersion;packageName;extensions=[];commands;defaultCommand;updateNotifierOptions;commandSection;constructor(e,t={}){let{argv:n,cwd:r,packageName:i,packageVersion:s}={argv:process$1.argv,cwd:process$1.cwd(),...t};this.argv=se(n),this.argv.includes("--quiet")||this.argv.includes("-q")?process$1.env.CEREBRO_OUTPUT_LEVEL=String(16):this.argv.includes("--verbose")||this.argv.includes("-v")?process$1.env.CEREBRO_OUTPUT_LEVEL=String(64):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in process$1.env?process$1.env.CEREBRO_OUTPUT_LEVEL=String(128):process$1.env.CEREBRO_OUTPUT_LEVEL=String(32);let a={32:"informational",64:"trace",128:"debug"};this.logger=server.createPail({logLevel:process$1.env.CEREBRO_OUTPUT_LEVEL?a[process$1.env.CEREBRO_OUTPUT_LEVEL]??"informational":"informational",...t.logger}),process$1.env.CEREBRO_OUTPUT_LEVEL===String(16)&&this.logger.disable(),Q(),ae(this.logger),this.cliName=e,this.packageVersion=s,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(K),this.addCommand(new H(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(t=>ee(t)),this.validateDoubleOptions(e),this.addNegatableOption(e),e.options?.forEach(t=>{t.__camelCaseName__=A(t.name);}),this.commands.set(e.name,e),e.alias!==void 0){let t=e.alias;typeof e.alias=="string"&&(t=[e.alias]),t.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.");let t=Object.keys(e);if(t.length>0&&!t.includes("alwaysRun")&&!t.includes("distTag")&&!t.includes("updateCheckInterval"))throw new Error("Invalid update notifier options, please check the documentation.");return this.updateNotifierOptions={alwaysRun:!1,debug:process$1.env.CEREBRO_OUTPUT_LEVEL===String(128),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={}){let{shouldExitProcess:t=!0,...n}=e,r=[...this.commands.keys()],i;this.logger.debug(`process.execPath: ${process$1.execPath}`),this.logger.debug(`process.execArgv: ${process$1.execArgv.join(" ")}`),this.logger.debug(`process.argv: ${process$1.argv.join(" ")}`);try{i=oe([null,...r],this.argv);}catch(h){if(h.name==="INVALID_COMMAND"&&h.command){let U="",k=D(h.command,[...this.commands.keys()]);k.length>0&&(U=` Did you mean: \r
27
27
  - ${k.join(` \r
28
- - `)}`),this.logger.error(`"${h.command}" is not an available command.${U}`);}else this.logger.error(h);return t?process$1.exit(1):void 0}let s=i.command??this.defaultCommand,a=this.commands.get(s);if(typeof a.execute!="function")return this.logger.error(`Command "${a.name}" has no function to execute.`),t?process$1.exit(1):void 0;let p=i.argv;this.logger.debug(`command '${s}' found, parsing command args: ${p.join(", ")}`);let c=ie([...a.options??[],...b]);c.forEach(h=>{if(h.multiple&&h.lazyMultiple)throw new Error(`Argument "${h.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}),a.argument&&(this.logger.debug("command has positional argument, parsing them..."),c=[{defaultOption:!0,description:a.argument?.description,group:"positionals",multiple:!0,name:C,type:a.argument?.type,typeLabel:a.argument?.typeLabel},...c]);let f=dt__default.default(c,{argv:te(p,a.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),T=Z(p,a.options??[]),O={...f,_all:{...f._all,...T}};this.validateCommandOptions(c,O,a);let u=new z(a.name,a);u.runtime=this,await this.registerExtensions(u),await this.updateNotifier(u);let{_all:x,positionals:ce}=O;return x[C]&&delete x[C],u.argument=ce?.[C]??[],u.argv=this.argv,u.options={...x,...n},this.mapNegatableOptions(u,a),this.mapImpliesOptions(u,a),this.validateCommandArgsForConflicts(c,u.options,a),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(O,u,a),t?process$1.exit(0):void 0}validateDoubleOptions(e){if(Array.isArray(e.options)){let t=e.options.reduce((i,s)=>{let a=`${s.name}-${s.alias}`;return i[a]||(i[a]=[]),i[a].push(s),i},{}),n=Object.values(t).filter(i=>i.length>1),r="";if(n.forEach(i=>{let s=i[0],a=i[1],p="alias";s.name===a.name&&(p="name",s.alias===a.alias&&(p+=" and alias")),r+=`Cannot add option ${p} "${JSON.stringify(a)}" to command "${e.name}" due to conflicting option ${JSON.stringify(s)}
29
- `;}),r.length>0)throw new Error(r)}}addCoreExtensions(){this.addExtension({execute:e=>{e.logger=this.logger;},name:"logger"});}async prepareToolboxResult(e,t,n){if(e.global?.help){this.logger.debug("'--help' option found, running 'help' for given command...");let r=this.commands.get("help");if(!r)throw new Error("Help command not found.");await r.execute(t);return}if(e.global?.version||e.global?.V){this.logger.debug("'--version' option found, running 'version' for given command...");let r=this.commands.get("version");if(!r)throw new Error("Version command not found.");await r.execute(t);return}await n.execute(t);}async updateNotifier({logger:e}){if(this.updateNotifierOptions&&this.updateNotifierOptions.alwaysRun||!(process$1.env.NO_UPDATE_NOTIFIER||process$1.env.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||gt)&&this.updateNotifierOptions){e.raw("Checking for updates...");let n=await(await import('./has-new-version-RB42Y6BN.cjs').then(r=>r.default))(this.updateNotifierOptions);if(n){let r="Update available "+colorize.dim(this.packageVersion+"")+colorize.reset(" \u2192 ")+colorize.green(n);this.logger.error(boxen.boxen(r,{borderColor:i=>colorize.yellow(i),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}));}}}validateCommandOptions(e,t,n){let r=ne(e,t);if(r.length>0)throw new Error(`You called the command "${n.name}" without the required options: ${r.map(i=>i.name).join(", ")}`);if(t._unknown&&t._unknown.length>0){let i=[];if(t._unknown.forEach(s=>{let a=s.startsWith("--"),p=`Found unknown ${a?"option":"argument"} "${s}"`;if(a){let c=D(s.replace("--",""),[...(n.options??[]).map(f=>f.name),...b.map(f=>f.name)]);if(c.length>0){let[f,...T]=c.map(O=>`--${O}`);p+=T.length>0?`, did you mean ${f} or ${T.join(", ")}?`:`, did you mean ${f}?`;}}i.push(p);}),i.length>0)throw new Error(i.join(`
28
+ - `)}`),this.logger.error(`"${h.command}" is not an available command.${U}`);}else this.logger.error(h);return t?process$1.exit(1):void 0}let s=i.command??this.defaultCommand,a=this.commands.get(s);if(typeof a.execute!="function")return this.logger.error(`Command "${a.name}" has no function to execute.`),t?process$1.exit(1):void 0;let p=i.argv;this.logger.debug(`command '${s}' found, parsing command args: ${p.join(", ")}`);let c=ie([...a.options??[],...b]);c.forEach(h=>{if(h.multiple&&h.lazyMultiple)throw new Error(`Argument "${h.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}),a.argument&&(this.logger.debug("command has positional argument, parsing them..."),c=[{defaultOption:!0,description:a.argument?.description,group:"positionals",multiple:!0,name:C,type:a.argument?.type,typeLabel:a.argument?.typeLabel},...c]);let f=dt__default.default(c,{argv:te(p,a.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),E=Z(p,a.options??[]),O={...f,_all:{...f._all,...E}};this.validateCommandOptions(c,O,a);let u=new z(a.name,a);u.runtime=this,await this.registerExtensions(u),await this.updateNotifier(u);let{_all:x,positionals:ce}=O;return x[C]&&delete x[C],u.argument=ce?.[C]??[],u.argv=this.argv,u.options={...x,...n},this.mapNegatableOptions(u,a),this.mapImpliesOptions(u,a),this.validateCommandArgsForConflicts(c,u.options,a),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(O,u,a),t?process$1.exit(0):void 0}validateDoubleOptions(e){if(Array.isArray(e.options)){let t=e.options.reduce((i,s)=>{let a=`${s.name}-${s.alias}`;return i[a]||(i[a]=[]),i[a].push(s),i},{}),n=Object.values(t).filter(i=>i.length>1),r="";if(n.forEach(i=>{let s=i[0],a=i[1],p="alias";s.name===a.name&&(p="name",s.alias===a.alias&&(p+=" and alias")),r+=`Cannot add option ${p} "${JSON.stringify(a)}" to command "${e.name}" due to conflicting option ${JSON.stringify(s)}
29
+ `;}),r.length>0)throw new Error(r)}}addCoreExtensions(){this.addExtension({execute:e=>{e.logger=this.logger;},name:"logger"});}async prepareToolboxResult(e,t,n){if(e.global?.help){this.logger.debug("'--help' option found, running 'help' for given command...");let r=this.commands.get("help");if(!r)throw new Error("Help command not found.");await r.execute(t);return}if(e.global?.version||e.global?.V){this.logger.debug("'--version' option found, running 'version' for given command...");let r=this.commands.get("version");if(!r)throw new Error("Version command not found.");await r.execute(t);return}await n.execute(t);}async updateNotifier({logger:e}){if(this.updateNotifierOptions&&this.updateNotifierOptions.alwaysRun||!(process$1.env.NO_UPDATE_NOTIFIER||process$1.env.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||gt)&&this.updateNotifierOptions){e.raw("Checking for updates...");let n=await(await import('./has-new-version-RB42Y6BN.cjs').then(r=>r.default))(this.updateNotifierOptions);if(n){let r="Update available "+colorize.dim(this.packageVersion+"")+colorize.reset(" \u2192 ")+colorize.green(n);this.logger.error(boxen.boxen(r,{borderColor:i=>colorize.yellow(i),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}));}}}validateCommandOptions(e,t,n){let r=ne(e,t);if(r.length>0)throw new Error(`You called the command "${n.name}" without the required options: ${r.map(i=>i.name).join(", ")}`);if(t._unknown&&t._unknown.length>0){let i=[];if(t._unknown.forEach(s=>{let a=s.startsWith("--"),p=`Found unknown ${a?"option":"argument"} "${s}"`;if(a){let c=D(s.replace("--",""),[...(n.options??[]).map(f=>f.name),...b.map(f=>f.name)]);if(c.length>0){let[f,...E]=c.map(O=>`--${O}`);p+=E.length>0?`, did you mean ${f} or ${E.join(", ")}?`:`, did you mean ${f}?`;}}i.push(p);}),i.length>0)throw new Error(i.join(`
30
30
  `))}}validateCommandArgsForConflicts(e,t,n){let r=e.filter(i=>i.conflicts!==void 0);if(r.length>0){let i=r.find(s=>Array.isArray(s.conflicts)?s.conflicts.some(a=>t[a]!==void 0):t[s.conflicts]!==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(t=>{if(t.name.startsWith("no-")&&!e.options.some(n=>n.name===t.name.replace("no-",""))){if(t.type!==Boolean){this.logger.debug(`Cannot add negated option "${t.name}" to command "${e.name}" because it is not a boolean.`);return}let n={...t,defaultValue:t.defaultValue===void 0?!0:!t.defaultValue,name:`${t.name.replace("no-","")}`};e.options.push(n);}});}async registerExtensions(e){let t=async n=>typeof n.execute!="function"?(this.logger.warn(`Skipped ${n.name} because execute is not a function.`),null):(await n.execute(e),null);for(let n of this.extensions)await t(n);}mapNegatableOptions(e,t){Object.entries(e.options).forEach(([n,r])=>{if(/^no\w+/.test(n)){let i=ut(n.replace("no",""));this.logger.debug(`mapping negated option "${n}" to "${i}"`),e.options[i]=!r,t.options?.forEach(s=>{s.name===i&&(s.__negated__=!0);});}});}mapImpliesOptions(e,t){Object.keys(e.options).forEach(n=>{let r=t.options?.find(i=>i.__camelCaseName__===n&&i.__negated__===void 0&&i.implies!==void 0);if(r?.implies){let i=r.implies;Object.entries(i).forEach(([s,a])=>{if(e.options[s]===void 0)e.options[s]=a;else {let p=t.options?.find(c=>c.name===s);(p?.defaultValue===void 0||e.options[s]===p.defaultValue)&&(e.options[s]=a);}});}});}};
31
31
 
32
32
  module.exports = B;