@visulima/cerebro 1.1.58 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +72 -1
- package/LICENSE.md +1360 -7
- package/README.md +74 -5
- package/dist/commands/completion-command.d.ts +6 -0
- package/dist/commands/completion-command.js +5 -0
- package/dist/commands/help-command.d.ts +12 -0
- package/dist/commands/help-command.js +1 -0
- package/dist/commands/readme-command.d.ts +6 -0
- package/dist/commands/readme-command.js +45 -0
- package/dist/commands/version-command.d.ts +6 -0
- package/dist/commands/version-command.js +1 -0
- package/dist/index.d.ts +39 -141
- package/dist/index.js +1 -0
- package/dist/logger/create-pail-logger.d.ts +5 -0
- package/dist/logger/create-pail-logger.js +1 -0
- package/dist/packem_chunks/has-new-version.js +1 -0
- package/dist/packem_shared/Cerebro-UuSm4ZWa.js +4 -0
- package/dist/packem_shared/VERBOSITY_QUIET-XPultrIA.js +1 -0
- package/dist/packem_shared/VisulimaError--04oA1Oy.js +76 -0
- package/dist/packem_shared/cerebro-error-BnJTixb2.js +1 -0
- package/dist/packem_shared/help-command-C_CdZQSd.js +1 -0
- package/dist/packem_shared/index-DQ3pvLQH.js +6 -0
- package/dist/packem_shared/index.d-BkzZomTF.d.ts +65 -0
- package/dist/packem_shared/isVisulimaError-jVZgumOU-C4fgdbWg.js +1 -0
- package/dist/packem_shared/plugin-manager-BjEuiNxv.d.ts +147 -0
- package/dist/packem_shared/renderError-ZMlMvw1N-eVUSdl6c.js +24 -0
- package/dist/packem_shared/runtime-process-G-n-wOub.js +1 -0
- package/dist/plugins/error-handler-plugin.d.ts +15 -0
- package/dist/plugins/error-handler-plugin.js +1 -0
- package/dist/plugins/runtime-version-check-plugin.d.ts +18 -0
- package/dist/plugins/runtime-version-check-plugin.js +1 -0
- package/dist/plugins/update-notifier/update-notifier-plugin.d.ts +21 -0
- package/dist/plugins/update-notifier/update-notifier-plugin.js +1 -0
- package/package.json +63 -27
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +0 -158
- package/dist/index.d.mts +0 -158
- package/dist/index.mjs +0 -1
- package/dist/packem_chunks/has-new-version.cjs +0 -1
- package/dist/packem_chunks/has-new-version.mjs +0 -1
- package/dist/packem_shared/default-BkkIk32s.mjs +0 -10
- package/dist/packem_shared/default-DpvcDeMt.cjs +0 -10
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
var oe=Object.defineProperty;var c=(t,e)=>oe(t,"name",{value:e,configurable:!0});import{createRequire as ne}from"node:module";import{boxen as le}from"@visulima/boxen";import{bold as ce,dim as pe,reset as ue,green as me,yellow as de}from"@visulima/colorize";import{MessageFormatterProcessor as ge,CallerProcessor as he}from"@visulima/pail/processor";import{createPail as fe}from"@visulima/pail/server";import ve from"command-line-args";import ye from"@visulima/colorize/template";const R=ne(import.meta.url),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,re=c(t=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[e,o]=f.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return f.getBuiltinModule(t)}return R(t)},"__cjs_getBuiltinModule"),{cwd:ae,argv:B,env:m,execPath:ie,execArgv:se,exit:x}=f,O=R("cli-table3"),be=re("node:os"),{distance:$e}=R("fastest-levenshtein");var we=Object.defineProperty,_=c((t,e)=>we(t,"name",{value:e,configurable:!0}),"f$4");const Ee=/[\p{Lu}]/u,Oe=/[\p{Ll}]/u,k=/^[\p{Lu}](?![\p{Lu}])/gu,W=/([\p{Alpha}\p{N}_]|$)/u,S=/[_.\- ]+/,Ce=new RegExp("^"+S.source),U=new RegExp(S.source+W.source,"gu"),I=new RegExp("\\d+"+W.source,"gu"),_e=_((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&&Ee.test(p)?(t=t.slice(0,l)+"-"+t.slice(l),r=!1,a=i,i=!0,l++):i&&a&&Oe.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"),Ae=_((t,e)=>(k.lastIndex=0,t.replaceAll(k,o=>e(o))),"preserveConsecutiveUppercase"),Ne=_((t,e)=>(U.lastIndex=0,I.lastIndex=0,t.replaceAll(I,(o,n,r)=>["_","-"].includes(t.charAt(r+o.length))?o:e(o)).replaceAll(U,(o,n)=>e(n))),"postProcess");function H(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=_e(t,o,n,e.preserveConsecutiveUppercase)),t=t.replace(Ce,""),t=e.preserveConsecutiveUppercase?Ae(t,o):o(t),e.pascalCase&&(t=n(t.charAt(0))+t.slice(1)),Ne(t,n))}c(H,"S");_(H,"camelCase");const C=[{description:"Turn on verbose output",group:"global",name:"verbose",type:Boolean},{description:"Turn on debugging output",group:"global",name:"debug",type:Boolean},{alias:"h",description:"Print out helpful usage information",group:"global",name:"help",type:Boolean},{alias:"q",description:"Silence output",group:"global",name:"quiet",type:Boolean},{alias:"V",description:"Print version info",group:"global",name:"version",type:Boolean},{description:"Turn off colored output",group:"global",name:"no-color",type:Boolean},{description:"Force colored output",group:"global",name:"color",type:Boolean}];var Le=Object.defineProperty,xe=c((t,e)=>Le(t,"name",{value:e,configurable:!0}),"e$4");const u=xe(t=>t?ye(Object.assign([],{raw:[t.replaceAll("`","\\`")]})):"","templateFormat");var je=Object.defineProperty,Pe=c((t,e)=>je(t,"name",{value:e,configurable:!0}),"t$6");let J=class{static{c(this,"n")}static{Pe(this,"BaseSection")}lines;constructor(){this.lines=[]}add(e){this.lines.push(e)}toString(){return this.lines.join(be.EOL)}header(e){this.add(ce(e)),this.lines.push("")}};var Re=Object.defineProperty,Se=c((t,e)=>Re(t,"name",{value:e,configurable:!0}),"p$4");const w={chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,60],style:{border:[],compact:!0,head:[],"padding-left":2,"padding-right":1},wordWrap:!0};let Te=class extends J{static{c(this,"y")}static{Se(this,"ContentSection")}constructor(e){if(super(),e.header&&this.header(u(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(u(n))):this.add(u(o))});else if(typeof e.content=="string")this.add(u(e.content));else throw new TypeError("Invalid raw content, must be a string or array of strings.");else this.add(this.getContentLines(e.content));this.add("")}}getContentLines(e){if(typeof e=="string"){const o=new O({...w,colWidths:[80]});return o.push([u(e)]),o.toString()}if(Array.isArray(e)&&e.every(o=>typeof o=="string"||Array.isArray(o)&&o.every(n=>typeof n=="string"))){const o=new O({...w});return e.forEach(n=>{Array.isArray(n)?o.push(n.map(r=>u(r))):o.push([u(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 O({...w,...o.options,style:{...w.style,...o.options.style}});return o.data.forEach(r=>{Array.isArray(r)?n.push(r.map(i=>u(i))):n.push([u(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 Ve=Object.defineProperty,Be=c((t,e)=>Ve(t,"name",{value:e,configurable:!0}),"a$1");let ke=class extends J{static{c(this,"c")}static{Be(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(u(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 O({chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,40],style:{"padding-left":2,"padding-right":1},wordWrap:!0});o.forEach(a=>i.push([this.getOptionNames(a,e.reverseNameOrder??!1,e.isArgument??!1),u(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=u(e.typeLabel??`{underline ${r}${i}}`);let a;if(e.alias)if(e.name){const s=n?e.name:`{yellow --${e.name}}`;a=u(o?`{bold ${s}}, {bold -${e.alias}} ${r}`:`{bold -${e.alias}}, {bold ${s}} ${r}`)}else o?a=u(`{bold -${e.alias}} ${r}`):a=u(`{bold -${e.alias}} ${r}`);else a=u(`{bold ${n?e.name:`{yellow --${e.name}}`}} ${r}`);return a}intersect(e,o){return e.some(n=>o.includes(n))}};var Ue=Object.defineProperty,Ie=c((t,e)=>Ue(t,"name",{value:e,configurable:!0}),"o$3");const z=Ie(t=>(Array.isArray(t)?t:[t]).length===0?"":`
|
|
5
|
-
${t.map(e=>e.optionList?new ke(e).toString():new Te(e).toString()).join(`
|
|
6
|
-
`)}`,"commandLineUsage");var De=Object.defineProperty,A=c((t,e)=>De(t,"name",{value:e,configurable:!0}),"l$5");const D="__Other",M=A(t=>t.charAt(0).toUpperCase()+t.slice(1),"upperFirstChar"),Me=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??D;return a[l]||(a[l]=[]),a[l].push(s),a},{});t.raw(z([{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===D||n?`{inverse.green Available${n?` ${M(n)}`:""} Commands }`:` {inverse.green ${M(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:C},{content:`Run "{cyan ${e.getCliName()}} {green help <command>}" or "{cyan ${e.getCliName()}} {green <command>} {yellow --help}" for help with a specific command.`,raw:!0}].filter(Boolean)))},"printGeneralHelp"),qe=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:C}),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(z(i))},"printCommandHelp");class Fe{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(u(s)),o==="help"?Me(n,i,this.commands,r?.group):qe(n,i,this.commands,o),a&&n.raw(u(a))}}var Ye=Object.defineProperty,Ge=c((t,e)=>Ye(t,"name",{value:e,configurable:!0}),"s$7");const We={alias:["v","V"],description:"Output the version number",execute:Ge(({logger:t,runtime:e})=>{const o=e.getPackageVersion();o===void 0?(t.warn("Unknown version"),t.debug("The version number was not provided by the cli constructor.")):t.info(o)},"execute"),name:"version",options:[],usage:[]},q=16,He=32,Je=64,j=128,E="positionals";var ze=Object.defineProperty,Ke=c((t,e)=>ze(t,"name",{value:e,configurable:!0}),"m$2");let Qe=class{static{c(this,"c")}static{Ke(this,"EmptyToolbox")}result;argv;options;argument;command;commandName;runtime;logger;constructor(e,o){this.commandName=e,this.command=o}};var Xe=Object.defineProperty,Ze=c((t,e)=>Xe(t,"name",{value:e,configurable:!0}),"s$6");const et=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 tt=Object.defineProperty,ot=c((t,e)=>tt(t,"name",{value:e,configurable:!0}),"r$4");const nt=/^-{1,2}(\w+)(=(\w+))?$/,K=ot((t,e)=>{const o=nt.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 rt=Object.defineProperty,at=c((t,e)=>rt(t,"name",{value:e,configurable:!0}),"i$3");const b=at(t=>t.type?.name==="Boolean","isBoolean");var it=Object.defineProperty,P=c((t,e)=>it(t,"name",{value:e,configurable:!0}),"n$2");const F=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"),st=new Set(["0","1","false","true"]),lt=P((t,e)=>{const o=P((n,r)=>{const{argName:i,argValue:a,option:s}=K(r,e),{lastOption:l}=n;return s&&b(s)&&a&&i?n.partial[i]=F(a,s):n.lastName&&l&&b(l)&&st.has(r)&&(n.partial[n.lastName]=F(r,l)),{lastName:i,lastOption:s,partial:n.partial}},"getBooleanValue");return t.reduce(o,{partial:{}}).partial},"getBooleanValues");var ct=Object.defineProperty,Q=c((t,e)=>ct(t,"name",{value:e,configurable:!0}),"p$1");const pt=Q(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"),ut=Q(t=>(b(t)||(t.typeLabel=t.typeLabel??pt(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var mt=Object.defineProperty,Y=c((t,e)=>mt(t,"name",{value:e,configurable:!0}),"s$3");const dt=new Set(["0","1","false","true"]),gt=Y((t,e)=>{const o=Y((n,r)=>{const{argValue:i,option:a}=K(r,e),{lastOption:s}=n;if(s&&b(s)&&dt.has(r)){const l=[...n.args];return l.pop(),{args:l}}return a&&b(a)&&i?{args:n.args}:{args:[...n.args,r],lastOption:a}},"removeBooleanArguments");return t.reduce(o,{args:[]}).args},"removeBooleanValues");var ht=Object.defineProperty,X=c((t,e)=>ht(t,"name",{value:e,configurable:!0}),"e$2");const ft=new RegExp(/^-([^\d-])$/),vt=new RegExp(/^--(\S+)/),yt=new RegExp(/^-([^\d-]{2,})$/),bt=X(t=>ft.test(t)||vt.test(t)||yt.test(t),"isOption"),$t=X((t,e)=>{const o=e[0]&&bt(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 wt=Object.defineProperty,Z=c((t,e)=>wt(t,"name",{value:e,configurable:!0}),"i$1");const Et=Z((t,e)=>$e(t,e)<=t.length/3||e.includes(t),"isSimilar"),G=Z((t,e)=>{const o=t.toLowerCase();return e.filter(n=>Et(n.toLowerCase(),o))},"findAlternatives");var Ot=Object.defineProperty,Ct=c((t,e)=>Ot(t,"name",{value:e,configurable:!0}),"t$3");const _t=Ct((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 At=Object.defineProperty,Nt=c((t,e)=>At(t,"name",{value:e,configurable:!0}),"t$2");const Lt=Nt(t=>{const e=new Map;return t.forEach(o=>{e.set(o.name,{...e.get(o.name),...o})}),[...e.values()]},"mergeArguments");var xt=Object.defineProperty,N=c((t,e)=>xt(t,"name",{value:e,configurable:!0}),"e$1");const jt=N(()=>!!process.versions.electron,"isElectronApp"),Pt=N(()=>jt()&&!process.defaultApp,"isBundledElectronApp"),Rt=N(()=>Pt()?0:1,"getProcessArgvBinIndex"),St=N(t=>t.slice(Rt()+1),"hideBin");var Tt=Object.defineProperty,ee=c((t,e)=>Tt(t,"name",{value:e,configurable:!0}),"i");const Vt=" ",Bt=ee((t,e)=>t.length===e.length&&t.every((o,n)=>o===e[n]),"equals"),kt=ee(t=>typeof t=="string"?t.split(Vt):Bt(t,process.argv)?St(t):t,"parseRawCommand");var Ut=Object.defineProperty,It=c((t,e)=>Ut(t,"name",{value:e,configurable:!0}),"t");const Dt=It(t=>{process.on("uncaughtException",e=>{t.error(`Uncaught exception: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)}),process.on("unhandledRejection",e=>{t.error(`Promise rejection: ${e}`),e?.stack&&t.error(e.stack),process.exit(1)})},"registerExceptionHandler");var Mt=Object.defineProperty,y=c((t,e)=>Mt(t,"name",{value:e,configurable:!0}),"g");const qt="CI"in m&&("GITHUB_ACTIONS"in m||"GITLAB_CI"in m||"CIRCLECI"in m),Ft=y(t=>t.charAt(0).toLowerCase()+t.slice(1),"lowerFirstChar");class oo{static{c(this,"Cli")}static{y(this,"Cli")}logger;argv;cwd;cliName;packageVersion;packageName;extensions=[];commands;defaultCommand;updateNotifierOptions;commandSection;constructor(e,o={}){const{argv:n,cwd:r,packageName:i,packageVersion:a}={argv:B,cwd:ae(),...o};this.argv=kt(n),this.argv.includes("--quiet")||this.argv.includes("-q")?m.CEREBRO_OUTPUT_LEVEL=String(q):this.argv.includes("--verbose")||this.argv.includes("-v")?m.CEREBRO_OUTPUT_LEVEL=String(Je):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in m?m.CEREBRO_OUTPUT_LEVEL=String(j):m.CEREBRO_OUTPUT_LEVEL=String(He);const s={32:"informational",64:"trace",128:"debug"},l=[new ge];m.CEREBRO_OUTPUT_LEVEL===String(j)&&l.push(new he),this.logger=fe({logLevel:m.CEREBRO_OUTPUT_LEVEL?s[m.CEREBRO_OUTPUT_LEVEL]??"informational":"informational",processors:l,...o.logger}),m.CEREBRO_OUTPUT_LEVEL===String(q)&&this.logger.disable(),et(),Dt(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(We),this.addCommand(new Fe(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=>ut(o)),this.validateDoubleOptions(e),this.addNegatableOption(e),e.options?.forEach(o=>{o.__camelCaseName__=H(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:m.CEREBRO_OUTPUT_LEVEL===String(j),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: ${ie}`),this.logger.debug(`process.execArgv: ${se.join(" ")}`),this.logger.debug(`process.argv: ${B.join(" ")}`);try{i=$t([null,...r],this.argv)}catch(h){if(h.name==="INVALID_COMMAND"&&h.command){let T="";const V=G(h.command,[...this.commands.keys()]);V.length>0&&(T=` Did you mean: \r
|
|
7
|
-
- ${V.join(` \r
|
|
8
|
-
- `)}`),this.logger.error(`"${h.command}" is not an available command.${T}`)}else this.logger.error(h);return o?x(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?x(1):void 0;const l=i.argv;this.logger.debug(`command '${a}' found, parsing command args: ${l.join(", ")}`);let p=Lt([...s.options??[],...C]);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:E,type:s.argument?.type,typeLabel:s.argument?.typeLabel},...p]);const g=ve(p,{argv:gt(l,s.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),$=lt(l,s.options??[]),v={...g,_all:{...g._all,...$}};this.validateCommandOptions(p,v,s);const d=new Qe(s.name,s);d.runtime=this,await this.registerExtensions(d),await this.updateNotifier(d);const{_all:L,positionals:te}=v;return L[E]&&delete L[E],d.argument=te?.[E]??[],d.argv=this.argv,d.options={...L,...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(v,d,s),o?x(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:y(e=>{e.logger=this.logger},"execute"),name:"logger"})}async prepareToolboxResult(e,o,n){if(e.global?.help){this.logger.debug("'--help' option found, running 'help' for given command...");const r=this.commands.get("help");if(!r)throw new Error("Help command not found.");await r.execute(o);return}if(e.global?.version||e.global?.V){this.logger.debug("'--version' option found, running 'version' for given command...");const r=this.commands.get("version");if(!r)throw new Error("Version command not found.");await r.execute(o);return}await n.execute(o)}async updateNotifier({logger:e}){if(this.updateNotifierOptions?.alwaysRun||!(m.NO_UPDATE_NOTIFIER||m.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||qt)&&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 ${pe(`${this.packageVersion}`)}${ue(" → ")}${me(o)}`;this.logger.error(le(n,{borderColor:y(r=>de(r),"borderColor"),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}))}}}validateCommandOptions(e,o,n){const r=_t(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=G(a.replace("--",""),[...(n.options??[]).map(g=>g.name),...C.map(g=>g.name)]);if(p.length>0){const[g,...$]=p.map(v=>`--${v}`);l+=$.length>0?`, did you mean ${g} or ${$.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=y(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=Ft(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{oo as Cli};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";var ne=Object.create;var P=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ae=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var c=(t,e)=>P(t,"name",{value:e,configurable:!0});var se=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of re(e))!ie.call(t,r)&&r!==n&&P(t,r,{get:()=>e[r],enumerable:!(o=oe(e,r))||o.enumerable});return t};var le=(t,e,n)=>(n=t!=null?ne(ae(t)):{},se(e||!t||!t.__esModule?P(n,"default",{value:t,enumerable:!0}):n,t));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("node:process"),ce=require("@visulima/boxen"),v=require("@visulima/colorize"),B=require("@visulima/pail/processor"),pe=require("@visulima/pail/server"),ue=require("command-line-args"),de=require("cli-table3"),me=require("@visulima/colorize/template"),ge=require("node:os"),he=require("fastest-levenshtein"),_=c(t=>t&&typeof t=="object"&&"default"in t?t.default:t,"_interopDefaultCompat"),fe=_(ue),O=_(de),ve=_(me),ye=_(ge);var be=Object.defineProperty,A=c((t,e)=>be(t,"name",{value:e,configurable:!0}),"f$4");const $e=/[\p{Lu}]/u,we=/[\p{Ll}]/u,k=/^[\p{Lu}](?![\p{Lu}])/gu,W=/([\p{Alpha}\p{N}_]|$)/u,R=/[_.\- ]+/,Ee=new RegExp("^"+R.source),U=new RegExp(R.source+W.source,"gu"),I=new RegExp("\\d+"+W.source,"gu"),Oe=A((t,e,n,o)=>{let r=!1,i=!1,a=!1,s=!1;for(let l=0;l<t.length;l++){const u=t[l];s=l>2?t[l-3]==="-":!0,r&&$e.test(u)?(t=t.slice(0,l)+"-"+t.slice(l),r=!1,a=i,i=!0,l++):i&&a&&we.test(u)&&(!s||o)?(t=t.slice(0,l-1)+"-"+t.slice(l-1),a=i,i=!1,r=!0):(r=e(u)===u&&n(u)!==u,a=i,i=n(u)===u&&e(u)!==u)}return t},"preserveCamelCase"),Ce=A((t,e)=>(k.lastIndex=0,t.replaceAll(k,n=>e(n))),"preserveConsecutiveUppercase"),_e=A((t,e)=>(U.lastIndex=0,I.lastIndex=0,t.replaceAll(I,(n,o,r)=>["_","-"].includes(t.charAt(r+n.length))?n:e(n)).replaceAll(U,(n,o)=>e(o))),"postProcess");function H(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 n=e.locale===!1?r=>r.toLowerCase():r=>r.toLocaleLowerCase(e.locale),o=e.locale===!1?r=>r.toUpperCase():r=>r.toLocaleUpperCase(e.locale);return t.length===1?R.test(t)?"":e.pascalCase?o(t):n(t):(t!==n(t)&&(t=Oe(t,n,o,e.preserveConsecutiveUppercase)),t=t.replace(Ee,""),t=e.preserveConsecutiveUppercase?Ce(t,n):n(t),e.pascalCase&&(t=o(t.charAt(0))+t.slice(1)),_e(t,o))}c(H,"S");A(H,"camelCase");const C=[{description:"Turn on verbose output",group:"global",name:"verbose",type:Boolean},{description:"Turn on debugging output",group:"global",name:"debug",type:Boolean},{alias:"h",description:"Print out helpful usage information",group:"global",name:"help",type:Boolean},{alias:"q",description:"Silence output",group:"global",name:"quiet",type:Boolean},{alias:"V",description:"Print version info",group:"global",name:"version",type:Boolean},{description:"Turn off colored output",group:"global",name:"no-color",type:Boolean},{description:"Force colored output",group:"global",name:"color",type:Boolean}];var Ae=Object.defineProperty,Ne=c((t,e)=>Ae(t,"name",{value:e,configurable:!0}),"e$4");const d=Ne(t=>t?ve(Object.assign([],{raw:[t.replaceAll("`","\\`")]})):"","templateFormat");var Le=Object.defineProperty,xe=c((t,e)=>Le(t,"name",{value:e,configurable:!0}),"t$6");let J=class{static{c(this,"n")}static{xe(this,"BaseSection")}lines;constructor(){this.lines=[]}add(e){this.lines.push(e)}toString(){return this.lines.join(ye.EOL)}header(e){this.add(v.bold(e)),this.lines.push("")}};var Pe=Object.defineProperty,Se=c((t,e)=>Pe(t,"name",{value:e,configurable:!0}),"p$4");const w={chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,60],style:{border:[],compact:!0,head:[],"padding-left":2,"padding-right":1},wordWrap:!0};let je=class extends J{static{c(this,"y")}static{Se(this,"ContentSection")}constructor(e){if(super(),e.header&&this.header(d(e.header)),e.content){if(e.raw)if(Array.isArray(e.content)&&e.content.every(n=>typeof n=="string"))e.content.forEach(n=>{Array.isArray(n)?n.forEach(o=>this.add(d(o))):this.add(d(n))});else if(typeof e.content=="string")this.add(d(e.content));else throw new TypeError("Invalid raw content, must be a string or array of strings.");else this.add(this.getContentLines(e.content));this.add("")}}getContentLines(e){if(typeof e=="string"){const n=new O({...w,colWidths:[80]});return n.push([d(e)]),n.toString()}if(Array.isArray(e)&&e.every(n=>typeof n=="string"||Array.isArray(n)&&n.every(o=>typeof o=="string"))){const n=new O({...w});return e.forEach(o=>{Array.isArray(o)?n.push(o.map(r=>d(r))):n.push([d(o)])}),n.toString()}if(typeof e=="object"){const n=e;if(!n.options||!n.data)throw new Error(`Must have an "options" or "data" property
|
|
2
|
-
${JSON.stringify(e)}`);const o=new O({...w,...n.options,style:{...w.style,...n.options.style}});return n.data.forEach(r=>{Array.isArray(r)?o.push(r.map(i=>d(i))):o.push([d(r)])}),o.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
|
|
3
|
-
|
|
4
|
-
${JSON.stringify(e)}`)}};var Re=Object.defineProperty,Te=c((t,e)=>Re(t,"name",{value:e,configurable:!0}),"a$1");let Ve=class extends J{static{c(this,"c")}static{Te(this,"OptionListSection")}constructor(e){super();let n=e.optionList??[];const o=Array.isArray(e.hide)?e.hide:[e.hide].filter(Boolean),r=Array.isArray(e.group)?e.group:[e.group].filter(Boolean);o.length>0&&(n=n.filter(a=>!o.includes(a.name))),e.header&&this.header(d(e.header)),r.length>0&&(n=n.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 O({chars:{bottom:"","bottom-left":"","bottom-mid":"","bottom-right":"",left:" ","left-mid":"",mid:"","mid-mid":"",middle:" ",right:"","right-mid":"",top:"","top-left":"","top-mid":"","top-right":""},colWidths:[40,40],style:{"padding-left":2,"padding-right":1},wordWrap:!0});n.forEach(a=>i.push([this.getOptionNames(a,e.reverseNameOrder??!1,e.isArgument??!1),d(a.description)])),this.add(i.toString()),this.lines.push("")}getOptionNames(e,n,o){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=d(e.typeLabel??`{underline ${r}${i}}`);let a;if(e.alias)if(e.name){const s=o?e.name:`{yellow --${e.name}}`;a=d(n?`{bold ${s}}, {bold -${e.alias}} ${r}`:`{bold -${e.alias}}, {bold ${s}} ${r}`)}else n?a=d(`{bold -${e.alias}} ${r}`):a=d(`{bold -${e.alias}} ${r}`);else a=d(`{bold ${o?e.name:`{yellow --${e.name}}`}} ${r}`);return a}intersect(e,n){return e.some(o=>n.includes(o))}};var Be=Object.defineProperty,ke=c((t,e)=>Be(t,"name",{value:e,configurable:!0}),"o$3");const z=ke(t=>(Array.isArray(t)?t:[t]).length===0?"":`
|
|
5
|
-
${t.map(e=>e.optionList?new Ve(e).toString():new je(e).toString()).join(`
|
|
6
|
-
`)}`,"commandLineUsage");var Ue=Object.defineProperty,N=c((t,e)=>Ue(t,"name",{value:e,configurable:!0}),"l$5");const D="__Other",M=N(t=>t.charAt(0).toUpperCase()+t.slice(1),"upperFirstChar"),Ie=N((t,e,n,o)=>{t.debug("no command given, printing general help...");let r=[...new Set(n.values())].filter(a=>!a.hidden);o&&(r=r.filter(a=>a.group===o));const i=r.reduce((a,s)=>{const l=s.group??D;return a[l]||(a[l]=[]),a[l].push(s),a},{});t.raw(z([{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===D||o?`{inverse.green Available${o?` ${M(o)}`:""} Commands }`:` {inverse.green ${M(a)} }`})),n.has("help")?{header:"{inverse.yellow Command Options }",optionList:n.get("help").options?.filter(a=>!a.hidden)}:void 0,{header:"{inverse.yellow Global Options }",optionList:C},{content:`Run "{cyan ${e.getCliName()}} {green help <command>}" or "{cyan ${e.getCliName()}} {green <command>} {yellow --help}" for help with a specific command.`,raw:!0}].filter(Boolean)))},"printGeneralHelp"),De=N((t,e,n,o)=>{const r=n.get(o),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:C}),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(z(i))},"printCommandHelp");class Me{static{c(this,"C")}static{N(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:n,logger:o,options:r,runtime:i}=e,{footer:a,header:s}=i.getCommandSection();s&&o.raw(d(s)),n==="help"?Ie(o,i,this.commands,r?.group):De(o,i,this.commands,n),a&&o.raw(d(a))}}var qe=Object.defineProperty,Fe=c((t,e)=>qe(t,"name",{value:e,configurable:!0}),"s$7");const Ye={alias:["v","V"],description:"Output the version number",execute:Fe(({logger:t,runtime:e})=>{const n=e.getPackageVersion();n===void 0?(t.warn("Unknown version"),t.debug("The version number was not provided by the cli constructor.")):t.info(n)},"execute"),name:"version",options:[],usage:[]},q=16,Ge=32,We=64,S=128,E="positionals";var He=Object.defineProperty,Je=c((t,e)=>He(t,"name",{value:e,configurable:!0}),"m$2");let ze=class{static{c(this,"c")}static{Je(this,"EmptyToolbox")}result;argv;options;argument;command;commandName;runtime;logger;constructor(e,n){this.commandName=e,this.command=n}};var Ke=Object.defineProperty,Qe=c((t,e)=>Ke(t,"name",{value:e,configurable:!0}),"s$6");const Xe=Qe(()=>{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 Ze=Object.defineProperty,et=c((t,e)=>Ze(t,"name",{value:e,configurable:!0}),"r$4");const tt=/^-{1,2}(\w+)(=(\w+))?$/,K=et((t,e)=>{const n=tt.exec(t);if(n==null)return{};const o=n[1],r=e.find(i=>i.name===o||i.alias===o);return r!==void 0?{argName:r.name,argValue:n[3],option:r}:{}},"getParameterOption");var nt=Object.defineProperty,ot=c((t,e)=>nt(t,"name",{value:e,configurable:!0}),"i$3");const b=ot(t=>t.type?.name==="Boolean","isBoolean");var rt=Object.defineProperty,j=c((t,e)=>rt(t,"name",{value:e,configurable:!0}),"n$2");const F=j((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"),at=new Set(["0","1","false","true"]),it=j((t,e)=>{const n=j((o,r)=>{const{argName:i,argValue:a,option:s}=K(r,e),{lastOption:l}=o;return s&&b(s)&&a&&i?o.partial[i]=F(a,s):o.lastName&&l&&b(l)&&at.has(r)&&(o.partial[o.lastName]=F(r,l)),{lastName:i,lastOption:s,partial:o.partial}},"getBooleanValue");return t.reduce(n,{partial:{}}).partial},"getBooleanValues");var st=Object.defineProperty,Q=c((t,e)=>st(t,"name",{value:e,configurable:!0}),"p$1");const lt=Q(t=>{let e=t.type?t.type.name.toLowerCase():"string";const n=t.multiple??t.lazyMultiple?"[]":"";return e&&(e=e==="boolean"?"":`{underline ${e}${n}}`),e},"getTypeLabel"),ct=Q(t=>(b(t)||(t.typeLabel=t.typeLabel??lt(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var pt=Object.defineProperty,Y=c((t,e)=>pt(t,"name",{value:e,configurable:!0}),"s$3");const ut=new Set(["0","1","false","true"]),dt=Y((t,e)=>{const n=Y((o,r)=>{const{argValue:i,option:a}=K(r,e),{lastOption:s}=o;if(s&&b(s)&&ut.has(r)){const l=[...o.args];return l.pop(),{args:l}}return a&&b(a)&&i?{args:o.args}:{args:[...o.args,r],lastOption:a}},"removeBooleanArguments");return t.reduce(n,{args:[]}).args},"removeBooleanValues");var mt=Object.defineProperty,X=c((t,e)=>mt(t,"name",{value:e,configurable:!0}),"e$2");const gt=new RegExp(/^-([^\d-])$/),ht=new RegExp(/^--(\S+)/),ft=new RegExp(/^-([^\d-]{2,})$/),vt=X(t=>gt.test(t)||ht.test(t)||ft.test(t),"isOption"),yt=X((t,e)=>{const n=e[0]&&vt(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(n)){const o=new Error(`Command not recognised: ${n}`);throw o.command=n,o.name="INVALID_COMMAND",o}return{argv:e,command:n}},"commandLineCommands");var bt=Object.defineProperty,Z=c((t,e)=>bt(t,"name",{value:e,configurable:!0}),"i$1");const $t=Z((t,e)=>he.distance(t,e)<=t.length/3||e.includes(t),"isSimilar"),G=Z((t,e)=>{const n=t.toLowerCase();return e.filter(o=>$t(o.toLowerCase(),n))},"findAlternatives");var wt=Object.defineProperty,Et=c((t,e)=>wt(t,"name",{value:e,configurable:!0}),"t$3");const Ot=Et((t,e)=>t.filter(n=>n.required&&e[n.name]==null).filter(n=>n.type?.name==="Boolean"?(e[n.name]=!1,!1):!0),"listMissingArguments");var Ct=Object.defineProperty,_t=c((t,e)=>Ct(t,"name",{value:e,configurable:!0}),"t$2");const At=_t(t=>{const e=new Map;return t.forEach(n=>{e.set(n.name,{...e.get(n.name),...n})}),[...e.values()]},"mergeArguments");var Nt=Object.defineProperty,L=c((t,e)=>Nt(t,"name",{value:e,configurable:!0}),"e$1");const Lt=L(()=>!!process.versions.electron,"isElectronApp"),xt=L(()=>Lt()&&!process.defaultApp,"isBundledElectronApp"),Pt=L(()=>xt()?0:1,"getProcessArgvBinIndex"),St=L(t=>t.slice(Pt()+1),"hideBin");var jt=Object.defineProperty,ee=c((t,e)=>jt(t,"name",{value:e,configurable:!0}),"i");const Rt=" ",Tt=ee((t,e)=>t.length===e.length&&t.every((n,o)=>n===e[o]),"equals"),Vt=ee(t=>typeof t=="string"?t.split(Rt):Tt(t,process.argv)?St(t):t,"parseRawCommand");var Bt=Object.defineProperty,kt=c((t,e)=>Bt(t,"name",{value:e,configurable:!0}),"t");const Ut=kt(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 It=Object.defineProperty,y=c((t,e)=>It(t,"name",{value:e,configurable:!0}),"g");const Dt="CI"in p.env&&("GITHUB_ACTIONS"in p.env||"GITLAB_CI"in p.env||"CIRCLECI"in p.env),Mt=y(t=>t.charAt(0).toLowerCase()+t.slice(1),"lowerFirstChar");class qt{static{c(this,"Cli")}static{y(this,"Cli")}logger;argv;cwd;cliName;packageVersion;packageName;extensions=[];commands;defaultCommand;updateNotifierOptions;commandSection;constructor(e,n={}){const{argv:o,cwd:r,packageName:i,packageVersion:a}={argv:p.argv,cwd:p.cwd(),...n};this.argv=Vt(o),this.argv.includes("--quiet")||this.argv.includes("-q")?p.env.CEREBRO_OUTPUT_LEVEL=String(q):this.argv.includes("--verbose")||this.argv.includes("-v")?p.env.CEREBRO_OUTPUT_LEVEL=String(We):this.argv.includes("--debug")||this.argv.includes("-vvv")||"DEBUG"in p.env?p.env.CEREBRO_OUTPUT_LEVEL=String(S):p.env.CEREBRO_OUTPUT_LEVEL=String(Ge);const s={32:"informational",64:"trace",128:"debug"},l=[new B.MessageFormatterProcessor];p.env.CEREBRO_OUTPUT_LEVEL===String(S)&&l.push(new B.CallerProcessor),this.logger=pe.createPail({logLevel:p.env.CEREBRO_OUTPUT_LEVEL?s[p.env.CEREBRO_OUTPUT_LEVEL]??"informational":"informational",processors:l,...n.logger}),p.env.CEREBRO_OUTPUT_LEVEL===String(q)&&this.logger.disable(),Xe(),Ut(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(Ye),this.addCommand(new Me(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(n=>ct(n)),this.validateDoubleOptions(e),this.addNegatableOption(e),e.options?.forEach(n=>{n.__camelCaseName__=H(n.name)}),this.commands.set(e.name,e),e.alias!==void 0){let n=e.alias;typeof e.alias=="string"&&(n=[e.alias]),n.forEach(o=>{if(this.logger.debug("adding alias",o),this.commands.has(o))throw new Error(`Ignoring command alias "${o}, command with the same name was found."`);this.commands.set(o,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 n=Object.keys(e);if(n.length>0&&!n.includes("alwaysRun")&&!n.includes("distTag")&&!n.includes("updateCheckInterval"))throw new Error("Invalid update notifier options, please check the documentation.");return this.updateNotifierOptions={alwaysRun:!1,debug:p.env.CEREBRO_OUTPUT_LEVEL===String(S),distTag:"latest",pkg:{name:this.packageName,version:this.packageVersion},updateCheckInterval:1e3*60*60*24,...e},this}getCliName(){return this.cliName}getPackageVersion(){return this.packageVersion}getPackageName(){return this.packageName}getCommands(){return this.commands}getCwd(){return this.cwd}async run(e={}){const{shouldExitProcess:n=!0,...o}=e,r=[...this.commands.keys()];let i;this.logger.debug(`process.execPath: ${p.execPath}`),this.logger.debug(`process.execArgv: ${p.execArgv.join(" ")}`),this.logger.debug(`process.argv: ${p.argv.join(" ")}`);try{i=yt([null,...r],this.argv)}catch(h){if(h.name==="INVALID_COMMAND"&&h.command){let T="";const V=G(h.command,[...this.commands.keys()]);V.length>0&&(T=` Did you mean: \r
|
|
7
|
-
- ${V.join(` \r
|
|
8
|
-
- `)}`),this.logger.error(`"${h.command}" is not an available command.${T}`)}else this.logger.error(h);return n?p.exit(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.`),n?p.exit(1):void 0;const l=i.argv;this.logger.debug(`command '${a}' found, parsing command args: ${l.join(", ")}`);let u=At([...s.options??[],...C]);u.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..."),u=[{defaultOption:!0,description:s.argument?.description,group:"positionals",multiple:!0,name:E,type:s.argument?.type,typeLabel:s.argument?.typeLabel},...u]);const g=fe(u,{argv:dt(l,s.options??[]),camelCase:!0,partial:!0,stopAtFirstUnknown:!0}),$=it(l,s.options??[]),f={...g,_all:{...g._all,...$}};this.validateCommandOptions(u,f,s);const m=new ze(s.name,s);m.runtime=this,await this.registerExtensions(m),await this.updateNotifier(m);const{_all:x,positionals:te}=f;return x[E]&&delete x[E],m.argument=te?.[E]??[],m.argv=this.argv,m.options={...x,...o},this.mapNegatableOptions(m,s),this.mapImpliesOptions(m,s),this.validateCommandArgsForConflicts(u,m.options,s),this.logger.debug("command options parsed from options:"),this.logger.debug(JSON.stringify(m.options,null,2)),this.logger.debug("command argument parsed from argument:"),this.logger.debug(JSON.stringify(m.argument,null,2)),await this.prepareToolboxResult(f,m,s),n?p.exit(0):void 0}validateDoubleOptions(e){if(Array.isArray(e.options)){const n=e.options.reduce((i,a)=>{const s=`${a.name}-${a.alias}`;return i[s]||(i[s]=[]),i[s].push(a),i},{}),o=Object.values(n).filter(i=>i.length>1);let r="";if(o.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:y(e=>{e.logger=this.logger},"execute"),name:"logger"})}async prepareToolboxResult(e,n,o){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(n);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(n);return}await o.execute(n)}async updateNotifier({logger:e}){if(this.updateNotifierOptions?.alwaysRun||!(p.env.NO_UPDATE_NOTIFIER||p.env.NODE_ENV==="test"||this.argv.includes("--no-update-notifier")||Dt)&&this.updateNotifierOptions){e.raw("Checking for updates...");const n=await(await import("../packem_chunks/has-new-version.cjs").then(o=>o.default))(this.updateNotifierOptions);if(n){const o=`Update available ${v.dim(`${this.packageVersion}`)}${v.reset(" → ")}${v.green(n)}`;this.logger.error(ce.boxen(o,{borderColor:y(r=>v.yellow(r),"borderColor"),borderStyle:"round",margin:1,padding:1,textAlignment:"center"}))}}}validateCommandOptions(e,n,o){const r=Ot(e,n);if(r.length>0)throw new Error(`You called the command "${o.name}" without the required options: ${r.map(i=>i.name).join(", ")}`);if(n._unknown&&n._unknown.length>0){const i=[];if(n._unknown.forEach(a=>{const s=a.startsWith("--");let l=`Found unknown ${s?"option":"argument"} "${a}"`;if(s){const u=G(a.replace("--",""),[...(o.options??[]).map(g=>g.name),...C.map(g=>g.name)]);if(u.length>0){const[g,...$]=u.map(f=>`--${f}`);l+=$.length>0?`, did you mean ${g} or ${$.join(", ")}?`:`, did you mean ${g}?`}}i.push(l)}),i.length>0)throw new Error(i.join(`
|
|
10
|
-
`))}}validateCommandArgsForConflicts(e,n,o){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=>n[s]!==void 0)&&n[a.name]!==void 0:n[a.conflicts]!==void 0&&n[a.name]!==void 0);if(i)throw new Error(`You called the command "${o.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(n=>{if(n.name.startsWith("no-")&&!e.options.some(o=>o.name===n.name.replace("no-",""))){if(n.type!==Boolean){this.logger.debug(`Cannot add negated option "${n.name}" to command "${e.name}" because it is not a boolean.`);return}const o={...n,defaultValue:n.defaultValue===void 0?!0:!n.defaultValue,name:`${n.name.replace("no-","")}`};e.options.push(o)}})}async registerExtensions(e){const n=y(async o=>typeof o.execute!="function"?(this.logger.warn(`Skipped ${o.name} because execute is not a function.`),null):(await o.execute(e),null),"callback");for(const o of this.extensions)await n(o)}mapNegatableOptions(e,n){Object.entries(e.options).forEach(([o,r])=>{if(/^no\w+/.test(o)){const i=Mt(o.replace("no",""));this.logger.debug(`mapping negated option "${o}" to "${i}"`),e.options[i]=!r,n.options?.forEach(a=>{a.name===i&&(a.__negated__=!0)})}})}mapImpliesOptions(e,n){Object.keys(e.options).forEach(o=>{const r=n.options?.find(i=>i.__camelCaseName__===o&&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=n.options?.find(u=>u.name===a);(l?.defaultValue===void 0||e.options[a]===l.defaultValue)&&(e.options[a]=s)}})}})}}exports.Cli=qt;
|