bob-core 3.0.0-beta.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/HelpFlag.d.ts +3 -3
- package/dist/cjs/args/index.d.ts +38 -17
- package/dist/cjs/flags/boolean.d.ts +4 -4
- package/dist/cjs/flags/custom.d.ts +1 -1
- package/dist/cjs/flags/directory.d.ts +9 -3
- package/dist/cjs/flags/file.d.ts +9 -3
- package/dist/cjs/flags/index.d.ts +42 -21
- package/dist/cjs/flags/number.d.ts +12 -3
- package/dist/cjs/flags/option.d.ts +26 -3
- package/dist/cjs/flags/string.d.ts +4 -4
- package/dist/cjs/flags/url.d.ts +4 -4
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/lib/types.d.ts +6 -6
- package/dist/cjs/shared/ask-helpers.d.ts +1 -1
- package/dist/cjs/shared/flagsUtils.d.ts +0 -2
- package/dist/esm/HelpFlag.d.ts +3 -3
- package/dist/esm/args/index.d.ts +38 -17
- package/dist/esm/flags/boolean.d.ts +4 -4
- package/dist/esm/flags/custom.d.ts +1 -1
- package/dist/esm/flags/directory.d.ts +9 -3
- package/dist/esm/flags/file.d.ts +9 -3
- package/dist/esm/flags/index.d.ts +42 -21
- package/dist/esm/flags/number.d.ts +12 -3
- package/dist/esm/flags/option.d.ts +26 -3
- package/dist/esm/flags/string.d.ts +4 -4
- package/dist/esm/flags/url.d.ts +4 -4
- package/dist/esm/index.js +3 -5
- package/dist/esm/lib/types.d.ts +6 -6
- package/dist/esm/shared/ask-helpers.d.ts +1 -1
- package/dist/esm/shared/flagsUtils.d.ts +0 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(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},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require(`chalk`);l=c(l,1);let u=require(`node:fs`);u=c(u,1);let d=require(`node:path`);d=c(d,1);let f=require(`minimist`);f=c(f,1);let p=require(`@inquirer/prompts`),ee=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)}},te=.1,ne=4,h=.5,g=class{calculateSimilarity(e,t){if(e===t)return 1;let n=e.toLowerCase(),r=t.toLowerCase();if(n===r)return 1;if(n.length===0||r.length===0)return 0;let i=this.jaro(n,r);if(i===0)return 0;let a=0,o=Math.min(ne,n.length,r.length);for(;a<o&&n[a]===r[a];)a++;let s=i+a*te*(1-i),c=Math.min(n.length,r.length)/Math.max(n.length,r.length);return s*(c<h?c/h:1)}jaro(e,t){let n=Math.max(0,Math.floor(Math.max(e.length,t.length)/2)-1),r=Array(e.length).fill(!1),i=Array(t.length).fill(!1),a=0;for(let o=0;o<e.length;o++){let s=Math.max(0,o-n),c=Math.min(o+n+1,t.length);for(let n=s;n<c;n++)if(!i[n]&&e[o]===t[n]){r[o]=!0,i[n]=!0,a++;break}}if(a===0)return 0;let o=0,s=0;for(let n=0;n<e.length;n++)if(r[n]){for(;!i[s];)s++;e[n]!==t[s]&&o++,s++}return o/=2,(a/e.length+a/t.length+(a-o)/a)/3}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}}},_=class extends Error{};function v(e){return l.default.bold.yellow(`'${e}'`)}var re=/\x1b\[[0-9;]*m/g;function ie(e){return e.replace(re,``).length}function y(e,t){let{title:n,details:r,hint:i}=t,a=r&&r.length>0||i!=null,o=l.default.dim(`│`),s=l.default.dim(`└─`);if(e.log(``),e.log(` ${l.default.red(`error:`)} ${n}`),a){if(e.log(` ${o}`),r&&r.length>0){let t=r.map(([e])=>ie(e)),n=Math.max(...t);for(let i=0;i<r.length;i++){let[a,s]=r[i],c=` `.repeat(n-t[i]);e.log(` ${o} ${a}${c} ${s}`)}}i==null?e.log(` ${o}`):(e.log(` ${o}`),e.log(` ${s} try: ${i}`))}e.log(``)}var ae=class extends _{$type=`CommandNotFoundError`;constructor(e){super(`Command "${e}" not found.`),this.command=e}pretty(e){y(e,{title:`command ${v(this.command)} not found`})}};function b(e,t){let n=t.multiple===!0,r=t.required?`${l.default.yellow.bold(e)} is required`:`Enter ${l.default.yellow.bold(e)}`;return t.description&&(r+=`: ${l.default.gray(`(${t.description})`)}`),r+=` ${l.default.green(`(${t.type}${n?`[]`:``})`)}\n`,r}function x(e){return e==null?[]:typeof e==`string`?[e]:e}function S(e){return e.length===1?`-${e}`:`--${e}`}function C(e){return e.type===`option`&&`options`in e}var w=class extends _{$type=`InvalidFlag`;constructor(e,t={}){super(`Flag ${e} is not recognized`),this.flag=e,this.flagsSchema=t}pretty(e){let t=Object.entries(this.flagsSchema).map(([e,t])=>{let n=x(t.alias),r=`--${e}${n.length>0?n.map(e=>`, ${S(e)}`).join(``):``}`,i=C(t)?t.options.join(` | `):t.type,a=t.description??``,o=a?`${a} ${l.default.dim(`(${i})`)}`:l.default.dim(`(${i})`);return[l.default.cyan(r),o]});y(e,{title:`flag ${v(this.flag)} is not recognized`,details:t})}},T=class extends _{$type=`MissingRequiredArgumentValue`;constructor(e){super(`Argument "${e}" is required.`),this.argument=e}pretty(e){y(e,{title:`argument ${v(this.argument)} is required`})}},E=class extends _{$type=`MissingRequiredFlagValue`;constructor(e){super(`Flag "${e}" is required.`),this.flag=e}pretty(e){y(e,{title:`flag ${v(this.flag)} is required`})}},D=class extends Error{constructor(e){super(e)}},O=class extends _{$type=`BadCommandArgument`;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=[];this.detail.value!=null&&t.push([l.default.dim(`value`),l.default.yellow(`"${this.detail.value}"`)]),this.detail.reason!=null&&t.push([l.default.dim(`reason`),this.detail.reason]),this.argDefinition?.help!=null&&t.push([l.default.dim(`help`),l.default.green(this.argDefinition.help)]),y(e,{title:`argument ${v(this.detail.arg)} is invalid`,details:t})}},k=class extends _{$type=`BadCommandFlag`;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=[];this.param.value!=null&&t.push([l.default.dim(`value`),l.default.yellow(`"${this.param.value}"`)]),this.param.reason!=null&&t.push([l.default.dim(`reason`),this.param.reason]),this.flagDefinition?.help!=null&&t.push([l.default.dim(`help`),l.default.green(this.flagDefinition.help)]),y(e,{title:`flag ${v(this.param.flag)} is invalid`,details:t})}},oe=class extends _{$type=`TooManyArguments`;constructor(e,t){super(`Too many arguments provided. Expected ${e}, got ${t}.`),this.expected=e,this.received=t}pretty(e){y(e,{title:`too many arguments`,details:[[l.default.dim(`expected`),l.default.green(String(this.expected))],[l.default.dim(`received`),l.default.bold.yellow(String(this.received))]]})}},se=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,f.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 w(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 O({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}isMissing(e){return e==null||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 w(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(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 oe(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.isMissing(e))return typeof t.default==`function`?await t.default():t.default;if(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??Q}}async safeParse(e,t,n,r){try{return t.parse(e,this.buildOpts(r?.name??``,t))}catch(t){if(t instanceof k||t instanceof O||!(t instanceof D)||!r)throw t;let i=t.message;throw n===`flag`?new k({flag:r.name,value:e,reason:i}):new O({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 E(r):new T(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 E(r):new T(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 A(e={}){return function(t){return{type:`custom`,default:e.multiple||t?.multiple?[]:null,parse:e=>e,...e,...t}}}function ce(e){if(typeof e==`boolean`)throw new D(`Expected a string, got boolean "${e}"`);return String(e)}function le(e,t){let n=typeof e==`number`?e:Number(e);if(isNaN(n))throw new D(`must be a valid number`);if(t?.min!==void 0&&n<t.min)throw new D(`is below minimum ${t.min}`);if(t?.max!==void 0&&n>t.max)throw new D(`exceeds maximum ${t.max}`);return n}function ue(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 D(`Invalid boolean value: "${e}". Expected true, false, 1, or 0.`)}function de(e,t){let n=String(e);if(!t.includes(n))throw new D(`must be one of: ${t.map(e=>`"${e}"`).join(`, `)}`);return n}function fe(e,t){let n=String(e);if(t?.exists)try{u.default.accessSync(n,u.default.constants.F_OK)}catch(e){let t=e.code;throw t===`ENOENT`?new D(`file does not exist`):t===`EACCES`?new D(`file is not accessible (permission denied)`):new D(`file is not accessible (${t??e.message})`)}return n}function pe(e,t){let n=String(e);if(t?.exists){let e;try{e=u.default.lstatSync(n)}catch(e){let t=e.code;throw t===`ENOENT`?new D(`directory does not exist`):t===`EACCES`?new D(`directory is not accessible (permission denied)`):t===`ELOOP`?new D(`symlink loop detected`):new D(`directory is not accessible (${t??e.message})`)}if(!e.isDirectory())throw new D(`path is not a directory`)}return n}function me(e){try{return new URL(String(e))}catch(t){throw new D(`Invalid URL "${e}": ${t instanceof Error?t.message:String(t)}`)}}var he=A({default:!1,parse:e=>ue(e),ask:async e=>{let t=b(e.name,e.definition);return await e.ux.askForToggle(t)},type:`boolean`});function j(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){if(e instanceof D)return e.message;throw e}return!0}}function M(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){if(e instanceof D)return`"${n}": ${e.message}`;throw e}}return!0}}async function ge(e){let t=e.definition,n=t.multiple===!0,r=b(e.name,t);return n?await e.ux.askForList(r+`Please provide one or more values, separated by commas:
|
|
2
2
|
`,{separator:`,`,validate:M(t,e)}):t.secret?e.ux.askForPassword(r,{validate:j(t,e)}):await e.ux.askForInput(r,{validate:j(t,e)})}async function _e(e){let t=e.definition,n=t.multiple===!0,r=b(e.name,t);return n?await e.ux.askForList(r+`Please provide one or more values, separated by commas:
|
|
3
|
-
`,{separator:`,`,validate:M(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){if(e instanceof D)return e.message;throw e}return!0}})}async function ve(e){let t=e.definition,n=t.multiple===!0,r=b(e.name,t);if(!C(t))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 ye(e){let t=b(e.name,e.definition);return e.ux.askForFile(t,{basePath:process.cwd()})}async function be(e){let t=b(e.name,e.definition);return e.ux.askForDirectory(t,{basePath:process.cwd()})}async function xe(e){let t=b(e.name,e.definition);return await e.ux.askForInput(t,{validate:j(e.definition,e)})}var N=A({parse:(e,t)=>pe(e,{exists:t.definition.exists}),ask:be,type:`directory`}),P=A({parse:(e,t)=>fe(e,{exists:t.definition.exists}),ask:ye,type:`file`}),F=A({parse:(e,t)=>le(e,{min:t.definition.min,max:t.definition.max}),ask:_e,type:`number`});function I(e){
|
|
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 Pe(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(l.default.bold(o));let s=i.map(e=>`-`.repeat(e)).join(` `);console.log(l.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 Z=class{askForConfirmation(e,t){return W(e,t)}askForInput(e,t){return J(e,t)}askForPassword(e,t){return Ee(e,t)}askForNumber(e,t){return X(e,t)}askForSelect(e,t,n){return ke(e,t,n)}askForCheckbox(e,t,n){return U(e,t,n)}askForSearch(e,t,n){return Oe(e,t,n)}askForList(e,t){return Y(e,t)}askForToggle(e,t){return Ae(e,t)}askForEditor(e,t){return G(e,t)}askForRawList(e,t,n){return De(e,t,n)}askForExpand(e,t,n){return K(e,t,n)}askForFile(e,t){return q(e,{...t,type:`file`})}askForDirectory(e,t){return q(e,{...t,type:`directory`})}askForFileSelector(e,t){return q(e,t)}keyValue(e,t){return je(e,t)}table(e,t){return Pe(e,t)}newProgressBar(e,t){return Ne(e,t)}newLoader(e,t,n){return Me(e,t,n)}},Q=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:Ce};newCommandParser(e){return new se({ux:e.ux,ctx:e.ctx,flags:e.flags,args:e.args,cmd:e.cmd})}newUX(){return new Z}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 0}}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 Fe(e){return e instanceof _}function $(e){return typeof e==`function`?e.prototype instanceof Q||e.$type===`BobCommand`:!1}var Ie=.75,Le=.55,Re=.05,ze=class{commands={};aliases={};ux;logger;stringSimilarity;constructor(e){this.logger=e?.logger??new m,this.ux=e?.ux??new Z,this.stringSimilarity=e?.stringSimilarity??new g}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`&&$(t)?t:null):null};withCommandResolver(e){return this.commandResolver=e,this}withFileImporter(e){return this.importFile=e,this}registerCommand(e,t=!1){if(!$(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);$(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 ae(t)}r=new i}else r=$(t)?new t:t;return await r.run({ctx:e,logger:this.logger,args:n})??0}async suggestCommand(e){let t=this.getAvailableCommands();if(t.length===0)return null;let{bestMatch:n,bestMatchIndex:r,ratings:i}=this.stringSimilarity.findBestMatch(e,t),a=[...i].sort((e,t)=>t.rating-e.rating),o=a[1]?.rating??0,s=a.filter(e=>e.rating>=Le).map(e=>e.target);if(n&&n.rating>=Ie&&n.rating-o>Re){let n=t[r],i=await this.askRunSimilarCommand(e,n);return i===!0?n:(i===null&&this.logger.debug(`suggestion prompt cancelled for "${e}"`),null)}if(s.length===1){let t=s[0],n=await this.askRunSimilarCommand(e,t);return n===!0?t:(n===null&&this.logger.debug(`suggestion prompt cancelled for "${e}"`),null)}if(s.length>1){let t=await this.ux.askForSelect(`${l.default.red(`unknown command`)} ${l.default.bold.yellow(`'${e}'`)} ${l.default.dim(`—`)} did you mean one of these?`,s);return t||(t===null&&this.logger.debug(`suggestion selection cancelled for "${e}"`),null)}return null}async askRunSimilarCommand(e,t){return this.ux.askForConfirmation(`${l.default.red(`unknown command`)} ${l.default.bold.yellow(`'${e}'`)} ${l.default.dim(`—`)} did you mean ${l.default.bold.green(`'${t}'`)}?`)}async*listCommandsFiles(e){let t;try{t=await u.default.promises.readdir(e,{withFileTypes:!0})}catch(t){throw Error(`Failed to read commands directory "${e}": ${t.message}`,{cause:t})}for(let n of t){let t=d.default.resolve(e,n.name);if(n.isDirectory())yield*this.listCommandsFiles(d.default.resolve(e,n.name));else{if(!t.endsWith(`.ts`)&&!t.endsWith(`.js`)&&!t.endsWith(`.mjs`)&&!t.endsWith(`.cjs`))continue;yield t}}}},Be=class{logger;constructor(e){this.logger=e}handle(e){if(Fe(e))return e.pretty(this.logger),-1;throw e}},Ve=c(Te(),1);function He(){try{let e=(0,u.readFileSync)((0,Ve.fileURLToPath)(new URL(`data:application/json;base64,
|
|
3
|
+
`,{separator:`,`,validate:M(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){if(e instanceof D)return e.message;throw e}return!0}})}async function ve(e){let t=e.definition,n=t.multiple===!0,r=b(e.name,t);if(!C(t))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 ye(e){let t=b(e.name,e.definition);return e.ux.askForFile(t,{basePath:process.cwd()})}async function be(e){let t=b(e.name,e.definition);return e.ux.askForDirectory(t,{basePath:process.cwd()})}async function xe(e){let t=b(e.name,e.definition);return await e.ux.askForInput(t,{validate:j(e.definition,e)})}var N=A({parse:(e,t)=>pe(e,{exists:t.definition.exists}),ask:be,type:`directory`}),P=A({parse:(e,t)=>fe(e,{exists:t.definition.exists}),ask:ye,type:`file`}),F=A({parse:(e,t)=>le(e,{min:t.definition.min,max:t.definition.max}),ask:_e,type:`number`});function I(e){return A({type:`option`,ask:ve,parse:t=>de(t,e.options??[])})(e)}var L=A({parse:e=>ce(e),ask:ge,type:`string`}),R=A({parse:e=>me(e),ask:xe,type:`url`}),z={string:L,number:F,option:I,file:P,directory:N,url:R,custom:A},B={string:L,number:F,boolean:he,option:I,file:P,directory:N,url:R,custom:A};function V(e){return Array(e+5).join(` `)}function Se(e){let t=e.type;return C(e)?`enum: ${e.options.join(`|`)}`:t??`custom`}var Ce=B.boolean({alias:[`h`],description:`Displays help information about the command`,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=x(t.alias);return{name:e,...t,flagWithAlias:`--${e}${n.map(e=>`, ${S(e)}`).join(``)}`}}),c=a.filter(([,e])=>e.required);console.log(l.default.yellow(`Description:`)),console.log(` ${n.description}\n`),n.aliases.length>0&&(console.log(l.default.yellow(`Aliases:`)),console.log(` ${n.aliases.join(`, `)}\n`)),console.log(l.default.yellow(`Usage:`)),console.log(` ${n.command} ${c.length>0?c.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${l.default.yellow(`Arguments`)}:`);for(let[e,t]of a){let n=V(f-e.length),r=` ${l.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+=` ${l.default.yellow(`[default: ${e}]`)}`}t.multiple&&(r+=` ${l.default.white(`(multiple)`)}`),console.log(r)}}if(o.length>0){console.log(`\n${l.default.yellow(`Options`)}:`);for(let e of s){let t=V(f-e.flagWithAlias.length),n=` ${l.default.green(e.flagWithAlias)} ${t} ${e.description??`\b`}`;if(e.type&&(n+=` ${l.default.white(`(${Se(e)})`)}`),e.default!==void 0&&!e.required){let t=typeof e.default==`function`?`(function)`:e.default;n+=` ${l.default.yellow(`[default: ${t}]`)}`}console.log(n)}}let p=n.examples??[];if(p.length>0){console.log(`\n${l.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(` ${l.default.green(`${e} ${n.command}`)}`)}return{shouldStop:!0}}}),we=class extends Error{name=`ExitPromptError`},Te=o(((e,t)=>{t.exports={}}));async function H(e,t){try{return await e()}catch(e){if(e instanceof we||e instanceof Error&&e.name===`ExitPromptError`)return t;throw e}}async function U(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 H(()=>(0,p.checkbox)({message:e,choices:r,required:n?.required,pageSize:n?.pageSize,loop:n?.loop,validate:n?.validate,shortcuts:n?.shortcuts}),null)}async function W(e=`Do you want to continue?`,t){return H(()=>(0,p.confirm)({message:e,default:t?.default??!1,transformer:t?.transformer}),null)}async function G(e,t){return H(()=>(0,p.editor)({message:e,default:t?.default,postfix:t?.postfix,waitForUserInput:t?.waitForUserInput,validate:t?.validate}),null)}async function K(e,t,n){return H(()=>(0,p.expand)({message:e,choices:t,default:n?.default}),null)}async function q(e,t){return H(async()=>{let n=await(0,ee.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 J(e,t){return H(()=>(0,p.input)({message:e,default:t?.default,required:t?.required,validate:t?.validate,transformer:t?.transformer}),null)}async function Y(e,t){let n=t?.separator??`,`;return H(async()=>(await(0,p.input)({message:e,default:t?.default,validate:t?.validate})).split(n).map(e=>e.trim()).filter(e=>e.length>0),null)}async function X(e,t){return H(async()=>await(0,p.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 Ee(e,t){return H(()=>(0,p.password)({message:e,mask:t?.mask,validate:t?.validate}),null)}async function De(e,t,n){return H(()=>(0,p.rawlist)({message:e,choices:t,loop:n?.loop}),null)}async function Oe(e,t,n){return H(()=>(0,p.search)({message:e,source:t,pageSize:n?.pageSize,validate:n?.validate}),null)}async function ke(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 H(()=>(0,p.select)({message:e,choices:r,default:n?.default,pageSize:n?.pageSize,loop:n?.loop}),null)}async function Ae(e,t){let n=t?.active??`Yes`,r=t?.inactive??`No`;return H(()=>(0,p.confirm)({message:e,default:t?.default??!1,transformer:e=>e?n:r}),null)}function je(e,t){let n=t?.separator??`: `,r=t?.keyStyle??l.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 Me(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&&process.stdout.cursorTo){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 Ne(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),l=`${r.repeat(s)+i.repeat(n-s)} ${Math.round(t*100)}% ${a}/${e}`;process.stdout.write(`\r`+l),(e<=0||a>=e)&&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 Pe(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(l.default.bold(o));let s=i.map(e=>`-`.repeat(e)).join(` `);console.log(l.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 Z=class{askForConfirmation(e,t){return W(e,t)}askForInput(e,t){return J(e,t)}askForPassword(e,t){return Ee(e,t)}askForNumber(e,t){return X(e,t)}askForSelect(e,t,n){return ke(e,t,n)}askForCheckbox(e,t,n){return U(e,t,n)}askForSearch(e,t,n){return Oe(e,t,n)}askForList(e,t){return Y(e,t)}askForToggle(e,t){return Ae(e,t)}askForEditor(e,t){return G(e,t)}askForRawList(e,t,n){return De(e,t,n)}askForExpand(e,t,n){return K(e,t,n)}askForFile(e,t){return q(e,{...t,type:`file`})}askForDirectory(e,t){return q(e,{...t,type:`directory`})}askForFileSelector(e,t){return q(e,t)}keyValue(e,t){return je(e,t)}table(e,t){return Pe(e,t)}newProgressBar(e,t){return Ne(e,t)}newLoader(e,t,n){return Me(e,t,n)}},Q=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:Ce};newCommandParser(e){return new se({ux:e.ux,ctx:e.ctx,flags:e.flags,args:e.args,cmd:e.cmd})}newUX(){return new Z}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 0}}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 Fe(e){return e instanceof _}function $(e){return typeof e==`function`?e.prototype instanceof Q||e.$type===`BobCommand`:!1}var Ie=.75,Le=.55,Re=.05,ze=class{commands={};aliases={};ux;logger;stringSimilarity;constructor(e){this.logger=e?.logger??new m,this.ux=e?.ux??new Z,this.stringSimilarity=e?.stringSimilarity??new g}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`&&$(t)?t:null):null};withCommandResolver(e){return this.commandResolver=e,this}withFileImporter(e){return this.importFile=e,this}registerCommand(e,t=!1){if(!$(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);$(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 ae(t)}r=new i}else r=$(t)?new t:t;return await r.run({ctx:e,logger:this.logger,args:n})??0}async suggestCommand(e){let t=this.getAvailableCommands();if(t.length===0)return null;let{bestMatch:n,bestMatchIndex:r,ratings:i}=this.stringSimilarity.findBestMatch(e,t),a=[...i].sort((e,t)=>t.rating-e.rating),o=a[1]?.rating??0,s=a.filter(e=>e.rating>=Le).map(e=>e.target);if(n&&n.rating>=Ie&&n.rating-o>Re){let n=t[r],i=await this.askRunSimilarCommand(e,n);return i===!0?n:(i===null&&this.logger.debug(`suggestion prompt cancelled for "${e}"`),null)}if(s.length===1){let t=s[0],n=await this.askRunSimilarCommand(e,t);return n===!0?t:(n===null&&this.logger.debug(`suggestion prompt cancelled for "${e}"`),null)}if(s.length>1){let t=await this.ux.askForSelect(`${l.default.red(`unknown command`)} ${l.default.bold.yellow(`'${e}'`)} ${l.default.dim(`—`)} did you mean one of these?`,s);return t||(t===null&&this.logger.debug(`suggestion selection cancelled for "${e}"`),null)}return null}async askRunSimilarCommand(e,t){return this.ux.askForConfirmation(`${l.default.red(`unknown command`)} ${l.default.bold.yellow(`'${e}'`)} ${l.default.dim(`—`)} did you mean ${l.default.bold.green(`'${t}'`)}?`)}async*listCommandsFiles(e){let t;try{t=await u.default.promises.readdir(e,{withFileTypes:!0})}catch(t){throw Error(`Failed to read commands directory "${e}": ${t.message}`,{cause:t})}for(let n of t){let t=d.default.resolve(e,n.name);if(n.isDirectory())yield*this.listCommandsFiles(d.default.resolve(e,n.name));else{if(!t.endsWith(`.ts`)&&!t.endsWith(`.js`)&&!t.endsWith(`.mjs`)&&!t.endsWith(`.cjs`))continue;yield t}}}},Be=class{logger;constructor(e){this.logger=e}handle(e){if(Fe(e))return e.pretty(this.logger),-1;throw e}},Ve=c(Te(),1);function He(){try{let e=(0,u.readFileSync)((0,Ve.fileURLToPath)(new URL(`data:application/json;base64,ewogICJuYW1lIjogImJvYi1jb3JlIiwKICAidmVyc2lvbiI6ICIzLjAuMCIsCiAgImRlc2NyaXB0aW9uIjogIkJPQiBDb3JlIiwKICAidHlwZSI6ICJtb2R1bGUiLAogICJtYWluIjogIi4vZGlzdC9janMvaW5kZXguanMiLAogICJtb2R1bGUiOiAiLi9kaXN0L2VzbS9pbmRleC5qcyIsCiAgInR5cGVzIjogIi4vZGlzdC9lc20vaW5kZXguZC50cyIsCiAgImZpbGVzIjogWwogICAgImRpc3QiCiAgXSwKICAiZXhwb3J0cyI6IHsKICAgICIuIjogewogICAgICAiaW1wb3J0IjogewogICAgICAgICJ0eXBlcyI6ICIuL2Rpc3QvZXNtL2luZGV4LmQudHMiLAogICAgICAgICJkZWZhdWx0IjogIi4vZGlzdC9lc20vaW5kZXguanMiCiAgICAgIH0sCiAgICAgICJyZXF1aXJlIjogewogICAgICAgICJ0eXBlcyI6ICIuL2Rpc3QvY2pzL2luZGV4LmQudHMiLAogICAgICAgICJkZWZhdWx0IjogIi4vZGlzdC9janMvaW5kZXguanMiCiAgICAgIH0KICAgIH0KICB9LAogICJzY3JpcHRzIjogewogICAgInN0YXJ0IjogIm5vZGUgLXIgQHN3Yy1ub2RlL3JlZ2lzdGVyIGRlYnVnL21haW4udHMiLAogICAgImJ1aWxkIjogInJtIC1yZiAuL2Rpc3QgJiYgdml0ZSBidWlsZCIsCiAgICAidHlwZWNoZWNrIjogInRzYyAtLW5vRW1pdCIsCiAgICAicHJlcGFjayI6ICJucG0gcnVuIGJ1aWxkIiwKICAgICJ0ZXN0IjogInZpdGVzdCBydW4iLAogICAgImxpbnQiOiAiZXNsaW50IC4iLAogICAgImxpbnQ6Zml4IjogImVzbGludCAuIC0tZml4IgogIH0sCiAgImF1dGhvciI6ICJMw6lvIEh1YmVydCIsCiAgImxpY2Vuc2UiOiAiSVNDIiwKICAiZGV2RGVwZW5kZW5jaWVzIjogewogICAgIkBlc2xpbnQvanMiOiAiXjkuMzkuNCIsCiAgICAiQGZha2VyLWpzL2Zha2VyIjogIl4xMC4zLjAiLAogICAgIkBzd2Mtbm9kZS9yZWdpc3RlciI6ICJeMS4xMS4xIiwKICAgICJAdHJpdmFnby9wcmV0dGllci1wbHVnaW4tc29ydC1pbXBvcnRzIjogIl41LjIuMiIsCiAgICAiQHR5cGVzL21pbmltaXN0IjogIl4xLjIuNSIsCiAgICAiQHR5cGVzL25vZGUiOiAiXjIwLjE0LjUiLAogICAgIkB0eXBlcy9zdHJpbmctc2ltaWxhcml0eSI6ICJeNC4wLjIiLAogICAgIkB2aXRlc3QvY292ZXJhZ2UtdjgiOiAiXjQuMS4wIiwKICAgICJlc2xpbnQiOiAiXjkuMzkuNCIsCiAgICAiZXNsaW50LWNvbmZpZy1wcmV0dGllciI6ICJeMTAuMS44IiwKICAgICJlc2xpbnQtcGx1Z2luLXByZXR0aWVyIjogIl41LjUuNSIsCiAgICAicHJldHRpZXIiOiAiXjMuNi4yIiwKICAgICJ0c3giOiAiXjQuMjEuMCIsCiAgICAidHlwZXNjcmlwdCI6ICJeNS45LjMiLAogICAgInR5cGVzY3JpcHQtZXNsaW50IjogIl44LjU3LjAiLAogICAgInZpdGUiOiAiXjguMC4wIiwKICAgICJ2aXRlLXBsdWdpbi1kdHMiOiAiXjQuNS40IiwKICAgICJ2aXRlc3QiOiAiXjQuMS4wIgogIH0sCiAgImRlcGVuZGVuY2llcyI6IHsKICAgICJAaW5xdWlyZXIvY29yZSI6ICJeMTEuMS44IiwKICAgICJAaW5xdWlyZXIvcHJvbXB0cyI6ICJeOC40LjEiLAogICAgImNoYWxrIjogIl41LjYuMiIsCiAgICAiaW5xdWlyZXItZmlsZS1zZWxlY3RvciI6ICJeMS4wLjEiLAogICAgIm1pbmltaXN0IjogIl4xLjIuOCIKICB9Cn0K`,``+{}.url)),`utf8`);return JSON.parse(e).version??`0.0.0`}catch{return`0.0.0`}}var Ue=class extends Q{static command=`help`;static description=l.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`,r=He();this.logger.log(`${t} ${l.default.green(n)} (core: ${l.default.yellow(r)})
|
|
5
5
|
|
|
6
6
|
${l.default.yellow(`Usage`)}:
|
|
7
7
|
command [options] [arguments]
|
package/dist/cjs/lib/types.d.ts
CHANGED
|
@@ -11,26 +11,26 @@ export type FlagKind = 'string' | 'number' | 'boolean' | 'option' | 'file' | 'di
|
|
|
11
11
|
* {@link FlagDefinition}, so handlers can read them without `any` casts while still
|
|
12
12
|
* being honest that they are optional at the type level.
|
|
13
13
|
*/
|
|
14
|
-
export type FlagOpts<
|
|
14
|
+
export type FlagOpts<T = any, C extends CustomOptions = CustomOptions> = {
|
|
15
15
|
name: string;
|
|
16
16
|
ux: UX;
|
|
17
|
-
ctx:
|
|
18
|
-
definition: FlagDefinition<
|
|
17
|
+
ctx: ContextDefinition;
|
|
18
|
+
definition: FlagDefinition<T, C>;
|
|
19
19
|
cmd: typeof Command;
|
|
20
20
|
};
|
|
21
21
|
export type FlagDefinition<T = any, C extends CustomOptions = CustomOptions> = {
|
|
22
22
|
[key in keyof C]: C[keyof C];
|
|
23
23
|
} & {
|
|
24
|
-
parse: (input: any, opts: FlagOpts<
|
|
24
|
+
parse: (input: any, opts: FlagOpts<T, C>) => T;
|
|
25
25
|
type?: FlagKind;
|
|
26
|
-
ask?: (opts: FlagOpts) => Promise<any>;
|
|
26
|
+
ask?: (opts: FlagOpts<T, C>) => Promise<any>;
|
|
27
27
|
description?: string;
|
|
28
28
|
required?: boolean;
|
|
29
29
|
default?: T | T[] | null | (() => T | T[] | null) | (() => Promise<T | T[] | null>);
|
|
30
30
|
multiple?: boolean;
|
|
31
31
|
help?: string;
|
|
32
32
|
alias?: string | readonly string[];
|
|
33
|
-
handler?: (value: T, opts: FlagOpts) => {
|
|
33
|
+
handler?: (value: T, opts: FlagOpts<T, C>) => {
|
|
34
34
|
shouldStop: boolean;
|
|
35
35
|
} | void;
|
|
36
36
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FlagOpts } from '../lib/types.js';
|
|
2
2
|
export declare function buildStringAsk(builderOpts: FlagOpts): Promise<any>;
|
|
3
3
|
export declare function buildNumberAsk(builderOpts: FlagOpts): Promise<any>;
|
|
4
|
-
export declare function buildOptionAsk(builderOpts: FlagOpts): Promise<any>;
|
|
4
|
+
export declare function buildOptionAsk(builderOpts: FlagOpts<any, any>): Promise<any>;
|
|
5
5
|
export declare function buildFileAsk(builderOpts: FlagOpts): Promise<any>;
|
|
6
6
|
export declare function buildDirectoryAsk(builderOpts: FlagOpts): Promise<any>;
|
|
7
7
|
export declare function buildUrlAsk(builderOpts: FlagOpts): Promise<any>;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { numberFlag } from '../flags/number.js';
|
|
2
1
|
import { optionFlag } from '../flags/option.js';
|
|
3
2
|
import { FlagDefinition } from '../lib/types.js';
|
|
4
|
-
export declare function isNumberFlag(flag: FlagDefinition): flag is ReturnType<typeof numberFlag>;
|
|
5
3
|
export declare function isOptionFlag(flag: FlagDefinition<any, any>): flag is ReturnType<typeof optionFlag>;
|
package/dist/esm/HelpFlag.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ import { FlagDefinition, FlagOpts } from './lib/types.js';
|
|
|
2
2
|
export declare const HelpCommandFlag: {
|
|
3
3
|
[x: string]: unknown;
|
|
4
4
|
} & {
|
|
5
|
-
parse: (input: any, opts: FlagOpts<
|
|
5
|
+
parse: (input: any, opts: FlagOpts<boolean, import('./lib/types.js').CustomOptions>) => boolean;
|
|
6
6
|
type?: import('./lib/types.js').FlagKind;
|
|
7
|
-
ask?: (opts: FlagOpts) => Promise<any
|
|
7
|
+
ask?: ((opts: FlagOpts<boolean, import('./lib/types.js').CustomOptions>) => Promise<any>) | undefined;
|
|
8
8
|
description?: string;
|
|
9
9
|
required?: boolean;
|
|
10
10
|
default?: boolean | boolean[] | (() => boolean | boolean[] | null) | (() => Promise<boolean | boolean[] | null>) | null | undefined;
|
|
11
11
|
multiple?: boolean;
|
|
12
12
|
help?: string;
|
|
13
13
|
alias?: string | readonly string[];
|
|
14
|
-
handler?: ((value: boolean, opts: FlagOpts) => {
|
|
14
|
+
handler?: ((value: boolean, opts: FlagOpts<boolean, import('./lib/types.js').CustomOptions>) => {
|
|
15
15
|
shouldStop: boolean;
|
|
16
16
|
} | void) | undefined;
|
|
17
17
|
} & Partial<FlagDefinition<boolean, import('./lib/types.js').CustomOptions>> & {
|
package/dist/esm/args/index.d.ts
CHANGED
|
@@ -7,42 +7,51 @@ import { optionFlag } from '../flags/option.js';
|
|
|
7
7
|
* positional inputs and the `ArgsSchema` type rejects them at compile time.
|
|
8
8
|
*/
|
|
9
9
|
export declare const Args: {
|
|
10
|
-
string: <const O extends Partial<import('../index.js').FlagDefinition<string, import('../index.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
10
|
+
string: <const O extends Partial<import('../index.js').FlagDefinition<string, import('../index.js').CustomOptions>> = Partial<import('../index.js').FlagDefinition<string, import('../index.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
11
11
|
[x: string]: unknown;
|
|
12
12
|
} & {
|
|
13
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
13
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<string, import('../index.js').CustomOptions>) => string;
|
|
14
14
|
type?: import('../index.js').FlagKind;
|
|
15
|
-
ask?: (opts: import('../index.js').FlagOpts) => Promise<any
|
|
15
|
+
ask?: ((opts: import('../index.js').FlagOpts<string, import('../index.js').CustomOptions>) => Promise<any>) | undefined;
|
|
16
16
|
description?: string;
|
|
17
17
|
required?: boolean;
|
|
18
18
|
default?: string | string[] | (() => string | string[] | null) | (() => Promise<string | string[] | null>) | null | undefined;
|
|
19
19
|
multiple?: boolean;
|
|
20
20
|
help?: string;
|
|
21
21
|
alias?: string | readonly string[];
|
|
22
|
-
handler?: ((value: string, opts: import('../index.js').FlagOpts) => {
|
|
22
|
+
handler?: ((value: string, opts: import('../index.js').FlagOpts<string, import('../index.js').CustomOptions>) => {
|
|
23
23
|
shouldStop: boolean;
|
|
24
24
|
} | void) | undefined;
|
|
25
25
|
} & Partial<import('../index.js').FlagDefinition<string, import('../index.js').CustomOptions>> & O;
|
|
26
26
|
number: <const O extends Partial<import('../index.js').FlagDefinition<number, {
|
|
27
27
|
min?: number;
|
|
28
28
|
max?: number;
|
|
29
|
+
}>> = Partial<import('../index.js').FlagDefinition<number, {
|
|
30
|
+
min?: number;
|
|
31
|
+
max?: number;
|
|
29
32
|
}>>>(overrides?: O | undefined) => {
|
|
30
33
|
min?: number | undefined;
|
|
31
34
|
max?: number | undefined;
|
|
32
35
|
} & {
|
|
33
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
36
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<number, {
|
|
34
37
|
min?: number;
|
|
35
38
|
max?: number;
|
|
36
39
|
}>) => number;
|
|
37
40
|
type?: import('../index.js').FlagKind;
|
|
38
|
-
ask?: (opts: import('../index.js').FlagOpts
|
|
41
|
+
ask?: ((opts: import('../index.js').FlagOpts<number, {
|
|
42
|
+
min?: number;
|
|
43
|
+
max?: number;
|
|
44
|
+
}>) => Promise<any>) | undefined;
|
|
39
45
|
description?: string;
|
|
40
46
|
required?: boolean;
|
|
41
47
|
default?: number | number[] | (() => number | number[] | null) | (() => Promise<number | number[] | null>) | null | undefined;
|
|
42
48
|
multiple?: boolean;
|
|
43
49
|
help?: string;
|
|
44
50
|
alias?: string | readonly string[];
|
|
45
|
-
handler?: ((value: number, opts: import('../index.js').FlagOpts
|
|
51
|
+
handler?: ((value: number, opts: import('../index.js').FlagOpts<number, {
|
|
52
|
+
min?: number;
|
|
53
|
+
max?: number;
|
|
54
|
+
}>) => {
|
|
46
55
|
shouldStop: boolean;
|
|
47
56
|
} | void) | undefined;
|
|
48
57
|
} & Partial<import('../index.js').FlagDefinition<number, {
|
|
@@ -52,21 +61,27 @@ export declare const Args: {
|
|
|
52
61
|
option: typeof optionFlag;
|
|
53
62
|
file: <const O extends Partial<import('../index.js').FlagDefinition<string, {
|
|
54
63
|
exists?: boolean;
|
|
64
|
+
}>> = Partial<import('../index.js').FlagDefinition<string, {
|
|
65
|
+
exists?: boolean;
|
|
55
66
|
}>>>(overrides?: O | undefined) => {
|
|
56
67
|
exists?: boolean | undefined;
|
|
57
68
|
} & {
|
|
58
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
69
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<string, {
|
|
59
70
|
exists?: boolean;
|
|
60
71
|
}>) => string;
|
|
61
72
|
type?: import('../index.js').FlagKind;
|
|
62
|
-
ask?: (opts: import('../index.js').FlagOpts
|
|
73
|
+
ask?: ((opts: import('../index.js').FlagOpts<string, {
|
|
74
|
+
exists?: boolean;
|
|
75
|
+
}>) => Promise<any>) | undefined;
|
|
63
76
|
description?: string;
|
|
64
77
|
required?: boolean;
|
|
65
78
|
default?: string | string[] | (() => string | string[] | null) | (() => Promise<string | string[] | null>) | null | undefined;
|
|
66
79
|
multiple?: boolean;
|
|
67
80
|
help?: string;
|
|
68
81
|
alias?: string | readonly string[];
|
|
69
|
-
handler?: ((value: string, opts: import('../index.js').FlagOpts
|
|
82
|
+
handler?: ((value: string, opts: import('../index.js').FlagOpts<string, {
|
|
83
|
+
exists?: boolean;
|
|
84
|
+
}>) => {
|
|
70
85
|
shouldStop: boolean;
|
|
71
86
|
} | void) | undefined;
|
|
72
87
|
} & Partial<import('../index.js').FlagDefinition<string, {
|
|
@@ -74,39 +89,45 @@ export declare const Args: {
|
|
|
74
89
|
}>> & O;
|
|
75
90
|
directory: <const O extends Partial<import('../index.js').FlagDefinition<string, {
|
|
76
91
|
exists?: boolean;
|
|
92
|
+
}>> = Partial<import('../index.js').FlagDefinition<string, {
|
|
93
|
+
exists?: boolean;
|
|
77
94
|
}>>>(overrides?: O | undefined) => {
|
|
78
95
|
exists?: boolean | undefined;
|
|
79
96
|
} & {
|
|
80
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
97
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<string, {
|
|
81
98
|
exists?: boolean;
|
|
82
99
|
}>) => string;
|
|
83
100
|
type?: import('../index.js').FlagKind;
|
|
84
|
-
ask?: (opts: import('../index.js').FlagOpts
|
|
101
|
+
ask?: ((opts: import('../index.js').FlagOpts<string, {
|
|
102
|
+
exists?: boolean;
|
|
103
|
+
}>) => Promise<any>) | undefined;
|
|
85
104
|
description?: string;
|
|
86
105
|
required?: boolean;
|
|
87
106
|
default?: string | string[] | (() => string | string[] | null) | (() => Promise<string | string[] | null>) | null | undefined;
|
|
88
107
|
multiple?: boolean;
|
|
89
108
|
help?: string;
|
|
90
109
|
alias?: string | readonly string[];
|
|
91
|
-
handler?: ((value: string, opts: import('../index.js').FlagOpts
|
|
110
|
+
handler?: ((value: string, opts: import('../index.js').FlagOpts<string, {
|
|
111
|
+
exists?: boolean;
|
|
112
|
+
}>) => {
|
|
92
113
|
shouldStop: boolean;
|
|
93
114
|
} | void) | undefined;
|
|
94
115
|
} & Partial<import('../index.js').FlagDefinition<string, {
|
|
95
116
|
exists?: boolean;
|
|
96
117
|
}>> & O;
|
|
97
|
-
url: <const O extends Partial<import('../index.js').FlagDefinition<URL, import('../index.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
118
|
+
url: <const O extends Partial<import('../index.js').FlagDefinition<URL, import('../index.js').CustomOptions>> = Partial<import('../index.js').FlagDefinition<URL, import('../index.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
98
119
|
[x: string]: unknown;
|
|
99
120
|
} & {
|
|
100
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
121
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<URL, import('../index.js').CustomOptions>) => URL;
|
|
101
122
|
type?: import('../index.js').FlagKind;
|
|
102
|
-
ask?: (opts: import('../index.js').FlagOpts) => Promise<any
|
|
123
|
+
ask?: ((opts: import('../index.js').FlagOpts<URL, import('../index.js').CustomOptions>) => Promise<any>) | undefined;
|
|
103
124
|
description?: string;
|
|
104
125
|
required?: boolean;
|
|
105
126
|
default?: URL | URL[] | (() => URL | URL[] | null) | (() => Promise<URL | URL[] | null>) | null | undefined;
|
|
106
127
|
multiple?: boolean;
|
|
107
128
|
help?: string;
|
|
108
129
|
alias?: string | readonly string[];
|
|
109
|
-
handler?: ((value: URL, opts: import('../index.js').FlagOpts) => {
|
|
130
|
+
handler?: ((value: URL, opts: import('../index.js').FlagOpts<URL, import('../index.js').CustomOptions>) => {
|
|
110
131
|
shouldStop: boolean;
|
|
111
132
|
} | void) | undefined;
|
|
112
133
|
} & Partial<import('../index.js').FlagDefinition<URL, import('../index.js').CustomOptions>> & O;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { FlagOpts } from '../lib/types.js';
|
|
2
2
|
/** Boolean flag (`--debug` / `--no-debug`). Defaults to `false` when omitted. */
|
|
3
|
-
export declare const booleanFlag: <const O extends Partial<import('../lib/types.js').FlagDefinition<boolean, import('../lib/types.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
3
|
+
export declare const booleanFlag: <const O extends Partial<import('../lib/types.js').FlagDefinition<boolean, import('../lib/types.js').CustomOptions>> = Partial<import('../lib/types.js').FlagDefinition<boolean, import('../lib/types.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
4
4
|
[x: string]: unknown;
|
|
5
5
|
} & {
|
|
6
|
-
parse: (input: any, opts: FlagOpts<
|
|
6
|
+
parse: (input: any, opts: FlagOpts<boolean, import('../lib/types.js').CustomOptions>) => boolean;
|
|
7
7
|
type?: import('../lib/types.js').FlagKind;
|
|
8
|
-
ask?: (opts: FlagOpts) => Promise<any
|
|
8
|
+
ask?: ((opts: FlagOpts<boolean, import('../lib/types.js').CustomOptions>) => Promise<any>) | undefined;
|
|
9
9
|
description?: string;
|
|
10
10
|
required?: boolean;
|
|
11
11
|
default?: boolean | boolean[] | (() => boolean | boolean[] | null) | (() => Promise<boolean | boolean[] | null>) | null | undefined;
|
|
12
12
|
multiple?: boolean;
|
|
13
13
|
help?: string;
|
|
14
14
|
alias?: string | readonly string[];
|
|
15
|
-
handler?: ((value: boolean, opts: FlagOpts) => {
|
|
15
|
+
handler?: ((value: boolean, opts: FlagOpts<boolean, import('../lib/types.js').CustomOptions>) => {
|
|
16
16
|
shouldStop: boolean;
|
|
17
17
|
} | void) | undefined;
|
|
18
18
|
} & Partial<import('../lib/types.js').FlagDefinition<boolean, import('../lib/types.js').CustomOptions>> & O;
|
|
@@ -9,4 +9,4 @@ import { CustomOptions, FlagDefinition, InitFlagDefinition } from '../lib/types.
|
|
|
9
9
|
* The `type` literal supplied in `defaults` is preserved in the returned shape
|
|
10
10
|
* so downstream consumers can rely on it (e.g. for help rendering).
|
|
11
11
|
*/
|
|
12
|
-
export declare function custom<T, C extends CustomOptions = CustomOptions, const D extends InitFlagDefinition<T, C> = InitFlagDefinition<T, C>>(defaults?: D): <const O extends
|
|
12
|
+
export declare function custom<T = string, C extends CustomOptions = CustomOptions, const D extends InitFlagDefinition<T, C> = InitFlagDefinition<T, C>>(defaults?: D): <const O extends InitFlagDefinition<T, C> = InitFlagDefinition<T, C>>(overrides?: O) => FlagDefinition<T, C> & D & O;
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
/** Filesystem directory flag. Pass `exists: true` to require the directory to exist at parse time. */
|
|
2
2
|
export declare const directoryFlag: <const O extends Partial<import('../index.js').FlagDefinition<string, {
|
|
3
3
|
exists?: boolean;
|
|
4
|
+
}>> = Partial<import('../index.js').FlagDefinition<string, {
|
|
5
|
+
exists?: boolean;
|
|
4
6
|
}>>>(overrides?: O | undefined) => {
|
|
5
7
|
exists?: boolean | undefined;
|
|
6
8
|
} & {
|
|
7
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
9
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<string, {
|
|
8
10
|
exists?: boolean;
|
|
9
11
|
}>) => string;
|
|
10
12
|
type?: import('../index.js').FlagKind;
|
|
11
|
-
ask?: (opts: import('../index.js').FlagOpts
|
|
13
|
+
ask?: ((opts: import('../index.js').FlagOpts<string, {
|
|
14
|
+
exists?: boolean;
|
|
15
|
+
}>) => Promise<any>) | undefined;
|
|
12
16
|
description?: string;
|
|
13
17
|
required?: boolean;
|
|
14
18
|
default?: string | string[] | (() => string | string[] | null) | (() => Promise<string | string[] | null>) | null | undefined;
|
|
15
19
|
multiple?: boolean;
|
|
16
20
|
help?: string;
|
|
17
21
|
alias?: string | readonly string[];
|
|
18
|
-
handler?: ((value: string, opts: import('../index.js').FlagOpts
|
|
22
|
+
handler?: ((value: string, opts: import('../index.js').FlagOpts<string, {
|
|
23
|
+
exists?: boolean;
|
|
24
|
+
}>) => {
|
|
19
25
|
shouldStop: boolean;
|
|
20
26
|
} | void) | undefined;
|
|
21
27
|
} & Partial<import('../index.js').FlagDefinition<string, {
|
package/dist/esm/flags/file.d.ts
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
/** Filesystem file flag. Pass `exists: true` to require the path to exist at parse time. */
|
|
2
2
|
export declare const fileFlag: <const O extends Partial<import('../index.js').FlagDefinition<string, {
|
|
3
3
|
exists?: boolean;
|
|
4
|
+
}>> = Partial<import('../index.js').FlagDefinition<string, {
|
|
5
|
+
exists?: boolean;
|
|
4
6
|
}>>>(overrides?: O | undefined) => {
|
|
5
7
|
exists?: boolean | undefined;
|
|
6
8
|
} & {
|
|
7
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
9
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<string, {
|
|
8
10
|
exists?: boolean;
|
|
9
11
|
}>) => string;
|
|
10
12
|
type?: import('../index.js').FlagKind;
|
|
11
|
-
ask?: (opts: import('../index.js').FlagOpts
|
|
13
|
+
ask?: ((opts: import('../index.js').FlagOpts<string, {
|
|
14
|
+
exists?: boolean;
|
|
15
|
+
}>) => Promise<any>) | undefined;
|
|
12
16
|
description?: string;
|
|
13
17
|
required?: boolean;
|
|
14
18
|
default?: string | string[] | (() => string | string[] | null) | (() => Promise<string | string[] | null>) | null | undefined;
|
|
15
19
|
multiple?: boolean;
|
|
16
20
|
help?: string;
|
|
17
21
|
alias?: string | readonly string[];
|
|
18
|
-
handler?: ((value: string, opts: import('../index.js').FlagOpts
|
|
22
|
+
handler?: ((value: string, opts: import('../index.js').FlagOpts<string, {
|
|
23
|
+
exists?: boolean;
|
|
24
|
+
}>) => {
|
|
19
25
|
shouldStop: boolean;
|
|
20
26
|
} | void) | undefined;
|
|
21
27
|
} & Partial<import('../index.js').FlagDefinition<string, {
|
|
@@ -17,82 +17,97 @@ import { optionFlag } from './option.js';
|
|
|
17
17
|
* default, multiple, ask, handler, help) plus its builder-specific extras.
|
|
18
18
|
*/
|
|
19
19
|
export declare const Flags: {
|
|
20
|
-
string: <const O extends Partial<import('../index.js').FlagDefinition<string, import('../index.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
20
|
+
string: <const O extends Partial<import('../index.js').FlagDefinition<string, import('../index.js').CustomOptions>> = Partial<import('../index.js').FlagDefinition<string, import('../index.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
21
21
|
[x: string]: unknown;
|
|
22
22
|
} & {
|
|
23
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
23
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<string, import('../index.js').CustomOptions>) => string;
|
|
24
24
|
type?: import('../index.js').FlagKind;
|
|
25
|
-
ask?: (opts: import('../index.js').FlagOpts) => Promise<any
|
|
25
|
+
ask?: ((opts: import('../index.js').FlagOpts<string, import('../index.js').CustomOptions>) => Promise<any>) | undefined;
|
|
26
26
|
description?: string;
|
|
27
27
|
required?: boolean;
|
|
28
28
|
default?: string | string[] | (() => string | string[] | null) | (() => Promise<string | string[] | null>) | null | undefined;
|
|
29
29
|
multiple?: boolean;
|
|
30
30
|
help?: string;
|
|
31
31
|
alias?: string | readonly string[];
|
|
32
|
-
handler?: ((value: string, opts: import('../index.js').FlagOpts) => {
|
|
32
|
+
handler?: ((value: string, opts: import('../index.js').FlagOpts<string, import('../index.js').CustomOptions>) => {
|
|
33
33
|
shouldStop: boolean;
|
|
34
34
|
} | void) | undefined;
|
|
35
35
|
} & Partial<import('../index.js').FlagDefinition<string, import('../index.js').CustomOptions>> & O;
|
|
36
36
|
number: <const O extends Partial<import('../index.js').FlagDefinition<number, {
|
|
37
37
|
min?: number;
|
|
38
38
|
max?: number;
|
|
39
|
+
}>> = Partial<import('../index.js').FlagDefinition<number, {
|
|
40
|
+
min?: number;
|
|
41
|
+
max?: number;
|
|
39
42
|
}>>>(overrides?: O | undefined) => {
|
|
40
43
|
min?: number | undefined;
|
|
41
44
|
max?: number | undefined;
|
|
42
45
|
} & {
|
|
43
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
46
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<number, {
|
|
44
47
|
min?: number;
|
|
45
48
|
max?: number;
|
|
46
49
|
}>) => number;
|
|
47
50
|
type?: import('../index.js').FlagKind;
|
|
48
|
-
ask?: (opts: import('../index.js').FlagOpts
|
|
51
|
+
ask?: ((opts: import('../index.js').FlagOpts<number, {
|
|
52
|
+
min?: number;
|
|
53
|
+
max?: number;
|
|
54
|
+
}>) => Promise<any>) | undefined;
|
|
49
55
|
description?: string;
|
|
50
56
|
required?: boolean;
|
|
51
57
|
default?: number | number[] | (() => number | number[] | null) | (() => Promise<number | number[] | null>) | null | undefined;
|
|
52
58
|
multiple?: boolean;
|
|
53
59
|
help?: string;
|
|
54
60
|
alias?: string | readonly string[];
|
|
55
|
-
handler?: ((value: number, opts: import('../index.js').FlagOpts
|
|
61
|
+
handler?: ((value: number, opts: import('../index.js').FlagOpts<number, {
|
|
62
|
+
min?: number;
|
|
63
|
+
max?: number;
|
|
64
|
+
}>) => {
|
|
56
65
|
shouldStop: boolean;
|
|
57
66
|
} | void) | undefined;
|
|
58
67
|
} & Partial<import('../index.js').FlagDefinition<number, {
|
|
59
68
|
min?: number;
|
|
60
69
|
max?: number;
|
|
61
70
|
}>> & O;
|
|
62
|
-
boolean: <const O extends Partial<import('../index.js').FlagDefinition<boolean, import('../index.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
71
|
+
boolean: <const O extends Partial<import('../index.js').FlagDefinition<boolean, import('../index.js').CustomOptions>> = Partial<import('../index.js').FlagDefinition<boolean, import('../index.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
63
72
|
[x: string]: unknown;
|
|
64
73
|
} & {
|
|
65
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
74
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<boolean, import('../index.js').CustomOptions>) => boolean;
|
|
66
75
|
type?: import('../index.js').FlagKind;
|
|
67
|
-
ask?: (opts: import('../index.js').FlagOpts) => Promise<any
|
|
76
|
+
ask?: ((opts: import('../index.js').FlagOpts<boolean, import('../index.js').CustomOptions>) => Promise<any>) | undefined;
|
|
68
77
|
description?: string;
|
|
69
78
|
required?: boolean;
|
|
70
79
|
default?: boolean | boolean[] | (() => boolean | boolean[] | null) | (() => Promise<boolean | boolean[] | null>) | null | undefined;
|
|
71
80
|
multiple?: boolean;
|
|
72
81
|
help?: string;
|
|
73
82
|
alias?: string | readonly string[];
|
|
74
|
-
handler?: ((value: boolean, opts: import('../index.js').FlagOpts) => {
|
|
83
|
+
handler?: ((value: boolean, opts: import('../index.js').FlagOpts<boolean, import('../index.js').CustomOptions>) => {
|
|
75
84
|
shouldStop: boolean;
|
|
76
85
|
} | void) | undefined;
|
|
77
86
|
} & Partial<import('../index.js').FlagDefinition<boolean, import('../index.js').CustomOptions>> & O;
|
|
78
87
|
option: typeof optionFlag;
|
|
79
88
|
file: <const O extends Partial<import('../index.js').FlagDefinition<string, {
|
|
80
89
|
exists?: boolean;
|
|
90
|
+
}>> = Partial<import('../index.js').FlagDefinition<string, {
|
|
91
|
+
exists?: boolean;
|
|
81
92
|
}>>>(overrides?: O | undefined) => {
|
|
82
93
|
exists?: boolean | undefined;
|
|
83
94
|
} & {
|
|
84
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
95
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<string, {
|
|
85
96
|
exists?: boolean;
|
|
86
97
|
}>) => string;
|
|
87
98
|
type?: import('../index.js').FlagKind;
|
|
88
|
-
ask?: (opts: import('../index.js').FlagOpts
|
|
99
|
+
ask?: ((opts: import('../index.js').FlagOpts<string, {
|
|
100
|
+
exists?: boolean;
|
|
101
|
+
}>) => Promise<any>) | undefined;
|
|
89
102
|
description?: string;
|
|
90
103
|
required?: boolean;
|
|
91
104
|
default?: string | string[] | (() => string | string[] | null) | (() => Promise<string | string[] | null>) | null | undefined;
|
|
92
105
|
multiple?: boolean;
|
|
93
106
|
help?: string;
|
|
94
107
|
alias?: string | readonly string[];
|
|
95
|
-
handler?: ((value: string, opts: import('../index.js').FlagOpts
|
|
108
|
+
handler?: ((value: string, opts: import('../index.js').FlagOpts<string, {
|
|
109
|
+
exists?: boolean;
|
|
110
|
+
}>) => {
|
|
96
111
|
shouldStop: boolean;
|
|
97
112
|
} | void) | undefined;
|
|
98
113
|
} & Partial<import('../index.js').FlagDefinition<string, {
|
|
@@ -100,39 +115,45 @@ export declare const Flags: {
|
|
|
100
115
|
}>> & O;
|
|
101
116
|
directory: <const O extends Partial<import('../index.js').FlagDefinition<string, {
|
|
102
117
|
exists?: boolean;
|
|
118
|
+
}>> = Partial<import('../index.js').FlagDefinition<string, {
|
|
119
|
+
exists?: boolean;
|
|
103
120
|
}>>>(overrides?: O | undefined) => {
|
|
104
121
|
exists?: boolean | undefined;
|
|
105
122
|
} & {
|
|
106
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
123
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<string, {
|
|
107
124
|
exists?: boolean;
|
|
108
125
|
}>) => string;
|
|
109
126
|
type?: import('../index.js').FlagKind;
|
|
110
|
-
ask?: (opts: import('../index.js').FlagOpts
|
|
127
|
+
ask?: ((opts: import('../index.js').FlagOpts<string, {
|
|
128
|
+
exists?: boolean;
|
|
129
|
+
}>) => Promise<any>) | undefined;
|
|
111
130
|
description?: string;
|
|
112
131
|
required?: boolean;
|
|
113
132
|
default?: string | string[] | (() => string | string[] | null) | (() => Promise<string | string[] | null>) | null | undefined;
|
|
114
133
|
multiple?: boolean;
|
|
115
134
|
help?: string;
|
|
116
135
|
alias?: string | readonly string[];
|
|
117
|
-
handler?: ((value: string, opts: import('../index.js').FlagOpts
|
|
136
|
+
handler?: ((value: string, opts: import('../index.js').FlagOpts<string, {
|
|
137
|
+
exists?: boolean;
|
|
138
|
+
}>) => {
|
|
118
139
|
shouldStop: boolean;
|
|
119
140
|
} | void) | undefined;
|
|
120
141
|
} & Partial<import('../index.js').FlagDefinition<string, {
|
|
121
142
|
exists?: boolean;
|
|
122
143
|
}>> & O;
|
|
123
|
-
url: <const O extends Partial<import('../index.js').FlagDefinition<URL, import('../index.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
144
|
+
url: <const O extends Partial<import('../index.js').FlagDefinition<URL, import('../index.js').CustomOptions>> = Partial<import('../index.js').FlagDefinition<URL, import('../index.js').CustomOptions>>>(overrides?: O | undefined) => {
|
|
124
145
|
[x: string]: unknown;
|
|
125
146
|
} & {
|
|
126
|
-
parse: (input: any, opts: import('../index.js').FlagOpts<
|
|
147
|
+
parse: (input: any, opts: import('../index.js').FlagOpts<URL, import('../index.js').CustomOptions>) => URL;
|
|
127
148
|
type?: import('../index.js').FlagKind;
|
|
128
|
-
ask?: (opts: import('../index.js').FlagOpts) => Promise<any
|
|
149
|
+
ask?: ((opts: import('../index.js').FlagOpts<URL, import('../index.js').CustomOptions>) => Promise<any>) | undefined;
|
|
129
150
|
description?: string;
|
|
130
151
|
required?: boolean;
|
|
131
152
|
default?: URL | URL[] | (() => URL | URL[] | null) | (() => Promise<URL | URL[] | null>) | null | undefined;
|
|
132
153
|
multiple?: boolean;
|
|
133
154
|
help?: string;
|
|
134
155
|
alias?: string | readonly string[];
|
|
135
|
-
handler?: ((value: URL, opts: import('../index.js').FlagOpts) => {
|
|
156
|
+
handler?: ((value: URL, opts: import('../index.js').FlagOpts<URL, import('../index.js').CustomOptions>) => {
|
|
136
157
|
shouldStop: boolean;
|
|
137
158
|
} | void) | undefined;
|
|
138
159
|
} & Partial<import('../index.js').FlagDefinition<URL, import('../index.js').CustomOptions>> & O;
|