@visulima/cerebro 1.0.49 → 1.0.50

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/dist/index.cjs CHANGED
@@ -26,7 +26,7 @@ ${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
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-RNHOSICQ.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(`
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-7NAF5SXW.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;
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ ${o.map(t=>t.optionList?new J(t).toString():new q(t).toString()).join(`
17
17
  `)}`,$=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
18
18
  - ${M.join(` \r
19
19
  - `)}`),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)}
20
- `;}),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-VQD7TTS7.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(`
20
+ `;}),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-QP2BT3PX.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(`
21
21
  `))}}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);}});}});}};
22
22
 
23
23
  export { U as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/cerebro",
3
- "version": "1.0.49",
3
+ "version": "1.0.50",
4
4
  "description": "A delightful toolkit for building Node-powered CLIs.",
5
5
  "keywords": [
6
6
  "command",
@@ -100,7 +100,7 @@
100
100
  "@types/command-line-args": "^5.2.3",
101
101
  "@types/node": "18.19.15",
102
102
  "@visulima/nextra-theme-docs": "4.0.26",
103
- "@visulima/package": "2.0.1",
103
+ "@visulima/package": "3.0.0",
104
104
  "@visulima/path": "1.0.2",
105
105
  "@vitest/coverage-v8": "^1.6.0",
106
106
  "camelcase": "8.0.0",