@visulima/cerebro 1.1.49 → 1.1.51

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.
@@ -0,0 +1,10 @@
1
+ var ee=Object.defineProperty;var c=(t,e)=>ee(t,"name",{value:e,configurable:!0});import{cwd as te,argv as V,env as u,execPath as oe,execArgv as ne,exit as L}from"node:process";import{boxen as re}from"@visulima/boxen";import{bold as ae,dim as ie,reset as se,green as le,yellow as ce}from"@visulima/colorize";import{MessageFormatterProcessor as pe,CallerProcessor as me}from"@visulima/pail/processor";import{createPail as ue}from"@visulima/pail/server";import de from"command-line-args";import E from"cli-table3";import ge from"@visulima/colorize/template";import he from"node:os";import{distance as fe}from"fastest-levenshtein";var ve=Object.defineProperty,C=c((t,e)=>ve(t,"name",{value:e,configurable:!0}),"f$3");const ye=/[\p{Lu}]/u,be=/[\p{Ll}]/u,T=/^[\p{Lu}](?![\p{Lu}])/gu,Y=/([\p{Alpha}\p{N}_]|$)/u,S=/[_.\- ]+/,$e=new RegExp("^"+S.source),B=new RegExp(S.source+Y.source,"gu"),k=new RegExp("\\d+"+Y.source,"gu"),we=C((t,e,o,n)=>{let r=!1,i=!1,a=!1,s=!1;for(let l=0;l<t.length;l++){const p=t[l];s=l>2?t[l-3]==="-":!0,r&&ye.test(p)?(t=t.slice(0,l)+"-"+t.slice(l),r=!1,a=i,i=!0,l++):i&&a&&be.test(p)&&(!s||n)?(t=t.slice(0,l-1)+"-"+t.slice(l-1),a=i,i=!1,r=!0):(r=e(p)===p&&o(p)!==p,a=i,i=o(p)===p&&e(p)!==p)}return t},"preserveCamelCase"),Ee=C((t,e)=>(T.lastIndex=0,t.replaceAll(T,o=>e(o))),"preserveConsecutiveUppercase"),Oe=C((t,e)=>(B.lastIndex=0,k.lastIndex=0,t.replaceAll(k,(o,n,r)=>["_","-"].includes(t.charAt(r+o.length))?o:e(o)).replaceAll(B,(o,n)=>e(n))),"postProcess");function G(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(r=>r.trim()).filter(r=>r.length).join("-"):t=t.trim(),t.length===0)return"";const o=e.locale===!1?r=>r.toLowerCase():r=>r.toLocaleLowerCase(e.locale),n=e.locale===!1?r=>r.toUpperCase():r=>r.toLocaleUpperCase(e.locale);return t.length===1?S.test(t)?"":e.pascalCase?n(t):o(t):(t!==o(t)&&(t=we(t,o,n,e.preserveConsecutiveUppercase)),t=t.replace($e,""),t=e.preserveConsecutiveUppercase?Ee(t,o):o(t),e.pascalCase&&(t=n(t.charAt(0))+t.slice(1)),Oe(t,n))}c(G,"S");C(G,"camelCase");const O=[{description:"Turn on verbose output",group:"global",name:"verbose",type:Boolean},{description:"Turn on debugging output",group:"global",name:"debug",type:Boolean},{alias:"h",description:"Print out helpful usage information",group:"global",name:"help",type:Boolean},{alias:"q",description:"Silence output",group:"global",name:"quiet",type:Boolean},{alias:"V",description:"Print version info",group:"global",name:"version",type:Boolean},{description:"Turn off colored output",group:"global",name:"no-color",type:Boolean},{description:"Force colored output",group:"global",name:"color",type:Boolean}];var Ce=Object.defineProperty,Ae=c((t,e)=>Ce(t,"name",{value:e,configurable:!0}),"e$4");const m=Ae(t=>t?ge(Object.assign([],{raw:[t.replaceAll("`","\\`")]})):"","templateFormat");var Ne=Object.defineProperty,_e=c((t,e)=>Ne(t,"name",{value:e,configurable:!0}),"t$6");let W=class{static{c(this,"n")}static{_e(this,"BaseSection")}lines;constructor(){this.lines=[]}add(e){this.lines.push(e)}toString(){return this.lines.join(he.EOL)}header(e){this.add(ae(e)),this.lines.push("")}};var Le=Object.defineProperty,xe=c((t,e)=>Le(t,"name",{value:e,configurable:!0}),"p$4");const $={chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,60],style:{border:[],compact:!0,head:[],"padding-left":2,"padding-right":1},wordWrap:!0};let Pe=class extends W{static{c(this,"y")}static{xe(this,"ContentSection")}constructor(e){if(super(),e.header&&this.header(m(e.header)),e.content){if(e.raw)if(Array.isArray(e.content)&&e.content.every(o=>typeof o=="string"))e.content.forEach(o=>{Array.isArray(o)?o.forEach(n=>this.add(m(n))):this.add(m(o))});else if(typeof e.content=="string")this.add(m(e.content));else throw new TypeError("Invalid raw content, must be a string or array of strings.");else this.add(this.getContentLines(e.content));this.add("")}}getContentLines(e){if(typeof e=="string"){const o=new E({...$,colWidths:[80]});return o.push([m(e)]),o.toString()}if(Array.isArray(e)&&e.every(o=>typeof o=="string"||Array.isArray(o)&&o.every(n=>typeof n=="string"))){const o=new E({...$});return e.forEach(n=>{Array.isArray(n)?o.push(n.map(r=>m(r))):o.push([m(n)])}),o.toString()}if(typeof e=="object"){const o=e;if(!o.options||!o.data)throw new Error(`Must have an "options" or "data" property
2
+ ${JSON.stringify(e)}`);const n=new E({...$,...o.options,style:{...$.style,...o.options.style}});return o.data.forEach(r=>{Array.isArray(r)?n.push(r.map(i=>m(i))):n.push([m(r)])}),n.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
3
+
4
+ ${JSON.stringify(e)}`)}};var Se=Object.defineProperty,Re=c((t,e)=>Se(t,"name",{value:e,configurable:!0}),"a$1");let je=class extends W{static{c(this,"c")}static{Re(this,"OptionListSection")}constructor(e){super();let o=e.optionList??[];const n=Array.isArray(e.hide)?e.hide:[e.hide].filter(Boolean),r=Array.isArray(e.group)?e.group:[e.group].filter(Boolean);n.length>0&&(o=o.filter(a=>!n.includes(a.name))),e.header&&this.header(m(e.header)),r.length>0&&(o=o.filter(a=>{const s=r.includes("_none")&&!a.group,l=this.intersect(Array.isArray(a.group)?a.group:[a.group],r);return s||l?a:void 0}));const i=new E({chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,40],style:{"padding-left":2,"padding-right":1},wordWrap:!0});o.forEach(a=>i.push([this.getOptionNames(a,e.reverseNameOrder??!1,e.isArgument??!1),m(a.description)])),this.add(i.toString()),this.lines.push("")}getOptionNames(e,o,n){if(!e.name)throw new TypeError("Invalid option definition, name is required.");let r=e.type?e.type.name.toLowerCase():"string";const i=e.multiple||e.lazyMultiple?"[]":"";r=m(e.typeLabel??`{underline ${r}${i}}`);let a;if(e.alias)if(e.name){const s=n?e.name:`{yellow --${e.name}}`;a=m(o?`{bold ${s}}, {bold -${e.alias}} ${r}`:`{bold -${e.alias}}, {bold ${s}} ${r}`)}else o?a=m(`{bold -${e.alias}} ${r}`):a=m(`{bold -${e.alias}} ${r}`);else a=m(`{bold ${n?e.name:`{yellow --${e.name}}`}} ${r}`);return a}intersect(e,o){return e.some(n=>o.includes(n))}};var Ve=Object.defineProperty,Te=c((t,e)=>Ve(t,"name",{value:e,configurable:!0}),"o$3");const H=Te(t=>(Array.isArray(t)?t:[t]).length===0?"":`
5
+ ${t.map(e=>e.optionList?new je(e).toString():new Pe(e).toString()).join(`
6
+ `)}`,"commandLineUsage");var Be=Object.defineProperty,A=c((t,e)=>Be(t,"name",{value:e,configurable:!0}),"l$5");const U="__Other",I=A(t=>t.charAt(0).toUpperCase()+t.slice(1),"upperFirstChar"),ke=A((t,e,o,n)=>{t.debug("no command given, printing general help...");let r=[...new Set(o.values())].filter(a=>!a.hidden);n&&(r=r.filter(a=>a.group===n));const i=r.reduce((a,s)=>{const l=s.group??U;return a[l]||(a[l]=[]),a[l].push(s),a},{});t.raw(H([{content:`{cyan ${e.getCliName()}} {green <command>} [positional arguments] {yellow [options]}`,header:"{inverse.cyan Usage }"},...Object.keys(i).map(a=>({content:i[a].map(s=>{let l="";return typeof s.alias=="string"?l=s.alias:Array.isArray(s.alias)&&(l=s.alias.join(", ")),l!==""&&(l=` [${l}]`),[`{green ${s.name}} ${l}`,s.description??""]}),header:a===U||n?`{inverse.green Available${n?` ${I(n)}`:""} Commands }`:` {inverse.green ${I(a)} }`})),o.has("help")?{header:"{inverse.yellow Command Options }",optionList:o.get("help").options?.filter(a=>!a.hidden)}:void 0,{header:"{inverse.yellow Global Options }",optionList:O},{content:`Run "{cyan ${e.getCliName()}} {green help <command>}" or "{cyan ${e.getCliName()}} {green <command>} {yellow --help}" for help with a specific command.`,raw:!0}].filter(Boolean)))},"printGeneralHelp"),Ue=A((t,e,o,n)=>{const r=o.get(n),i=[];if(i.push({content:`{cyan ${e.getCliName()}} {green ${r.name}}${r.argument?" [positional arguments]":""}${r.options?" [options]":""}`,header:"{inverse.cyan Usage }"}),r.description&&i.push({content:r.description,header:"{inverse.green Description }"}),r.argument&&i.push({header:"Command Positional Arguments",isArgument:!0,optionList:[r.argument]}),Array.isArray(r.options)&&r.options.length>0&&i.push({header:"{inverse.yellow Command Options }",optionList:r.options.filter(a=>!a.hidden)}),i.push({header:"{inverse.yellow Global Options }",optionList:O}),r.alias!==void 0&&r.alias.length>0){let a=r.alias;typeof r.alias=="string"&&(a=[r.alias]),i.splice(1,0,{content:a,header:"Alias(es)"})}Array.isArray(r.examples)&&r.examples.length>0&&i.push({content:r.examples,header:"Examples"}),t.raw(H(i))},"printCommandHelp");class Ie{static{c(this,"C")}static{A(this,"HelpCommand")}name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(e){this.commands=e}execute(e){const{commandName:o,logger:n,options:r,runtime:i}=e,{footer:a,header:s}=i.getCommandSection();s&&n.raw(m(s)),o==="help"?ke(n,i,this.commands,r?.group):Ue(n,i,this.commands,o),a&&n.raw(m(a))}}var De=Object.defineProperty,Me=c((t,e)=>De(t,"name",{value:e,configurable:!0}),"s$7");const Fe={alias:["v","V"],description:"Output the version number",execute:Me(({logger:t,runtime:e})=>{const o=e.getPackageVersion();o===void 0?(t.warn("Unknown version"),t.debug("The version number was not provided by the cli constructor.")):t.info(o)},"execute"),name:"version",options:[],usage:[]},D=16,qe=32,Ye=64,x=128,w="positionals";var Ge=Object.defineProperty,We=c((t,e)=>Ge(t,"name",{value:e,configurable:!0}),"m$2");let He=class{static{c(this,"c")}static{We(this,"EmptyToolbox")}result;argv;options;argument;command;commandName;runtime;logger;constructor(e,o){this.commandName=e,this.command=o}};var Je=Object.defineProperty,ze=c((t,e)=>Je(t,"name",{value:e,configurable:!0}),"s$6");const Ke=ze(()=>{const t=process.env.CEREBRO_MIN_NODE_VERSION?Number(process.env.CEREBRO_MIN_NODE_VERSION):18,e=process.version.replace("v","");Number(/v([^.]+)/.exec(process.version)[1])<t&&(console.log(`cerebro supports a minimum Node version of ${t}. You have ${e}. Read our version support policy: https://github.com/visulima/visulima#supported-nodejs-versions`),process.exit(1))},"checkNodeVersion");var Qe=Object.defineProperty,Xe=c((t,e)=>Qe(t,"name",{value:e,configurable:!0}),"r$4");const Ze=/^-{1,2}(\w+)(=(\w+))?$/,J=Xe((t,e)=>{const o=Ze.exec(t);if(o==null)return{};const n=o[1],r=e.find(i=>i.name===n||i.alias===n);return r!==void 0?{argName:r.name,argValue:o[3],option:r}:{}},"getParameterOption");var et=Object.defineProperty,tt=c((t,e)=>et(t,"name",{value:e,configurable:!0}),"i$3");const y=tt(t=>t.type?.name==="Boolean","isBoolean");var ot=Object.defineProperty,P=c((t,e)=>ot(t,"name",{value:e,configurable:!0}),"n$2");const M=P((t,e)=>{if(e.type===void 0)return t;if(e.type.name==="Boolean"){if(t==="true"||t==="1")return e.type(!0);if(t==="false"||t==="0")return e.type(!1)}return e.type(t)},"convertType"),nt=new Set(["1","0","true","false"]),rt=P((t,e)=>{const o=P((n,r)=>{const{argName:i,argValue:a,option:s}=J(r,e),{lastOption:l}=n;return s&&y(s)&&a&&i?n.partial[i]=M(a,s):n.lastName&&l&&y(l)&&nt.has(r)&&(n.partial[n.lastName]=M(r,l)),{lastName:i,lastOption:s,partial:n.partial}},"getBooleanValue");return t.reduce(o,{partial:{}}).partial},"getBooleanValues");var at=Object.defineProperty,z=c((t,e)=>at(t,"name",{value:e,configurable:!0}),"p$1");const it=z(t=>{let e=t.type?t.type.name.toLowerCase():"string";const o=t.multiple??t.lazyMultiple?"[]":"";return e&&(e=e==="boolean"?"":`{underline ${e}${o}}`),e},"getTypeLabel"),st=z(t=>(y(t)||(t.typeLabel=t.typeLabel??it(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var lt=Object.defineProperty,F=c((t,e)=>lt(t,"name",{value:e,configurable:!0}),"s$3");const ct=new Set(["1","0","true","false"]),pt=F((t,e)=>{const o=F((n,r)=>{const{argValue:i,option:a}=J(r,e),{lastOption:s}=n;if(s&&y(s)&&ct.has(r)){const l=[...n.args];return l.pop(),{args:l}}return a&&y(a)&&i?{args:n.args}:{args:[...n.args,r],lastOption:a}},"removeBooleanArguments");return t.reduce(o,{args:[]}).args},"removeBooleanValues");var mt=Object.defineProperty,K=c((t,e)=>mt(t,"name",{value:e,configurable:!0}),"e$2");const ut=new RegExp(/^-([^\d-])$/),dt=new RegExp(/^--(\S+)/),gt=new RegExp(/^-([^\d-]{2,})$/),ht=K(t=>ut.test(t)||dt.test(t)||gt.test(t),"isOption"),ft=K((t,e)=>{const o=e[0]&&ht(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(o)){const n=new Error(`Command not recognised: ${o}`);throw n.command=o,n.name="INVALID_COMMAND",n}return{argv:e,command:o}},"commandLineCommands");var vt=Object.defineProperty,Q=c((t,e)=>vt(t,"name",{value:e,configurable:!0}),"i$1");const yt=Q((t,e)=>fe(t,e)<=t.length/3||e.includes(t),"isSimilar"),q=Q((t,e)=>{const o=t.toLowerCase();return e.filter(n=>yt(n.toLowerCase(),o))},"findAlternatives");var bt=Object.defineProperty,$t=c((t,e)=>bt(t,"name",{value:e,configurable:!0}),"t$3");const wt=$t((t,e)=>t.filter(o=>o.required&&e[o.name]==null).filter(o=>o.type?.name==="Boolean"?(e[o.name]=!1,!1):!0),"listMissingArguments");var Et=Object.defineProperty,Ot=c((t,e)=>Et(t,"name",{value:e,configurable:!0}),"t$2");const Ct=Ot(t=>{const e=new Map;return t.forEach(o=>{e.set(o.name,{...e.get(o.name),...o})}),[...e.values()]},"mergeArguments");var At=Object.defineProperty,N=c((t,e)=>At(t,"name",{value:e,configurable:!0}),"e$1");const Nt=N(()=>!!process.versions.electron,"isElectronApp"),_t=N(()=>Nt()&&!process.defaultApp,"isBundledElectronApp"),Lt=N(()=>_t()?0:1,"getProcessArgvBinIndex"),xt=N(t=>t.slice(Lt()+1),"hideBin");var Pt=Object.defineProperty,X=c((t,e)=>Pt(t,"name",{value:e,configurable:!0}),"i");const St=" ",Rt=X((t,e)=>t.length===e.length&&t.every((o,n)=>o===e[n]),"equals"),jt=X(t=>typeof t=="string"?t.split(St):Rt(t,process.argv)?xt(t):t,"parseRawCommand");var Vt=Object.defineProperty,Tt=c((t,e)=>Vt(t,"name",{value:e,configurable:!0}),"t");const Bt=Tt(t=>{process.on("uncaughtException",e=>{t.error(`Uncaught exception: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)}),process.on("unhandledRejection",e=>{t.error(`Promise rejection: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)})},"registerExceptionHandler");var kt=Object.defineProperty,v=c((t,e)=>kt(t,"name",{value:e,configurable:!0}),"g");const Ut="CI"in u&&("GITHUB_ACTIONS"in u||"GITLAB_CI"in u||"CIRCLECI"in u),It=v(t=>t.charAt(0).toLowerCase()+t.slice(1),"lowerFirstChar");class to{static{c(this,"Cli")}static{v(this,"Cli")}logger;argv;cwd;cliName;packageVersion;packageName;extensions=[];commands;defaultCommand;updateNotifierOptions;commandSection;constructor(e,o={}){const{argv:n,cwd:r,packageName:i,packageVersion:a}={argv:V,cwd:te(),...o};this.argv=jt(n),this.argv.includes("--quiet")||this.argv.includes("-q")?u.CEREBRO_OUTPUT_LEVEL=String(D):this.argv.includes("--verbose")||this.argv.includes("-v")?u.CEREBRO_OUTPUT_LEVEL=String(Ye):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in u?u.CEREBRO_OUTPUT_LEVEL=String(x):u.CEREBRO_OUTPUT_LEVEL=String(qe);const s={32:"informational",64:"trace",128:"debug"},l=[new pe];u.CEREBRO_OUTPUT_LEVEL===String(x)&&l.push(new me),this.logger=ue({logLevel:u.CEREBRO_OUTPUT_LEVEL?s[u.CEREBRO_OUTPUT_LEVEL]??"informational":"informational",processors:l,...o.logger}),u.CEREBRO_OUTPUT_LEVEL===String(D)&&this.logger.disable(),Ke(),Bt(this.logger),this.cliName=e,this.packageVersion=a,this.packageName=i,this.cwd=r,this.defaultCommand="help",this.commandSection={header:`${this.cliName}${this.packageVersion?` v${this.packageVersion}`:""}`},this.commands=new Map,this.addCoreExtensions(),this.addCommand(Fe),this.addCommand(new Ie(this.commands))}setCommandSection(e){return this.commandSection=e,this}getCommandSection(){return this.commandSection}setDefaultCommand(e){return this.defaultCommand=e,this}addCommand(e){if(this.commands.has(e.name))throw new Error(`Ignored command with name "${e.name}", it was found in the command list.`);if(e.options?.map(o=>st(o)),this.validateDoubleOptions(e),this.addNegatableOption(e),e.options?.forEach(o=>{o.__camelCaseName__=G(o.name)}),this.commands.set(e.name,e),e.alias!==void 0){let o=e.alias;typeof e.alias=="string"&&(o=[e.alias]),o.forEach(n=>{if(this.logger.debug("adding alias",n),this.commands.has(n))throw new Error(`Ignoring command alias "${n}, command with the same name was found."`);this.commands.set(n,e)})}return this}addExtension(e){return this.extensions.push(e),this}enableUpdateNotifier(e={}){if(!this.packageName||!this.packageVersion)throw new Error("Cannot enable update notifier without package name and version.");const o=Object.keys(e);if(o.length>0&&!o.includes("alwaysRun")&&!o.includes("distTag")&&!o.includes("updateCheckInterval"))throw new Error("Invalid update notifier options, please check the documentation.");return this.updateNotifierOptions={alwaysRun:!1,debug:u.CEREBRO_OUTPUT_LEVEL===String(x),distTag:"latest",pkg:{name:this.packageName,version:this.packageVersion},updateCheckInterval:1e3*60*60*24,...e},this}getCliName(){return this.cliName}getPackageVersion(){return this.packageVersion}getPackageName(){return this.packageName}getCommands(){return this.commands}getCwd(){return this.cwd}async run(e={}){const{shouldExitProcess:o=!0,...n}=e,r=[...this.commands.keys()];let i;this.logger.debug(`process.execPath: ${oe}`),this.logger.debug(`process.execArgv: ${ne.join(" ")}`),this.logger.debug(`process.argv: ${V.join(" ")}`);try{i=ft([null,...r],this.argv)}catch(h){if(h.name==="INVALID_COMMAND"&&h.command){let R="";const j=q(h.command,[...this.commands.keys()]);j.length>0&&(R=` Did you mean: \r
7
+ - ${j.join(` \r
8
+ - `)}`),this.logger.error(`"${h.command}" is not an available command.${R}`)}else this.logger.error(h);return o?L(1):void 0}const a=i.command??this.defaultCommand,s=this.commands.get(a);if(typeof s.execute!="function")return this.logger.error(`Command "${s.name}" has no function to execute.`),o?L(1):void 0;const l=i.argv;this.logger.debug(`command '${a}' found, parsing command args: ${l.join(", ")}`);let p=Ct([...s.options??[],...O]);p.forEach(h=>{if(h.multiple&&h.lazyMultiple)throw new Error(`Argument "${h.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}),s.argument&&(this.logger.debug("command has positional argument, parsing them..."),p=[{defaultOption:!0,description:s.argument?.description,group:"positionals",multiple:!0,name:w,type:s.argument?.type,typeLabel:s.argument?.typeLabel},...p]);const g=de(p,{argv:pt(l,s.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),b=rt(l,s.options??[]),f={...g,_all:{...g._all,...b}};this.validateCommandOptions(p,f,s);const d=new He(s.name,s);d.runtime=this,await this.registerExtensions(d),await this.updateNotifier(d);const{_all:_,positionals:Z}=f;return _[w]&&delete _[w],d.argument=Z?.[w]??[],d.argv=this.argv,d.options={..._,...n},this.mapNegatableOptions(d,s),this.mapImpliesOptions(d,s),this.validateCommandArgsForConflicts(p,d.options,s),this.logger.debug("command options parsed from options:"),this.logger.debug(JSON.stringify(d.options,null,2)),this.logger.debug("command argument parsed from argument:"),this.logger.debug(JSON.stringify(d.argument,null,2)),await this.prepareToolboxResult(f,d,s),o?L(0):void 0}validateDoubleOptions(e){if(Array.isArray(e.options)){const o=e.options.reduce((i,a)=>{const s=`${a.name}-${a.alias}`;return i[s]||(i[s]=[]),i[s].push(a),i},{}),n=Object.values(o).filter(i=>i.length>1);let r="";if(n.forEach(i=>{const a=i[0],s=i[1];let l="alias";a.name===s.name&&(l="name",a.alias===s.alias&&(l+=" and alias")),r+=`Cannot add option ${l} "${JSON.stringify(s)}" to command "${e.name}" due to conflicting option ${JSON.stringify(a)}
9
+ `}),r.length>0)throw new Error(r)}}addCoreExtensions(){this.addExtension({execute:v(e=>{e.logger=this.logger},"execute"),name:"logger"})}async prepareToolboxResult(e,o,n){if(e.global?.help){this.logger.debug("'--help' option found, running 'help' for given command...");const r=this.commands.get("help");if(!r)throw new Error("Help command not found.");await r.execute(o);return}if(e.global?.version||e.global?.V){this.logger.debug("'--version' option found, running 'version' for given command...");const r=this.commands.get("version");if(!r)throw new Error("Version command not found.");await r.execute(o);return}await n.execute(o)}async updateNotifier({logger:e}){if(this.updateNotifierOptions?.alwaysRun||!(u.NO_UPDATE_NOTIFIER||u.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||Ut)&&this.updateNotifierOptions){e.raw("Checking for updates...");const o=await(await import("../packem_chunks/has-new-version.mjs").then(n=>n.default))(this.updateNotifierOptions);if(o){const n="Update available "+ie(this.packageVersion+"")+se(" → ")+le(o);this.logger.error(re(n,{borderColor:v(r=>ce(r),"borderColor"),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}))}}}validateCommandOptions(e,o,n){const r=wt(e,o);if(r.length>0)throw new Error(`You called the command "${n.name}" without the required options: ${r.map(i=>i.name).join(", ")}`);if(o._unknown&&o._unknown.length>0){const i=[];if(o._unknown.forEach(a=>{const s=a.startsWith("--");let l=`Found unknown ${s?"option":"argument"} "${a}"`;if(s){const p=q(a.replace("--",""),[...(n.options??[]).map(g=>g.name),...O.map(g=>g.name)]);if(p.length>0){const[g,...b]=p.map(f=>`--${f}`);l+=b.length>0?`, did you mean ${g} or ${b.join(", ")}?`:`, did you mean ${g}?`}}i.push(l)}),i.length>0)throw new Error(i.join(`
10
+ `))}}validateCommandArgsForConflicts(e,o,n){const r=e.filter(i=>i.conflicts!==void 0);if(r.length>0){const i=r.find(a=>Array.isArray(a.conflicts)?a.conflicts.some(s=>o[s]!==void 0)&&o[a.name]!==void 0:o[a.conflicts]!==void 0&&o[a.name]!==void 0);if(i)throw new Error(`You called the command "${n.name}" with conflicting options: ${i.name} and ${typeof i.conflicts=="string"?i.conflicts:i.conflicts?.join(", ")}`)}}addNegatableOption(e){Array.isArray(e.options)&&e.options.forEach(o=>{if(o.name.startsWith("no-")&&!e.options.some(n=>n.name===o.name.replace("no-",""))){if(o.type!==Boolean){this.logger.debug(`Cannot add negated option "${o.name}" to command "${e.name}" because it is not a boolean.`);return}const n={...o,defaultValue:o.defaultValue===void 0?!0:!o.defaultValue,name:`${o.name.replace("no-","")}`};e.options.push(n)}})}async registerExtensions(e){const o=v(async n=>typeof n.execute!="function"?(this.logger.warn(`Skipped ${n.name} because execute is not a function.`),null):(await n.execute(e),null),"callback");for(const n of this.extensions)await o(n)}mapNegatableOptions(e,o){Object.entries(e.options).forEach(([n,r])=>{if(/^no\w+/.test(n)){const i=It(n.replace("no",""));this.logger.debug(`mapping negated option "${n}" to "${i}"`),e.options[i]=!r,o.options?.forEach(a=>{a.name===i&&(a.__negated__=!0)})}})}mapImpliesOptions(e,o){Object.keys(e.options).forEach(n=>{const r=o.options?.find(i=>i.__camelCaseName__===n&&i.__negated__===void 0&&i.implies!==void 0);if(r?.implies){const i=r.implies;Object.entries(i).forEach(([a,s])=>{if(e.options[a]===void 0)e.options[a]=s;else{const l=o.options?.find(p=>p.name===a);(l?.defaultValue===void 0||e.options[a]===l.defaultValue)&&(e.options[a]=s)}})}})}}export{to as Cli};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/cerebro",
3
- "version": "1.1.49",
3
+ "version": "1.1.51",
4
4
  "description": "A delightful toolkit for building Node-powered CLIs.",
5
5
  "keywords": [
6
6
  "command",
@@ -88,11 +88,12 @@
88
88
  "dependencies": {
89
89
  "@visulima/boxen": "2.0.3",
90
90
  "@visulima/colorize": "1.4.23",
91
- "@visulima/find-cache-dir": "1.0.33",
92
- "@visulima/pail": "2.1.27",
91
+ "@visulima/find-cache-dir": "1.0.35",
92
+ "@visulima/pail": "2.1.29",
93
93
  "cli-table3": "^0.6.5",
94
94
  "command-line-args": "^6.0.1",
95
- "fastest-levenshtein": "^1.0.16"
95
+ "fastest-levenshtein": "^1.0.16",
96
+ "publint": "^0.3.12"
96
97
  },
97
98
  "engines": {
98
99
  "node": ">=18.0.0 <=23.x"