UNPKG

create-abi

Version:

Interactive CLI for create Abi.js projects.

2 lines (1 loc) 4.77 kB
import{A as y,C as g,D as u,E as l,F as d,H as x,Q as A,R as C,S as v,T as w,U as O,c as s,d as r,e as o,v as h,w as p,x as c,y as f,z as b}from"./chunk-5AAY5SUW.js";import{m as E,n as I}from"./chunk-TP6KBC4Q.js";import V from"yargs";import{hideBin as P}from"yargs/helpers";var m=class{constructor(n,t){this.signature=n;this.description=t}arguments=new Map;options=new Map;examples=new Set;#n="";setArgument(n,t){return this.arguments.set(n,t),this}getArgument(n){return this.arguments.get(n)}hasArgument(n){return this.arguments.has(n)}argument(n,t){return t?this.setArgument(n,t):this.getArgument(n)}setOption(n,t){return this.options.set(n,t),this}getOption(n){return this.options.get(n)}hasOption(n){return this.options.has(n)}option(n,t){return t?this.setOption(n,t):this.getOption(n)}addExample(n,t){return this.examples.add({command:n,description:t}),this}getExample(n){return this.examples.values().find(t=>t.command===n||t.description===n)}example(n,t){return t?this.addExample(n,t):this.getExample(n)}getExamples(){return this.examples.values().toArray()}setUsage(n){return this.#n=n,this}getUsage(){return this.#n}usage(n){return n?this.setUsage(n):this.getUsage()}},k=class{constructor(n,t){this.name=n;this.version=t;this.configure()}#n=!1;#i=!1;#t=!1;#e=!1;#s={};commands=new Set;aliases=new Set;interactions=new Map;configure(){}addCommand(n,t){let e=new m(n,t);return this.#t&&e.option("yes",{alias:"y",type:"boolean",desc:"Skip all prompts by accepting defaults"}),this.#e&&e.option("no",{alias:"n",type:"boolean",desc:"Skip all prompts by declining defaults"}),this.commands.add(e),e}getCommand(n){return this.commands.values().find(t=>t.signature===n||t.description===n)}command(n,t){return t?this.addCommand(n,t):this.getCommand(n)}getCommands(){return this.commands.values().toArray()}strict(n=!0){return this.#n=n,this}conflict(n,t){return this.#s[n]=t,this}interactive(n=!0){return this.#i=n,this}useYes(n=!0){return this.#t=n,this}useNo(n=!0){return this.#e=n,this}addAlias(n,t){return this.aliases.add({shortName:n,longName:t}),this}getAlias(n){return this.aliases.values().find(t=>t.shortName===n||t.longName===n)}alias(n,t){return t?this.addAlias(n,t):this.getAlias(n)}getAliases(){return this.aliases.values().toArray()}async run(n=process.argv){let t=P(n),e=this.parse(t),i;return this.isIt()?i=await this.interact(e):i=this.validate(e),await this.execute(i)}isIt(){return this.#i&&!(I()||E())}intercept(n,t){return this.setInteraction(n,t)}async interact(n){return this.validate(n)}parse(n){let t=V(n);t.scriptName(this.name),this.#n&&t.strict(),this.#t&&this.#e&&t.conflicts("yes","no"),this.#r(t),t.version(this.version);for(let[i,a]of Object.entries(this.#s))t.conflicts(i,a);for(let{shortName:i,longName:a}of this.aliases)t.alias(i,a);return t.argv}#r(n){for(let t of this.commands)this.#o(n,t)}#o(n,t){n.command(t.signature,t.description,e=>{this.#a(n,t.arguments),this.#u(n,t.options),this.#d(n,t.examples),e.usage(t.usage())})}#a(n,t){for(let[e,i]of t)this.#g(n,e,i)}#g(n,t,e){n.positional(t,e)}#u(n,t){for(let[e,i]of t)this.#l(n,e,i)}#l(n,t,e){n.option(t,e)}#d(n,t){for(let e of t)this.#m(n,e.command,e.description)}#m(n,t,e){n.example(t,e)}getInteraction(n){for(let t of this.interactions.keys())if(n.includes(t)||RegExp(t).test(n))return this.interactions.get(t)}setInteraction(n,t){return this.interactions.set(n,t),this}async scanBoolean(n,t,e){let i=this.getInteraction(t);return i!==void 0?(x(i),i):e!==void 0?l(t,e,this.isIt(),this.#t&&n.yes,this.#e&&n.no):l(t,void 0,this.isIt(),this.#t&&n.yes,this.#e&&n.no)}async scanString(n,t){let e=this.getInteraction(n);return e!==void 0?(d(e),e):t?g(n,t,this.isIt()):g(n,void 0,this.isIt())}async scanChoice(n,t,e){let i=this.getInteraction(n);return i!==void 0?(d(i,a=>t.find(S=>S.value===a)!==void 0),i):e?u(n,t,e,this.isIt()):u(n,t,void 0,this.isIt())}panic(n){y(n)}cancel(n){A(n)}intro(n){C(n)}outro(n){w(n)}note(n,t){v(n,t)}spinner(){return O()}info(n){h(n)}warn(n){f(n)}error(n){b(n)}step(n){c(n)}success(n){p(n)}red(n){return s.red(n)}green(n){return s.green(n)}blue(n){return s.blue(n)}yellow(n){return s.yellow(n)}magenta(n){return s.magenta(n)}cyan(n){return s.cyan(n)}gray(n){return s.gray(n)}grey(n){return s.grey(n)}white(n){return s.white(n)}black(n){return s.black(n)}bgRed(n){return r.red(n)}bgGreen(n){return r.green(n)}bgBlue(n){return r.blue(n)}bgYellow(n){return r.yellow(n)}bgMagenta(n){return r.magenta(n)}bgCyan(n){return r.cyan(n)}bgWhite(n){return r.white(n)}bgBlack(n){return r.black(n)}reset(n){return o.reset(n)}dim(n){return o.dim(n)}bold(n){return o.bold(n)}italic(n){return o.italic(n)}underline(n){return o.underline(n)}inverse(n){return o.inverse(n)}hidden(n){return o.hidden(n)}strikethrough(n){return o.strikethrough(n)}};export{m as a,k as b};