Socket
Socket
Sign inDemoInstall

@visulima/cerebro

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@visulima/cerebro - npm Package Compare versions

Comparing version 1.0.38 to 1.0.39

11

CHANGELOG.md

@@ -0,1 +1,12 @@

## @visulima/cerebro [1.0.39](https://github.com/visulima/visulima/compare/@visulima/cerebro@1.0.38...@visulima/cerebro@1.0.39) (2024-06-14)
### Bug Fixes
* **cerebro:** fixed wrong typing of error log ([2aee6e4](https://github.com/visulima/visulima/commit/2aee6e4b8aa8d20f252aba52c7d73d83e4979163))
### Dependencies
* **@visulima/pail:** upgraded to 1.2.2
## @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,0 +13,0 @@

10

dist/index.js

@@ -9,6 +9,6 @@ import { c } from './chunk-5IGWF4F6.js';

import Ce from '@visulima/colorize/template';
import Ee from 'node:os';
import Te from 'node:os';
import { distance } from 'fastest-levenshtein';
c();c();c();var ge=/[\p{Lu}]/u,ue=/[\p{Ll}]/u,j=/^[\p{Lu}](?![\p{Lu}])/gu,G=/([\p{Alpha}\p{N}_]|$)/u,A=/[_.\- ]+/,fe=new RegExp("^"+A.source),Y=new RegExp(A.source+G.source,"gu"),F=new RegExp("\\d+"+G.source,"gu"),he=(o,e,t,n)=>{let r=!1,i=!1,s=!1,a=!1;for(let p=0;p<o.length;p++){let d=o[p];a=p>2?o[p-3]==="-":!0,r&&ge.test(d)?(o=o.slice(0,p)+"-"+o.slice(p),r=!1,s=i,i=!0,p++):i&&s&&ue.test(d)&&(!a||n)?(o=o.slice(0,p-1)+"-"+o.slice(p-1),s=i,i=!1,r=!0):(r=e(d)===d&&t(d)!==d,s=i,i=t(d)===d&&e(d)!==d);}return o},ye=(o,e)=>(j.lastIndex=0,o.replaceAll(j,t=>e(t))),be=(o,e)=>(Y.lastIndex=0,F.lastIndex=0,o.replaceAll(F,(t,n,r)=>["_","-"].includes(o.charAt(r+t.length))?t:e(t)).replaceAll(Y,(t,n)=>e(n)));function N(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?A.test(o)?"":e.pascalCase?n(o):t(o):(o!==t(o)&&(o=he(o,t,n,e.preserveConsecutiveUppercase)),o=o.replace(fe,""),o=e.preserveConsecutiveUppercase?ye(o,t):t(o),e.pascalCase&&(o=n(o.charAt(0))+o.slice(1)),be(o,n))}c();c();var Oe=[{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}],O=Oe;c();c();c();var Te=o=>o?Ce(Object.assign([],{raw:[o.replaceAll("`","\\`")]})):"",g=Te;c();var L=class{lines;constructor(){this.lines=[];}add(e){this.lines.push(e);}toString(){return this.lines.join(Ee.EOL)}header(e){this.add(bold(e)),this.lines.push("");}},v=L;var I={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},_=class extends v{constructor(e){if(super(),e.header&&this.header(g(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(g(n))):this.add(g(t));});else if(typeof e.content=="string")this.add(g(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 P({...I,colWidths:[80]});return t.push([g(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 P({...I});return e.forEach(n=>{Array.isArray(n)?t.push(n.map(r=>g(r))):t.push([g(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
c();c();c();var ge=/[\p{Lu}]/u,ue=/[\p{Ll}]/u,j=/^[\p{Lu}](?![\p{Lu}])/gu,G=/([\p{Alpha}\p{N}_]|$)/u,A=/[_.\- ]+/,fe=new RegExp("^"+A.source),Y=new RegExp(A.source+G.source,"gu"),F=new RegExp("\\d+"+G.source,"gu"),he=(o,e,t,n)=>{let r=!1,i=!1,s=!1,a=!1;for(let p=0;p<o.length;p++){let d=o[p];a=p>2?o[p-3]==="-":!0,r&&ge.test(d)?(o=o.slice(0,p)+"-"+o.slice(p),r=!1,s=i,i=!0,p++):i&&s&&ue.test(d)&&(!a||n)?(o=o.slice(0,p-1)+"-"+o.slice(p-1),s=i,i=!1,r=!0):(r=e(d)===d&&t(d)!==d,s=i,i=t(d)===d&&e(d)!==d);}return o},ye=(o,e)=>(j.lastIndex=0,o.replaceAll(j,t=>e(t))),be=(o,e)=>(Y.lastIndex=0,F.lastIndex=0,o.replaceAll(F,(t,n,r)=>["_","-"].includes(o.charAt(r+t.length))?t:e(t)).replaceAll(Y,(t,n)=>e(n)));function N(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?A.test(o)?"":e.pascalCase?n(o):t(o):(o!==t(o)&&(o=he(o,t,n,e.preserveConsecutiveUppercase)),o=o.replace(fe,""),o=e.preserveConsecutiveUppercase?ye(o,t):t(o),e.pascalCase&&(o=n(o.charAt(0))+o.slice(1)),be(o,n))}c();c();var Oe=[{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}],O=Oe;c();c();c();var Ee=o=>o?Ce(Object.assign([],{raw:[o.replaceAll("`","\\`")]})):"",g=Ee;c();var L=class{lines;constructor(){this.lines=[];}add(e){this.lines.push(e);}toString(){return this.lines.join(Te.EOL)}header(e){this.add(bold(e)),this.lines.push("");}},v=L;var I={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},_=class extends v{constructor(e){if(super(),e.header&&this.header(g(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(g(n))):this.add(g(t));});else if(typeof e.content=="string")this.add(g(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 P({...I,colWidths:[80]});return t.push([g(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 P({...I});return e.forEach(n=>{Array.isArray(n)?t.push(n.map(r=>g(r))):t.push([g(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
${JSON.stringify(e)}`);let n=new P({...I,...t.options,style:{...I.style,...t.options.style}});return t.data.forEach(r=>{Array.isArray(r)?n.push(r.map(i=>g(i))):n.push([g(r)]);}),n.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:

@@ -18,6 +18,6 @@

${o.map(t=>t.optionList?new J(t).toString():new q(t).toString()).join(`
`)}`,$=xe;var W="__Other",H=o=>o.charAt(0).toUpperCase()+o.slice(1),we=(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??W;return s[p]||(s[p]=[]),s[p].push(a),s},{});o.raw($([{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===W||n?`{inverse.green Available${n?` ${H(n)}`:""} Commands }`:` {inverse.green ${H(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: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)));},Ae=(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:O}),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($(i));},S=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(g(a)),t==="help"?we(n,i,this.commands,r?.group):Ae(n,i,this.commands,t),s&&n.raw(g(s));}},K=S;c();var z={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:[]};c();var T="positionals";c();var D=class{result;argv;options;argument;command;commandName;runtime;logger;constructor(e,t){this.commandName=e,this.command=t;}},Q=D;c();var Ne=()=>{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));},X=Ne;c();c();var Le=/^-{1,2}(\w+)(=(\w+))?$/,Pe=(o,e)=>{let t=Le.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}:{}},x=Pe;c();var _e=o=>o.type?.name==="Boolean",b=_e;var Z=(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)},Re=new Set(["1","0","true","false"]),$e=(o,e)=>{let t=(n,r)=>{let{argName:i,argValue:s,option:a}=x(r,e),{lastOption:p}=n;return a&&b(a)&&s&&i?n.partial[i]=Z(s,a):n.lastName&&p&&b(p)&&Re.has(r)&&(n.partial[n.lastName]=Z(r,p)),{lastName:i,lastOption:a,partial:n.partial}};return o.reduce(t,{partial:{}}).partial},ee=$e;c();var Se=o=>{let e=o.type?o.type.name.toLowerCase():"string",t=o.multiple??o.lazyMultiple?"[]":"";return e&&(e=e==="boolean"?"":`{underline ${e}${t}}`),e},De=o=>(b(o)||(o.typeLabel=o.typeLabel??Se(o),o.defaultOption&&(o.typeLabel=`${o.typeLabel} (D)`),o.required&&(o.typeLabel=`${o.typeLabel} (R)`)),o),te=De;c();var Ve=new Set(["1","0","true","false"]),Be=(o,e)=>{let t=(n,r)=>{let{argValue:i,option:s}=x(r,e),{lastOption:a}=n;if(a&&b(a)&&Ve.has(r)){let p=[...n.args];return p.pop(),{args:p}}return s&&b(s)&&i?{args:n.args}:{args:[...n.args,r],lastOption:s}};return o.reduce(t,{args:[]}).args},oe=Be;c();var Ue=new RegExp(/^-([^\d-])$/),ke=new RegExp(/^--(\S+)/),Me=new RegExp(/^-([^\d-]{2,})$/),je=o=>Ue.test(o)||ke.test(o)||Me.test(o),Ye=(o,e)=>{let t=e[0]&&je(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}},ne=Ye;c();var Ge=(o,e)=>distance(o,e)<=o.length/3||e.includes(o),qe=(o,e)=>{let t=o.toLowerCase();return e.filter(n=>Ge(n.toLowerCase(),t))},V=qe;c();var Je=(o,e)=>o.filter(t=>t.required&&e[t.name]==null).filter(t=>t.type?.name==="Boolean"?(e[t.name]=!1,!1):!0),ie=Je;c();var We=o=>{let e=new Map;return o.forEach(t=>{e.set(t.name,{...e.get(t.name),...t});}),[...e.values()]},re=We;c();c();var He=()=>!!process.versions.electron,Ke=()=>He()&&!process.defaultApp,ze=()=>Ke()?0:1,Qe=o=>o.slice(ze()+1),se=Qe;var Xe=" ",Ze=(o,e)=>o.length===e.length&&o.every((t,n)=>t===e[n]),et=o=>typeof o=="string"?o.split(Xe):Ze(o,process.argv)?se(o):o,ae=et;c();var tt=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);});},le=tt;var ut="CI"in env&&("GITHUB_ACTIONS"in env||"GITLAB_CI"in env||"CIRCLECI"in env),ft=o=>o.charAt(0).toLowerCase()+o.slice(1),U=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:argv,cwd:cwd(),...t};this.argv=ae(n),this.argv.includes("--quiet")||this.argv.includes("-q")?env.CEREBRO_OUTPUT_LEVEL=String(16):this.argv.includes("--verbose")||this.argv.includes("-v")?env.CEREBRO_OUTPUT_LEVEL=String(64):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in env?env.CEREBRO_OUTPUT_LEVEL=String(128):env.CEREBRO_OUTPUT_LEVEL=String(32);let a={32:"informational",64:"trace",128:"debug"};this.logger=createPail({logLevel:env.CEREBRO_OUTPUT_LEVEL?a[env.CEREBRO_OUTPUT_LEVEL]??"informational":"informational",...t.logger}),env.CEREBRO_OUTPUT_LEVEL===String(16)&&this.logger.disable(),X(),le(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(z),this.addCommand(new K(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=>te(t)),this.validateDoubleOptions(e),this.addNegatableOption(e),e.options?.forEach(t=>{t.__camelCaseName__=N(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: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: ${execPath}`),this.logger.debug(`process.execArgv: ${execArgv.join(" ")}`),this.logger.debug(`process.argv: ${argv.join(" ")}`);try{i=ne([null,...r],this.argv);}catch(y){if(y.name==="INVALID_COMMAND"&&y.command){let k="",M=V(y.command,[...this.commands.keys()]);M.length>0&&(k=` Did you mean: \r
`)}`,$=xe;var W="__Other",H=o=>o.charAt(0).toUpperCase()+o.slice(1),we=(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??W;return s[p]||(s[p]=[]),s[p].push(a),s},{});o.raw($([{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===W||n?`{inverse.green Available${n?` ${H(n)}`:""} Commands }`:` {inverse.green ${H(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: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)));},Ae=(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:O}),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($(i));},S=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(g(a)),t==="help"?we(n,i,this.commands,r?.group):Ae(n,i,this.commands,t),s&&n.raw(g(s));}},K=S;c();var z={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:[]};c();var E="positionals";c();var D=class{result;argv;options;argument;command;commandName;runtime;logger;constructor(e,t){this.commandName=e,this.command=t;}},Q=D;c();var Ne=()=>{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));},X=Ne;c();c();var Le=/^-{1,2}(\w+)(=(\w+))?$/,Pe=(o,e)=>{let t=Le.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}:{}},x=Pe;c();var _e=o=>o.type?.name==="Boolean",b=_e;var Z=(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)},Re=new Set(["1","0","true","false"]),$e=(o,e)=>{let t=(n,r)=>{let{argName:i,argValue:s,option:a}=x(r,e),{lastOption:p}=n;return a&&b(a)&&s&&i?n.partial[i]=Z(s,a):n.lastName&&p&&b(p)&&Re.has(r)&&(n.partial[n.lastName]=Z(r,p)),{lastName:i,lastOption:a,partial:n.partial}};return o.reduce(t,{partial:{}}).partial},ee=$e;c();var Se=o=>{let e=o.type?o.type.name.toLowerCase():"string",t=o.multiple??o.lazyMultiple?"[]":"";return e&&(e=e==="boolean"?"":`{underline ${e}${t}}`),e},De=o=>(b(o)||(o.typeLabel=o.typeLabel??Se(o),o.defaultOption&&(o.typeLabel=`${o.typeLabel} (D)`),o.required&&(o.typeLabel=`${o.typeLabel} (R)`)),o),te=De;c();var Ve=new Set(["1","0","true","false"]),Be=(o,e)=>{let t=(n,r)=>{let{argValue:i,option:s}=x(r,e),{lastOption:a}=n;if(a&&b(a)&&Ve.has(r)){let p=[...n.args];return p.pop(),{args:p}}return s&&b(s)&&i?{args:n.args}:{args:[...n.args,r],lastOption:s}};return o.reduce(t,{args:[]}).args},oe=Be;c();var Ue=new RegExp(/^-([^\d-])$/),ke=new RegExp(/^--(\S+)/),Me=new RegExp(/^-([^\d-]{2,})$/),je=o=>Ue.test(o)||ke.test(o)||Me.test(o),Ye=(o,e)=>{let t=e[0]&&je(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}},ne=Ye;c();var Ge=(o,e)=>distance(o,e)<=o.length/3||e.includes(o),qe=(o,e)=>{let t=o.toLowerCase();return e.filter(n=>Ge(n.toLowerCase(),t))},V=qe;c();var Je=(o,e)=>o.filter(t=>t.required&&e[t.name]==null).filter(t=>t.type?.name==="Boolean"?(e[t.name]=!1,!1):!0),ie=Je;c();var We=o=>{let e=new Map;return o.forEach(t=>{e.set(t.name,{...e.get(t.name),...t});}),[...e.values()]},re=We;c();c();var He=()=>!!process.versions.electron,Ke=()=>He()&&!process.defaultApp,ze=()=>Ke()?0:1,Qe=o=>o.slice(ze()+1),se=Qe;var Xe=" ",Ze=(o,e)=>o.length===e.length&&o.every((t,n)=>t===e[n]),et=o=>typeof o=="string"?o.split(Xe):Ze(o,process.argv)?se(o):o,ae=et;c();var tt=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);});},le=tt;var ut="CI"in env&&("GITHUB_ACTIONS"in env||"GITLAB_CI"in env||"CIRCLECI"in env),ft=o=>o.charAt(0).toLowerCase()+o.slice(1),U=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:argv,cwd:cwd(),...t};this.argv=ae(n),this.argv.includes("--quiet")||this.argv.includes("-q")?env.CEREBRO_OUTPUT_LEVEL=String(16):this.argv.includes("--verbose")||this.argv.includes("-v")?env.CEREBRO_OUTPUT_LEVEL=String(64):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in env?env.CEREBRO_OUTPUT_LEVEL=String(128):env.CEREBRO_OUTPUT_LEVEL=String(32);let a={32:"informational",64:"trace",128:"debug"};this.logger=createPail({logLevel:env.CEREBRO_OUTPUT_LEVEL?a[env.CEREBRO_OUTPUT_LEVEL]??"informational":"informational",...t.logger}),env.CEREBRO_OUTPUT_LEVEL===String(16)&&this.logger.disable(),X(),le(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(z),this.addCommand(new K(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=>te(t)),this.validateDoubleOptions(e),this.addNegatableOption(e),e.options?.forEach(t=>{t.__camelCaseName__=N(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: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: ${execPath}`),this.logger.debug(`process.execArgv: ${execArgv.join(" ")}`),this.logger.debug(`process.argv: ${argv.join(" ")}`);try{i=ne([null,...r],this.argv);}catch(y){if(y.name==="INVALID_COMMAND"&&y.command){let k="",M=V(y.command,[...this.commands.keys()]);M.length>0&&(k=` Did you mean: \r
- ${M.join(` \r
- `)}`),this.logger.error(`"${y.command}" is not an available command.${k}`);}else this.logger.error(y);return t?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?exit(1):void 0;let p=i.argv;this.logger.debug(`command '${s}' found, parsing command args: ${p.join(", ")}`);let d=re([...a.options??[],...O]);d.forEach(y=>{if(y.multiple&&y.lazyMultiple)throw new Error(`Argument "${y.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}),a.argument&&(this.logger.debug("command has positional argument, parsing them..."),d=[{defaultOption:!0,description:a.argument?.description,group:"positionals",multiple:!0,name:T,type:a.argument?.type,typeLabel:a.argument?.typeLabel},...d]);let h=gt(d,{argv:oe(p,a.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),E=ee(p,a.options??[]),C={...h,_all:{...h._all,...E}};this.validateCommandOptions(d,C,a);let f=new Q(a.name,a);f.runtime=this,await this.registerExtensions(f),await this.updateNotifier(f);let{_all:w,positionals:de}=C;return w[T]&&delete w[T],f.argument=de?.[T]??[],f.argv=this.argv,f.options={...w,...n},this.mapNegatableOptions(f,a),this.mapImpliesOptions(f,a),this.validateCommandArgsForConflicts(d,f.options,a),this.logger.debug("command options parsed from options:"),this.logger.debug(JSON.stringify(f.options,null,2)),this.logger.debug("command argument parsed from argument:"),this.logger.debug(JSON.stringify(f.argument,null,2)),await this.prepareToolboxResult(C,f,a),t?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)}
`;}),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||!(env.NO_UPDATE_NOTIFIER||env.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||ut)&&this.updateNotifierOptions){e.raw("Checking for updates...");let n=await(await import('./has-new-version-DAOL7F5M.js').then(r=>r.default))(this.updateNotifierOptions);if(n){let r="Update available "+dim(this.packageVersion+"")+reset(" \u2192 ")+green(n);this.logger.error(boxen(r,{borderColor:i=>yellow(i),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}));}}}validateCommandOptions(e,t,n){let r=ie(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 d=V(s.replace("--",""),[...(n.options??[]).map(h=>h.name),...O.map(h=>h.name)]);if(d.length>0){let[h,...E]=d.map(C=>`--${C}`);p+=E.length>0?`, did you mean ${h} or ${E.join(", ")}?`:`, did you mean ${h}?`;}}i.push(p);}),i.length>0)throw new Error(i.join(`
- `)}`),this.logger.error(`"${y.command}" is not an available command.${k}`);}else this.logger.error(y);return t?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?exit(1):void 0;let p=i.argv;this.logger.debug(`command '${s}' found, parsing command args: ${p.join(", ")}`);let d=re([...a.options??[],...O]);d.forEach(y=>{if(y.multiple&&y.lazyMultiple)throw new Error(`Argument "${y.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}),a.argument&&(this.logger.debug("command has positional argument, parsing them..."),d=[{defaultOption:!0,description:a.argument?.description,group:"positionals",multiple:!0,name:E,type:a.argument?.type,typeLabel:a.argument?.typeLabel},...d]);let h=gt(d,{argv:oe(p,a.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),T=ee(p,a.options??[]),C={...h,_all:{...h._all,...T}};this.validateCommandOptions(d,C,a);let f=new Q(a.name,a);f.runtime=this,await this.registerExtensions(f),await this.updateNotifier(f);let{_all:w,positionals:de}=C;return w[E]&&delete w[E],f.argument=de?.[E]??[],f.argv=this.argv,f.options={...w,...n},this.mapNegatableOptions(f,a),this.mapImpliesOptions(f,a),this.validateCommandArgsForConflicts(d,f.options,a),this.logger.debug("command options parsed from options:"),this.logger.debug(JSON.stringify(f.options,null,2)),this.logger.debug("command argument parsed from argument:"),this.logger.debug(JSON.stringify(f.argument,null,2)),await this.prepareToolboxResult(C,f,a),t?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)}
`;}),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||!(env.NO_UPDATE_NOTIFIER||env.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||ut)&&this.updateNotifierOptions){e.raw("Checking for updates...");let n=await(await import('./has-new-version-DAOL7F5M.js').then(r=>r.default))(this.updateNotifierOptions);if(n){let r="Update available "+dim(this.packageVersion+"")+reset(" \u2192 ")+green(n);this.logger.error(boxen(r,{borderColor:i=>yellow(i),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}));}}}validateCommandOptions(e,t,n){let r=ie(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 d=V(s.replace("--",""),[...(n.options??[]).map(h=>h.name),...O.map(h=>h.name)]);if(d.length>0){let[h,...T]=d.map(C=>`--${C}`);p+=T.length>0?`, did you mean ${h} or ${T.join(", ")}?`:`, did you mean ${h}?`;}}i.push(p);}),i.length>0)throw new Error(i.join(`
`))}}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=ft(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(d=>d.name===s);(p?.defaultValue===void 0||e.options[s]===p.defaultValue)&&(e.options[s]=a);}});}});}};

@@ -24,0 +24,0 @@

{
"name": "@visulima/cerebro",
"version": "1.0.38",
"version": "1.0.39",
"description": "A delightful toolkit for building Node-powered CLIs.",

@@ -82,3 +82,3 @@ "keywords": [

"@visulima/colorize": "1.4.3",
"@visulima/pail": "1.2.1",
"@visulima/pail": "1.2.2",
"cli-table3": "^0.6.5",

@@ -85,0 +85,0 @@ "command-line-args": "^5.2.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc