@visulima/cerebro
Version:
A delightful toolkit for building cross-runtime CLIs for Node.js, Deno, and Bun.
2 lines (1 loc) • 4.85 kB
JavaScript
var E=Object.defineProperty;var g=(i,r)=>E(i,"name",{value:r,configurable:!0});import{green as d,inverse as s,cyan as c,yellow as f}from"@visulima/colorize";import{f as y,p as $}from"./index-DQ3pvLQH.js";const O=[{defaultValue:"32",description:"Controls the verbosity level of output. Valid values: '16' (quiet), '32' (normal), '64' (verbose), '128' (debug)",name:"CEREBRO_OUTPUT_LEVEL",type:String},{description:"Sets the minimum required Node.js version. Overrides the default minimum version check",name:"CEREBRO_MIN_NODE_VERSION",type:Number},{defaultValue:!1,description:"When set, disables the update notifier check",name:"NO_UPDATE_NOTIFIER",type:Boolean},{description:"Standard Node.js environment variable. When set to 'test', disables update notifier",name:"NODE_ENV",type:String},{defaultValue:!1,description:"When set, enables debug output (same as --debug flag)",name:"DEBUG",type:Boolean},{description:"Sets the terminal width for table rendering. Useful for testing and consistent output",name:"CEREBRO_TERMINAL_WIDTH",type:Number}],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 N=Object.defineProperty,u=g((i,r)=>N(i,"name",{value:r,configurable:!0}),"p");const b="__Other",v=u(i=>i.charAt(0).toUpperCase()+i.slice(1),"upperFirstChar"),A=u((i,r,p,t)=>{i.debug("no command given, printing general help...");let n=[...new Set(p.values())].filter(e=>!e.hidden);t&&(n=n.filter(e=>e.group===t));const a=n.reduce((e,o)=>{const l=o.group??b;return e[l]||(e[l]=[]),e[l].push(o),e},{}),m=u(e=>e.map(o=>{let l="";typeof o.alias=="string"?l=o.alias:Array.isArray(o.alias)&&(l=o.alias.join(", ")),l!==""&&(l=` [${l}]`);let h=o.name;return o.commandPath&&o.commandPath.length>0&&(h=`${o.commandPath.join(" ")} ${o.name}`),[`${d(h)}${l}`,o.description??""]}),"buildCommandList");(i?.raw??i.log)($([{content:`${c(r.getCliName())} ${d("<command>")} [positional arguments] ${f("[options]")}`,header:s.cyan(" Usage ")},...Object.keys(a).map(e=>{const o=t?` ${v(t)}`:"";return{content:m(a[e]),header:e===b||t?s.green(` Available${o} Commands `):` ${s.green(` ${v(e)} `)}`}}),p.has("help")?{header:s.yellow(" Command Options "),optionList:p.get("help").options?.filter(e=>!e.hidden)}:void 0,{header:s.yellow(" Global Options "),optionList:C},{content:O.filter(e=>!e.hidden).map(e=>[e.name,e.description??""]),header:s.magenta(" Environment Variables ")},{content:`Run "${c(r.getCliName())} ${d("help <command>")}" or "${c(r.getCliName())} ${d("<command>")} ${f("--help")}" for help with a specific command.`,raw:!0}].filter(Boolean)))},"printGeneralHelp"),B=u((i,r,p,t)=>{let n=p.get(t);if(!n)for(const e of p.values()){const o=e.commandPath?[...e.commandPath,e.name]:[e.name];if(o[o.length-1]===t||o.join(" ")===t){n=e;break}}if(!n){i.error(`Command "${t}" not found`);return}const a=[],m=(n.commandPath?[...n.commandPath,n.name]:[n.name]).join(" ");if(a.push({content:`${c(r.getCliName())} ${d(m)}${n.argument?" [positional arguments]":""}${n.options?" [options]":""}`,header:s.cyan(" Usage ")}),n.description&&a.push({content:n.description,header:s.green(" Description ")}),n.argument&&a.push({header:"Command Positional Arguments",isArgument:!0,optionList:[n.argument]}),Array.isArray(n.options)&&n.options.length>0&&a.push({header:s.yellow(" Command Options "),optionList:n.options.filter(e=>!e.hidden)}),a.push({header:s.yellow(" Global Options "),optionList:C}),Array.isArray(n.env)&&n.env.length>0){const e=n.env.filter(o=>!o.hidden);e.length>0&&a.push({content:e.map(o=>[o.name,o.description??""]),header:s.magenta(" Environment Variables ")})}if(n.alias!==void 0&&n.alias.length>0){let e=n.alias;typeof n.alias=="string"&&(e=[n.alias]),a.splice(1,0,{content:e,header:"Alias(es)"})}Array.isArray(n.examples)&&n.examples.length>0&&a.push({content:n.examples,header:"Examples"}),(i?.raw??i.log)($(a))},"printCommandHelp");class R{static{g(this,"D")}static{u(this,"HelpCommand")}name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(r){this.commands=r}execute(r){const{commandName:p,logger:t,options:n,runtime:a}=r,{footer:m,header:e}=a.getCommandSection();e&&(t?.raw??t.log)(y(e)),p==="help"?A(t,a,this.commands,typeof n?.group=="string"?n.group:void 0):B(t,a,this.commands,p),m&&(t?.raw??t.log)(y(m))}}export{R as D,C as o};