bob-core 3.0.0-alpha.8 → 3.0.0-beta.2
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/package-BI6Z9-0r.cjs +1 -0
- package/dist/cjs/src/flags/option.d.ts +0 -2
- package/dist/cjs/src/index.js +5 -5
- package/dist/cjs/src/lib/types.d.ts +1 -6
- package/dist/cjs/src/shared/parsers.d.ts +1 -1
- package/dist/esm/{package-r-7jybWO.js → package-BLXL_OAz.js} +3 -2
- package/dist/esm/src/flags/option.d.ts +0 -2
- package/dist/esm/src/index.js +155 -163
- package/dist/esm/src/lib/types.d.ts +1 -6
- package/dist/esm/src/shared/parsers.d.ts +1 -1
- package/package.json +3 -2
- package/dist/cjs/package-raEIIM6S.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e={name:`bob-core`,version:`3.0.0-beta.2`,description:`BOB Core`,type:`module`,main:`./dist/cjs/src/index.js`,module:`./dist/esm/src/index.js`,types:`./dist/esm/src/index.d.ts`,files:[`dist`],exports:{".":{import:{types:`./dist/esm/src/index.d.ts`,default:`./dist/esm/src/index.js`},require:{types:`./dist/cjs/src/index.d.ts`,default:`./dist/cjs/src/index.js`}}},scripts:{start:`node -r @swc-node/register debug/main.ts`,build:`rm -rf ./dist && vite build`,typecheck:`tsc --noEmit`,prepack:`npm run build`,test:`vitest run`,lint:`eslint .`,"lint:fix":`eslint . --fix`},author:`Léo Hubert`,license:`ISC`,devDependencies:{"@eslint/js":`^9.39.4`,"@faker-js/faker":`^10.3.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/string-similarity":`^4.0.2`,"@vitest/coverage-v8":`^4.1.0`,eslint:`^9.39.4`,"eslint-config-prettier":`^10.1.8`,"eslint-plugin-prettier":`^5.5.5`,prettier:`^3.6.2`,tsx:`^4.21.0`,typescript:`^5.9.3`,"typescript-eslint":`^8.57.0`,vite:`^8.0.0`,"vite-plugin-dts":`^4.5.4`,vitest:`^4.1.0`},dependencies:{"@inquirer/core":`^11.1.8`,"@inquirer/prompts":`^8.4.1`,chalk:`^4.1.2`,"inquirer-file-selector":`^1.0.1`,minimist:`^1.2.8`}};exports.default=e;
|
|
@@ -2,7 +2,5 @@ import { FlagProps, ParameterOpts } from '../lib/types.js';
|
|
|
2
2
|
export declare function optionFlag<const T extends readonly string[], const U extends Partial<FlagProps>>(opts: {
|
|
3
3
|
options: T;
|
|
4
4
|
} & U): U & FlagProps<T[number]> & {
|
|
5
|
-
type: 'option';
|
|
6
|
-
options: T;
|
|
7
5
|
parse(input: any, opts: ParameterOpts): T[number];
|
|
8
6
|
};
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`chalk`);c=s(c);let l=require(`node:fs`);l=s(l);let u=require(`node:path`);u=s(u);let d=require(`minimist`);d=s(d);let f=require(`@inquirer/prompts`),p=require(`inquirer-file-selector`);var m=class{level;constructor(e={}){this.level=e.level??`info`}shouldLog(e){let 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)}},h=class{getBigrams(e){let t=[],n=e.toLowerCase();for(let e=0;e<n.length-1;e++)t.push(n.slice(e,e+2));return t}calculateSimilarity(e,t){if(e===t)return 1;if(e.length<2||t.length<2)return 0;let n=this.getBigrams(e),r=this.getBigrams(t),i=new Set(r),a=0;for(let e of n)i.has(e)&&(a++,i.delete(e));return 2*a/(n.length+r.length)}findBestMatch(e,t){let n=t.map(t=>({target:t,rating:this.calculateSimilarity(e,t)})),r=0,i=n[0]?.rating??0;for(let e=1;e<n.length;e++)n[e].rating>i&&(i=n[e].rating,r=e);return{ratings:n,bestMatch:n[r],bestMatchIndex:r}}},g=class extends Error{$type=`BobError`},_=class extends g{constructor(e){super(`Command "${e}" not found.`),this.command=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Command ${c.default.bold.yellow(this.command)} not found.`),e.log(``)}},v=class extends g{constructor(e,t={}){super(`Flag ${e} is not recognized`),this.flag=e,this.flagsSchema=t}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.flag)} is not recognized.`);let t=Object.entries(this.flagsSchema);if(t.length>0){e.log(``),e.log(` ${c.default.dim(`Available flags:`)}`),e.log(``);let n=t.map(([e,t])=>{let n=t.alias?typeof t.alias==`string`?[t.alias]:t.alias:[],r=t.type===`option`&&`options`in t&&t.options?t.options.join(` | `):t.type;return{nameWithAlias:`--${e}${n.length>0?n.map(e=>`, -${e}`).join(``):``}`,description:t.description||``,typeDisplay:r}}),r=Math.max(...n.map(e=>e.nameWithAlias.length));for(let t of n){let n=` `.repeat(r-t.nameWithAlias.length+2);e.log(` ${c.default.green(t.nameWithAlias)}${n}${t.description} ${c.default.dim(`(${t.typeDisplay})`)}`)}}e.log(``)}},y=class extends g{constructor(e){super(`Argument "${e}" is required.`),this.argument=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Argument ${c.default.bold.yellow(this.argument)} is required.`),e.log(``)}},b=class extends g{constructor(e){super(`Flag "${e}" is required.`),this.flag=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.flag)} is required.`),e.log(``)}},x=class extends g{constructor(e,t){let n=`Argument "${e.arg}" value is invalid.`;e.reason?n+=` Reason: ${e.reason}`:n+=` Value: "${e.value}"`,super(n),this.detail=e,this.argDefinition=t}pretty(e){let t=[];if(this.detail.reason!=null&&t.push([`Reason`,this.detail.reason]),this.detail.value!=null&&t.push([`Value`,this.detail.value]),this.argDefinition?.help!=null&&t.push([`Help`,c.default.green(this.argDefinition.help)]),e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Argument ${c.default.bold.yellow(this.detail.arg)} value is invalid.`),t.length>0){e.log(``);let n=Math.max(...t.map(([e])=>e.length));for(let[r,i]of t)e.log(` ${` `.repeat(n-r.length)}${c.default.dim(r)} ${i}`)}e.log(``)}},S=class extends g{constructor(e,t){let n=`Flag "${e.flag}" value is invalid.`;e.reason?n+=` Reason: ${e.reason}`:n+=` Value: "${e.value}"`,super(n),this.param=e,this.flagDefinition=t}pretty(e){let t=[];if(this.param.reason!=null&&t.push([`Reason`,this.param.reason]),this.param.value!=null&&t.push([`Value`,this.param.value]),this.flagDefinition?.help!=null&&t.push([`Help`,c.default.green(this.flagDefinition.help)]),e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.param.flag)} value is invalid.`),t.length>0){e.log(``);let n=Math.max(...t.map(([e])=>e.length));for(let[r,i]of t)e.log(` ${` `.repeat(n-r.length)}${c.default.dim(r)} ${i}`)}e.log(``)}},C=class extends g{constructor(e,t){super(`Too many arguments provided. Expected ${e}, got ${t}.`),this.expected=e,this.received=t}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Too many arguments. Expected ${c.default.bold.yellow(String(this.expected))}, got ${c.default.bold.yellow(String(this.received))}.`),e.log(``)}},w=class extends Error{constructor(e){super(e)}},T=class{flags;parsedFlags=null;args;parsedArgs=null;ux;shouldPromptForMissingFlags=!0;shouldValidateUnknownFlags=!0;shouldRejectExtraArguments=!1;constructor(e){this.opts=e,this.ux=e.ux,this.flags=e.flags,this.args=e.args}async init(e){let{_:t,...n}=(0,d.default)(e);return this.shouldValidateUnknownFlags&&this.validateUnknownFlags(n),this.parsedFlags=await this.handleOptions(n),this.parsedArgs=await this.handleArguments(t),{flags:this.parsedFlags,args:this.parsedArgs}}async validate(){await this.validateSchema(this.flags,this.parsedFlags,`flag`),await this.validateSchema(this.args,this.parsedArgs,`arg`)}flag(e,t){if(!this.parsedFlags)throw Error(`Flags have not been parsed yet. Call init() first.`);return this.isEmptyValue(this.parsedFlags[e])&&t!==void 0?t:this.parsedFlags[e]}async setFlag(e,t){if(!this.parsedFlags)throw Error(`Flags have not been parsed yet. Call init() first.`);if(!(e in this.flags))throw new v(e,this.flags);this.parsedFlags[e]=t}argument(e,t){if(!this.parsedArgs)throw Error(`Arguments have not been parsed yet. Call init() first.`);return this.isEmptyValue(this.parsedArgs[e])&&t!==void 0?t:this.parsedArgs[e]}async setArgument(e,t){if(!this.parsedArgs)throw Error(`Arguments have not been parsed yet. Call init() first.`);if(!(e in this.args))throw new x({arg:e,reason:`Argument "${e}" is not recognized`});this.parsedArgs[e]=t}isEmptyValue(e){return e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0}validateUnknownFlags(e){let t=new Set;for(let e in this.flags){t.add(e);let n=this.flags[e],r=Array.isArray(n.alias)?n.alias:n.alias?[n.alias]:[];for(let e of r)t.add(e)}for(let n in e)if(!t.has(n))throw new v(n,this.flags)}async handleOptions(e){let t={};for(let n in this.flags)t[n]=await this.resolveFlagValue(n,this.flags[n],e);return t}async handleArguments(e){let t={},n=[...e],r=Object.keys(this.args).length;for(let e in this.args){let r=this.args[e];if(`multiple`in r&&r.multiple){t[e]=await this.parseValue(n,r,`arg`,{name:e}),n.length=0;continue}t[e]=await this.parseValue(n.shift(),r,`arg`,{name:e})}if(this.shouldRejectExtraArguments&&n.length>0)throw new C(r,r+n.length);return t}async resolveFlagValue(e,t,n){let r,i=[e];t.alias&&i.push(...Array.isArray(t.alias)?t.alias:[t.alias]);for(let e of i)if(e in n){r=n[e];break}return this.parseValue(r,t,`flag`,{name:e})}async parseValue(e,t,n,r){if(this.isEmptyValue(e))return typeof t.default==`function`?await t.default():t.default;if(`multiple`in t&&t.multiple){Array.isArray(e)||(e=[e]);let i=[];for(let a of e)i.push(await this.safeParse(a,t,n,r));return i}return this.safeParse(e,t,n,r)}buildOpts(e,t){return{name:e,ux:this.ux,ctx:this.opts.ctx,definition:t,cmd:this.opts.cmd??Z}}async safeParse(e,t,n,r){try{return t.parse(e,this.buildOpts(r?.name??``,t))}catch(t){if(t instanceof S||t instanceof x||!r)throw t;let i=t instanceof Error?t.message:String(t);throw n===`flag`?new S({flag:r.name,value:e,reason:i}):new x({arg:r.name,value:e,reason:i})}}async validateSchema(e,t,n){for(let r in e){let i=e[r],a=t?.[r],o=this.isEmptyValue(a);if(i.required&&o){if(!this.shouldPromptForMissingFlags)throw n===`flag`?new b(r):new y(r);let e=await this.promptFor(r,i);if(e!=null&&t)a=await this.parseValue(e,i,n,{name:r}),t[r]=a;else throw n===`flag`?new b(r):new y(r)}}}disablePrompting(){return this.shouldPromptForMissingFlags=!1,this}allowUnknownFlags(){return this.shouldValidateUnknownFlags=!1,this}strictMode(){return this.shouldRejectExtraArguments=!0,this}async promptFor(e,t){return t.ask?t.ask(this.buildOpts(e,t)):null}};function E(e){return t=>({type:`custom`,default:e?.multiple||t?.multiple?[]:null,parse:e=>e,...e,...t})}function D(e,t){let n=`multiple`in t&&t.multiple,r=`${c.default.yellow.bold(e)} is required`;return t.description&&(r+=`: ${c.default.gray(`(${t.description})`)}`),r+=` ${c.default.green(`(${t.type}${n?`[]`:``})`)}\n`,r}function ee(e){if(typeof e==`boolean`)throw Error(`Expected a string, got boolean "${e}"`);return String(e)}function te(e,t){let n=typeof e==`number`?e:Number(e);if(isNaN(n))throw new w(`must be a valid number`);if(t?.min!==void 0&&n<t.min)throw new w(`is below minimum ${t.min}`);if(t?.max!==void 0&&n>t.max)throw new w(`exceeds maximum ${t.max}`);return n}function ne(e){if(typeof e==`boolean`)return e;let t=String(e).toLowerCase();if(t===`true`||t===`1`)return!0;if(t===`false`||t===`0`)return!1;throw new w(`Invalid boolean value: "${e}". Expected true, false, 1, or 0.`)}function re(e,t){let n=String(e);if(!t.includes(n))throw new w(`must be one of: ${t.map(e=>`"${e}"`).join(`, `)}`);return n}function ie(e,t){let n=String(e);if(t?.exists&&!l.default.existsSync(n))throw new w(`file does not exist`);return n}function ae(e,t){let n=String(e);if(t?.exists&&!(l.default.existsSync(n)&&l.default.lstatSync(n).isDirectory()))throw new w(`directory does not exist`);return n}function oe(e){try{return new URL(String(e))}catch{throw new w(`Invalid URL: "${e}"`)}}var se=E({default:!1,parse:e=>ne(e),ask:async e=>{let t=D(e.name,e.definition);return await e.ux.askForToggle(t)},type:`boolean`});async function ce(e){let t=e.definition,n=`multiple`in t&&t.multiple,r=D(e.name,t);return n?await e.ux.askForList(r+`Please provide one or more values, separated by commas:
|
|
2
|
-
`,{separator:`,`,validate:
|
|
3
|
-
`,{separator:`,`,validate:
|
|
4
|
-
`))};return s(),{increment:(t=1)=>{o||(a=Math.min(a+t,e),s())},update:t=>{o||(a=Math.max(0,Math.min(t,e)),s())},stop:c,[Symbol.dispose]:c,[Symbol.asyncDispose]:c}}function
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`chalk`);c=s(c,1);let l=require(`node:fs`);l=s(l,1);let u=require(`node:path`);u=s(u,1);let d=require(`minimist`);d=s(d,1);let f=require(`@inquirer/prompts`),p=require(`inquirer-file-selector`);var m=class{level;constructor(e={}){this.level=e.level??`info`}shouldLog(e){let 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)}},ee=class{getBigrams(e){let t=[],n=e.toLowerCase();for(let e=0;e<n.length-1;e++)t.push(n.slice(e,e+2));return t}calculateSimilarity(e,t){if(e===t)return 1;if(e.length<2||t.length<2)return 0;let n=this.getBigrams(e),r=this.getBigrams(t),i=new Set(r),a=0;for(let e of n)i.has(e)&&(a++,i.delete(e));return 2*a/(n.length+r.length)}findBestMatch(e,t){let n=t.map(t=>({target:t,rating:this.calculateSimilarity(e,t)})),r=0,i=n[0]?.rating??0;for(let e=1;e<n.length;e++)n[e].rating>i&&(i=n[e].rating,r=e);return{ratings:n,bestMatch:n[r],bestMatchIndex:r}}},h=class extends Error{$type=`BobError`},g=class extends h{constructor(e){super(`Command "${e}" not found.`),this.command=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Command ${c.default.bold.yellow(this.command)} not found.`),e.log(``)}},_=class extends h{constructor(e,t={}){super(`Flag ${e} is not recognized`),this.flag=e,this.flagsSchema=t}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.flag)} is not recognized.`);let t=Object.entries(this.flagsSchema);if(t.length>0){e.log(``),e.log(` ${c.default.dim(`Available flags:`)}`),e.log(``);let n=t.map(([e,t])=>{let n=t.alias?typeof t.alias==`string`?[t.alias]:t.alias:[],r=t.type===`option`&&`options`in t&&t.options?t.options.join(` | `):t.type;return{nameWithAlias:`--${e}${n.length>0?n.map(e=>`, -${e}`).join(``):``}`,description:t.description||``,typeDisplay:r}}),r=Math.max(...n.map(e=>e.nameWithAlias.length));for(let t of n){let n=` `.repeat(r-t.nameWithAlias.length+2);e.log(` ${c.default.green(t.nameWithAlias)}${n}${t.description} ${c.default.dim(`(${t.typeDisplay})`)}`)}}e.log(``)}},v=class extends h{constructor(e){super(`Argument "${e}" is required.`),this.argument=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Argument ${c.default.bold.yellow(this.argument)} is required.`),e.log(``)}},y=class extends h{constructor(e){super(`Flag "${e}" is required.`),this.flag=e}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.flag)} is required.`),e.log(``)}},b=class extends h{constructor(e,t){let n=`Argument "${e.arg}" value is invalid.`;e.reason?n+=` Reason: ${e.reason}`:n+=` Value: "${e.value}"`,super(n),this.detail=e,this.argDefinition=t}pretty(e){let t=[];if(this.detail.reason!=null&&t.push([`Reason`,this.detail.reason]),this.detail.value!=null&&t.push([`Value`,c.default.yellow(this.detail.value)]),this.argDefinition?.help!=null&&t.push([`Help`,c.default.green(this.argDefinition.help)]),e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Argument ${c.default.bold.yellow(this.detail.arg)} value is invalid.`),t.length>0){e.log(``);let n=Math.max(...t.map(([e])=>e.length));for(let[r,i]of t)e.log(` ${` `.repeat(n-r.length)}${c.default.dim(r)} ${i}`)}e.log(``)}},x=class extends h{constructor(e,t){let n=`Flag "${e.flag}" value is invalid.`;e.reason?n+=` Reason: ${e.reason}`:n+=` Value: "${e.value}"`,super(n),this.param=e,this.flagDefinition=t}pretty(e){let t=[];if(this.param.reason!=null&&t.push([`Reason`,this.param.reason]),this.param.value!=null&&t.push([`Value`,c.default.yellow(this.param.value)]),this.flagDefinition?.help!=null&&t.push([`Help`,c.default.green(this.flagDefinition.help)]),e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Flag ${c.default.bold.yellow(this.param.flag)} value is invalid.`),t.length>0){e.log(``);let n=Math.max(...t.map(([e])=>e.length));for(let[r,i]of t)e.log(` ${` `.repeat(n-r.length)}${c.default.dim(r)} ${i}`)}e.log(``)}},te=class extends h{constructor(e,t){super(`Too many arguments provided. Expected ${e}, got ${t}.`),this.expected=e,this.received=t}pretty(e){e.log(``),e.log(` ${c.default.bold.white.bgRed(` ERROR `)} Too many arguments. Expected ${c.default.bold.yellow(String(this.expected))}, got ${c.default.bold.yellow(String(this.received))}.`),e.log(``)}},S=class extends Error{constructor(e){super(e)}},C=class{flags;parsedFlags=null;args;parsedArgs=null;ux;shouldPromptForMissingFlags=!0;shouldValidateUnknownFlags=!0;shouldRejectExtraArguments=!1;constructor(e){this.opts=e,this.ux=e.ux,this.flags=e.flags,this.args=e.args}async init(e){let{_:t,...n}=(0,d.default)(e);return this.shouldValidateUnknownFlags&&this.validateUnknownFlags(n),this.parsedFlags=await this.handleOptions(n),this.parsedArgs=await this.handleArguments(t),{flags:this.parsedFlags,args:this.parsedArgs}}async validate(){await this.validateSchema(this.flags,this.parsedFlags,`flag`),await this.validateSchema(this.args,this.parsedArgs,`arg`)}flag(e,t){if(!this.parsedFlags)throw Error(`Flags have not been parsed yet. Call init() first.`);return this.isEmptyValue(this.parsedFlags[e])&&t!==void 0?t:this.parsedFlags[e]}async setFlag(e,t){if(!this.parsedFlags)throw Error(`Flags have not been parsed yet. Call init() first.`);if(!(e in this.flags))throw new _(e,this.flags);this.parsedFlags[e]=t}argument(e,t){if(!this.parsedArgs)throw Error(`Arguments have not been parsed yet. Call init() first.`);return this.isEmptyValue(this.parsedArgs[e])&&t!==void 0?t:this.parsedArgs[e]}async setArgument(e,t){if(!this.parsedArgs)throw Error(`Arguments have not been parsed yet. Call init() first.`);if(!(e in this.args))throw new b({arg:e,reason:`Argument "${e}" is not recognized`});this.parsedArgs[e]=t}isEmptyValue(e){return e==null||typeof e==`string`&&e.trim()===``||Array.isArray(e)&&e.length===0}validateUnknownFlags(e){let t=new Set;for(let e in this.flags){t.add(e);let n=this.flags[e],r=Array.isArray(n.alias)?n.alias:n.alias?[n.alias]:[];for(let e of r)t.add(e)}for(let n in e)if(!t.has(n))throw new _(n,this.flags)}async handleOptions(e){let t={};for(let n in this.flags)t[n]=await this.resolveFlagValue(n,this.flags[n],e);return t}async handleArguments(e){let t={},n=[...e],r=Object.keys(this.args).length;for(let e in this.args){let r=this.args[e];if(`multiple`in r&&r.multiple){t[e]=await this.parseValue(n,r,`arg`,{name:e}),n.length=0;continue}t[e]=await this.parseValue(n.shift(),r,`arg`,{name:e})}if(this.shouldRejectExtraArguments&&n.length>0)throw new te(r,r+n.length);return t}async resolveFlagValue(e,t,n){let r,i=[e];t.alias&&i.push(...Array.isArray(t.alias)?t.alias:[t.alias]);for(let e of i)if(e in n){r=n[e];break}return this.parseValue(r,t,`flag`,{name:e})}async parseValue(e,t,n,r){if(this.isEmptyValue(e))return typeof t.default==`function`?await t.default():t.default;if(`multiple`in t&&t.multiple){Array.isArray(e)||(e=[e]);let i=[];for(let a of e)i.push(await this.safeParse(a,t,n,r));return i}return this.safeParse(e,t,n,r)}buildOpts(e,t){return{name:e,ux:this.ux,ctx:this.opts.ctx,definition:t,cmd:this.opts.cmd??Z}}async safeParse(e,t,n,r){try{return t.parse(e,this.buildOpts(r?.name??``,t))}catch(t){if(t instanceof x||t instanceof b||!r)throw t;let i=t instanceof Error?t.message:String(t);throw n===`flag`?new x({flag:r.name,value:e,reason:i}):new b({arg:r.name,value:e,reason:i})}}async validateSchema(e,t,n){for(let r in e){let i=e[r],a=t?.[r],o=this.isEmptyValue(a);if(i.required&&o){if(!this.shouldPromptForMissingFlags)throw n===`flag`?new y(r):new v(r);let e=await this.promptFor(r,i);if(e!=null&&t)a=await this.parseValue(e,i,n,{name:r}),t[r]=a;else throw n===`flag`?new y(r):new v(r)}}}disablePrompting(){return this.shouldPromptForMissingFlags=!1,this}allowUnknownFlags(){return this.shouldValidateUnknownFlags=!1,this}strictMode(){return this.shouldRejectExtraArguments=!0,this}async promptFor(e,t){return t.ask?t.ask(this.buildOpts(e,t)):null}};function w(e){return t=>({type:`custom`,default:e?.multiple||t?.multiple?[]:null,parse:e=>e,...e,...t})}function T(e,t){let n=`multiple`in t&&t.multiple,r=`${c.default.yellow.bold(e)} is required`;return t.description&&(r+=`: ${c.default.gray(`(${t.description})`)}`),r+=` ${c.default.green(`(${t.type}${n?`[]`:``})`)}\n`,r}function ne(e){if(typeof e==`boolean`)throw Error(`Expected a string, got boolean "${e}"`);return String(e)}function re(e,t){let n=typeof e==`number`?e:Number(e);if(isNaN(n))throw new S(`must be a valid number`);if(t?.min!==void 0&&n<t.min)throw new S(`is below minimum ${t.min}`);if(t?.max!==void 0&&n>t.max)throw new S(`exceeds maximum ${t.max}`);return n}function ie(e){if(typeof e==`boolean`)return e;let t=String(e).toLowerCase();if(t===`true`||t===`1`)return!0;if(t===`false`||t===`0`)return!1;throw new S(`Invalid boolean value: "${e}". Expected true, false, 1, or 0.`)}function ae(e,t){let n=String(e);if(!t.includes(n))throw new S(`must be one of: ${t.map(e=>`"${e}"`).join(`, `)}`);return n}function oe(e,t){let n=String(e);if(t?.exists&&!l.default.existsSync(n))throw new S(`file does not exist`);return n}function se(e,t){let n=String(e);if(t?.exists)try{if(!l.default.lstatSync(n).isDirectory())throw new S(`directory does not exist`)}catch(e){throw e instanceof S?e:new S(`directory does not exist`)}return n}function ce(e){try{return new URL(String(e))}catch{throw new S(`Invalid URL: "${e}"`)}}var le=w({default:!1,parse:e=>ie(e),ask:async e=>{let t=T(e.name,e.definition);return await e.ux.askForToggle(t)},type:`boolean`});function E(e,t){return n=>{if((n==null||typeof n==`string`&&n.trim()===``)&&e.required)return`This value is required`;try{e.parse(n,t)}catch(e){return e instanceof S?e.message:`Invalid value`}return!0}}function D(e,t){return n=>{if((n==null||n.trim()===``)&&e.required)return`Please enter at least one value`;for(let r of n.split(`,`)){let n=r.trim();if(n!==``)try{e.parse(n,t)}catch(e){return e instanceof S?`"${n}": ${e.message}`:`"${n}": Invalid value`}}return!0}}async function ue(e){let t=e.definition,n=`multiple`in t&&t.multiple,r=T(e.name,t);return n?await e.ux.askForList(r+`Please provide one or more values, separated by commas:
|
|
2
|
+
`,{separator:`,`,validate:D(t,e)}):`secret`in t&&t.secret?e.ux.askForPassword(r,{validate:E(t,e)}):await e.ux.askForInput(r,{validate:E(t,e)})}async function de(e){let t=e.definition,n=`multiple`in t&&t.multiple,r=T(e.name,t);return n?await e.ux.askForList(r+`Please provide one or more values, separated by commas:
|
|
3
|
+
`,{separator:`,`,validate:D(t,e)}):await e.ux.askForNumber(r,{validate:n=>{if(n===void 0&&t.required)return`This value is required`;if(n!==void 0)try{t.parse(String(n),e)}catch(e){return e instanceof S?e.message:`Invalid value`}return!0}})}async function fe(e){let t=e.definition,n=`multiple`in t&&t.multiple,r=T(e.name,t);if(t.type!==`option`)return null;let i=t.options.map(e=>({name:e,value:e}));return n?await e.ux.askForCheckbox(r,i):await e.ux.askForSelect(r,i)}async function pe(e){let t=T(e.name,e.definition);return e.ux.askForFile(t,{basePath:process.cwd()})}async function me(e){let t=T(e.name,e.definition);return e.ux.askForDirectory(t,{basePath:process.cwd()})}async function he(e){let t=T(e.name,e.definition);return await e.ux.askForInput(t,{validate:E(e.definition,e)})}var O=w({parse:(e,t)=>se(e,{exists:t.definition.exists}),ask:me,type:`directory`}),k=w({parse:(e,t)=>oe(e,{exists:t.definition.exists}),ask:pe,type:`file`}),A=w({parse:(e,t)=>re(e,{min:t.definition.min,max:t.definition.max}),ask:de,type:`number`});function j(e){return w({parse:(e,t)=>ae(e,t.definition.options),ask:fe,...e,type:`option`})()}var M=w({parse:e=>ne(e),ask:ue,type:`string`}),N=w({parse:e=>ce(e),ask:he,type:`url`}),P={string:M,number:A,option:j,file:k,directory:O,url:N,custom:w},F={string:M,number:A,boolean:le,option:j,file:k,directory:O,url:N,custom:w};function I(e){return Array(e+5).join(` `)}function ge(e){let t=e.type;return t===`option`&&`options`in e&&e.options?`enum: ${e.options.join(`|`)}`:t??`custom`}var L=F.boolean({alias:[`h`],handler:(e,t)=>{if(!e)return{shouldStop:!1};let n=t.cmd,r=n.args,i={...n.baseFlags,...n.flags},a=Object.entries(r),o=Object.entries(i),s=o.map(([e,t])=>{let n=Array.isArray(t.alias)?t.alias:t.alias?[t.alias]:[];return{name:e,...t,flagWithAlias:`--${e}${n.map(e=>`, -${e}`).join(``)}`}}),l=a.filter(([,e])=>e.required);console.log(c.default.yellow(`Description:`)),console.log(` ${n.description}\n`),n.aliases.length>0&&(console.log(c.default.yellow(`Aliases:`)),console.log(` ${n.aliases.join(`, `)}\n`)),console.log(c.default.yellow(`Usage:`)),console.log(` ${n.command} ${l.length>0?l.map(([e])=>`<${e}>`).join(` `):`\b`} [options]`);let u=Math.max(...s.map(e=>e.flagWithAlias.length),0),d=Math.max(...a.map(([e])=>e.length),0),f=d>u?d:u;if(a.length>0){console.log(`\n${c.default.yellow(`Arguments`)}:`);for(let[e,t]of a){let n=I(f-e.length),r=` ${c.default.green(e)} ${n} ${t.description??`\b`}`;if(t.default!==void 0&&!t.required){let e=typeof t.default==`function`?`[function]`:t.multiple?JSON.stringify(t.default):t.default;r+=` ${c.default.yellow(`[default: ${e}]`)}`}`multiple`in t&&t.multiple&&(r+=` ${c.default.white(`(variadic)`)}`),console.log(r)}}if(o.length>0){console.log(`\n${c.default.yellow(`Options`)}:`);for(let e of s){let t=I(f-e.flagWithAlias.length),n=` ${c.default.green(e.flagWithAlias)} ${t} ${e.description??`\b`}`;if(e.type&&(n+=` ${c.default.white(`(${ge(e)})`)}`),e.default!==void 0&&!e.required){let t=typeof e.default==`function`?`(function)`:e.default;n+=` ${c.default.yellow(`[default: ${t}]`)}`}console.log(n)}}let p=n.examples??[];if(p.length>0){console.log(`\n${c.default.yellow(`Examples`)}:`);let e=process.argv[0].split(`/`).pop();e===`node`&&(e+=` `+process.argv[1].split(`/`).pop());for(let[t,n]of p.entries())t>0&&console.log(``),console.log(` ${n.description}\n`),console.log(` ${c.default.green(`${e} ${n.command}`)}`)}return{shouldStop:!0}}}),_e=class extends Error{name=`ExitPromptError`};async function R(e,t){try{return await e()}catch(e){if(e instanceof _e||e instanceof Error&&e.name===`ExitPromptError`)return t;throw e}}async function z(e,t,n){if(t.length===0)throw Error(`No options provided`);let r=t.map(e=>typeof e==`string`?{name:e,value:e}:{name:e.name,value:e.value,disabled:e.disabled,checked:e.checked,description:e.description});return R(()=>(0,f.checkbox)({message:e,choices:r,required:n?.required,pageSize:n?.pageSize,loop:n?.loop,validate:n?.validate,shortcuts:n?.shortcuts}),null)}async function B(e=`Do you want to continue?`,t){return R(()=>(0,f.confirm)({message:e,default:t?.default??!1,transformer:t?.transformer}),!1)}async function ve(e,t){return R(()=>(0,f.editor)({message:e,default:t?.default,postfix:t?.postfix,waitForUserInput:t?.waitForUserInput,validate:t?.validate}),null)}async function V(e,t,n){return R(()=>(0,f.expand)({message:e,choices:t,default:n?.default}),null)}async function H(e,t){return R(async()=>{let n=await(0,p.fileSelector)({message:e,basePath:t?.basePath,type:t?.type===`file+directory`?void 0:t?.type,filter:t?.filter,allowCancel:!0,pageSize:t?.pageSize,loop:t?.loop});return n===null?null:n.path},null)}async function U(e,t){return R(()=>(0,f.input)({message:e,default:t?.default,required:t?.required,validate:t?.validate,transformer:t?.transformer}),null)}async function W(e,t){let n=t?.separator??`,`;return R(async()=>(await(0,f.input)({message:e,default:t?.default,validate:t?.validate})).split(n).map(e=>e.trim()).filter(e=>e.length>0),null)}async function G(e,t){return R(async()=>await(0,f.number)({message:e,default:t?.default,required:t?.required,min:t?.min,max:t?.max,step:t?.step,validate:t?.validate})??null,null)}async function K(e,t){return R(()=>(0,f.password)({message:e,mask:t?.mask,validate:t?.validate}),null)}async function q(e,t,n){return R(()=>(0,f.rawlist)({message:e,choices:t,loop:n?.loop}),null)}async function J(e,t,n){return R(()=>(0,f.search)({message:e,source:t,pageSize:n?.pageSize,validate:n?.validate}),null)}async function ye(e,t,n){if(t.length===0)throw Error(`No options provided`);let r=t.map(e=>typeof e==`string`?{name:e,value:e}:e);return R(()=>(0,f.select)({message:e,choices:r,default:n?.default,pageSize:n?.pageSize,loop:n?.loop}),null)}async function be(e,t){let n=t?.active??`Yes`,r=t?.inactive??`No`;return R(()=>(0,f.confirm)({message:e,default:t?.default??!1,transformer:e=>e?n:r}),!1)}function xe(e,t){let n=t?.separator??`: `,r=t?.keyStyle??c.default.bold,i=Array.isArray(e)?e:Object.entries(e);if(i.length===0)return;let a=Math.max(...i.map(([e])=>e.length));for(let[e,t]of i)console.log(r(e.padEnd(a))+n+String(t??``))}function Se(e=``,t=[`⠙`,`⠘`,`⠰`,`⠴`,`⠤`,`⠦`,`⠆`,`⠃`,`⠋`,`⠉`],n=100){let r=e,i=null,a=e.length,o=0,s=e=>{let t=process.stdout.columns||80,n=e+2,r=Math.max(1,Math.ceil(n/t));if(process.stdout.isTTY&&process.stdout.clearLine&&process.stdout.moveCursor){r>1&&process.stdout.moveCursor(0,-(r-1));for(let e=0;e<r;e++)process.stdout.cursorTo(0),process.stdout.clearLine(1),e<r-1&&process.stdout.moveCursor(0,1);r>1&&process.stdout.moveCursor(0,-(r-1)),process.stdout.cursorTo(0)}else process.stdout.write(`\r`+` `.repeat(e+5)+`\r`)},c=setInterval(function(){i!==null&&(s(Math.max(i.length,r.length)),i=null),process.stdout.write(`\r`+t[o++]+` `+r),o%=t.length},n),l=()=>{clearInterval(c),s(a)};return{[Symbol.dispose]:l,[Symbol.asyncDispose]:l,updateText:e=>{i=r,r=e,a=Math.max(a,e.length)},stop:l}}function Ce(e,t){let n=t?.width??30,r=t?.completeChar??`█`,i=t?.incompleteChar??`░`,a=0,o=!1,s=()=>{if(o)return;let t=e<=0?1:Math.min(a/e,1),s=Math.round(t*n),c=`${r.repeat(s)+i.repeat(n-s)} ${Math.round(t*100)}% ${a}/${e}`;process.stdout.write(`\r`+c)},c=()=>{o||(o=!0,process.stdout.write(`
|
|
4
|
+
`))};return s(),{increment:(t=1)=>{o||(a=Math.min(a+t,e),s())},update:t=>{o||(a=Math.max(0,Math.min(t,e)),s())},stop:c,[Symbol.dispose]:c,[Symbol.asyncDispose]:c}}function Y(e,t){if(e.length===0)return;let n=t??Object.keys(e[0]).map(e=>({key:e})),r=n.map(e=>e.header??e.key.toUpperCase()),i=n.map((t,n)=>{let i=Math.max(r[n].length,...e.map(e=>(t.format?t.format(e[t.key]):String(e[t.key]??``)).length));return t.width?Math.min(i,t.width):i}),a=(e,t,n=`left`)=>{if(e.length>t)return e.slice(0,t-1)+`…`;switch(n){case`right`:return e.padStart(t);case`center`:{let n=Math.floor((t-e.length)/2);return` `.repeat(n)+e+` `.repeat(t-e.length-n)}default:return e.padEnd(t)}},o=n.map((e,t)=>a(r[t],i[t],e.alignment)).join(` `);console.log(c.default.bold(o));let s=i.map(e=>`-`.repeat(e)).join(` `);console.log(c.default.dim(s));for(let t of e){let e=n.map((e,n)=>a(e.format?e.format(t[e.key]):String(t[e.key]??``),i[n],e.alignment)).join(` `);console.log(e)}}var X=class{askForConfirmation(e,t){return B(e,t)}askForInput(e,t){return U(e,t)}askForPassword(e,t){return K(e,t)}askForNumber(e,t){return G(e,t)}askForSelect(e,t,n){return ye(e,t,n)}askForCheckbox(e,t,n){return z(e,t,n)}askForSearch(e,t,n){return J(e,t,n)}askForList(e,t){return W(e,t)}askForToggle(e,t){return be(e,t)}askForEditor(e,t){return ve(e,t)}askForRawList(e,t,n){return q(e,t,n)}askForExpand(e,t,n){return V(e,t,n)}askForFile(e,t){return H(e,{...t,type:`file`})}askForDirectory(e,t){return H(e,{...t,type:`directory`})}askForFileSelector(e,t){return H(e,t)}keyValue(e,t){return xe(e,t)}table(e,t){return Y(e,t)}newProgressBar(e,t){return Ce(e,t)}newLoader(e,t,n){return Se(e,t,n)}},Z=class{static $type=`BobCommand`;static command=``;static description=``;static group;static args={};static flags={};static examples=[];static hidden=!1;static aliases=[];static disableDefaultOptions=!1;static disablePrompting=!1;static allowUnknownFlags=!1;static strictMode=!1;ctx;logger;ux;parser;static baseFlags={help:L};newCommandParser(e){return new C({ux:e.ux,ctx:e.ctx,flags:e.flags,args:e.args,cmd:e.cmd})}newUX(){return new X}async run(e){let t=this.constructor;this.ctx=e.ctx,this.logger=e.logger,this.ux=this.newUX();let n;if(`flags`in e)n={flags:e.flags,args:e.args};else{this.parser=this.newCommandParser({ctx:this.ctx,ux:this.ux,flags:t.disableDefaultOptions?t.flags:{...t.baseFlags,...t.flags},args:t.args,cmd:t}),t.allowUnknownFlags&&this.parser.allowUnknownFlags(),t.strictMode&&this.parser.strictMode(),t.disablePrompting&&this.parser.disablePrompting();let r=await this.parser.init(e.args);for(let n in r.flags){let i=r.flags[n],a=t.flags[n]||t.baseFlags[n];if(a&&a.handler){let r={name:n,ux:this.ux,ctx:e.ctx,definition:a,cmd:t},o=a.handler(i,r);if(o&&o.shouldStop)return-1}}await this.parser.validate(),n={flags:r.flags,args:r.args}}if(this.preHandle){let e=await this.preHandle();if(e&&e!==0)return e}return await this.handle(this.ctx,n)??0}};function we(e){return typeof e==`object`&&!!e&&`$type`in e&&e.$type===`BobError`}function Q(e){return typeof e==`function`?e.prototype instanceof Z||e.$type===`BobCommand`:!1}var Te=class{commands={};aliases={};ux;logger;stringSimilarity;constructor(e){this.logger=e?.logger??new m,this.ux=e?.ux??new X,this.stringSimilarity=e?.stringSimilarity??new ee}getAvailableCommands(){return[...Object.keys(this.commands),...Object.keys(this.aliases)]}getCommands(){return Object.values(this.commands)}importFile=async e=>(await import(e)).default;commandResolver=async e=>{let t=await this.importFile(e);return t?(t&&typeof t==`object`&&`default`in t&&(t=t.default),typeof t==`function`&&Q(t)?t:null):null};withCommandResolver(e){return this.commandResolver=e,this}withFileImporter(e){return this.importFile=e,this}registerCommand(e,t=!1){if(!Q(e))throw Error(`Invalid command, it must extend the Command class.`);let n=e.command;if(!n)throw Error(`Cannot register a command with no name. ${e.name} `);if(!t&&this.commands[n])throw Error(`Command ${n} already registered.`);if(!t&&this.aliases[n])throw Error(`Command name ${n} conflicts with an existing alias.`);this.commands[n]=e;for(let r of e.aliases){if(!t&&this.commands[r])throw Error(`Alias ${r} conflicts with an existing command name.`);if(!t&&this.aliases[r])throw Error(`Alias ${r} already registered.`);this.aliases[r]=n}}async loadCommandsPath(e){for await(let t of this.listCommandsFiles(e))try{let e=await this.commandResolver(t);Q(e)&&this.registerCommand(e)}catch(e){throw Error(`Command ${t} failed to load. ${e}`,{cause:e})}}async runCommand(e,t,...n){let r;if(typeof t==`string`){let i=this.commands[t]??this.commands[this.aliases[t]];if(!i){let r=await this.suggestCommand(t);if(r)return await this.runCommand(e,r,...n);throw new g(t)}r=new i}else r=Q(t)?new t:t;return await r.run({ctx:e,logger:this.logger,args:n})??0}async suggestCommand(e){let t=this.getAvailableCommands(),{bestMatch:n,bestMatchIndex:r,ratings:i}=this.stringSimilarity.findBestMatch(e,t),a=i.filter(e=>e.rating>.3).map(e=>e.target);if(n&&(n.rating>0&&a.length<=1||n.rating>.7&&a.length>1)){let n=t[r];return await this.askRunSimilarCommand(e,n)?n:null}if(a.length){this.logger.error(`${c.default.bgRed(` ERROR `)} Command ${c.default.yellow(e)} not found.\n`);let t=await this.ux.askForSelect(c.default.green(`Did you mean to run one of these commands instead?`),a);if(t)return t}throw new g(e)}async askRunSimilarCommand(e,t){return this.logger.error(`${c.default.bgRed(` ERROR `)} Command ${c.default.yellow(e)} not found.\n`),this.ux.askForConfirmation(`${c.default.green(`Do you want to run ${c.default.yellow(t)} instead?`)} `)}async*listCommandsFiles(e){let t=await l.default.promises.readdir(e,{withFileTypes:!0});for(let n of t){let t=u.default.resolve(e,n.name);if(n.isDirectory())yield*this.listCommandsFiles(u.default.resolve(e,n.name));else{if(!t.endsWith(`.ts`)&&!t.endsWith(`.js`)&&!t.endsWith(`.mjs`)&&!t.endsWith(`.cjs`))continue;yield t}}}},Ee=class{logger;constructor(e){this.logger=e}handle(e){if(we(e))return e.pretty(this.logger),-1;throw e}},De,Oe=class extends Z{static command=`help`;static description=c.default.bold(`Show help information about the CLI and its commands`);constructor(e){super(),this.opts=e}async handle(){let e=this.opts.commandRegistry.getCommands().filter(e=>!e.hidden),t=this.opts.cliName??`Bob CLI`,n=this.opts.cliVersion??`0.0.0`;De??=(await Promise.resolve().then(()=>require(`../package-BI6Z9-0r.cjs`)))?.default?.version??`0.0.0`;let r=De;this.logger.log(`${t} ${c.default.green(n)} (core: ${c.default.yellow(r)})
|
|
5
5
|
|
|
6
6
|
${c.default.yellow(`Usage`)}:
|
|
7
7
|
command [options] [arguments]
|
|
8
8
|
|
|
9
9
|
${c.default.yellow(`Available commands`)}:
|
|
10
|
-
`);let i=Math.max(...e.map(e=>{let t=e.aliases.length>0?` (${e.aliases.join(`, `)})`:``;return e.command.length+t.length}))??0,a={};for(let t of e){let e=t.group??t.command.split(`:`)[0];a[e]||(a[e]=[]),a[e].push(t)}let o=Object.entries(a).sort(([e],[t])=>e.toLowerCase().localeCompare(t.toLowerCase())).sort(([,e],[,t])=>e.length-t.length);for(let[e,t]of o){let n=t.length>1;n&&this.logger.log(c.default.yellow(`${e}:`));let r=t.sort((e,t)=>e.command.toLowerCase().localeCompare(t.command.toLowerCase()));for(let e of r){let t=e.aliases.length>0?c.default.gray(` (${e.aliases.join(`, `)})`):``,r=I(i-(e.command.length+(e.aliases.length>0?` (${e.aliases.join(`, `)})`.length:0)));n&&(r=r.slice(2)),this.logger.log(`${n?` `:``}${c.default.green(e.command)}${t} ${r} ${e.description}`)}}}},
|
|
10
|
+
`);let i=Math.max(...e.map(e=>{let t=e.aliases.length>0?` (${e.aliases.join(`, `)})`:``;return e.command.length+t.length}))??0,a={};for(let t of e){let e=t.group??t.command.split(`:`)[0];a[e]||(a[e]=[]),a[e].push(t)}let o=Object.entries(a).sort(([e],[t])=>e.toLowerCase().localeCompare(t.toLowerCase())).sort(([,e],[,t])=>e.length-t.length);for(let[e,t]of o){let n=t.length>1;n&&this.logger.log(c.default.yellow(`${e}:`));let r=t.sort((e,t)=>e.command.toLowerCase().localeCompare(t.command.toLowerCase()));for(let e of r){let t=e.aliases.length>0?c.default.gray(` (${e.aliases.join(`, `)})`):``,r=I(i-(e.command.length+(e.aliases.length>0?` (${e.aliases.join(`, `)})`.length:0)));n&&(r=r.slice(2)),this.logger.log(`${n?` `:``}${c.default.green(e.command)}${t} ${r} ${e.description}`)}}}},ke=class{ctx;logger;commandRegistry;exceptionHandler;helpCommand;newCommandRegistry(e){return new Te(e)}newHelpCommand(e){return new Oe(e)}newExceptionHandler(e){return new Ee(e.logger)}constructor(e={}){this.ctx=e.ctx,this.logger=e.logger??new m,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(let t of e)typeof t==`string`?await this.commandRegistry.loadCommandsPath(t):typeof t==`function`?this.registerCommand(t):this.registerCommand(t.constructor)}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)}},$=class e{static parse(t,n={}){let[r,...i]=t.split(/\{(.*?)\}/g).map(e=>e.trim()).filter(Boolean),a={},o={};for(let t of i){let r=e.parseParamSignature(t,n);r.isFlag?a[r.name]=r.definition:o[r.name]=r.definition}return{command:r,flags:a,args:o}}static parseParamSignature(e,t){let n=e,r=!1,i,a,o,s=!1,c=!1,l=!0;if(n.includes(`:`)){let[e,t]=n.split(`:`);n=e.trim(),i=t.trim()}if(n.includes(`=`)){let[e,t]=n.split(`=`);n=e.trim();let r=t.trim();l=!1,r.length?r===`*`?(c=!0,a=[]):r===`true`?(s=!0,a=!0):r===`false`?(s=!0,a=!1):a=r:a=null}else n.startsWith(`--`)&&(s=!0,l=!1,a=!1);if(n.includes(`|`)){let[e,...t]=n.split(`|`);n=e.trim(),o=t.map(e=>e.trim())}n.startsWith(`--`)&&(r=!0,n=n.slice(2)),n.endsWith(`?`)&&(l=!1,n=n.slice(0,-1)),n.endsWith(`*`)&&(c=!0,a=[],n=n.slice(0,-1)),i=i??t[n]??t[`--${n}`];let u;return u=r?s?F.boolean({description:i,alias:o,...a===void 0?{}:{default:a}}):c?F.string({description:i,alias:o,multiple:!0,...l?{required:!0}:{},default:a??[]}):F.string({description:i,alias:o,...l?{required:!0}:{},...a===void 0?{}:{default:a}}):c?P.string({description:i,multiple:!0,...l?{required:!0}:{},default:a??[]}):P.string({description:i,...l?{required:!0}:{},...a===void 0?{}:{default:a}}),{name:n,isFlag:r,definition:u}}},Ae=class extends Z{static signature=``;static helperDefinitions={};static get command(){return this.signature.split(/\s/)[0]||``}async run(e){let t=this.constructor;if(t.signature&&!Object.prototype.hasOwnProperty.call(t,`_signatureParsed`)){let e=$.parse(t.signature,t.helperDefinitions),n=Object.prototype.hasOwnProperty.call(t,`flags`)?t.flags:{},r=Object.prototype.hasOwnProperty.call(t,`args`)?t.args:{};t.flags={...e.flags,...n},t.args={...e.args,...r},Object.defineProperty(t,`_signatureParsed`,{value:!0})}return super.run(e)}option(e,t=null){return this.parser.flag(e,t)}argument(e,t=null){return this.parser.argument(e,t)}};exports.Args=P,exports.BadCommandArgument=b,exports.BadCommandFlag=x,exports.BobError=h,exports.Cli=ke,exports.Command=Z,exports.CommandNotFoundError=g,exports.CommandParser=C,exports.CommandRegistry=Te,exports.CommandSignatureParser=$,exports.CommandWithSignature=Ae,exports.ExceptionHandler=Ee,exports.Flags=F,exports.HelpCommandFlag=L,exports.InvalidFlag=_,exports.Logger=m,exports.MissingRequiredArgumentValue=v,exports.MissingRequiredFlagValue=y,exports.StringSimilarity=ee,exports.TooManyArguments=te,exports.UX=X,exports.ValidationError=S,exports.askForCheckbox=z,exports.askForConfirmation=B,exports.askForEditor=ve,exports.askForExpand=V,exports.askForFileSelector=H,exports.askForInput=U,exports.askForList=W,exports.askForNumber=G,exports.askForPassword=K,exports.askForRawList=q,exports.askForSearch=J,exports.askForSelect=ye,exports.askForToggle=be,exports.keyValue=xe,exports.newLoader=Se,exports.newProgressBar=Ce,exports.table=Y,exports.withCancelHandling=R;
|
|
@@ -10,7 +10,7 @@ export type ParameterOpts<C extends ContextDefinition = ContextDefinition> = {
|
|
|
10
10
|
cmd: typeof Command;
|
|
11
11
|
};
|
|
12
12
|
export type FlagProps<T = any> = {
|
|
13
|
-
type?: string;
|
|
13
|
+
type?: 'string' | 'number' | 'boolean' | 'option' | 'file' | 'directory' | 'url' | 'custom';
|
|
14
14
|
parse?: (input: any, opts: ParameterOpts) => T;
|
|
15
15
|
ask?: (opts: ParameterOpts) => Promise<any>;
|
|
16
16
|
description?: string;
|
|
@@ -27,11 +27,6 @@ export type FlagDefinition = FlagProps & {
|
|
|
27
27
|
parse(input: any, opts: ParameterOpts): any;
|
|
28
28
|
};
|
|
29
29
|
export type FlagType<O> = O extends {
|
|
30
|
-
type: 'option';
|
|
31
|
-
options: infer T extends readonly string[];
|
|
32
|
-
} ? O extends {
|
|
33
|
-
multiple: true;
|
|
34
|
-
} ? [T[number]] extends [Array<unknown>] ? T[number] : T[number][] : T[number] : O extends {
|
|
35
30
|
parse: (...args: any[]) => infer R;
|
|
36
31
|
} ? O extends {
|
|
37
32
|
multiple: true;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var e = {
|
|
2
2
|
name: "bob-core",
|
|
3
|
-
version: "3.0.0-
|
|
3
|
+
version: "3.0.0-beta.2",
|
|
4
4
|
description: "BOB Core",
|
|
5
5
|
type: "module",
|
|
6
6
|
main: "./dist/cjs/src/index.js",
|
|
@@ -49,7 +49,8 @@ var e = {
|
|
|
49
49
|
vitest: "^4.1.0"
|
|
50
50
|
},
|
|
51
51
|
dependencies: {
|
|
52
|
-
"@inquirer/
|
|
52
|
+
"@inquirer/core": "^11.1.8",
|
|
53
|
+
"@inquirer/prompts": "^8.4.1",
|
|
53
54
|
chalk: "^4.1.2",
|
|
54
55
|
"inquirer-file-selector": "^1.0.1",
|
|
55
56
|
minimist: "^1.2.8"
|
|
@@ -2,7 +2,5 @@ import { FlagProps, ParameterOpts } from '../lib/types.js';
|
|
|
2
2
|
export declare function optionFlag<const T extends readonly string[], const U extends Partial<FlagProps>>(opts: {
|
|
3
3
|
options: T;
|
|
4
4
|
} & U): U & FlagProps<T[number]> & {
|
|
5
|
-
type: 'option';
|
|
6
|
-
options: T;
|
|
7
5
|
parse(input: any, opts: ParameterOpts): T[number];
|
|
8
6
|
};
|
package/dist/esm/src/index.js
CHANGED
|
@@ -119,7 +119,7 @@ var m = class {
|
|
|
119
119
|
}
|
|
120
120
|
pretty(t) {
|
|
121
121
|
let n = [];
|
|
122
|
-
if (this.detail.reason != null && n.push(["Reason", this.detail.reason]), this.detail.value != null && n.push(["Value", this.detail.value]), this.argDefinition?.help != null && n.push(["Help", e.green(this.argDefinition.help)]), t.log(""), t.log(` ${e.bold.white.bgRed(" ERROR ")} Argument ${e.bold.yellow(this.detail.arg)} value is invalid.`), n.length > 0) {
|
|
122
|
+
if (this.detail.reason != null && n.push(["Reason", this.detail.reason]), this.detail.value != null && n.push(["Value", e.yellow(this.detail.value)]), this.argDefinition?.help != null && n.push(["Help", e.green(this.argDefinition.help)]), t.log(""), t.log(` ${e.bold.white.bgRed(" ERROR ")} Argument ${e.bold.yellow(this.detail.arg)} value is invalid.`), n.length > 0) {
|
|
123
123
|
t.log("");
|
|
124
124
|
let r = Math.max(...n.map(([e]) => e.length));
|
|
125
125
|
for (let [i, a] of n) t.log(` ${" ".repeat(r - i.length)}${e.dim(i)} ${a}`);
|
|
@@ -133,7 +133,7 @@ var m = class {
|
|
|
133
133
|
}
|
|
134
134
|
pretty(t) {
|
|
135
135
|
let n = [];
|
|
136
|
-
if (this.param.reason != null && n.push(["Reason", this.param.reason]), this.param.value != null && n.push(["Value", this.param.value]), this.flagDefinition?.help != null && n.push(["Help", e.green(this.flagDefinition.help)]), t.log(""), t.log(` ${e.bold.white.bgRed(" ERROR ")} Flag ${e.bold.yellow(this.param.flag)} value is invalid.`), n.length > 0) {
|
|
136
|
+
if (this.param.reason != null && n.push(["Reason", this.param.reason]), this.param.value != null && n.push(["Value", e.yellow(this.param.value)]), this.flagDefinition?.help != null && n.push(["Help", e.green(this.flagDefinition.help)]), t.log(""), t.log(` ${e.bold.white.bgRed(" ERROR ")} Flag ${e.bold.yellow(this.param.flag)} value is invalid.`), n.length > 0) {
|
|
137
137
|
t.log("");
|
|
138
138
|
let r = Math.max(...n.map(([e]) => e.length));
|
|
139
139
|
for (let [i, a] of n) t.log(` ${" ".repeat(r - i.length)}${e.dim(i)} ${a}`);
|
|
@@ -249,7 +249,7 @@ var m = class {
|
|
|
249
249
|
ux: this.ux,
|
|
250
250
|
ctx: this.opts.ctx,
|
|
251
251
|
definition: t,
|
|
252
|
-
cmd: this.opts.cmd ??
|
|
252
|
+
cmd: this.opts.cmd ?? Z
|
|
253
253
|
};
|
|
254
254
|
}
|
|
255
255
|
async safeParse(e, t, n, r) {
|
|
@@ -342,7 +342,11 @@ function ae(e, n) {
|
|
|
342
342
|
}
|
|
343
343
|
function oe(e, n) {
|
|
344
344
|
let r = String(e);
|
|
345
|
-
if (n?.exists
|
|
345
|
+
if (n?.exists) try {
|
|
346
|
+
if (!t.lstatSync(r).isDirectory()) throw new w("directory does not exist");
|
|
347
|
+
} catch (e) {
|
|
348
|
+
throw e instanceof w ? e : new w("directory does not exist");
|
|
349
|
+
}
|
|
346
350
|
return r;
|
|
347
351
|
}
|
|
348
352
|
function se(e) {
|
|
@@ -365,56 +369,43 @@ var ce = E({
|
|
|
365
369
|
});
|
|
366
370
|
//#endregion
|
|
367
371
|
//#region src/shared/ask-helpers.ts
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
separator: ",",
|
|
372
|
-
validate: (n) => {
|
|
373
|
-
if ((n == null || n.trim() === "") && t.required) return "Please enter at least one value";
|
|
374
|
-
for (let r of n.split(",")) {
|
|
375
|
-
let n = r.trim();
|
|
376
|
-
if (n !== "") try {
|
|
377
|
-
t.parse(n, e);
|
|
378
|
-
} catch (e) {
|
|
379
|
-
return e instanceof w ? `"${n}": ${e.message}` : `"${n}": Invalid value`;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
return !0;
|
|
383
|
-
}
|
|
384
|
-
}) : "secret" in t && t.secret ? e.ux.askForPassword(r, { validate: (n) => {
|
|
385
|
-
if ((n == null || typeof n == "string" && n.trim() === "") && t.required) return "This value is required";
|
|
372
|
+
function O(e, t) {
|
|
373
|
+
return (n) => {
|
|
374
|
+
if ((n == null || typeof n == "string" && n.trim() === "") && e.required) return "This value is required";
|
|
386
375
|
try {
|
|
387
|
-
|
|
376
|
+
e.parse(n, t);
|
|
388
377
|
} catch (e) {
|
|
389
378
|
return e instanceof w ? e.message : "Invalid value";
|
|
390
379
|
}
|
|
391
380
|
return !0;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function k(e, t) {
|
|
384
|
+
return (n) => {
|
|
385
|
+
if ((n == null || n.trim() === "") && e.required) return "Please enter at least one value";
|
|
386
|
+
for (let r of n.split(",")) {
|
|
387
|
+
let n = r.trim();
|
|
388
|
+
if (n !== "") try {
|
|
389
|
+
e.parse(n, t);
|
|
390
|
+
} catch (e) {
|
|
391
|
+
return e instanceof w ? `"${n}": ${e.message}` : `"${n}": Invalid value`;
|
|
392
|
+
}
|
|
398
393
|
}
|
|
399
394
|
return !0;
|
|
400
|
-
}
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
async function le(e) {
|
|
398
|
+
let t = e.definition, n = "multiple" in t && t.multiple, r = D(e.name, t);
|
|
399
|
+
return n ? await e.ux.askForList(r + "Please provide one or more values, separated by commas:\n", {
|
|
400
|
+
separator: ",",
|
|
401
|
+
validate: k(t, e)
|
|
402
|
+
}) : "secret" in t && t.secret ? e.ux.askForPassword(r, { validate: O(t, e) }) : await e.ux.askForInput(r, { validate: O(t, e) });
|
|
401
403
|
}
|
|
402
404
|
async function ue(e) {
|
|
403
405
|
let t = e.definition, n = "multiple" in t && t.multiple, r = D(e.name, t);
|
|
404
406
|
return n ? await e.ux.askForList(r + "Please provide one or more values, separated by commas:\n", {
|
|
405
407
|
separator: ",",
|
|
406
|
-
validate: (
|
|
407
|
-
if ((n == null || n.trim() === "") && t.required) return "Please enter at least one value";
|
|
408
|
-
for (let r of n.split(",")) {
|
|
409
|
-
let n = r.trim();
|
|
410
|
-
if (n !== "") try {
|
|
411
|
-
t.parse(n, e);
|
|
412
|
-
} catch (e) {
|
|
413
|
-
return e instanceof w ? `"${n}": ${e.message}` : `"${n}": Invalid value`;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
return !0;
|
|
417
|
-
}
|
|
408
|
+
validate: k(t, e)
|
|
418
409
|
}) : await e.ux.askForNumber(r, { validate: (n) => {
|
|
419
410
|
if (n === void 0 && t.required) return "This value is required";
|
|
420
411
|
if (n !== void 0) try {
|
|
@@ -444,27 +435,19 @@ async function pe(e) {
|
|
|
444
435
|
}
|
|
445
436
|
async function me(e) {
|
|
446
437
|
let t = D(e.name, e.definition);
|
|
447
|
-
return await e.ux.askForInput(t, { validate: (
|
|
448
|
-
if ((t == null || typeof t == "string" && t.trim() === "") && e.definition.required) return "This value is required";
|
|
449
|
-
try {
|
|
450
|
-
e.definition.parse(t, e);
|
|
451
|
-
} catch (e) {
|
|
452
|
-
return e instanceof w ? e.message : "Invalid value";
|
|
453
|
-
}
|
|
454
|
-
return !0;
|
|
455
|
-
} });
|
|
438
|
+
return await e.ux.askForInput(t, { validate: O(e.definition, e) });
|
|
456
439
|
}
|
|
457
440
|
//#endregion
|
|
458
441
|
//#region src/flags/directory.ts
|
|
459
|
-
var
|
|
442
|
+
var A = E({
|
|
460
443
|
parse: (e, t) => oe(e, { exists: t.definition.exists }),
|
|
461
444
|
ask: pe,
|
|
462
445
|
type: "directory"
|
|
463
|
-
}),
|
|
446
|
+
}), j = E({
|
|
464
447
|
parse: (e, t) => ae(e, { exists: t.definition.exists }),
|
|
465
448
|
ask: fe,
|
|
466
449
|
type: "file"
|
|
467
|
-
}),
|
|
450
|
+
}), M = E({
|
|
468
451
|
parse: (e, t) => ne(e, {
|
|
469
452
|
min: t.definition.min,
|
|
470
453
|
max: t.definition.max
|
|
@@ -474,7 +457,7 @@ var O = E({
|
|
|
474
457
|
});
|
|
475
458
|
//#endregion
|
|
476
459
|
//#region src/flags/option.ts
|
|
477
|
-
function
|
|
460
|
+
function N(e) {
|
|
478
461
|
return E({
|
|
479
462
|
parse: (e, t) => ie(e, t.definition.options),
|
|
480
463
|
ask: de,
|
|
@@ -484,35 +467,35 @@ function j(e) {
|
|
|
484
467
|
}
|
|
485
468
|
//#endregion
|
|
486
469
|
//#region src/flags/string.ts
|
|
487
|
-
var
|
|
470
|
+
var P = E({
|
|
488
471
|
parse: (e) => te(e),
|
|
489
472
|
ask: le,
|
|
490
473
|
type: "string"
|
|
491
|
-
}),
|
|
474
|
+
}), F = E({
|
|
492
475
|
parse: (e) => se(e),
|
|
493
476
|
ask: me,
|
|
494
477
|
type: "url"
|
|
495
|
-
}),
|
|
496
|
-
string:
|
|
497
|
-
number:
|
|
498
|
-
option:
|
|
499
|
-
file:
|
|
500
|
-
directory:
|
|
501
|
-
url:
|
|
478
|
+
}), I = {
|
|
479
|
+
string: P,
|
|
480
|
+
number: M,
|
|
481
|
+
option: N,
|
|
482
|
+
file: j,
|
|
483
|
+
directory: A,
|
|
484
|
+
url: F,
|
|
502
485
|
custom: E
|
|
503
|
-
},
|
|
504
|
-
string:
|
|
505
|
-
number:
|
|
486
|
+
}, L = {
|
|
487
|
+
string: P,
|
|
488
|
+
number: M,
|
|
506
489
|
boolean: ce,
|
|
507
|
-
option:
|
|
508
|
-
file:
|
|
509
|
-
directory:
|
|
510
|
-
url:
|
|
490
|
+
option: N,
|
|
491
|
+
file: j,
|
|
492
|
+
directory: A,
|
|
493
|
+
url: F,
|
|
511
494
|
custom: E
|
|
512
495
|
};
|
|
513
496
|
//#endregion
|
|
514
497
|
//#region src/lib/string.ts
|
|
515
|
-
function
|
|
498
|
+
function R(e) {
|
|
516
499
|
return Array(e + 5).join(" ");
|
|
517
500
|
}
|
|
518
501
|
//#endregion
|
|
@@ -521,7 +504,7 @@ function he(e) {
|
|
|
521
504
|
let t = e.type;
|
|
522
505
|
return t === "option" && "options" in e && e.options ? `enum: ${e.options.join("|")}` : t ?? "custom";
|
|
523
506
|
}
|
|
524
|
-
var
|
|
507
|
+
var z = L.boolean({
|
|
525
508
|
alias: ["h"],
|
|
526
509
|
handler: (t, n) => {
|
|
527
510
|
if (!t) return { shouldStop: !1 };
|
|
@@ -541,7 +524,7 @@ var L = F.boolean({
|
|
|
541
524
|
if (o.length > 0) {
|
|
542
525
|
console.log(`\n${e.yellow("Arguments")}:`);
|
|
543
526
|
for (let [t, n] of o) {
|
|
544
|
-
let r =
|
|
527
|
+
let r = R(f - t.length), i = ` ${e.green(t)} ${r} ${n.description ?? "\b"}`;
|
|
545
528
|
if (n.default !== void 0 && !n.required) {
|
|
546
529
|
let t = typeof n.default == "function" ? "[function]" : n.multiple ? JSON.stringify(n.default) : n.default;
|
|
547
530
|
i += ` ${e.yellow(`[default: ${t}]`)}`;
|
|
@@ -552,7 +535,7 @@ var L = F.boolean({
|
|
|
552
535
|
if (s.length > 0) {
|
|
553
536
|
console.log(`\n${e.yellow("Options")}:`);
|
|
554
537
|
for (let t of c) {
|
|
555
|
-
let n =
|
|
538
|
+
let n = R(f - t.flagWithAlias.length), r = ` ${e.green(t.flagWithAlias)} ${n} ${t.description ?? "\b"}`;
|
|
556
539
|
if (t.type && (r += ` ${e.white(`(${he(t)})`)}`), t.default !== void 0 && !t.required) {
|
|
557
540
|
let n = typeof t.default == "function" ? "(function)" : t.default;
|
|
558
541
|
r += ` ${e.yellow(`[default: ${n}]`)}`;
|
|
@@ -574,7 +557,7 @@ var L = F.boolean({
|
|
|
574
557
|
};
|
|
575
558
|
//#endregion
|
|
576
559
|
//#region src/ux/helpers.ts
|
|
577
|
-
async function
|
|
560
|
+
async function B(e, t) {
|
|
578
561
|
try {
|
|
579
562
|
return await e();
|
|
580
563
|
} catch (e) {
|
|
@@ -584,7 +567,7 @@ async function R(e, t) {
|
|
|
584
567
|
}
|
|
585
568
|
//#endregion
|
|
586
569
|
//#region src/ux/askForCheckbox.ts
|
|
587
|
-
async function
|
|
570
|
+
async function V(e, t, n) {
|
|
588
571
|
if (t.length === 0) throw Error("No options provided");
|
|
589
572
|
let r = t.map((e) => typeof e == "string" ? {
|
|
590
573
|
name: e,
|
|
@@ -596,7 +579,7 @@ async function z(e, t, n) {
|
|
|
596
579
|
checked: e.checked,
|
|
597
580
|
description: e.description
|
|
598
581
|
});
|
|
599
|
-
return
|
|
582
|
+
return B(() => i({
|
|
600
583
|
message: e,
|
|
601
584
|
choices: r,
|
|
602
585
|
required: n?.required,
|
|
@@ -608,8 +591,8 @@ async function z(e, t, n) {
|
|
|
608
591
|
}
|
|
609
592
|
//#endregion
|
|
610
593
|
//#region src/ux/askForConfirmation.ts
|
|
611
|
-
async function
|
|
612
|
-
return
|
|
594
|
+
async function H(e = "Do you want to continue?", t) {
|
|
595
|
+
return B(() => a({
|
|
613
596
|
message: e,
|
|
614
597
|
default: t?.default ?? !1,
|
|
615
598
|
transformer: t?.transformer
|
|
@@ -617,8 +600,8 @@ async function B(e = "Do you want to continue?", t) {
|
|
|
617
600
|
}
|
|
618
601
|
//#endregion
|
|
619
602
|
//#region src/ux/askForEditor.ts
|
|
620
|
-
async function
|
|
621
|
-
return
|
|
603
|
+
async function U(e, t) {
|
|
604
|
+
return B(() => o({
|
|
622
605
|
message: e,
|
|
623
606
|
default: t?.default,
|
|
624
607
|
postfix: t?.postfix,
|
|
@@ -628,8 +611,8 @@ async function V(e, t) {
|
|
|
628
611
|
}
|
|
629
612
|
//#endregion
|
|
630
613
|
//#region src/ux/askForExpand.ts
|
|
631
|
-
async function
|
|
632
|
-
return
|
|
614
|
+
async function W(e, t, n) {
|
|
615
|
+
return B(() => s({
|
|
633
616
|
message: e,
|
|
634
617
|
choices: t,
|
|
635
618
|
default: n?.default
|
|
@@ -637,8 +620,8 @@ async function H(e, t, n) {
|
|
|
637
620
|
}
|
|
638
621
|
//#endregion
|
|
639
622
|
//#region src/ux/askForFileSelector.ts
|
|
640
|
-
async function
|
|
641
|
-
return
|
|
623
|
+
async function G(e, t) {
|
|
624
|
+
return B(async () => {
|
|
642
625
|
let n = await ee({
|
|
643
626
|
message: e,
|
|
644
627
|
basePath: t?.basePath,
|
|
@@ -653,8 +636,8 @@ async function U(e, t) {
|
|
|
653
636
|
}
|
|
654
637
|
//#endregion
|
|
655
638
|
//#region src/ux/askForInput.ts
|
|
656
|
-
async function
|
|
657
|
-
return
|
|
639
|
+
async function K(e, t) {
|
|
640
|
+
return B(() => c({
|
|
658
641
|
message: e,
|
|
659
642
|
default: t?.default,
|
|
660
643
|
required: t?.required,
|
|
@@ -664,9 +647,9 @@ async function W(e, t) {
|
|
|
664
647
|
}
|
|
665
648
|
//#endregion
|
|
666
649
|
//#region src/ux/askForList.ts
|
|
667
|
-
async function
|
|
650
|
+
async function q(e, t) {
|
|
668
651
|
let n = t?.separator ?? ",";
|
|
669
|
-
return
|
|
652
|
+
return B(async () => (await c({
|
|
670
653
|
message: e,
|
|
671
654
|
default: t?.default,
|
|
672
655
|
validate: t?.validate
|
|
@@ -674,8 +657,8 @@ async function G(e, t) {
|
|
|
674
657
|
}
|
|
675
658
|
//#endregion
|
|
676
659
|
//#region src/ux/askForNumber.ts
|
|
677
|
-
async function
|
|
678
|
-
return
|
|
660
|
+
async function J(e, t) {
|
|
661
|
+
return B(async () => await l({
|
|
679
662
|
message: e,
|
|
680
663
|
default: t?.default,
|
|
681
664
|
required: t?.required,
|
|
@@ -687,8 +670,8 @@ async function K(e, t) {
|
|
|
687
670
|
}
|
|
688
671
|
//#endregion
|
|
689
672
|
//#region src/ux/askForPassword.ts
|
|
690
|
-
async function
|
|
691
|
-
return
|
|
673
|
+
async function _e(e, t) {
|
|
674
|
+
return B(() => u({
|
|
692
675
|
message: e,
|
|
693
676
|
mask: t?.mask,
|
|
694
677
|
validate: t?.validate
|
|
@@ -696,8 +679,8 @@ async function q(e, t) {
|
|
|
696
679
|
}
|
|
697
680
|
//#endregion
|
|
698
681
|
//#region src/ux/askForRawList.ts
|
|
699
|
-
async function
|
|
700
|
-
return
|
|
682
|
+
async function ve(e, t, n) {
|
|
683
|
+
return B(() => d({
|
|
701
684
|
message: e,
|
|
702
685
|
choices: t,
|
|
703
686
|
loop: n?.loop
|
|
@@ -705,8 +688,8 @@ async function J(e, t, n) {
|
|
|
705
688
|
}
|
|
706
689
|
//#endregion
|
|
707
690
|
//#region src/ux/askForSearch.ts
|
|
708
|
-
async function
|
|
709
|
-
return
|
|
691
|
+
async function ye(e, t, n) {
|
|
692
|
+
return B(() => f({
|
|
710
693
|
message: e,
|
|
711
694
|
source: t,
|
|
712
695
|
pageSize: n?.pageSize,
|
|
@@ -715,13 +698,13 @@ async function _e(e, t, n) {
|
|
|
715
698
|
}
|
|
716
699
|
//#endregion
|
|
717
700
|
//#region src/ux/askForSelect.ts
|
|
718
|
-
async function
|
|
701
|
+
async function be(e, t, n) {
|
|
719
702
|
if (t.length === 0) throw Error("No options provided");
|
|
720
703
|
let r = t.map((e) => typeof e == "string" ? {
|
|
721
704
|
name: e,
|
|
722
705
|
value: e
|
|
723
706
|
} : e);
|
|
724
|
-
return
|
|
707
|
+
return B(() => p({
|
|
725
708
|
message: e,
|
|
726
709
|
choices: r,
|
|
727
710
|
default: n?.default,
|
|
@@ -731,9 +714,9 @@ async function ve(e, t, n) {
|
|
|
731
714
|
}
|
|
732
715
|
//#endregion
|
|
733
716
|
//#region src/ux/askForToggle.ts
|
|
734
|
-
async function
|
|
717
|
+
async function Y(e, t) {
|
|
735
718
|
let n = t?.active ?? "Yes", r = t?.inactive ?? "No";
|
|
736
|
-
return
|
|
719
|
+
return B(() => a({
|
|
737
720
|
message: e,
|
|
738
721
|
default: t?.default ?? !1,
|
|
739
722
|
transformer: (e) => e ? n : r
|
|
@@ -741,7 +724,7 @@ async function ye(e, t) {
|
|
|
741
724
|
}
|
|
742
725
|
//#endregion
|
|
743
726
|
//#region src/ux/keyValue.ts
|
|
744
|
-
function
|
|
727
|
+
function xe(t, n) {
|
|
745
728
|
let r = n?.separator ?? ": ", i = n?.keyStyle ?? e.bold, a = Array.isArray(t) ? t : Object.entries(t);
|
|
746
729
|
if (a.length === 0) return;
|
|
747
730
|
let o = Math.max(...a.map(([e]) => e.length));
|
|
@@ -749,7 +732,7 @@ function be(t, n) {
|
|
|
749
732
|
}
|
|
750
733
|
//#endregion
|
|
751
734
|
//#region src/ux/loader.ts
|
|
752
|
-
function
|
|
735
|
+
function Se(e = "", t = [
|
|
753
736
|
"⠙",
|
|
754
737
|
"⠘",
|
|
755
738
|
"⠰",
|
|
@@ -761,23 +744,30 @@ function xe(e = "", t = [
|
|
|
761
744
|
"⠋",
|
|
762
745
|
"⠉"
|
|
763
746
|
], n = 100) {
|
|
764
|
-
let r = e, i = null, a =
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
747
|
+
let r = e, i = null, a = e.length, o = 0, s = (e) => {
|
|
748
|
+
let t = process.stdout.columns || 80, n = e + 2, r = Math.max(1, Math.ceil(n / t));
|
|
749
|
+
if (process.stdout.isTTY && process.stdout.clearLine && process.stdout.moveCursor) {
|
|
750
|
+
r > 1 && process.stdout.moveCursor(0, -(r - 1));
|
|
751
|
+
for (let e = 0; e < r; e++) process.stdout.cursorTo(0), process.stdout.clearLine(1), e < r - 1 && process.stdout.moveCursor(0, 1);
|
|
752
|
+
r > 1 && process.stdout.moveCursor(0, -(r - 1)), process.stdout.cursorTo(0);
|
|
753
|
+
} else process.stdout.write("\r" + " ".repeat(e + 5) + "\r");
|
|
754
|
+
}, c = setInterval(function() {
|
|
755
|
+
i !== null && (s(Math.max(i.length, r.length)), i = null), process.stdout.write("\r" + t[o++] + " " + r), o %= t.length;
|
|
756
|
+
}, n), l = () => {
|
|
757
|
+
clearInterval(c), s(a);
|
|
768
758
|
};
|
|
769
759
|
return {
|
|
770
|
-
[Symbol.dispose]:
|
|
771
|
-
[Symbol.asyncDispose]:
|
|
760
|
+
[Symbol.dispose]: l,
|
|
761
|
+
[Symbol.asyncDispose]: l,
|
|
772
762
|
updateText: (e) => {
|
|
773
|
-
i = r, r = e;
|
|
763
|
+
i = r, r = e, a = Math.max(a, e.length);
|
|
774
764
|
},
|
|
775
|
-
stop:
|
|
765
|
+
stop: l
|
|
776
766
|
};
|
|
777
767
|
}
|
|
778
768
|
//#endregion
|
|
779
769
|
//#region src/ux/progressBar.ts
|
|
780
|
-
function
|
|
770
|
+
function Ce(e, t) {
|
|
781
771
|
let n = t?.width ?? 30, r = t?.completeChar ?? "█", i = t?.incompleteChar ?? "░", a = 0, o = !1, s = () => {
|
|
782
772
|
if (o) return;
|
|
783
773
|
let t = e <= 0 ? 1 : Math.min(a / e, 1), s = Math.round(t * n), c = `${r.repeat(s) + i.repeat(n - s)} ${Math.round(t * 100)}% ${a}/${e}`;
|
|
@@ -799,7 +789,7 @@ function Se(e, t) {
|
|
|
799
789
|
}
|
|
800
790
|
//#endregion
|
|
801
791
|
//#region src/ux/table.ts
|
|
802
|
-
function
|
|
792
|
+
function we(t, n) {
|
|
803
793
|
if (t.length === 0) return;
|
|
804
794
|
let r = n ?? Object.keys(t[0]).map((e) => ({ key: e })), i = r.map((e) => e.header ?? e.key.toUpperCase()), a = r.map((e, n) => {
|
|
805
795
|
let r = Math.max(i[n].length, ...t.map((t) => (e.format ? e.format(t[e.key]) : String(t[e.key] ?? "")).length));
|
|
@@ -825,71 +815,71 @@ function Ce(t, n) {
|
|
|
825
815
|
}
|
|
826
816
|
//#endregion
|
|
827
817
|
//#region src/ux/index.ts
|
|
828
|
-
var
|
|
818
|
+
var X = class {
|
|
829
819
|
askForConfirmation(e, t) {
|
|
830
|
-
return
|
|
820
|
+
return H(e, t);
|
|
831
821
|
}
|
|
832
822
|
askForInput(e, t) {
|
|
833
|
-
return
|
|
823
|
+
return K(e, t);
|
|
834
824
|
}
|
|
835
825
|
askForPassword(e, t) {
|
|
836
|
-
return
|
|
826
|
+
return _e(e, t);
|
|
837
827
|
}
|
|
838
828
|
askForNumber(e, t) {
|
|
839
|
-
return
|
|
829
|
+
return J(e, t);
|
|
840
830
|
}
|
|
841
831
|
askForSelect(e, t, n) {
|
|
842
|
-
return
|
|
832
|
+
return be(e, t, n);
|
|
843
833
|
}
|
|
844
834
|
askForCheckbox(e, t, n) {
|
|
845
|
-
return
|
|
835
|
+
return V(e, t, n);
|
|
846
836
|
}
|
|
847
837
|
askForSearch(e, t, n) {
|
|
848
|
-
return
|
|
838
|
+
return ye(e, t, n);
|
|
849
839
|
}
|
|
850
840
|
askForList(e, t) {
|
|
851
|
-
return
|
|
841
|
+
return q(e, t);
|
|
852
842
|
}
|
|
853
843
|
askForToggle(e, t) {
|
|
854
|
-
return
|
|
844
|
+
return Y(e, t);
|
|
855
845
|
}
|
|
856
846
|
askForEditor(e, t) {
|
|
857
|
-
return
|
|
847
|
+
return U(e, t);
|
|
858
848
|
}
|
|
859
849
|
askForRawList(e, t, n) {
|
|
860
|
-
return
|
|
850
|
+
return ve(e, t, n);
|
|
861
851
|
}
|
|
862
852
|
askForExpand(e, t, n) {
|
|
863
|
-
return
|
|
853
|
+
return W(e, t, n);
|
|
864
854
|
}
|
|
865
855
|
askForFile(e, t) {
|
|
866
|
-
return
|
|
856
|
+
return G(e, {
|
|
867
857
|
...t,
|
|
868
858
|
type: "file"
|
|
869
859
|
});
|
|
870
860
|
}
|
|
871
861
|
askForDirectory(e, t) {
|
|
872
|
-
return
|
|
862
|
+
return G(e, {
|
|
873
863
|
...t,
|
|
874
864
|
type: "directory"
|
|
875
865
|
});
|
|
876
866
|
}
|
|
877
867
|
askForFileSelector(e, t) {
|
|
878
|
-
return
|
|
868
|
+
return G(e, t);
|
|
879
869
|
}
|
|
880
870
|
keyValue(e, t) {
|
|
881
|
-
return
|
|
871
|
+
return xe(e, t);
|
|
882
872
|
}
|
|
883
873
|
table(e, t) {
|
|
884
|
-
return
|
|
874
|
+
return we(e, t);
|
|
885
875
|
}
|
|
886
876
|
newProgressBar(e, t) {
|
|
887
|
-
return
|
|
877
|
+
return Ce(e, t);
|
|
888
878
|
}
|
|
889
879
|
newLoader(e, t, n) {
|
|
890
|
-
return
|
|
880
|
+
return Se(e, t, n);
|
|
891
881
|
}
|
|
892
|
-
},
|
|
882
|
+
}, Z = class {
|
|
893
883
|
static $type = "BobCommand";
|
|
894
884
|
static command = "";
|
|
895
885
|
static description = "";
|
|
@@ -907,7 +897,7 @@ var Y = class {
|
|
|
907
897
|
logger;
|
|
908
898
|
ux;
|
|
909
899
|
parser;
|
|
910
|
-
static baseFlags = { help:
|
|
900
|
+
static baseFlags = { help: z };
|
|
911
901
|
newCommandParser(e) {
|
|
912
902
|
return new T({
|
|
913
903
|
ux: e.ux,
|
|
@@ -918,7 +908,7 @@ var Y = class {
|
|
|
918
908
|
});
|
|
919
909
|
}
|
|
920
910
|
newUX() {
|
|
921
|
-
return new
|
|
911
|
+
return new X();
|
|
922
912
|
}
|
|
923
913
|
async run(e) {
|
|
924
914
|
let t = this.constructor;
|
|
@@ -967,22 +957,22 @@ var Y = class {
|
|
|
967
957
|
};
|
|
968
958
|
//#endregion
|
|
969
959
|
//#region src/lib/helpers.ts
|
|
970
|
-
function
|
|
960
|
+
function Te(e) {
|
|
971
961
|
return typeof e == "object" && !!e && "$type" in e && e.$type === "BobError";
|
|
972
962
|
}
|
|
973
|
-
function
|
|
974
|
-
return typeof e == "function" ? e.prototype instanceof
|
|
963
|
+
function Q(e) {
|
|
964
|
+
return typeof e == "function" ? e.prototype instanceof Z || e.$type === "BobCommand" : !1;
|
|
975
965
|
}
|
|
976
966
|
//#endregion
|
|
977
967
|
//#region src/CommandRegistry.ts
|
|
978
|
-
var
|
|
968
|
+
var Ee = class {
|
|
979
969
|
commands = {};
|
|
980
970
|
aliases = {};
|
|
981
971
|
ux;
|
|
982
972
|
logger;
|
|
983
973
|
stringSimilarity;
|
|
984
974
|
constructor(e) {
|
|
985
|
-
this.logger = e?.logger ?? new m(), this.ux = e?.ux ?? new
|
|
975
|
+
this.logger = e?.logger ?? new m(), this.ux = e?.ux ?? new X(), this.stringSimilarity = e?.stringSimilarity ?? new h();
|
|
986
976
|
}
|
|
987
977
|
getAvailableCommands() {
|
|
988
978
|
return [...Object.keys(this.commands), ...Object.keys(this.aliases)];
|
|
@@ -993,7 +983,7 @@ var Q = class {
|
|
|
993
983
|
importFile = async (e) => (await import(e)).default;
|
|
994
984
|
commandResolver = async (e) => {
|
|
995
985
|
let t = await this.importFile(e);
|
|
996
|
-
return t ? (t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" &&
|
|
986
|
+
return t ? (t && typeof t == "object" && "default" in t && (t = t.default), typeof t == "function" && Q(t) ? t : null) : null;
|
|
997
987
|
};
|
|
998
988
|
withCommandResolver(e) {
|
|
999
989
|
return this.commandResolver = e, this;
|
|
@@ -1002,7 +992,7 @@ var Q = class {
|
|
|
1002
992
|
return this.importFile = e, this;
|
|
1003
993
|
}
|
|
1004
994
|
registerCommand(e, t = !1) {
|
|
1005
|
-
if (!
|
|
995
|
+
if (!Q(e)) throw Error("Invalid command, it must extend the Command class.");
|
|
1006
996
|
let n = e.command;
|
|
1007
997
|
if (!n) throw Error(`Cannot register a command with no name. ${e.name} `);
|
|
1008
998
|
if (!t && this.commands[n]) throw Error(`Command ${n} already registered.`);
|
|
@@ -1017,7 +1007,7 @@ var Q = class {
|
|
|
1017
1007
|
async loadCommandsPath(e) {
|
|
1018
1008
|
for await (let t of this.listCommandsFiles(e)) try {
|
|
1019
1009
|
let e = await this.commandResolver(t);
|
|
1020
|
-
|
|
1010
|
+
Q(e) && this.registerCommand(e);
|
|
1021
1011
|
} catch (e) {
|
|
1022
1012
|
throw Error(`Command ${t} failed to load. ${e}`, { cause: e });
|
|
1023
1013
|
}
|
|
@@ -1032,7 +1022,7 @@ var Q = class {
|
|
|
1032
1022
|
throw new _(t);
|
|
1033
1023
|
}
|
|
1034
1024
|
r = new i();
|
|
1035
|
-
} else r =
|
|
1025
|
+
} else r = Q(t) ? new t() : t;
|
|
1036
1026
|
return await r.run({
|
|
1037
1027
|
ctx: e,
|
|
1038
1028
|
logger: this.logger,
|
|
@@ -1056,7 +1046,7 @@ var Q = class {
|
|
|
1056
1046
|
return this.logger.error(`${e.bgRed(" ERROR ")} Command ${e.yellow(t)} not found.\n`), this.ux.askForConfirmation(`${e.green(`Do you want to run ${e.yellow(n)} instead?`)} `);
|
|
1057
1047
|
}
|
|
1058
1048
|
async *listCommandsFiles(e) {
|
|
1059
|
-
let r = t.
|
|
1049
|
+
let r = await t.promises.readdir(e, { withFileTypes: !0 });
|
|
1060
1050
|
for (let t of r) {
|
|
1061
1051
|
let r = n.resolve(e, t.name);
|
|
1062
1052
|
if (t.isDirectory()) yield* this.listCommandsFiles(n.resolve(e, t.name));
|
|
@@ -1066,23 +1056,25 @@ var Q = class {
|
|
|
1066
1056
|
}
|
|
1067
1057
|
}
|
|
1068
1058
|
}
|
|
1069
|
-
},
|
|
1059
|
+
}, De = class {
|
|
1070
1060
|
logger;
|
|
1071
1061
|
constructor(e) {
|
|
1072
1062
|
this.logger = e;
|
|
1073
1063
|
}
|
|
1074
1064
|
handle(e) {
|
|
1075
|
-
if (
|
|
1065
|
+
if (Te(e)) return e.pretty(this.logger), -1;
|
|
1076
1066
|
throw e;
|
|
1077
1067
|
}
|
|
1078
|
-
},
|
|
1068
|
+
}, Oe, ke = class extends Z {
|
|
1079
1069
|
static command = "help";
|
|
1080
1070
|
static description = e.bold("Show help information about the CLI and its commands");
|
|
1081
1071
|
constructor(e) {
|
|
1082
1072
|
super(), this.opts = e;
|
|
1083
1073
|
}
|
|
1084
1074
|
async handle() {
|
|
1085
|
-
let t = this.opts.commandRegistry.getCommands().filter((e) => !e.hidden), n = this.opts.cliName ?? "Bob CLI", r = this.opts.cliVersion ?? "0.0.0"
|
|
1075
|
+
let t = this.opts.commandRegistry.getCommands().filter((e) => !e.hidden), n = this.opts.cliName ?? "Bob CLI", r = this.opts.cliVersion ?? "0.0.0";
|
|
1076
|
+
Oe ??= (await import("../package-BLXL_OAz.js"))?.default?.version ?? "0.0.0";
|
|
1077
|
+
let i = Oe;
|
|
1086
1078
|
this.logger.log(`${n} ${e.green(r)} (core: ${e.yellow(i)})
|
|
1087
1079
|
|
|
1088
1080
|
${e.yellow("Usage")}:
|
|
@@ -1104,25 +1096,25 @@ ${e.yellow("Available commands")}:
|
|
|
1104
1096
|
r && this.logger.log(e.yellow(`${t}:`));
|
|
1105
1097
|
let i = n.sort((e, t) => e.command.toLowerCase().localeCompare(t.command.toLowerCase()));
|
|
1106
1098
|
for (let t of i) {
|
|
1107
|
-
let n = t.aliases.length > 0 ? e.gray(` (${t.aliases.join(", ")})`) : "", i =
|
|
1099
|
+
let n = t.aliases.length > 0 ? e.gray(` (${t.aliases.join(", ")})`) : "", i = R(a - (t.command.length + (t.aliases.length > 0 ? ` (${t.aliases.join(", ")})`.length : 0)));
|
|
1108
1100
|
r && (i = i.slice(2)), this.logger.log(`${r ? " " : ""}${e.green(t.command)}${n} ${i} ${t.description}`);
|
|
1109
1101
|
}
|
|
1110
1102
|
}
|
|
1111
1103
|
}
|
|
1112
|
-
},
|
|
1104
|
+
}, Ae = class {
|
|
1113
1105
|
ctx;
|
|
1114
1106
|
logger;
|
|
1115
1107
|
commandRegistry;
|
|
1116
1108
|
exceptionHandler;
|
|
1117
1109
|
helpCommand;
|
|
1118
1110
|
newCommandRegistry(e) {
|
|
1119
|
-
return new
|
|
1111
|
+
return new Ee(e);
|
|
1120
1112
|
}
|
|
1121
1113
|
newHelpCommand(e) {
|
|
1122
|
-
return new
|
|
1114
|
+
return new ke(e);
|
|
1123
1115
|
}
|
|
1124
1116
|
newExceptionHandler(e) {
|
|
1125
|
-
return new
|
|
1117
|
+
return new De(e.logger);
|
|
1126
1118
|
}
|
|
1127
1119
|
constructor(e = {}) {
|
|
1128
1120
|
this.ctx = e.ctx, this.logger = e.logger ?? new m(), this.commandRegistry = this.newCommandRegistry({ logger: this.logger }), this.exceptionHandler = this.newExceptionHandler({ logger: this.logger }), this.helpCommand = this.newHelpCommand({
|
|
@@ -1180,27 +1172,27 @@ ${e.yellow("Available commands")}:
|
|
|
1180
1172
|
}
|
|
1181
1173
|
n.startsWith("--") && (r = !0, n = n.slice(2)), n.endsWith("?") && (l = !1, n = n.slice(0, -1)), n.endsWith("*") && (c = !0, a = [], n = n.slice(0, -1)), i = i ?? t[n] ?? t[`--${n}`];
|
|
1182
1174
|
let u;
|
|
1183
|
-
return u = r ? s ?
|
|
1175
|
+
return u = r ? s ? L.boolean({
|
|
1184
1176
|
description: i,
|
|
1185
1177
|
alias: o,
|
|
1186
1178
|
...a === void 0 ? {} : { default: a }
|
|
1187
|
-
}) : c ?
|
|
1179
|
+
}) : c ? L.string({
|
|
1188
1180
|
description: i,
|
|
1189
1181
|
alias: o,
|
|
1190
1182
|
multiple: !0,
|
|
1191
1183
|
...l ? { required: !0 } : {},
|
|
1192
1184
|
default: a ?? []
|
|
1193
|
-
}) :
|
|
1185
|
+
}) : L.string({
|
|
1194
1186
|
description: i,
|
|
1195
1187
|
alias: o,
|
|
1196
1188
|
...l ? { required: !0 } : {},
|
|
1197
1189
|
...a === void 0 ? {} : { default: a }
|
|
1198
|
-
}) : c ?
|
|
1190
|
+
}) : c ? I.string({
|
|
1199
1191
|
description: i,
|
|
1200
1192
|
multiple: !0,
|
|
1201
1193
|
...l ? { required: !0 } : {},
|
|
1202
1194
|
default: a ?? []
|
|
1203
|
-
}) :
|
|
1195
|
+
}) : I.string({
|
|
1204
1196
|
description: i,
|
|
1205
1197
|
...l ? { required: !0 } : {},
|
|
1206
1198
|
...a === void 0 ? {} : { default: a }
|
|
@@ -1210,7 +1202,7 @@ ${e.yellow("Available commands")}:
|
|
|
1210
1202
|
definition: u
|
|
1211
1203
|
};
|
|
1212
1204
|
}
|
|
1213
|
-
},
|
|
1205
|
+
}, je = class extends Z {
|
|
1214
1206
|
static signature = "";
|
|
1215
1207
|
static helperDefinitions = {};
|
|
1216
1208
|
static get command() {
|
|
@@ -1238,4 +1230,4 @@ ${e.yellow("Available commands")}:
|
|
|
1238
1230
|
}
|
|
1239
1231
|
};
|
|
1240
1232
|
//#endregion
|
|
1241
|
-
export {
|
|
1233
|
+
export { I as Args, x as BadCommandArgument, S as BadCommandFlag, g as BobError, Ae as Cli, Z as Command, _ as CommandNotFoundError, T as CommandParser, Ee as CommandRegistry, $ as CommandSignatureParser, je as CommandWithSignature, De as ExceptionHandler, L as Flags, z as HelpCommandFlag, v as InvalidFlag, m as Logger, y as MissingRequiredArgumentValue, b as MissingRequiredFlagValue, h as StringSimilarity, C as TooManyArguments, X as UX, w as ValidationError, V as askForCheckbox, H as askForConfirmation, U as askForEditor, W as askForExpand, G as askForFileSelector, K as askForInput, q as askForList, J as askForNumber, _e as askForPassword, ve as askForRawList, ye as askForSearch, be as askForSelect, Y as askForToggle, xe as keyValue, Se as newLoader, Ce as newProgressBar, we as table, B as withCancelHandling };
|
|
@@ -10,7 +10,7 @@ export type ParameterOpts<C extends ContextDefinition = ContextDefinition> = {
|
|
|
10
10
|
cmd: typeof Command;
|
|
11
11
|
};
|
|
12
12
|
export type FlagProps<T = any> = {
|
|
13
|
-
type?: string;
|
|
13
|
+
type?: 'string' | 'number' | 'boolean' | 'option' | 'file' | 'directory' | 'url' | 'custom';
|
|
14
14
|
parse?: (input: any, opts: ParameterOpts) => T;
|
|
15
15
|
ask?: (opts: ParameterOpts) => Promise<any>;
|
|
16
16
|
description?: string;
|
|
@@ -27,11 +27,6 @@ export type FlagDefinition = FlagProps & {
|
|
|
27
27
|
parse(input: any, opts: ParameterOpts): any;
|
|
28
28
|
};
|
|
29
29
|
export type FlagType<O> = O extends {
|
|
30
|
-
type: 'option';
|
|
31
|
-
options: infer T extends readonly string[];
|
|
32
|
-
} ? O extends {
|
|
33
|
-
multiple: true;
|
|
34
|
-
} ? [T[number]] extends [Array<unknown>] ? T[number] : T[number][] : T[number] : O extends {
|
|
35
30
|
parse: (...args: any[]) => infer R;
|
|
36
31
|
} ? O extends {
|
|
37
32
|
multiple: true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bob-core",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.2",
|
|
4
4
|
"description": "BOB Core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/src/index.js",
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
"vitest": "^4.1.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@inquirer/
|
|
56
|
+
"@inquirer/core": "^11.1.8",
|
|
57
|
+
"@inquirer/prompts": "^8.4.1",
|
|
57
58
|
"chalk": "^4.1.2",
|
|
58
59
|
"inquirer-file-selector": "^1.0.1",
|
|
59
60
|
"minimist": "^1.2.8"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e={name:`bob-core`,version:`3.0.0-alpha.8`,description:`BOB Core`,type:`module`,main:`./dist/cjs/src/index.js`,module:`./dist/esm/src/index.js`,types:`./dist/esm/src/index.d.ts`,files:[`dist`],exports:{".":{import:{types:`./dist/esm/src/index.d.ts`,default:`./dist/esm/src/index.js`},require:{types:`./dist/cjs/src/index.d.ts`,default:`./dist/cjs/src/index.js`}}},scripts:{start:`node -r @swc-node/register debug/main.ts`,build:`rm -rf ./dist && vite build`,typecheck:`tsc --noEmit`,prepack:`npm run build`,test:`vitest run`,lint:`eslint .`,"lint:fix":`eslint . --fix`},author:`Léo Hubert`,license:`ISC`,devDependencies:{"@eslint/js":`^9.39.4`,"@faker-js/faker":`^10.3.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/string-similarity":`^4.0.2`,"@vitest/coverage-v8":`^4.1.0`,eslint:`^9.39.4`,"eslint-config-prettier":`^10.1.8`,"eslint-plugin-prettier":`^5.5.5`,prettier:`^3.6.2`,tsx:`^4.21.0`,typescript:`^5.9.3`,"typescript-eslint":`^8.57.0`,vite:`^8.0.0`,"vite-plugin-dts":`^4.5.4`,vitest:`^4.1.0`},dependencies:{"@inquirer/prompts":`^8.3.0`,chalk:`^4.1.2`,"inquirer-file-selector":`^1.0.1`,minimist:`^1.2.8`}};exports.default=e;
|