bob-core 2.0.0-beta.12 → 2.0.0-beta.13
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/cjs/index.js +12 -12
- package/dist/cjs/{package-Crgs52BZ.cjs → package-6GoPiEev.cjs} +1 -1
- package/dist/cjs/src/CommandParser.d.ts +11 -3
- package/dist/cjs/src/CommandWithSignature.d.ts +1 -1
- package/dist/esm/index.js +241 -231
- package/dist/esm/{package-B07Xl_ue.js → package-CtFSlXKR.js} +1 -1
- package/dist/esm/src/CommandParser.d.ts +11 -3
- package/dist/esm/src/CommandWithSignature.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("prompts"),ie=require("minimist"),se=require("node:fs"),V=require("path"),oe=require("string-similarity");function Q(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const ae=Q(se),le=Q(oe);class I{logger;constructor(e){this.logger=e}log(...e){this.logger.log(...e)}info(...e){this.logger.info(...e)}warn(...e){this.logger.warn(...e)}error(...e){this.logger.error(...e)}debug(...e){this.logger.debug(...e)}async askForConfirmation(e="Do you want to continue?",t){return(await w({type:"confirm",name:"value",message:e,initial:t??!1})).value}async askForInput(e,t,n){return(await w({type:"text",name:"value",message:e,initial:t,...n}))?.value??null}async askForDate(e,t,n){return(await w({type:"date",name:"value",message:e,initial:t,...n}))?.value??null}async askForList(e,t,n){return(await w({type:"list",name:"value",message:e,initial:t,...n}))?.value??null}async askForToggle(e,t,n){return(await w({type:"toggle",name:"value",message:e,initial:t,...n}))?.value??null}async askForSelect(e,t,n){if(t.length===0)throw new Error("No options provided");const i=[];for(const o of t)typeof o=="string"?i.push({title:o,value:o}):i.push(o);return(await w({type:"select",name:"value",message:e,choices:i,...n}))?.value??null}newLoader(e="",t=["⠙","⠘","⠰","⠴","⠤","⠦","⠆","⠃","⠋","⠉"],n=100){let i=e,s=null,o=0;const u=setInterval(function(){s&&(process.stdout.write(new TextEncoder().encode("\r"+" ".repeat(s.length+5)+"\r")),s=null),process.stdout.write(new TextEncoder().encode("\r"+t[o++]+" "+i)),o=o%t.length},n),m=()=>{clearInterval(u),process.stdout.write(new TextEncoder().encode("\r"+" ".repeat(i.length+5)+"\r"))};return{[Symbol.dispose]:m,[Symbol.asyncDispose]:m,updateText:h=>{s=i,i=h},stop:m}}}const k=10,D=(r=0)=>e=>`\x1B[${e+r}m`,H=(r=0)=>e=>`\x1B[${38+r};5;${e}m`,W=(r=0)=>(e,t,n)=>`\x1B[${38+r};2;${e};${t};${n}m`,c={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(c.modifier);const ue=Object.keys(c.color),me=Object.keys(c.bgColor);[...ue,...me];function de(){const r=new Map;for(const[e,t]of Object.entries(c)){for(const[n,i]of Object.entries(t))c[n]={open:`\x1B[${i[0]}m`,close:`\x1B[${i[1]}m`},t[n]=c[n],r.set(i[0],i[1]);Object.defineProperty(c,e,{value:t,enumerable:!1})}return Object.defineProperty(c,"codes",{value:r,enumerable:!1}),c.color.close="\x1B[39m",c.bgColor.close="\x1B[49m",c.color.ansi=D(),c.color.ansi256=H(),c.color.ansi16m=W(),c.bgColor.ansi=D(k),c.bgColor.ansi256=H(k),c.bgColor.ansi16m=W(k),Object.defineProperties(c,{rgbToAnsi256:{value(e,t,n){return e===t&&t===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5)},enumerable:!1},hexToRgb:{value(e){const t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[n]=t;n.length===3&&(n=[...n].map(s=>s+s).join(""));const i=Number.parseInt(n,16);return[i>>16&255,i>>8&255,i&255]},enumerable:!1},hexToAnsi256:{value:e=>c.rgbToAnsi256(...c.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,n,i;if(e>=232)t=((e-232)*10+8)/255,n=t,i=t;else{e-=16;const u=e%36;t=Math.floor(e/36)/5,n=Math.floor(u/6)/5,i=u%6/5}const s=Math.max(t,n,i)*2;if(s===0)return 30;let o=30+(Math.round(i)<<2|Math.round(n)<<1|Math.round(t));return s===2&&(o+=60),o},enumerable:!1},rgbToAnsi:{value:(e,t,n)=>c.ansi256ToAnsi(c.rgbToAnsi256(e,t,n)),enumerable:!1},hexToAnsi:{value:e=>c.ansi256ToAnsi(c.hexToAnsi256(e)),enumerable:!1}}),c}const f=de(),_=(()=>{if(!("navigator"in globalThis))return 0;if(globalThis.navigator.userAgentData){const r=navigator.userAgentData.brands.find(({brand:e})=>e==="Chromium");if(r&&r.version>93)return 3}return/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)?1:0})(),G=_!==0&&{level:_},ce={stdout:G,stderr:G};function he(r,e,t){let n=r.indexOf(e);if(n===-1)return r;const i=e.length;let s=0,o="";do o+=r.slice(s,n)+e+t,s=n+i,n=r.indexOf(e,s);while(n!==-1);return o+=r.slice(s),o}function pe(r,e,t,n){let i=0,s="";do{const o=r[n-1]==="\r";s+=r.slice(i,o?n-1:n)+e+(o?`\r
|
|
2
2
|
`:`
|
|
3
|
-
`)+t,
|
|
4
|
-
`,
|
|
5
|
-
`);return
|
|
6
|
-
${a.yellow("Available options")}:`);for(const[n,
|
|
3
|
+
`)+t,i=n+1,n=r.indexOf(`
|
|
4
|
+
`,i)}while(n!==-1);return s+=r.slice(i),s}const{stdout:U,stderr:Y}=ce,P=Symbol("GENERATOR"),v=Symbol("STYLER"),A=Symbol("IS_EMPTY"),z=["ansi","ansi","ansi256","ansi16m"],C=Object.create(null),ge=(r,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const t=U?U.level:0;r.level=e.level===void 0?t:e.level},fe=r=>{const e=(...t)=>t.join(" ");return ge(e,r),Object.setPrototypeOf(e,x.prototype),e};function x(r){return fe(r)}Object.setPrototypeOf(x.prototype,Function.prototype);for(const[r,e]of Object.entries(f))C[r]={get(){const t=S(this,B(e.open,e.close,this[v]),this[A]);return Object.defineProperty(this,r,{value:t}),t}};C.visible={get(){const r=S(this,this[v],!0);return Object.defineProperty(this,"visible",{value:r}),r}};const T=(r,e,t,...n)=>r==="rgb"?e==="ansi16m"?f[t].ansi16m(...n):e==="ansi256"?f[t].ansi256(f.rgbToAnsi256(...n)):f[t].ansi(f.rgbToAnsi(...n)):r==="hex"?T("rgb",e,t,...f.hexToRgb(...n)):f[t][r](...n),ye=["rgb","hex","ansi256"];for(const r of ye){C[r]={get(){const{level:t}=this;return function(...n){const i=B(T(r,z[t],"color",...n),f.color.close,this[v]);return S(this,i,this[A])}}};const e="bg"+r[0].toUpperCase()+r.slice(1);C[e]={get(){const{level:t}=this;return function(...n){const i=B(T(r,z[t],"bgColor",...n),f.bgColor.close,this[v]);return S(this,i,this[A])}}}}const be=Object.defineProperties(()=>{},{...C,level:{enumerable:!0,get(){return this[P].level},set(r){this[P].level=r}}}),B=(r,e,t)=>{let n,i;return t===void 0?(n=r,i=e):(n=t.openAll+r,i=e+t.closeAll),{open:r,close:e,openAll:n,closeAll:i,parent:t}},S=(r,e,t)=>{const n=(...i)=>we(n,i.length===1?""+i[0]:i.join(" "));return Object.setPrototypeOf(n,be),n[P]=r,n[v]=e,n[A]=t,n},we=(r,e)=>{if(r.level<=0||!e)return r[A]?"":e;let t=r[v];if(t===void 0)return e;const{openAll:n,closeAll:i}=t;if(e.includes("\x1B"))for(;t!==void 0;)e=he(e,t.close,t.open),t=t.parent;const s=e.indexOf(`
|
|
5
|
+
`);return s!==-1&&(e=pe(e,i,n,s)),n+e+i};Object.defineProperties(x.prototype,C);const a=x();x({level:Y?Y.level:0});class b extends Error{}function J(r){if(r==="string"||r==="number")return null;if(r==="boolean")return!1;if(Array.isArray(r)&&r.length===1){if(r[0]==="string")return[];if(r[0]==="number")return[]}throw new Error("Invalid option type: "+r)}function K(r){return typeof r=="string"||Array.isArray(r)?J(r):r.default!==void 0?r.default:J(r.type)}function y(r){return typeof r=="string"||Array.isArray(r)?{alias:[],default:K(r),description:"",required:!1,secret:!1,type:r,variadic:!1}:{alias:r.alias?Array.isArray(r.alias)?r.alias:[r.alias]:[],default:r.default??K(r.type),description:r.description??"",required:r.required??!1,secret:r.secret??!1,type:r.type,variadic:r.variadic??!1}}class E extends b{constructor(e,t={}){super(`Invalid option ${e} in not recognized`),this.option=e,this.optionsSchema=t}pretty(e){const t=Object.entries(this.optionsSchema);if(t.length>0){e.log(`
|
|
6
|
+
${a.yellow("Available options")}:`);for(const[n,i]of t){const s=y(i),o=typeof s.alias=="string"?[s.alias]:s.alias,u=Array.isArray(s.type)?`[${s.type[0]}]`:s.type,m=`--${n}${o.length>0?o.map(l=>`, -${l}`).join(""):""}`,h=" ".repeat(30-m.length);e.log(` ${a.green(m)} ${h} ${s.description||"\b"} ${a.white(`(${u})`)}`)}e.log("")}e.log(`${a.white.bgRed(" ERROR ")} Option ${a.bold.yellow(this.option)} is not recognized.`)}}class N extends b{constructor(e){super(`Argument "${e}" is required.`),this.argument=e}pretty(e){e.log(`${a.white.bgRed(" ERROR ")} Argument ${a.bold.yellow(this.argument)} is required.`)}}class X extends b{constructor(e){super(`Argument "${e}" is required.`),this.option=e}pretty(e){e.log(`${a.white.bgRed(" ERROR ")} Option ${a.bold.yellow(this.option)} is required.`)}}class ve extends b{constructor(e){let t=`Argument "${e.param}" value is invalid.`;e.reason?t+=` Reason: ${e.reason}`:t+=` Value: "${e.value}"`,super(t),this.param=e}pretty(e){e.log(` ${a.white.bgRed(" ERROR ")} Argument ${a.bold.yellow(this.param.param)} value is invalid. `),(this.param.value||this.param.reason)&&e.log(""),this.param.value&&e.log(` ${a.blue("Value")}: ${this.param.value}`),this.param.reason&&e.log(` ${a.yellow("Reason")}: ${this.param.reason}`)}}class F extends b{constructor(e){let t=`Option "${e.option}" value is invalid.`;e.reason?t+=` Reason: ${e.reason}`:t+=` Value: "${e.value}"`,super(t),this.param=e}pretty(e){e.log(` ${a.white.bgRed(" ERROR ")} Option ${a.bold.yellow(this.param.option)} value is invalid. `),(this.param.value||this.param.reason)&&e.log(""),this.param.value&&e.log(` ${a.blue("Value")}: ${this.param.value}`),this.param.reason&&e.log(` ${a.yellow("Reason")}: ${this.param.reason}`)}}class Z extends b{constructor(e){super(`Command "${e}" not found.`),this.command=e}pretty(e){e.log(`${a.bgRed(" ERROR ")} Command ${a.yellow(this.command)} not found.`)}}function O(r,e,t,n){if(r==null)return n??null;if(e==="string")return String(r);if(e==="number"){const i=Number(r);if(isNaN(i))throw new F({option:t,reason:`Expected a number, got "${r}"`});return i}if(e==="boolean")return typeof r=="boolean"?r:r==="true"||r==="1"?!0:r==="false"||r==="0"?!1:!!r;if(Array.isArray(e)){const i=e[0],s=Array.isArray(r)?r:[r];if(i==="string")return s.map(o=>String(o));if(i==="number")return s.map(o=>{const u=Number(o);if(isNaN(u))throw new F({option:t,reason:`Expected array of numbers, got "${o}" in array`});return u})}return r}class M{options;parsedOptions=null;arguments;parsedArguments=null;io;shouldPromptForMissingOptions=!0;constructor(e){this.options=e.options,this.arguments=e.arguments,this.io=e.io}init(e){const{_:t,...n}=ie(e);return this.validateUnknownOptions(n),this.parsedOptions=this.handleOptions(n),this.parsedArguments=this.handleArguments(t),{options:this.parsedOptions,arguments:this.parsedArguments}}async validate(){for(const e in this.options)if(y(this.options[e]).required&&(this.parsedOptions?.[e]===void 0||this.parsedOptions?.[e]===null))throw new X(e);for(const e in this.arguments){const t=y(this.arguments[e]),n=this.parsedArguments?.[e];if(t.required&&n==null){if(this.shouldPromptForMissingOptions){const i=await this.promptForArgument(e,t);if(i&&this.parsedArguments){this.parsedArguments[e]=O(i,t.type,e);continue}}throw new N(e)}if(t.required&&t.variadic&&Array.isArray(n)&&n.length===0){if(this.shouldPromptForMissingOptions){const i=await this.promptForArgument(e,t);if(i&&this.parsedArguments){this.parsedArguments[e]=O(i,t.type,e);continue}}throw new N(e)}}}option(e,t){if(!this.parsedOptions)throw new Error("Options have not been parsed yet. Call init() first.");return this.isEmptyValue(this.parsedOptions[e])&&t!==void 0?t:this.parsedOptions[e]}setOption(e,t){if(!this.parsedOptions)throw new Error("Options have not been parsed yet. Call init() first.");if(!(e in this.options))throw new E(e,this.options);this.parsedOptions[e]=t}argument(e,t){if(!this.parsedArguments)throw new Error("Arguments have not been parsed yet. Call init() first.");return this.isEmptyValue(this.parsedArguments[e])&&t!==void 0?t:this.parsedArguments[e]}setArgument(e,t){if(!this.parsedArguments)throw new Error("Arguments have not been parsed yet. Call init() first.");if(!(e in this.arguments))throw new E(e,this.arguments);this.parsedArguments[e]=t}isEmptyValue(e){return e==null||Array.isArray(e)&&e.length===0}validateUnknownOptions(e){const t=new Set;for(const n in this.options){t.add(n);const i=y(this.options[n]);for(const s of i.alias)t.add(s)}for(const n in e)if(!t.has(n))throw new E(n,this.options)}handleOptions(e){const t={};for(const n in this.options){const i=y(this.options[n]);t[n]=this.resolveOptionValue(n,i,e)}return t}handleArguments(e){const t={},n=[...e];for(const i in this.arguments){const s=y(this.arguments[i]);if(s.variadic){t[i]=this.handleVariadicArgument(i,s,n);continue}t[i]=this.resolveArgumentValue(i,s,n.shift())}return t}handleVariadicArgument(e,t,n){return n.length?O(n,t.type,e,t.default):t.default}resolveArgumentValue(e,t,n){return n===void 0?t.default:O(n,t.type,e,t.default)}resolveOptionValue(e,t,n){let i;const s=[e,...t.alias];for(const o of s)if(o in n){i=n[o];break}if(i===void 0){if(t.required)throw new F({option:e,reason:"Required option is missing"});return t.default}return O(i,t.type,e,t.default)}optionDefinitions(){const e={};for(const t in this.options)e[t]=y(this.options[t]);return e}argumentDefinitions(){const e={};for(const t in this.arguments)e[t]=y(this.arguments[t]);return e}availableOptions(){return Object.keys(this.options)}availableArguments(){return Object.keys(this.arguments)}disablePrompting(){return this.shouldPromptForMissingOptions=!1,this}async promptForArgument(e,t){if(!Array.isArray(t.type)&&!["string","number","secret"].includes(t.type))return null;let n=`${a.yellow.bold(e)} is required`;return t.description&&(n+=`: ${a.gray(`(${t.description})`)}`),n+=` ${a.green(`(${t.type}${t.variadic==!0?"[]":""})`)}
|
|
7
7
|
`,Array.isArray(t.type)?(n+=`Please provide one or more values, separated by commas:
|
|
8
|
-
`,await this.io.askForList(n,void 0,{separator:",",validate:
|
|
9
|
-
`),this.io.log(a.yellow("Usage:")),this.io.log(` ${this.command} ${o.length>0?o.map(([l])=>`<${l}>`).join(" "):"\b"} [options]`);const u=Math.max(...
|
|
10
|
-
${a.yellow("Arguments")}:`);for(const[l,d]of n){const p=
|
|
11
|
-
${a.yellow("Options")}:`);for(const l of
|
|
8
|
+
`,await this.io.askForList(n,void 0,{separator:",",validate:i=>{if(!i.length)return"Please enter at least one value";if(t.type[0]==="number"){for(const s of i.split(","))if(isNaN(Number(s)))return"Please enter only valid numbers"}return!0}})):await this.io.askForInput(n,void 0,{type:t.type==="number"?"number":t.secret?"password":"text",validate:i=>{if(i==null||typeof i=="string"&&!i.length)return"This value is required";if(t.type==="number"){const s=Number(i);if(isNaN(s))return"Please enter a valid number"}else if(t.type==="string"&&(typeof i!="string"||!i.length))return"Please enter a valid text";return!0}})}}function j(r){return new Array(r+5).join(" ")}class ee{type="boolean";option="help";alias=["h"];default=!1;description=`Display help for the given command. When no command is given display help for the ${a.green("list")} command`;async handler(){const e=this.parser.argumentDefinitions(),t=this.parser.optionDefinitions(),n=Object.entries(e),i=Object.entries(t),s=i.map(([l,d])=>{const p=Array.isArray(d.alias)?d.alias:d.alias?[d.alias]:[];return{name:l,...d,optionWithAlias:`--${l}${p.map(g=>`, -${g}`).join("")}`}}),o=n.filter(([,l])=>l.required);this.io.log(a.yellow("Description:")),this.io.log(` ${this.description}
|
|
9
|
+
`),this.io.log(a.yellow("Usage:")),this.io.log(` ${this.command} ${o.length>0?o.map(([l])=>`<${l}>`).join(" "):"\b"} [options]`);const u=Math.max(...s.map(l=>l.optionWithAlias.length),0),m=Math.max(...n.map(([l])=>l.length),0),h=m>u?m:u;if(n.length>0){this.io.log(`
|
|
10
|
+
${a.yellow("Arguments")}:`);for(const[l,d]of n){const p=j(h-l.length);let g=` ${a.green(l)} ${p} ${d.description??"\b"}`;if(d.default!==void 0&&!d.required){const re=(Array.isArray(d.type)?`[${d.type[0]}]`:d.type)==="array"||Array.isArray(d.type)?JSON.stringify(d.default):d.default;g+=` ${a.yellow(`[default: ${re}]`)}`}d.variadic&&(g+=` ${a.white("(variadic)")}`),this.io.log(g)}}if(i.length>0){this.io.log(`
|
|
11
|
+
${a.yellow("Options")}:`);for(const l of s){const d=j(h-l.optionWithAlias.length);let p=`${a.green(l.optionWithAlias)} ${d} ${l.description??"\b"}`;if(l.type){const g=Array.isArray(l.type)?`[${l.type[0]}]`:l.type;p+=` ${a.white(`(${g})`)}`}if(l.default!==void 0&&!l.required){const L=(Array.isArray(l.type)?`[${l.type[0]}]`:l.type)==="array"||Array.isArray(l.type)?JSON.stringify(l.default):l.default;p+=` ${a.yellow(`[default: ${L}]`)}`}this.io.log(p)}}if(this.commandsExamples.length>0){this.io.log(`
|
|
12
12
|
${a.yellow("Examples")}:`);let l=process.argv[0].split("/").pop();l==="node"&&(l+=" "+process.argv[1].split("/").pop());for(const[d,p]of this.commandsExamples.entries())d>0&&this.io.log(""),this.io.log(` ${p.description}
|
|
13
|
-
`),this.io.log(` ${a.green(`${l} ${p.command}`)}`)}return-1}}class
|
|
13
|
+
`),this.io.log(` ${a.green(`${l} ${p.command}`)}`)}return-1}}class ${_command;description;group;commandsExamples=[];get command(){return this._command}ctx;io;logger;parser;disablePromptingFlag=!1;_preHandler;_handler;tmp;defaultOptions(){return[new ee]}newCommandParser(e){return new M({io:e.io,options:e.options,arguments:e.arguments})}newCommandIO(e){return new I(e.logger)}constructor(e,t){this._command=e,this.description=t?.description??"",this.group=t?.group,this.tmp={options:t?.options??{},arguments:t?.arguments??{}};const n=this.defaultOptions();if(n.length>0)for(const i of n)this.tmp.options[i.option]=i}disablePrompting(){return this.disablePromptingFlag=!0,this}preHandler(e){return this._preHandler=e,this}handler(e){return this._handler=e,this}options(e){return this.tmp={options:{...this.tmp?.options??{},...e},arguments:this.tmp?.arguments??{}},this}arguments(e){return this.tmp={options:this.tmp?.options??{},arguments:{...this.tmp?.arguments??{},...e}},this}async run(e){if(!this._handler&&!this.handle)throw new Error(`No handler defined for command ${this.command||"(unknown)"}`);let t;if(this.ctx=e.ctx,this.logger=e.logger,this.io=this.newCommandIO({logger:e.logger}),e&&"args"in e){const s=this.tmp?.options??{};for(const o of this.defaultOptions())o.option in s||(s[o.option]=o);this.parser=this.newCommandParser({io:this.io,options:s,arguments:this.tmp?.arguments??{}}),t=this.parser.init(e.args);for(const o of this.defaultOptions())if(t.options[o.option]===!0){const u=await o.handler.call(this);if(u&&u!==0)return u}this.disablePromptingFlag&&this.parser.disablePrompting(),await this.parser.validate()}else t={options:e.options,arguments:e.arguments};const n=this.preHandle?await this.preHandle():null;if(n&&n!==0)return n;if(!this._handler&&this.handle)this._handler=this.handle.bind(this);else if(!this._handler)throw new Error(`No handler defined for command ${this.command||"(unknown)"}`);return await this._handler(e.ctx,t)??0}}class R extends M{command;constructor(e){const t=R.parseSignature(e.signature,e.helperDefinitions,e.defaultOptions);super({io:e.io,options:t.options,arguments:t.arguments}),this.command=t.command}static parseSignature(e,t,n){const[i,...s]=e.split(/\{(.*?)\}/g).map(m=>m.trim()).filter(Boolean),o={},u={};for(const m of s){const{name:h,isOption:l,definition:d}=R.parseParamSignature(m,t);l?o[h]=d:u[h]=d}for(const m of n)o[m.option]={type:m.type,required:m.required,alias:m.alias,variadic:m.variadic??!1,description:m.description,default:m.default??null};return{command:i,options:o,arguments:u}}static parseParamSignature(e,t){let n=e,i=!1;const s={required:!0,type:"string",description:void 0,default:null,variadic:!1};if(n.includes(":")){const[o,u]=n.split(":");n=o.trim(),s.description=u.trim()}if(n.includes("=")){const[o,u]=n.split("=");n=o.trim(),s.default=u.trim(),s.required=!1,typeof s.default=="string"&&!s.default.length?s.default=null:s.default==="true"?(s.default=!0,s.type="boolean"):s.default==="false"&&(s.default=!1,s.type="boolean")}else n.startsWith("--")&&(s.required=!1,s.default=!1,s.type="boolean");if(n.includes("|")){const[o,...u]=n.split("|");n=o.trim(),s.alias=u.map(m=>m.trim())}return n.startsWith("--")&&(i=!0,n=n.slice(2)),s.default==="*"&&(s.default=[],s.type=["string"]),n.endsWith("?")&&(s.required=!1,n=n.slice(0,-1)),n.endsWith("*")&&(s.type=["string"],s.variadic=!0,s.default=[],n=n.slice(0,-1)),s.description=s.description??t[n]??t[`--${n}`],{name:n,isOption:i,definition:s}}}class Ce extends ${helperDefinitions={};get command(){return this.parser?this.parser.command:this.signature.split(" ")[0]}newCommandParser(e){return new R({io:e.io,signature:this.signature,helperDefinitions:this.helperDefinitions,defaultOptions:this.defaultOptions()})}constructor(){super("")}option(e,t=null){return this.parser.option(e,t)}argument(e,t=null){return this.parser.argument(e,t)}async askForConfirmation(...e){return this.io.askForConfirmation(...e)}async askForInput(...e){return this.io.askForInput(...e)}async askForSelect(...e){return this.io.askForSelect(...e)}newLoader(...e){return this.io.newLoader(...e)}}class q{level;constructor(e={}){this.level=e.level??"info"}shouldLog(e){const t=["debug","info","warn","error"],n=t.indexOf(this.level);return t.indexOf(e)>=n}setLevel(e){this.level=e}getLevel(){return this.level}log(...e){console.log(...e)}info(...e){this.shouldLog("info")&&console.log(...e)}warn(...e){this.shouldLog("warn")&&console.warn(...e)}error(...e){this.shouldLog("error")&&console.error(...e)}debug(...e){this.shouldLog("debug")&&console.log(...e)}}class te{commands={};io;logger;get CommandIOClass(){return I}constructor(e){this.logger=e??new q,this.io=new this.CommandIOClass(this.logger)}getAvailableCommands(){return Object.keys(this.commands)}getCommands(){return Object.values(this.commands)}importFile=async e=>(await import(e)).default;commandResolver=async e=>{let t=await this.importFile(e);if(!t)throw new Error(`The command at path ${e} does not have a default export.`);return t&&typeof t=="object"&&"default"in t&&(t=t.default),typeof t=="function"?new t:t instanceof $?t:null};withCommandResolver(e){return this.commandResolver=e,this}withFileImporter(e){return this.importFile=e,this}registerCommand(e,t=!1){const n=e.command;if(!n)throw new Error("Command signature is invalid, it must have a command name.");if(!t&&this.commands[n])throw new Error(`Command ${n} already registered.`);this.commands[n]=e}async loadCommandsPath(e){for await(const t of this.listCommandsFiles(e))try{const n=await this.commandResolver(t);n instanceof $&&this.registerCommand(n)}catch(n){throw new Error(`Command ${t} failed to load. ${n}`,{cause:n})}}async runCommand(e,t,...n){const i=typeof t=="string"?this.commands[t]:t,s=typeof t=="string"?t:i.command;if(!i){const o=await this.suggestCommand(s);return o?await this.runCommand(e,o,...n):1}return await i.run({ctx:e,logger:this.logger,args:n})??0}async suggestCommand(e){const t=this.getAvailableCommands(),{bestMatch:n,bestMatchIndex:i,ratings:s}=le.findBestMatch(e,t),o=s.filter(u=>u.rating>.3).map(u=>u.target);if(n.rating>0&&o.length<=1||n.rating>.7&&o.length>1){const u=t[i];return await this.askRunSimilarCommand(e,u)?u:null}if(o.length){this.io.error(`${a.bgRed(" ERROR ")} Command ${a.yellow(e)} not found.
|
|
14
14
|
`);const u=await this.io.askForSelect(a.green("Did you mean to run one of these commands instead?"),o);if(u)return u}throw new Z(e)}async askRunSimilarCommand(e,t){return this.io.error(`${a.bgRed(" ERROR ")} Command ${a.yellow(e)} not found.
|
|
15
|
-
`),this.io.askForConfirmation(`${a.green(`Do you want to run ${a.yellow(t)} instead?`)} `)}async*listCommandsFiles(e){const t=ae.readdirSync(e,{withFileTypes:!0});for(const n of t){const
|
|
15
|
+
`),this.io.askForConfirmation(`${a.green(`Do you want to run ${a.yellow(t)} instead?`)} `)}async*listCommandsFiles(e){const t=ae.readdirSync(e,{withFileTypes:!0});for(const n of t){const i=V.resolve(e,n.name);if(n.isDirectory())yield*this.listCommandsFiles(V.resolve(e,n.name));else{if(!i.endsWith(".ts")&&!i.endsWith(".js")&&!i.endsWith(".mjs")&&!i.endsWith(".cjs"))continue;yield i}}}}class ne{logger;constructor(e){this.logger=e}handle(e){if(e instanceof b)return e.pretty(this.logger),-1;throw e}}class Oe extends ${constructor(e){super("help",{description:a.bold("Show help information about the CLI and its commands")}),this.opts=e}async handle(){const e=this.opts.commandRegistry.getCommands(),t=this.opts.cliName??"Bob CLI",n=this.opts.cliVersion??"0.0.0",i=(await Promise.resolve().then(()=>require("./package-6GoPiEev.cjs")))?.default?.version??"0.0.0";this.io.log(`${t} ${a.green(n)} (core: ${a.yellow(i)})
|
|
16
16
|
|
|
17
17
|
${a.yellow("Usage")}:
|
|
18
18
|
command [options] [arguments]
|
|
19
19
|
|
|
20
20
|
${a.yellow("Available commands")}:
|
|
21
|
-
`);const
|
|
21
|
+
`);const s=Math.max(...e.map(m=>m.command.length))??0,o={};for(const m of e){const h=m.group??m.command.split(":")[0];o[h]||(o[h]=[]),o[h].push(m)}const u=Object.entries(o).sort(([m],[h])=>m.toLowerCase().localeCompare(h.toLowerCase())).sort(([,m],[,h])=>m.length-h.length);for(const[m,h]of u){const l=h.length>1;l&&this.io.log(a.yellow(`${m}:`));const d=h.sort((p,g)=>p.command.toLowerCase().localeCompare(g.command.toLowerCase()));for(const p of d){let g=j(s-p.command.length);l&&(g=g.slice(2)),this.io.log(`${l?" ":""}${a.green(p.command)} ${g} ${p.description}`)}}}}class Ae{ctx;logger;commandRegistry;exceptionHandler;helpCommand;newCommandRegistry(e){return new te(e.logger)}newHelpCommand(e){return new Oe(e)}newExceptionHandler(e){return new ne(e.logger)}constructor(e={}){this.ctx=e.ctx,this.logger=e.logger??new q,this.commandRegistry=this.newCommandRegistry({logger:this.logger}),this.exceptionHandler=this.newExceptionHandler({logger:this.logger}),this.helpCommand=this.newHelpCommand({cliName:e.name,cliVersion:e.version,commandRegistry:this.commandRegistry})}withCommandResolver(e){return this.commandRegistry.withCommandResolver(e),this}withFileImporter(e){return this.commandRegistry.withFileImporter(e),this}async withCommands(...e){for(const t of e)typeof t=="string"?await this.commandRegistry.loadCommandsPath(t):typeof t=="function"?this.registerCommand(new t):this.registerCommand(t)}async runCommand(e,...t){return e?await this.commandRegistry.runCommand(this.ctx??{},e,...t).catch(this.exceptionHandler.handle.bind(this.exceptionHandler)):await this.runHelpCommand()}async runHelpCommand(){return await this.runCommand(this.helpCommand)}registerCommand(e){this.commandRegistry.registerCommand(e)}}exports.BadCommandOption=F;exports.BadCommandParameter=ve;exports.BobError=b;exports.Cli=Ae;exports.Command=$;exports.CommandIO=I;exports.CommandNotFoundError=Z;exports.CommandParser=M;exports.CommandRegistry=te;exports.CommandSignatureParser=R;exports.CommandWithSignature=Ce;exports.ExceptionHandler=ne;exports.HelpOption=ee;exports.InvalidOption=E;exports.Logger=q;exports.MissingRequiredArgumentValue=N;exports.MissingRequiredOptionValue=X;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="bob-core",t="2.0.0-beta.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="bob-core",t="2.0.0-beta.13",s="BOB Core",i="module",n=!1,r=["dist/**"],o={".":{import:"./dist/esm/index.js",require:"./dist/cjs/index.js"}},c={"*":{"*":["./dist/cjs/*.d.ts"]}},p={start:"node -r @swc-node/register debug/main.ts",build:"rimraf ./dist && vite build",typecheck:"tsc --noEmit",prepack:"npm run build",test:"vitest run",lint:"eslint .","lint:fix":"eslint . --fix"},d="Léo Hubert",l="ISC",a={"@eslint/js":"^9.37.0","@faker-js/faker":"^10.0.0","@swc-node/register":"^1.11.1","@trivago/prettier-plugin-sort-imports":"^5.2.2","@types/minimist":"^1.2.5","@types/node":"^20.14.5","@types/prompts":"^2.4.9","@types/string-similarity":"^4.0.2","@vitest/coverage-v8":"^3.2.4",eslint:"^9.37.0","eslint-config-prettier":"^10.1.8","eslint-plugin-prettier":"^5.5.4",prettier:"^3.6.2",rimraf:"^6.0.1",tsx:"^4.20.6",typescript:"^5.7.3","typescript-eslint":"^8.46.0",vite:"^7.1.6","vite-plugin-dts":"^4.5.4",vitest:"^3.2.4"},m={chalk:"^5.6.2",minimist:"^1.2.8",prompts:"^2.4.2","string-similarity":"^4.0.4"},u={name:e,version:t,description:s,type:i,sideEffects:n,files:r,exports:o,typesVersions:c,scripts:p,author:d,license:l,devDependencies:a,dependencies:m};exports.author=d;exports.default=u;exports.dependencies=m;exports.description=s;exports.devDependencies=a;exports.exports=o;exports.files=r;exports.license=l;exports.name=e;exports.scripts=p;exports.sideEffects=n;exports.type=i;exports.typesVersions=c;exports.version=t;
|
|
@@ -21,7 +21,7 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
21
21
|
* Parses raw command-line arguments into structured options and arguments
|
|
22
22
|
* @param args - Raw command line arguments (typically from process.argv.slice(2))
|
|
23
23
|
* @returns Object containing parsed options and arguments
|
|
24
|
-
* @throws {InvalidOption} If an
|
|
24
|
+
* @throws {InvalidOption} If an naan option is provided
|
|
25
25
|
* @throws {BadCommandOption} If a value cannot be converted to the expected type
|
|
26
26
|
*/
|
|
27
27
|
init(args: string[]): {
|
|
@@ -36,19 +36,27 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
36
36
|
/**
|
|
37
37
|
* Retrieves a parsed option value by name
|
|
38
38
|
* @param name - The option name
|
|
39
|
+
* @param defaultValue - Optional default value if option is not set
|
|
39
40
|
* @returns The typed option value
|
|
40
41
|
* @throws {Error} If init() has not been called yet
|
|
41
42
|
*/
|
|
42
|
-
option<OptsName extends keyof Options>(name: OptsName): OptionReturnType<Options[OptsName]>;
|
|
43
|
+
option<OptsName extends keyof Options>(name: OptsName, defaultValue?: OptionReturnType<Options[OptsName]>): OptionReturnType<Options[OptsName]>;
|
|
43
44
|
setOption<OptsName extends keyof Options>(name: OptsName, value: OptionReturnType<Options[OptsName]>): void;
|
|
44
45
|
/**
|
|
45
46
|
* Retrieves a parsed argument value by name
|
|
46
47
|
* @param name - The argument name
|
|
48
|
+
* @param defaultValue - Optional default value if argument is not set
|
|
47
49
|
* @returns The typed argument value
|
|
48
50
|
* @throws {Error} If init() has not been called yet
|
|
49
51
|
*/
|
|
50
|
-
argument<ArgName extends keyof Arguments>(name: ArgName): OptionReturnType<Arguments[ArgName]>;
|
|
52
|
+
argument<ArgName extends keyof Arguments>(name: ArgName, defaultValue?: OptionReturnType<Arguments[ArgName]>): OptionReturnType<Arguments[ArgName]>;
|
|
51
53
|
setArgument<ArgName extends keyof Arguments>(name: ArgName, value: OptionReturnType<Arguments[ArgName]>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a value should be considered "empty" for default value purposes
|
|
56
|
+
* @param value - The value to check
|
|
57
|
+
* @returns true if the value is null, undefined, or an empty array
|
|
58
|
+
*/
|
|
59
|
+
private isEmptyValue;
|
|
52
60
|
/**
|
|
53
61
|
* Validates that all provided options are recognized
|
|
54
62
|
* @throws {InvalidOption} If an unknown option is found
|
|
@@ -8,8 +8,8 @@ export declare abstract class CommandWithSignature<C extends ContextDefinition =
|
|
|
8
8
|
protected helperDefinitions: {
|
|
9
9
|
[key: string]: string;
|
|
10
10
|
};
|
|
11
|
+
protected parser: CommandSignatureParser<Opts, Args>;
|
|
11
12
|
get command(): string;
|
|
12
|
-
parser: CommandSignatureParser<Opts, Args>;
|
|
13
13
|
protected newCommandParser(opts: {
|
|
14
14
|
io: CommandIO;
|
|
15
15
|
options: Opts;
|
package/dist/esm/index.js
CHANGED
|
@@ -37,43 +37,43 @@ class z {
|
|
|
37
37
|
initial: t ?? !1
|
|
38
38
|
})).value;
|
|
39
39
|
}
|
|
40
|
-
async askForInput(e, t,
|
|
40
|
+
async askForInput(e, t, r) {
|
|
41
41
|
return (await b({
|
|
42
42
|
type: "text",
|
|
43
43
|
name: "value",
|
|
44
44
|
message: e,
|
|
45
45
|
initial: t,
|
|
46
|
-
...
|
|
46
|
+
...r
|
|
47
47
|
}))?.value ?? null;
|
|
48
48
|
}
|
|
49
|
-
async askForDate(e, t,
|
|
49
|
+
async askForDate(e, t, r) {
|
|
50
50
|
return (await b({
|
|
51
51
|
type: "date",
|
|
52
52
|
name: "value",
|
|
53
53
|
message: e,
|
|
54
54
|
initial: t,
|
|
55
|
-
...
|
|
55
|
+
...r
|
|
56
56
|
}))?.value ?? null;
|
|
57
57
|
}
|
|
58
|
-
async askForList(e, t,
|
|
58
|
+
async askForList(e, t, r) {
|
|
59
59
|
return (await b({
|
|
60
60
|
type: "list",
|
|
61
61
|
name: "value",
|
|
62
62
|
message: e,
|
|
63
63
|
initial: t,
|
|
64
|
-
...
|
|
64
|
+
...r
|
|
65
65
|
}))?.value ?? null;
|
|
66
66
|
}
|
|
67
|
-
async askForToggle(e, t,
|
|
67
|
+
async askForToggle(e, t, r) {
|
|
68
68
|
return (await b({
|
|
69
69
|
type: "toggle",
|
|
70
70
|
name: "value",
|
|
71
71
|
message: e,
|
|
72
72
|
initial: t,
|
|
73
|
-
...
|
|
73
|
+
...r
|
|
74
74
|
}))?.value ?? null;
|
|
75
75
|
}
|
|
76
|
-
async askForSelect(e, t,
|
|
76
|
+
async askForSelect(e, t, r) {
|
|
77
77
|
if (t.length === 0)
|
|
78
78
|
throw new Error("No options provided");
|
|
79
79
|
const s = [];
|
|
@@ -84,14 +84,14 @@ class z {
|
|
|
84
84
|
name: "value",
|
|
85
85
|
message: e,
|
|
86
86
|
choices: s,
|
|
87
|
-
...
|
|
87
|
+
...r
|
|
88
88
|
}))?.value ?? null;
|
|
89
89
|
}
|
|
90
|
-
newLoader(e = "", t = ["⠙", "⠘", "⠰", "⠴", "⠤", "⠦", "⠆", "⠃", "⠋", "⠉"],
|
|
90
|
+
newLoader(e = "", t = ["⠙", "⠘", "⠰", "⠴", "⠤", "⠦", "⠆", "⠃", "⠋", "⠉"], r = 100) {
|
|
91
91
|
let s = e, i = null, o = 0;
|
|
92
92
|
const u = setInterval(function() {
|
|
93
93
|
i && (process.stdout.write(new TextEncoder().encode("\r" + " ".repeat(i.length + 5) + "\r")), i = null), process.stdout.write(new TextEncoder().encode("\r" + t[o++] + " " + s)), o = o % t.length;
|
|
94
|
-
},
|
|
94
|
+
}, r), m = () => {
|
|
95
95
|
clearInterval(u), process.stdout.write(new TextEncoder().encode("\r" + " ".repeat(s.length + 5) + "\r"));
|
|
96
96
|
};
|
|
97
97
|
return {
|
|
@@ -104,7 +104,7 @@ class z {
|
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
const
|
|
107
|
+
const F = 10, L = (n = 0) => (e) => `\x1B[${e + n}m`, M = (n = 0) => (e) => `\x1B[${38 + n};5;${e}m`, V = (n = 0) => (e, t, r) => `\x1B[${38 + n};2;${e};${t};${r}m`, c = {
|
|
108
108
|
modifier: {
|
|
109
109
|
reset: [0, 0],
|
|
110
110
|
// 21 isn't widely supported and 22 does the same thing
|
|
@@ -165,28 +165,28 @@ const E = 10, L = (r = 0) => (e) => `\x1B[${e + r}m`, M = (r = 0) => (e) => `\x1
|
|
|
165
165
|
}
|
|
166
166
|
};
|
|
167
167
|
Object.keys(c.modifier);
|
|
168
|
-
const te = Object.keys(c.color),
|
|
169
|
-
[...te, ...
|
|
170
|
-
function
|
|
171
|
-
const
|
|
168
|
+
const te = Object.keys(c.color), re = Object.keys(c.bgColor);
|
|
169
|
+
[...te, ...re];
|
|
170
|
+
function ne() {
|
|
171
|
+
const n = /* @__PURE__ */ new Map();
|
|
172
172
|
for (const [e, t] of Object.entries(c)) {
|
|
173
|
-
for (const [
|
|
174
|
-
c[
|
|
173
|
+
for (const [r, s] of Object.entries(t))
|
|
174
|
+
c[r] = {
|
|
175
175
|
open: `\x1B[${s[0]}m`,
|
|
176
176
|
close: `\x1B[${s[1]}m`
|
|
177
|
-
}, t[
|
|
177
|
+
}, t[r] = c[r], n.set(s[0], s[1]);
|
|
178
178
|
Object.defineProperty(c, e, {
|
|
179
179
|
value: t,
|
|
180
180
|
enumerable: !1
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
return Object.defineProperty(c, "codes", {
|
|
184
|
-
value:
|
|
184
|
+
value: n,
|
|
185
185
|
enumerable: !1
|
|
186
|
-
}), c.color.close = "\x1B[39m", c.bgColor.close = "\x1B[49m", c.color.ansi = L(), c.color.ansi256 = M(), c.color.ansi16m =
|
|
186
|
+
}), c.color.close = "\x1B[39m", c.bgColor.close = "\x1B[49m", c.color.ansi = L(), c.color.ansi256 = M(), c.color.ansi16m = V(), c.bgColor.ansi = L(F), c.bgColor.ansi256 = M(F), c.bgColor.ansi16m = V(F), Object.defineProperties(c, {
|
|
187
187
|
rgbToAnsi256: {
|
|
188
|
-
value(e, t,
|
|
189
|
-
return e === t && t ===
|
|
188
|
+
value(e, t, r) {
|
|
189
|
+
return e === t && t === r ? e < 8 ? 16 : e > 248 ? 231 : Math.round((e - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(e / 255 * 5) + 6 * Math.round(t / 255 * 5) + Math.round(r / 255 * 5);
|
|
190
190
|
},
|
|
191
191
|
enumerable: !1
|
|
192
192
|
},
|
|
@@ -195,9 +195,9 @@ function re() {
|
|
|
195
195
|
const t = /[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));
|
|
196
196
|
if (!t)
|
|
197
197
|
return [0, 0, 0];
|
|
198
|
-
let [
|
|
199
|
-
|
|
200
|
-
const s = Number.parseInt(
|
|
198
|
+
let [r] = t;
|
|
199
|
+
r.length === 3 && (r = [...r].map((i) => i + i).join(""));
|
|
200
|
+
const s = Number.parseInt(r, 16);
|
|
201
201
|
return [
|
|
202
202
|
/* eslint-disable no-bitwise */
|
|
203
203
|
s >> 16 & 255,
|
|
@@ -218,24 +218,24 @@ function re() {
|
|
|
218
218
|
return 30 + e;
|
|
219
219
|
if (e < 16)
|
|
220
220
|
return 90 + (e - 8);
|
|
221
|
-
let t,
|
|
221
|
+
let t, r, s;
|
|
222
222
|
if (e >= 232)
|
|
223
|
-
t = ((e - 232) * 10 + 8) / 255,
|
|
223
|
+
t = ((e - 232) * 10 + 8) / 255, r = t, s = t;
|
|
224
224
|
else {
|
|
225
225
|
e -= 16;
|
|
226
226
|
const u = e % 36;
|
|
227
|
-
t = Math.floor(e / 36) / 5,
|
|
227
|
+
t = Math.floor(e / 36) / 5, r = Math.floor(u / 6) / 5, s = u % 6 / 5;
|
|
228
228
|
}
|
|
229
|
-
const i = Math.max(t,
|
|
229
|
+
const i = Math.max(t, r, s) * 2;
|
|
230
230
|
if (i === 0)
|
|
231
231
|
return 30;
|
|
232
|
-
let o = 30 + (Math.round(s) << 2 | Math.round(
|
|
232
|
+
let o = 30 + (Math.round(s) << 2 | Math.round(r) << 1 | Math.round(t));
|
|
233
233
|
return i === 2 && (o += 60), o;
|
|
234
234
|
},
|
|
235
235
|
enumerable: !1
|
|
236
236
|
},
|
|
237
237
|
rgbToAnsi: {
|
|
238
|
-
value: (e, t,
|
|
238
|
+
value: (e, t, r) => c.ansi256ToAnsi(c.rgbToAnsi256(e, t, r)),
|
|
239
239
|
enumerable: !1
|
|
240
240
|
},
|
|
241
241
|
hexToAnsi: {
|
|
@@ -244,92 +244,92 @@ function re() {
|
|
|
244
244
|
}
|
|
245
245
|
}), c;
|
|
246
246
|
}
|
|
247
|
-
const f =
|
|
247
|
+
const f = ne(), q = (() => {
|
|
248
248
|
if (!("navigator" in globalThis))
|
|
249
249
|
return 0;
|
|
250
250
|
if (globalThis.navigator.userAgentData) {
|
|
251
|
-
const
|
|
252
|
-
if (
|
|
251
|
+
const n = navigator.userAgentData.brands.find(({ brand: e }) => e === "Chromium");
|
|
252
|
+
if (n && n.version > 93)
|
|
253
253
|
return 3;
|
|
254
254
|
}
|
|
255
255
|
return /\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent) ? 1 : 0;
|
|
256
|
-
})(),
|
|
257
|
-
level:
|
|
256
|
+
})(), D = q !== 0 && {
|
|
257
|
+
level: q
|
|
258
258
|
}, se = {
|
|
259
|
-
stdout:
|
|
260
|
-
stderr:
|
|
259
|
+
stdout: D,
|
|
260
|
+
stderr: D
|
|
261
261
|
};
|
|
262
|
-
function ie(
|
|
263
|
-
let
|
|
264
|
-
if (
|
|
265
|
-
return
|
|
262
|
+
function ie(n, e, t) {
|
|
263
|
+
let r = n.indexOf(e);
|
|
264
|
+
if (r === -1)
|
|
265
|
+
return n;
|
|
266
266
|
const s = e.length;
|
|
267
267
|
let i = 0, o = "";
|
|
268
268
|
do
|
|
269
|
-
o +=
|
|
270
|
-
while (
|
|
271
|
-
return o +=
|
|
269
|
+
o += n.slice(i, r) + e + t, i = r + s, r = n.indexOf(e, i);
|
|
270
|
+
while (r !== -1);
|
|
271
|
+
return o += n.slice(i), o;
|
|
272
272
|
}
|
|
273
|
-
function oe(
|
|
273
|
+
function oe(n, e, t, r) {
|
|
274
274
|
let s = 0, i = "";
|
|
275
275
|
do {
|
|
276
|
-
const o = r
|
|
277
|
-
i +=
|
|
276
|
+
const o = n[r - 1] === "\r";
|
|
277
|
+
i += n.slice(s, o ? r - 1 : r) + e + (o ? `\r
|
|
278
278
|
` : `
|
|
279
|
-
`) + t, s =
|
|
279
|
+
`) + t, s = r + 1, r = n.indexOf(`
|
|
280
280
|
`, s);
|
|
281
|
-
} while (
|
|
282
|
-
return i +=
|
|
281
|
+
} while (r !== -1);
|
|
282
|
+
return i += n.slice(s), i;
|
|
283
283
|
}
|
|
284
|
-
const { stdout: H, stderr: W } = se, S = Symbol("GENERATOR"),
|
|
284
|
+
const { stdout: H, stderr: W } = se, S = Symbol("GENERATOR"), v = Symbol("STYLER"), C = Symbol("IS_EMPTY"), G = [
|
|
285
285
|
"ansi",
|
|
286
286
|
"ansi",
|
|
287
287
|
"ansi256",
|
|
288
288
|
"ansi16m"
|
|
289
|
-
], A = /* @__PURE__ */ Object.create(null), ae = (
|
|
289
|
+
], A = /* @__PURE__ */ Object.create(null), ae = (n, e = {}) => {
|
|
290
290
|
if (e.level && !(Number.isInteger(e.level) && e.level >= 0 && e.level <= 3))
|
|
291
291
|
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
292
292
|
const t = H ? H.level : 0;
|
|
293
|
-
|
|
294
|
-
}, le = (
|
|
293
|
+
n.level = e.level === void 0 ? t : e.level;
|
|
294
|
+
}, le = (n) => {
|
|
295
295
|
const e = (...t) => t.join(" ");
|
|
296
|
-
return ae(e,
|
|
296
|
+
return ae(e, n), Object.setPrototypeOf(e, O.prototype), e;
|
|
297
297
|
};
|
|
298
|
-
function
|
|
299
|
-
return le(
|
|
298
|
+
function O(n) {
|
|
299
|
+
return le(n);
|
|
300
300
|
}
|
|
301
|
-
Object.setPrototypeOf(
|
|
302
|
-
for (const [
|
|
303
|
-
A[
|
|
301
|
+
Object.setPrototypeOf(O.prototype, Function.prototype);
|
|
302
|
+
for (const [n, e] of Object.entries(f))
|
|
303
|
+
A[n] = {
|
|
304
304
|
get() {
|
|
305
|
-
const t =
|
|
306
|
-
return Object.defineProperty(this,
|
|
305
|
+
const t = R(this, N(e.open, e.close, this[v]), this[C]);
|
|
306
|
+
return Object.defineProperty(this, n, { value: t }), t;
|
|
307
307
|
}
|
|
308
308
|
};
|
|
309
309
|
A.visible = {
|
|
310
310
|
get() {
|
|
311
|
-
const
|
|
312
|
-
return Object.defineProperty(this, "visible", { value:
|
|
311
|
+
const n = R(this, this[v], !0);
|
|
312
|
+
return Object.defineProperty(this, "visible", { value: n }), n;
|
|
313
313
|
}
|
|
314
314
|
};
|
|
315
|
-
const T = (
|
|
316
|
-
for (const
|
|
317
|
-
A[
|
|
315
|
+
const T = (n, e, t, ...r) => n === "rgb" ? e === "ansi16m" ? f[t].ansi16m(...r) : e === "ansi256" ? f[t].ansi256(f.rgbToAnsi256(...r)) : f[t].ansi(f.rgbToAnsi(...r)) : n === "hex" ? T("rgb", e, t, ...f.hexToRgb(...r)) : f[t][n](...r), ue = ["rgb", "hex", "ansi256"];
|
|
316
|
+
for (const n of ue) {
|
|
317
|
+
A[n] = {
|
|
318
318
|
get() {
|
|
319
319
|
const { level: t } = this;
|
|
320
|
-
return function(...
|
|
321
|
-
const s = N(T(
|
|
322
|
-
return
|
|
320
|
+
return function(...r) {
|
|
321
|
+
const s = N(T(n, G[t], "color", ...r), f.color.close, this[v]);
|
|
322
|
+
return R(this, s, this[C]);
|
|
323
323
|
};
|
|
324
324
|
}
|
|
325
325
|
};
|
|
326
|
-
const e = "bg" +
|
|
326
|
+
const e = "bg" + n[0].toUpperCase() + n.slice(1);
|
|
327
327
|
A[e] = {
|
|
328
328
|
get() {
|
|
329
329
|
const { level: t } = this;
|
|
330
|
-
return function(...
|
|
331
|
-
const s = N(T(
|
|
332
|
-
return
|
|
330
|
+
return function(...r) {
|
|
331
|
+
const s = N(T(n, G[t], "bgColor", ...r), f.bgColor.close, this[v]);
|
|
332
|
+
return R(this, s, this[C]);
|
|
333
333
|
};
|
|
334
334
|
}
|
|
335
335
|
};
|
|
@@ -342,70 +342,70 @@ const me = Object.defineProperties(() => {
|
|
|
342
342
|
get() {
|
|
343
343
|
return this[S].level;
|
|
344
344
|
},
|
|
345
|
-
set(
|
|
346
|
-
this[S].level =
|
|
345
|
+
set(n) {
|
|
346
|
+
this[S].level = n;
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
|
-
}), N = (
|
|
350
|
-
let
|
|
351
|
-
return t === void 0 ? (
|
|
352
|
-
open:
|
|
349
|
+
}), N = (n, e, t) => {
|
|
350
|
+
let r, s;
|
|
351
|
+
return t === void 0 ? (r = n, s = e) : (r = t.openAll + n, s = e + t.closeAll), {
|
|
352
|
+
open: n,
|
|
353
353
|
close: e,
|
|
354
|
-
openAll:
|
|
354
|
+
openAll: r,
|
|
355
355
|
closeAll: s,
|
|
356
356
|
parent: t
|
|
357
357
|
};
|
|
358
|
-
},
|
|
359
|
-
const
|
|
360
|
-
return Object.setPrototypeOf(
|
|
361
|
-
}, de = (
|
|
362
|
-
if (
|
|
363
|
-
return
|
|
364
|
-
let t =
|
|
358
|
+
}, R = (n, e, t) => {
|
|
359
|
+
const r = (...s) => de(r, s.length === 1 ? "" + s[0] : s.join(" "));
|
|
360
|
+
return Object.setPrototypeOf(r, me), r[S] = n, r[v] = e, r[C] = t, r;
|
|
361
|
+
}, de = (n, e) => {
|
|
362
|
+
if (n.level <= 0 || !e)
|
|
363
|
+
return n[C] ? "" : e;
|
|
364
|
+
let t = n[v];
|
|
365
365
|
if (t === void 0)
|
|
366
366
|
return e;
|
|
367
|
-
const { openAll:
|
|
367
|
+
const { openAll: r, closeAll: s } = t;
|
|
368
368
|
if (e.includes("\x1B"))
|
|
369
369
|
for (; t !== void 0; )
|
|
370
370
|
e = ie(e, t.close, t.open), t = t.parent;
|
|
371
371
|
const i = e.indexOf(`
|
|
372
372
|
`);
|
|
373
|
-
return i !== -1 && (e = oe(e, s,
|
|
373
|
+
return i !== -1 && (e = oe(e, s, r, i)), r + e + s;
|
|
374
374
|
};
|
|
375
|
-
Object.defineProperties(
|
|
376
|
-
const a =
|
|
377
|
-
|
|
375
|
+
Object.defineProperties(O.prototype, A);
|
|
376
|
+
const a = O();
|
|
377
|
+
O({ level: W ? W.level : 0 });
|
|
378
378
|
class w extends Error {
|
|
379
379
|
}
|
|
380
|
-
function _(
|
|
381
|
-
if (
|
|
382
|
-
if (
|
|
383
|
-
if (Array.isArray(
|
|
384
|
-
if (
|
|
385
|
-
if (
|
|
386
|
-
}
|
|
387
|
-
throw new Error("Invalid option type: " +
|
|
380
|
+
function _(n) {
|
|
381
|
+
if (n === "string" || n === "number") return null;
|
|
382
|
+
if (n === "boolean") return !1;
|
|
383
|
+
if (Array.isArray(n) && n.length === 1) {
|
|
384
|
+
if (n[0] === "string") return [];
|
|
385
|
+
if (n[0] === "number") return [];
|
|
386
|
+
}
|
|
387
|
+
throw new Error("Invalid option type: " + n);
|
|
388
388
|
}
|
|
389
|
-
function U(
|
|
390
|
-
return
|
|
389
|
+
function U(n) {
|
|
390
|
+
return typeof n == "string" || Array.isArray(n) ? _(n) : n.default !== void 0 ? n.default : _(n.type);
|
|
391
391
|
}
|
|
392
|
-
function y(
|
|
393
|
-
return typeof
|
|
392
|
+
function y(n) {
|
|
393
|
+
return typeof n == "string" || Array.isArray(n) ? {
|
|
394
394
|
alias: [],
|
|
395
|
-
default: U(
|
|
395
|
+
default: U(n),
|
|
396
396
|
description: "",
|
|
397
397
|
required: !1,
|
|
398
398
|
secret: !1,
|
|
399
|
-
type:
|
|
399
|
+
type: n,
|
|
400
400
|
variadic: !1
|
|
401
401
|
} : {
|
|
402
|
-
alias:
|
|
403
|
-
default:
|
|
404
|
-
description:
|
|
405
|
-
required:
|
|
406
|
-
secret:
|
|
407
|
-
type:
|
|
408
|
-
variadic:
|
|
402
|
+
alias: n.alias ? Array.isArray(n.alias) ? n.alias : [n.alias] : [],
|
|
403
|
+
default: n.default ?? U(n.type),
|
|
404
|
+
description: n.description ?? "",
|
|
405
|
+
required: n.required ?? !1,
|
|
406
|
+
secret: n.secret ?? !1,
|
|
407
|
+
type: n.type,
|
|
408
|
+
variadic: n.variadic ?? !1
|
|
409
409
|
};
|
|
410
410
|
}
|
|
411
411
|
class k extends w {
|
|
@@ -417,8 +417,8 @@ class k extends w {
|
|
|
417
417
|
if (t.length > 0) {
|
|
418
418
|
e.log(`
|
|
419
419
|
${a.yellow("Available options")}:`);
|
|
420
|
-
for (const [
|
|
421
|
-
const i = y(s), o = typeof i.alias == "string" ? [i.alias] : i.alias, u = Array.isArray(i.type) ? `[${i.type[0]}]` : i.type, m = `--${
|
|
420
|
+
for (const [r, s] of t) {
|
|
421
|
+
const i = y(s), o = typeof i.alias == "string" ? [i.alias] : i.alias, u = Array.isArray(i.type) ? `[${i.type[0]}]` : i.type, m = `--${r}${o.length > 0 ? o.map((l) => `, -${l}`).join("") : ""}`, h = " ".repeat(30 - m.length);
|
|
422
422
|
e.log(` ${a.green(m)} ${h} ${i.description || "\b"} ${a.white(`(${u})`)}`);
|
|
423
423
|
}
|
|
424
424
|
e.log("");
|
|
@@ -442,7 +442,7 @@ class ce extends w {
|
|
|
442
442
|
e.log(`${a.white.bgRed(" ERROR ")} Option ${a.bold.yellow(this.option)} is required.`);
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
|
-
class
|
|
445
|
+
class Ae extends w {
|
|
446
446
|
constructor(e) {
|
|
447
447
|
let t = `Argument "${e.param}" value is invalid.`;
|
|
448
448
|
e.reason ? t += ` Reason: ${e.reason}` : t += ` Value: "${e.value}"`, super(t), this.param = e;
|
|
@@ -468,24 +468,24 @@ class he extends w {
|
|
|
468
468
|
e.log(`${a.bgRed(" ERROR ")} Command ${a.yellow(this.command)} not found.`);
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
|
-
function
|
|
472
|
-
if (
|
|
473
|
-
return
|
|
471
|
+
function $(n, e, t, r) {
|
|
472
|
+
if (n == null)
|
|
473
|
+
return r ?? null;
|
|
474
474
|
if (e === "string")
|
|
475
|
-
return String(
|
|
475
|
+
return String(n);
|
|
476
476
|
if (e === "number") {
|
|
477
|
-
const s = Number(
|
|
477
|
+
const s = Number(n);
|
|
478
478
|
if (isNaN(s))
|
|
479
479
|
throw new B({
|
|
480
480
|
option: t,
|
|
481
|
-
reason: `Expected a number, got "${
|
|
481
|
+
reason: `Expected a number, got "${n}"`
|
|
482
482
|
});
|
|
483
483
|
return s;
|
|
484
484
|
}
|
|
485
485
|
if (e === "boolean")
|
|
486
|
-
return typeof
|
|
486
|
+
return typeof n == "boolean" ? n : n === "true" || n === "1" ? !0 : n === "false" || n === "0" ? !1 : !!n;
|
|
487
487
|
if (Array.isArray(e)) {
|
|
488
|
-
const s = e[0], i = Array.isArray(
|
|
488
|
+
const s = e[0], i = Array.isArray(n) ? n : [n];
|
|
489
489
|
if (s === "string")
|
|
490
490
|
return i.map((o) => String(o));
|
|
491
491
|
if (s === "number")
|
|
@@ -499,7 +499,7 @@ function C(r, e, t, n) {
|
|
|
499
499
|
return u;
|
|
500
500
|
});
|
|
501
501
|
}
|
|
502
|
-
return
|
|
502
|
+
return n;
|
|
503
503
|
}
|
|
504
504
|
class J {
|
|
505
505
|
options;
|
|
@@ -516,12 +516,12 @@ class J {
|
|
|
516
516
|
* Parses raw command-line arguments into structured options and arguments
|
|
517
517
|
* @param args - Raw command line arguments (typically from process.argv.slice(2))
|
|
518
518
|
* @returns Object containing parsed options and arguments
|
|
519
|
-
* @throws {InvalidOption} If an
|
|
519
|
+
* @throws {InvalidOption} If an naan option is provided
|
|
520
520
|
* @throws {BadCommandOption} If a value cannot be converted to the expected type
|
|
521
521
|
*/
|
|
522
522
|
init(e) {
|
|
523
|
-
const { _: t, ...
|
|
524
|
-
return this.validateUnknownOptions(
|
|
523
|
+
const { _: t, ...r } = X(e);
|
|
524
|
+
return this.validateUnknownOptions(r), this.parsedOptions = this.handleOptions(r), this.parsedArguments = this.handleArguments(t), {
|
|
525
525
|
options: this.parsedOptions,
|
|
526
526
|
arguments: this.parsedArguments
|
|
527
527
|
};
|
|
@@ -535,22 +535,22 @@ class J {
|
|
|
535
535
|
if (y(this.options[e]).required && (this.parsedOptions?.[e] === void 0 || this.parsedOptions?.[e] === null))
|
|
536
536
|
throw new ce(e);
|
|
537
537
|
for (const e in this.arguments) {
|
|
538
|
-
const t = y(this.arguments[e]),
|
|
539
|
-
if (t.required &&
|
|
538
|
+
const t = y(this.arguments[e]), r = this.parsedArguments?.[e];
|
|
539
|
+
if (t.required && r == null) {
|
|
540
540
|
if (this.shouldPromptForMissingOptions) {
|
|
541
541
|
const s = await this.promptForArgument(e, t);
|
|
542
542
|
if (s && this.parsedArguments) {
|
|
543
|
-
this.parsedArguments[e] =
|
|
543
|
+
this.parsedArguments[e] = $(s, t.type, e);
|
|
544
544
|
continue;
|
|
545
545
|
}
|
|
546
546
|
}
|
|
547
547
|
throw new Y(e);
|
|
548
548
|
}
|
|
549
|
-
if (t.required && t.variadic && Array.isArray(
|
|
549
|
+
if (t.required && t.variadic && Array.isArray(r) && r.length === 0) {
|
|
550
550
|
if (this.shouldPromptForMissingOptions) {
|
|
551
551
|
const s = await this.promptForArgument(e, t);
|
|
552
552
|
if (s && this.parsedArguments) {
|
|
553
|
-
this.parsedArguments[e] =
|
|
553
|
+
this.parsedArguments[e] = $(s, t.type, e);
|
|
554
554
|
continue;
|
|
555
555
|
}
|
|
556
556
|
}
|
|
@@ -561,13 +561,14 @@ class J {
|
|
|
561
561
|
/**
|
|
562
562
|
* Retrieves a parsed option value by name
|
|
563
563
|
* @param name - The option name
|
|
564
|
+
* @param defaultValue - Optional default value if option is not set
|
|
564
565
|
* @returns The typed option value
|
|
565
566
|
* @throws {Error} If init() has not been called yet
|
|
566
567
|
*/
|
|
567
|
-
option(e) {
|
|
568
|
+
option(e, t) {
|
|
568
569
|
if (!this.parsedOptions)
|
|
569
570
|
throw new Error("Options have not been parsed yet. Call init() first.");
|
|
570
|
-
return this.parsedOptions[e];
|
|
571
|
+
return this.isEmptyValue(this.parsedOptions[e]) && t !== void 0 ? t : this.parsedOptions[e];
|
|
571
572
|
}
|
|
572
573
|
setOption(e, t) {
|
|
573
574
|
if (!this.parsedOptions)
|
|
@@ -579,13 +580,14 @@ class J {
|
|
|
579
580
|
/**
|
|
580
581
|
* Retrieves a parsed argument value by name
|
|
581
582
|
* @param name - The argument name
|
|
583
|
+
* @param defaultValue - Optional default value if argument is not set
|
|
582
584
|
* @returns The typed argument value
|
|
583
585
|
* @throws {Error} If init() has not been called yet
|
|
584
586
|
*/
|
|
585
|
-
argument(e) {
|
|
587
|
+
argument(e, t) {
|
|
586
588
|
if (!this.parsedArguments)
|
|
587
589
|
throw new Error("Arguments have not been parsed yet. Call init() first.");
|
|
588
|
-
return this.parsedArguments[e];
|
|
590
|
+
return this.isEmptyValue(this.parsedArguments[e]) && t !== void 0 ? t : this.parsedArguments[e];
|
|
589
591
|
}
|
|
590
592
|
setArgument(e, t) {
|
|
591
593
|
if (!this.parsedArguments)
|
|
@@ -595,30 +597,38 @@ class J {
|
|
|
595
597
|
this.parsedArguments[e] = t;
|
|
596
598
|
}
|
|
597
599
|
// === PRIVATE HELPERS ===
|
|
600
|
+
/**
|
|
601
|
+
* Checks if a value should be considered "empty" for default value purposes
|
|
602
|
+
* @param value - The value to check
|
|
603
|
+
* @returns true if the value is null, undefined, or an empty array
|
|
604
|
+
*/
|
|
605
|
+
isEmptyValue(e) {
|
|
606
|
+
return e == null || Array.isArray(e) && e.length === 0;
|
|
607
|
+
}
|
|
598
608
|
/**
|
|
599
609
|
* Validates that all provided options are recognized
|
|
600
610
|
* @throws {InvalidOption} If an unknown option is found
|
|
601
611
|
*/
|
|
602
612
|
validateUnknownOptions(e) {
|
|
603
613
|
const t = /* @__PURE__ */ new Set();
|
|
604
|
-
for (const
|
|
605
|
-
t.add(
|
|
606
|
-
const s = y(this.options[
|
|
614
|
+
for (const r in this.options) {
|
|
615
|
+
t.add(r);
|
|
616
|
+
const s = y(this.options[r]);
|
|
607
617
|
for (const i of s.alias)
|
|
608
618
|
t.add(i);
|
|
609
619
|
}
|
|
610
|
-
for (const
|
|
611
|
-
if (!t.has(
|
|
612
|
-
throw new k(
|
|
620
|
+
for (const r in e)
|
|
621
|
+
if (!t.has(r))
|
|
622
|
+
throw new k(r, this.options);
|
|
613
623
|
}
|
|
614
624
|
/**
|
|
615
625
|
* Processes named options from minimist output
|
|
616
626
|
*/
|
|
617
627
|
handleOptions(e) {
|
|
618
628
|
const t = {};
|
|
619
|
-
for (const
|
|
620
|
-
const s = y(this.options[
|
|
621
|
-
t[
|
|
629
|
+
for (const r in this.options) {
|
|
630
|
+
const s = y(this.options[r]);
|
|
631
|
+
t[r] = this.resolveOptionValue(r, s, e);
|
|
622
632
|
}
|
|
623
633
|
return t;
|
|
624
634
|
}
|
|
@@ -626,40 +636,40 @@ class J {
|
|
|
626
636
|
* Processes positional arguments from minimist output
|
|
627
637
|
*/
|
|
628
638
|
handleArguments(e) {
|
|
629
|
-
const t = {},
|
|
639
|
+
const t = {}, r = [...e];
|
|
630
640
|
for (const s in this.arguments) {
|
|
631
641
|
const i = y(this.arguments[s]);
|
|
632
642
|
if (i.variadic) {
|
|
633
|
-
t[s] = this.handleVariadicArgument(s, i,
|
|
643
|
+
t[s] = this.handleVariadicArgument(s, i, r);
|
|
634
644
|
continue;
|
|
635
645
|
}
|
|
636
|
-
t[s] = this.resolveArgumentValue(s, i,
|
|
646
|
+
t[s] = this.resolveArgumentValue(s, i, r.shift());
|
|
637
647
|
}
|
|
638
648
|
return t;
|
|
639
649
|
}
|
|
640
650
|
/**
|
|
641
651
|
* Handles variadic arguments that consume all remaining positional values
|
|
642
652
|
*/
|
|
643
|
-
handleVariadicArgument(e, t,
|
|
644
|
-
return
|
|
653
|
+
handleVariadicArgument(e, t, r) {
|
|
654
|
+
return r.length ? $(r, t.type, e, t.default) : t.default;
|
|
645
655
|
}
|
|
646
656
|
/**
|
|
647
657
|
* Resolves a single positional argument value with defaults and type conversion
|
|
648
658
|
* Note: Does not validate required arguments - validation happens in subclass validate() methods
|
|
649
659
|
*/
|
|
650
|
-
resolveArgumentValue(e, t,
|
|
651
|
-
return
|
|
660
|
+
resolveArgumentValue(e, t, r) {
|
|
661
|
+
return r === void 0 ? t.default : $(r, t.type, e, t.default);
|
|
652
662
|
}
|
|
653
663
|
/**
|
|
654
664
|
* Resolves an option value from the parsed option values object
|
|
655
665
|
* Handles alias resolution, defaults, and type conversion
|
|
656
666
|
*/
|
|
657
|
-
resolveOptionValue(e, t,
|
|
667
|
+
resolveOptionValue(e, t, r) {
|
|
658
668
|
let s;
|
|
659
669
|
const i = [e, ...t.alias];
|
|
660
670
|
for (const o of i)
|
|
661
|
-
if (o in
|
|
662
|
-
s =
|
|
671
|
+
if (o in r) {
|
|
672
|
+
s = r[o];
|
|
663
673
|
break;
|
|
664
674
|
}
|
|
665
675
|
if (s === void 0) {
|
|
@@ -670,7 +680,7 @@ class J {
|
|
|
670
680
|
});
|
|
671
681
|
return t.default;
|
|
672
682
|
}
|
|
673
|
-
return
|
|
683
|
+
return $(s, t.type, e, t.default);
|
|
674
684
|
}
|
|
675
685
|
optionDefinitions() {
|
|
676
686
|
const e = {};
|
|
@@ -707,10 +717,10 @@ class J {
|
|
|
707
717
|
async promptForArgument(e, t) {
|
|
708
718
|
if (!Array.isArray(t.type) && !["string", "number", "secret"].includes(t.type))
|
|
709
719
|
return null;
|
|
710
|
-
let
|
|
711
|
-
return t.description && (
|
|
712
|
-
`, Array.isArray(t.type) ? (
|
|
713
|
-
`, await this.io.askForList(
|
|
720
|
+
let r = `${a.yellow.bold(e)} is required`;
|
|
721
|
+
return t.description && (r += `: ${a.gray(`(${t.description})`)}`), r += ` ${a.green(`(${t.type}${t.variadic == !0 ? "[]" : ""})`)}
|
|
722
|
+
`, Array.isArray(t.type) ? (r += `Please provide one or more values, separated by commas:
|
|
723
|
+
`, await this.io.askForList(r, void 0, {
|
|
714
724
|
separator: ",",
|
|
715
725
|
validate: (s) => {
|
|
716
726
|
if (!s.length)
|
|
@@ -722,7 +732,7 @@ class J {
|
|
|
722
732
|
}
|
|
723
733
|
return !0;
|
|
724
734
|
}
|
|
725
|
-
})) : await this.io.askForInput(
|
|
735
|
+
})) : await this.io.askForInput(r, void 0, {
|
|
726
736
|
type: t.type === "number" ? "number" : t.secret ? "password" : "text",
|
|
727
737
|
validate: (s) => {
|
|
728
738
|
if (s == null || typeof s == "string" && !s.length)
|
|
@@ -738,8 +748,8 @@ class J {
|
|
|
738
748
|
});
|
|
739
749
|
}
|
|
740
750
|
}
|
|
741
|
-
function j(
|
|
742
|
-
return new Array(
|
|
751
|
+
function j(n) {
|
|
752
|
+
return new Array(n + 5).join(" ");
|
|
743
753
|
}
|
|
744
754
|
class pe {
|
|
745
755
|
type = "boolean";
|
|
@@ -748,21 +758,21 @@ class pe {
|
|
|
748
758
|
default = !1;
|
|
749
759
|
description = `Display help for the given command. When no command is given display help for the ${a.green("list")} command`;
|
|
750
760
|
async handler() {
|
|
751
|
-
const e = this.parser.argumentDefinitions(), t = this.parser.optionDefinitions(),
|
|
761
|
+
const e = this.parser.argumentDefinitions(), t = this.parser.optionDefinitions(), r = Object.entries(e), s = Object.entries(t), i = s.map(([l, d]) => {
|
|
752
762
|
const p = Array.isArray(d.alias) ? d.alias : d.alias ? [d.alias] : [];
|
|
753
763
|
return {
|
|
754
764
|
name: l,
|
|
755
765
|
...d,
|
|
756
766
|
optionWithAlias: `--${l}${p.map((g) => `, -${g}`).join("")}`
|
|
757
767
|
};
|
|
758
|
-
}), o =
|
|
768
|
+
}), o = r.filter(([, l]) => l.required);
|
|
759
769
|
this.io.log(a.yellow("Description:")), this.io.log(` ${this.description}
|
|
760
770
|
`), this.io.log(a.yellow("Usage:")), this.io.log(` ${this.command} ${o.length > 0 ? o.map(([l]) => `<${l}>`).join(" ") : "\b"} [options]`);
|
|
761
|
-
const u = Math.max(...i.map((l) => l.optionWithAlias.length), 0), m = Math.max(...
|
|
762
|
-
if (
|
|
771
|
+
const u = Math.max(...i.map((l) => l.optionWithAlias.length), 0), m = Math.max(...r.map(([l]) => l.length), 0), h = m > u ? m : u;
|
|
772
|
+
if (r.length > 0) {
|
|
763
773
|
this.io.log(`
|
|
764
774
|
${a.yellow("Arguments")}:`);
|
|
765
|
-
for (const [l, d] of
|
|
775
|
+
for (const [l, d] of r) {
|
|
766
776
|
const p = j(h - l.length);
|
|
767
777
|
let g = ` ${a.green(l)} ${p} ${d.description ?? "\b"}`;
|
|
768
778
|
if (d.default !== void 0 && !d.required) {
|
|
@@ -801,9 +811,9 @@ ${a.yellow("Examples")}:`);
|
|
|
801
811
|
return -1;
|
|
802
812
|
}
|
|
803
813
|
}
|
|
804
|
-
class
|
|
814
|
+
class x {
|
|
805
815
|
_command;
|
|
806
|
-
description
|
|
816
|
+
description;
|
|
807
817
|
group;
|
|
808
818
|
commandsExamples = [];
|
|
809
819
|
get command() {
|
|
@@ -835,9 +845,9 @@ class F {
|
|
|
835
845
|
options: t?.options ?? {},
|
|
836
846
|
arguments: t?.arguments ?? {}
|
|
837
847
|
};
|
|
838
|
-
const
|
|
839
|
-
if (
|
|
840
|
-
for (const s of
|
|
848
|
+
const r = this.defaultOptions();
|
|
849
|
+
if (r.length > 0)
|
|
850
|
+
for (const s of r)
|
|
841
851
|
this.tmp.options[s.option] = s;
|
|
842
852
|
}
|
|
843
853
|
disablePrompting() {
|
|
@@ -894,9 +904,9 @@ class F {
|
|
|
894
904
|
options: e.options,
|
|
895
905
|
arguments: e.arguments
|
|
896
906
|
};
|
|
897
|
-
const
|
|
898
|
-
if (
|
|
899
|
-
return
|
|
907
|
+
const r = this.preHandle ? await this.preHandle() : null;
|
|
908
|
+
if (r && r !== 0)
|
|
909
|
+
return r;
|
|
900
910
|
if (!this._handler && this.handle)
|
|
901
911
|
this._handler = this.handle.bind(this);
|
|
902
912
|
else if (!this._handler)
|
|
@@ -904,10 +914,10 @@ class F {
|
|
|
904
914
|
return await this._handler(e.ctx, t) ?? 0;
|
|
905
915
|
}
|
|
906
916
|
}
|
|
907
|
-
class
|
|
917
|
+
class E extends J {
|
|
908
918
|
command;
|
|
909
919
|
constructor(e) {
|
|
910
|
-
const t =
|
|
920
|
+
const t = E.parseSignature(e.signature, e.helperDefinitions, e.defaultOptions);
|
|
911
921
|
super({
|
|
912
922
|
io: e.io,
|
|
913
923
|
options: t.options,
|
|
@@ -918,13 +928,13 @@ class v extends J {
|
|
|
918
928
|
* Parses command signature string into command name and parameter schemas
|
|
919
929
|
* Example: "migrate {name} {--force}" -> { command: "migrate", arguments: {name: ...}, options: {force: ...} }
|
|
920
930
|
*/
|
|
921
|
-
static parseSignature(e, t,
|
|
931
|
+
static parseSignature(e, t, r) {
|
|
922
932
|
const [s, ...i] = e.split(/\{(.*?)\}/g).map((m) => m.trim()).filter(Boolean), o = {}, u = {};
|
|
923
933
|
for (const m of i) {
|
|
924
|
-
const { name: h, isOption: l, definition: d } =
|
|
934
|
+
const { name: h, isOption: l, definition: d } = E.parseParamSignature(m, t);
|
|
925
935
|
l ? o[h] = d : u[h] = d;
|
|
926
936
|
}
|
|
927
|
-
for (const m of
|
|
937
|
+
for (const m of r)
|
|
928
938
|
o[m.option] = {
|
|
929
939
|
type: m.type,
|
|
930
940
|
required: m.required,
|
|
@@ -954,7 +964,7 @@ class v extends J {
|
|
|
954
964
|
* - {--opt|o} -> option with alias
|
|
955
965
|
*/
|
|
956
966
|
static parseParamSignature(e, t) {
|
|
957
|
-
let
|
|
967
|
+
let r = e, s = !1;
|
|
958
968
|
const i = {
|
|
959
969
|
required: !0,
|
|
960
970
|
type: "string",
|
|
@@ -962,28 +972,28 @@ class v extends J {
|
|
|
962
972
|
default: null,
|
|
963
973
|
variadic: !1
|
|
964
974
|
};
|
|
965
|
-
if (
|
|
966
|
-
const [o, u] =
|
|
967
|
-
|
|
975
|
+
if (r.includes(":")) {
|
|
976
|
+
const [o, u] = r.split(":");
|
|
977
|
+
r = o.trim(), i.description = u.trim();
|
|
968
978
|
}
|
|
969
|
-
if (
|
|
970
|
-
const [o, u] =
|
|
971
|
-
|
|
972
|
-
} else
|
|
973
|
-
if (
|
|
974
|
-
const [o, ...u] =
|
|
975
|
-
|
|
979
|
+
if (r.includes("=")) {
|
|
980
|
+
const [o, u] = r.split("=");
|
|
981
|
+
r = o.trim(), i.default = u.trim(), i.required = !1, typeof i.default == "string" && !i.default.length ? i.default = null : i.default === "true" ? (i.default = !0, i.type = "boolean") : i.default === "false" && (i.default = !1, i.type = "boolean");
|
|
982
|
+
} else r.startsWith("--") && (i.required = !1, i.default = !1, i.type = "boolean");
|
|
983
|
+
if (r.includes("|")) {
|
|
984
|
+
const [o, ...u] = r.split("|");
|
|
985
|
+
r = o.trim(), i.alias = u.map((m) => m.trim());
|
|
976
986
|
}
|
|
977
|
-
return
|
|
987
|
+
return r.startsWith("--") && (s = !0, r = r.slice(2)), i.default === "*" && (i.default = [], i.type = ["string"]), r.endsWith("?") && (i.required = !1, r = r.slice(0, -1)), r.endsWith("*") && (i.type = ["string"], i.variadic = !0, i.default = [], r = r.slice(0, -1)), i.description = i.description ?? t[r] ?? t[`--${r}`], { name: r, isOption: s, definition: i };
|
|
978
988
|
}
|
|
979
989
|
}
|
|
980
|
-
class
|
|
990
|
+
class $e extends x {
|
|
981
991
|
helperDefinitions = {};
|
|
982
992
|
get command() {
|
|
983
993
|
return this.parser ? this.parser.command : this.signature.split(" ")[0];
|
|
984
994
|
}
|
|
985
995
|
newCommandParser(e) {
|
|
986
|
-
return new
|
|
996
|
+
return new E({
|
|
987
997
|
io: e.io,
|
|
988
998
|
signature: this.signature,
|
|
989
999
|
helperDefinitions: this.helperDefinitions,
|
|
@@ -994,10 +1004,10 @@ class Ae extends F {
|
|
|
994
1004
|
super("");
|
|
995
1005
|
}
|
|
996
1006
|
option(e, t = null) {
|
|
997
|
-
return this.parser
|
|
1007
|
+
return this.parser.option(e, t);
|
|
998
1008
|
}
|
|
999
1009
|
argument(e, t = null) {
|
|
1000
|
-
return this.parser
|
|
1010
|
+
return this.parser.argument(e, t);
|
|
1001
1011
|
}
|
|
1002
1012
|
// Prompt utils
|
|
1003
1013
|
async askForConfirmation(...e) {
|
|
@@ -1019,8 +1029,8 @@ class K {
|
|
|
1019
1029
|
this.level = e.level ?? "info";
|
|
1020
1030
|
}
|
|
1021
1031
|
shouldLog(e) {
|
|
1022
|
-
const t = ["debug", "info", "warn", "error"],
|
|
1023
|
-
return t.indexOf(e) >=
|
|
1032
|
+
const t = ["debug", "info", "warn", "error"], r = t.indexOf(this.level);
|
|
1033
|
+
return t.indexOf(e) >= r;
|
|
1024
1034
|
}
|
|
1025
1035
|
setLevel(e) {
|
|
1026
1036
|
this.level = e;
|
|
@@ -1065,7 +1075,7 @@ class ge {
|
|
|
1065
1075
|
let t = await this.importFile(e);
|
|
1066
1076
|
if (!t)
|
|
1067
1077
|
throw new Error(`The command at path ${e} does not have a default export.`);
|
|
1068
|
-
return t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" ? new t() : t instanceof
|
|
1078
|
+
return t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" ? new t() : t instanceof x ? t : null;
|
|
1069
1079
|
};
|
|
1070
1080
|
withCommandResolver(e) {
|
|
1071
1081
|
return this.commandResolver = e, this;
|
|
@@ -1074,39 +1084,39 @@ class ge {
|
|
|
1074
1084
|
return this.importFile = e, this;
|
|
1075
1085
|
}
|
|
1076
1086
|
registerCommand(e, t = !1) {
|
|
1077
|
-
const
|
|
1078
|
-
if (!
|
|
1087
|
+
const r = e.command;
|
|
1088
|
+
if (!r)
|
|
1079
1089
|
throw new Error("Command signature is invalid, it must have a command name.");
|
|
1080
|
-
if (!t && this.commands[
|
|
1081
|
-
throw new Error(`Command ${
|
|
1082
|
-
this.commands[
|
|
1090
|
+
if (!t && this.commands[r])
|
|
1091
|
+
throw new Error(`Command ${r} already registered.`);
|
|
1092
|
+
this.commands[r] = e;
|
|
1083
1093
|
}
|
|
1084
1094
|
async loadCommandsPath(e) {
|
|
1085
1095
|
for await (const t of this.listCommandsFiles(e))
|
|
1086
1096
|
try {
|
|
1087
|
-
const
|
|
1088
|
-
|
|
1089
|
-
} catch (
|
|
1090
|
-
throw new Error(`Command ${t} failed to load. ${
|
|
1091
|
-
cause:
|
|
1097
|
+
const r = await this.commandResolver(t);
|
|
1098
|
+
r instanceof x && this.registerCommand(r);
|
|
1099
|
+
} catch (r) {
|
|
1100
|
+
throw new Error(`Command ${t} failed to load. ${r}`, {
|
|
1101
|
+
cause: r
|
|
1092
1102
|
});
|
|
1093
1103
|
}
|
|
1094
1104
|
}
|
|
1095
|
-
async runCommand(e, t, ...
|
|
1105
|
+
async runCommand(e, t, ...r) {
|
|
1096
1106
|
const s = typeof t == "string" ? this.commands[t] : t, i = typeof t == "string" ? t : s.command;
|
|
1097
1107
|
if (!s) {
|
|
1098
1108
|
const o = await this.suggestCommand(i);
|
|
1099
|
-
return o ? await this.runCommand(e, o, ...
|
|
1109
|
+
return o ? await this.runCommand(e, o, ...r) : 1;
|
|
1100
1110
|
}
|
|
1101
1111
|
return await s.run({
|
|
1102
1112
|
ctx: e,
|
|
1103
1113
|
logger: this.logger,
|
|
1104
|
-
args:
|
|
1114
|
+
args: r
|
|
1105
1115
|
}) ?? 0;
|
|
1106
1116
|
}
|
|
1107
1117
|
async suggestCommand(e) {
|
|
1108
|
-
const t = this.getAvailableCommands(), { bestMatch:
|
|
1109
|
-
if (
|
|
1118
|
+
const t = this.getAvailableCommands(), { bestMatch: r, bestMatchIndex: s, ratings: i } = ee.findBestMatch(e, t), o = i.filter((u) => u.rating > 0.3).map((u) => u.target);
|
|
1119
|
+
if (r.rating > 0 && o.length <= 1 || r.rating > 0.7 && o.length > 1) {
|
|
1110
1120
|
const u = t[s];
|
|
1111
1121
|
return await this.askRunSimilarCommand(e, u) ? u : null;
|
|
1112
1122
|
}
|
|
@@ -1125,10 +1135,10 @@ class ge {
|
|
|
1125
1135
|
}
|
|
1126
1136
|
async *listCommandsFiles(e) {
|
|
1127
1137
|
const t = Z.readdirSync(e, { withFileTypes: !0 });
|
|
1128
|
-
for (const
|
|
1129
|
-
const s = I.resolve(e,
|
|
1130
|
-
if (
|
|
1131
|
-
yield* this.listCommandsFiles(I.resolve(e,
|
|
1138
|
+
for (const r of t) {
|
|
1139
|
+
const s = I.resolve(e, r.name);
|
|
1140
|
+
if (r.isDirectory())
|
|
1141
|
+
yield* this.listCommandsFiles(I.resolve(e, r.name));
|
|
1132
1142
|
else {
|
|
1133
1143
|
if (!s.endsWith(".ts") && !s.endsWith(".js") && !s.endsWith(".mjs") && !s.endsWith(".cjs"))
|
|
1134
1144
|
continue;
|
|
@@ -1148,15 +1158,15 @@ class fe {
|
|
|
1148
1158
|
throw e;
|
|
1149
1159
|
}
|
|
1150
1160
|
}
|
|
1151
|
-
class ye extends
|
|
1161
|
+
class ye extends x {
|
|
1152
1162
|
constructor(e) {
|
|
1153
1163
|
super("help", {
|
|
1154
1164
|
description: a.bold("Show help information about the CLI and its commands")
|
|
1155
1165
|
}), this.opts = e;
|
|
1156
1166
|
}
|
|
1157
1167
|
async handle() {
|
|
1158
|
-
const e = this.opts.commandRegistry.getCommands(), t = this.opts.cliName ?? "Bob CLI",
|
|
1159
|
-
this.io.log(`${t} ${a.green(
|
|
1168
|
+
const e = this.opts.commandRegistry.getCommands(), t = this.opts.cliName ?? "Bob CLI", r = this.opts.cliVersion ?? "0.0.0", s = (await import("./package-CtFSlXKR.js"))?.default?.version ?? "0.0.0";
|
|
1169
|
+
this.io.log(`${t} ${a.green(r)} (core: ${a.yellow(s)})
|
|
1160
1170
|
|
|
1161
1171
|
${a.yellow("Usage")}:
|
|
1162
1172
|
command [options] [arguments]
|
|
@@ -1228,16 +1238,16 @@ class Ce {
|
|
|
1228
1238
|
}
|
|
1229
1239
|
export {
|
|
1230
1240
|
B as BadCommandOption,
|
|
1231
|
-
|
|
1241
|
+
Ae as BadCommandParameter,
|
|
1232
1242
|
w as BobError,
|
|
1233
1243
|
Ce as Cli,
|
|
1234
|
-
|
|
1244
|
+
x as Command,
|
|
1235
1245
|
z as CommandIO,
|
|
1236
1246
|
he as CommandNotFoundError,
|
|
1237
1247
|
J as CommandParser,
|
|
1238
1248
|
ge as CommandRegistry,
|
|
1239
|
-
|
|
1240
|
-
|
|
1249
|
+
E as CommandSignatureParser,
|
|
1250
|
+
$e as CommandWithSignature,
|
|
1241
1251
|
fe as ExceptionHandler,
|
|
1242
1252
|
pe as HelpOption,
|
|
1243
1253
|
k as InvalidOption,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const t = "bob-core", e = "2.0.0-beta.
|
|
1
|
+
const t = "bob-core", e = "2.0.0-beta.13", s = "BOB Core", i = "module", m = !1, n = ["dist/**"], r = { ".": { import: "./dist/esm/index.js", require: "./dist/cjs/index.js" } }, o = { "*": { "*": ["./dist/cjs/*.d.ts"] } }, c = { start: "node -r @swc-node/register debug/main.ts", build: "rimraf ./dist && vite build", typecheck: "tsc --noEmit", prepack: "npm run build", test: "vitest run", lint: "eslint .", "lint:fix": "eslint . --fix" }, p = "Léo Hubert", d = "ISC", l = { "@eslint/js": "^9.37.0", "@faker-js/faker": "^10.0.0", "@swc-node/register": "^1.11.1", "@trivago/prettier-plugin-sort-imports": "^5.2.2", "@types/minimist": "^1.2.5", "@types/node": "^20.14.5", "@types/prompts": "^2.4.9", "@types/string-similarity": "^4.0.2", "@vitest/coverage-v8": "^3.2.4", eslint: "^9.37.0", "eslint-config-prettier": "^10.1.8", "eslint-plugin-prettier": "^5.5.4", prettier: "^3.6.2", rimraf: "^6.0.1", tsx: "^4.20.6", typescript: "^5.7.3", "typescript-eslint": "^8.46.0", vite: "^7.1.6", "vite-plugin-dts": "^4.5.4", vitest: "^3.2.4" }, a = { chalk: "^5.6.2", minimist: "^1.2.8", prompts: "^2.4.2", "string-similarity": "^4.0.4" }, f = {
|
|
2
2
|
name: t,
|
|
3
3
|
version: e,
|
|
4
4
|
description: s,
|
|
@@ -21,7 +21,7 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
21
21
|
* Parses raw command-line arguments into structured options and arguments
|
|
22
22
|
* @param args - Raw command line arguments (typically from process.argv.slice(2))
|
|
23
23
|
* @returns Object containing parsed options and arguments
|
|
24
|
-
* @throws {InvalidOption} If an
|
|
24
|
+
* @throws {InvalidOption} If an naan option is provided
|
|
25
25
|
* @throws {BadCommandOption} If a value cannot be converted to the expected type
|
|
26
26
|
*/
|
|
27
27
|
init(args: string[]): {
|
|
@@ -36,19 +36,27 @@ export declare class CommandParser<Options extends OptionsSchema, Arguments exte
|
|
|
36
36
|
/**
|
|
37
37
|
* Retrieves a parsed option value by name
|
|
38
38
|
* @param name - The option name
|
|
39
|
+
* @param defaultValue - Optional default value if option is not set
|
|
39
40
|
* @returns The typed option value
|
|
40
41
|
* @throws {Error} If init() has not been called yet
|
|
41
42
|
*/
|
|
42
|
-
option<OptsName extends keyof Options>(name: OptsName): OptionReturnType<Options[OptsName]>;
|
|
43
|
+
option<OptsName extends keyof Options>(name: OptsName, defaultValue?: OptionReturnType<Options[OptsName]>): OptionReturnType<Options[OptsName]>;
|
|
43
44
|
setOption<OptsName extends keyof Options>(name: OptsName, value: OptionReturnType<Options[OptsName]>): void;
|
|
44
45
|
/**
|
|
45
46
|
* Retrieves a parsed argument value by name
|
|
46
47
|
* @param name - The argument name
|
|
48
|
+
* @param defaultValue - Optional default value if argument is not set
|
|
47
49
|
* @returns The typed argument value
|
|
48
50
|
* @throws {Error} If init() has not been called yet
|
|
49
51
|
*/
|
|
50
|
-
argument<ArgName extends keyof Arguments>(name: ArgName): OptionReturnType<Arguments[ArgName]>;
|
|
52
|
+
argument<ArgName extends keyof Arguments>(name: ArgName, defaultValue?: OptionReturnType<Arguments[ArgName]>): OptionReturnType<Arguments[ArgName]>;
|
|
51
53
|
setArgument<ArgName extends keyof Arguments>(name: ArgName, value: OptionReturnType<Arguments[ArgName]>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if a value should be considered "empty" for default value purposes
|
|
56
|
+
* @param value - The value to check
|
|
57
|
+
* @returns true if the value is null, undefined, or an empty array
|
|
58
|
+
*/
|
|
59
|
+
private isEmptyValue;
|
|
52
60
|
/**
|
|
53
61
|
* Validates that all provided options are recognized
|
|
54
62
|
* @throws {InvalidOption} If an unknown option is found
|
|
@@ -8,8 +8,8 @@ export declare abstract class CommandWithSignature<C extends ContextDefinition =
|
|
|
8
8
|
protected helperDefinitions: {
|
|
9
9
|
[key: string]: string;
|
|
10
10
|
};
|
|
11
|
+
protected parser: CommandSignatureParser<Opts, Args>;
|
|
11
12
|
get command(): string;
|
|
12
|
-
parser: CommandSignatureParser<Opts, Args>;
|
|
13
13
|
protected newCommandParser(opts: {
|
|
14
14
|
io: CommandIO;
|
|
15
15
|
options: Opts;
|