cli-kiss 0.2.2 → 0.2.3
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/index.d.ts +509 -820
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/.vitepress/config.mts +3 -0
- package/docs/guide/01_getting_started.md +4 -4
- package/docs/guide/02_commands.md +5 -10
- package/docs/guide/03_options.md +4 -6
- package/docs/guide/04_positionals.md +6 -8
- package/docs/guide/05_types.md +8 -10
- package/docs/guide/06_run.md +3 -4
- package/docs/index.md +3 -3
- package/package.json +1 -1
- package/src/lib/Command.ts +178 -245
- package/src/lib/Operation.ts +60 -80
- package/src/lib/Option.ts +112 -123
- package/src/lib/Positional.ts +59 -92
- package/src/lib/Reader.ts +53 -78
- package/src/lib/Run.ts +39 -57
- package/src/lib/Type.ts +81 -141
- package/src/lib/Typo.ts +121 -164
- package/src/lib/Usage.ts +56 -18
- package/tests/unit.command.execute.ts +81 -69
- package/tests/unit.command.usage.ts +228 -107
- package/tests/unit.runner.cycle.ts +37 -7
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var J=Object.defineProperty;var wt=Object.getOwnPropertyDescriptor;var ft=Object.getOwnPropertyNames;var xt=Object.prototype.hasOwnProperty;var ct=e=>{throw TypeError(e)};var bt=(e,t)=>{for(var n in t)J(e,n,{get:t[n],enumerable:!0})},Ct=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ft(t))!xt.call(e,o)&&o!==n&&J(e,o,{get:()=>t[o],enumerable:!(r=wt(t,o))||r.enumerable});return e};var St=e=>Ct(J({},"__esModule",{value:!0}),e);var z=(e,t,n)=>t.has(e)||ct("Cannot "+n);var c=(e,t,n)=>(z(e,t,"read from private field"),n?n.call(e):t.get(e)),w=(e,t,n)=>t.has(e)?ct("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),m=(e,t,n,r)=>(z(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),h=(e,t,n)=>(z(e,t,"access private method"),n);var gt=(e,t,n,r)=>({set _(o){m(e,t,o,n)},get _(){return c(e,t,r)}});var ee={};bt(ee,{ReaderArgs:()=>N,TypoError:()=>d,TypoGrid:()=>A,TypoString:()=>s,TypoSupport:()=>k,TypoText:()=>l,command:()=>$t,commandChained:()=>vt,commandWithSubcommands:()=>At,operation:()=>Ft,optionFlag:()=>Yt,optionRepeatable:()=>Ht,optionSingleValue:()=>qt,positionalOptional:()=>Jt,positionalRequired:()=>Qt,positionalVariadics:()=>zt,runAndExit:()=>te,typeBoolean:()=>q,typeConverted:()=>Kt,typeDate:()=>Bt,typeInteger:()=>Wt,typeList:()=>jt,typeNumber:()=>Lt,typeOneOf:()=>Dt,typeString:()=>Mt,typeTuple:()=>Nt,typeUrl:()=>Gt,typoStyleConstants:()=>x,typoStyleFailure:()=>dt,typoStyleLogic:()=>S,typoStyleQuote:()=>f,typoStyleRegularStrong:()=>Z,typoStyleRegularWeaker:()=>_,typoStyleTitle:()=>X,typoStyleUserInput:()=>b,usageToStyledLines:()=>lt});module.exports=St(ee);var X={fgColor:"darkGreen",bold:!0},S={fgColor:"darkMagenta",bold:!0},f={fgColor:"darkYellow",bold:!0},dt={fgColor:"darkRed",bold:!0},x={fgColor:"darkCyan",bold:!0},b={fgColor:"darkBlue",bold:!0},Z={bold:!0},_={italic:!0,dim:!0},B,D,s=class{constructor(t,n={}){w(this,B);w(this,D);m(this,B,t),m(this,D,n)}getRawString(){return c(this,B)}computeStyledString(t){return t.computeStyledString(c(this,B),c(this,D))}};B=new WeakMap,D=new WeakMap;var U,tt=class tt{constructor(...t){w(this,U);m(this,U,[]);for(let n of t)n instanceof tt?this.pushText(n):n instanceof s?this.pushString(n):typeof n=="string"&&this.pushString(new s(n))}pushString(t){c(this,U).push(t)}pushText(t){for(let n of c(t,U))c(this,U).push(n)}computeStyledString(t){return c(this,U).map(n=>n.computeStyledString(t)).join("")}computeRawString(){return c(this,U).map(t=>t.getRawString()).join("")}computeRawLength(){let t=0;for(let n of c(this,U))t+=n.getRawString().length;return t}};U=new WeakMap;var l=tt,$,A=class{constructor(){w(this,$);m(this,$,[])}pushRow(t){c(this,$).push(t)}computeStyledGrid(t){let n=new Array,r=new Array;for(let o of c(this,$))for(let a=0;a<o.length;a++){let i=o[a].computeRawLength();(n[a]===void 0||i>n[a])&&(n[a]=i)}for(let o of c(this,$)){let a=new Array;for(let p=0;p<o.length;p++){let i=o[p],u=i.computeStyledString(t);if(a.push(u),p<o.length-1){let g=i.computeRawLength(),T=" ".repeat(n[p]-g);a.push(T)}}r.push(a)}return r}};$=new WeakMap;var L,Y=class Y extends Error{constructor(n,r){let o=new l;o.pushText(n),r instanceof Y?(o.pushString(new s(": ")),o.pushText(c(r,L))):r instanceof Error?o.pushString(new s(`: ${r.message}`)):r!==void 0&&o.pushString(new s(`: ${String(r)}`));super(o.computeRawString());w(this,L);m(this,L,o)}computeStyledString(n){return c(this,L).computeStyledString(n)}static tryWithContext(n,r){try{return n()}catch(o){throw new Y(r(),o)}}};L=new WeakMap;var d=Y,P,C=class C{constructor(t){w(this,P);m(this,P,t)}static none(){return new C("none")}static tty(){return new C("tty")}static mock(){return new C("mock")}static inferFromProcess(){if(!process)return C.none();if(process.env){if(process.env.FORCE_COLOR==="0")return C.none();if(process.env.FORCE_COLOR)return C.tty();if("NO_COLOR"in process.env)return C.none()}return process.stdout&&process.stdout.isTTY?C.tty():C.none()}computeStyledString(t,n){if(c(this,P)==="none")return t;if(c(this,P)==="tty"){let r=n.fgColor?Vt[n.fgColor]:"",o=n.bgColor?It[n.bgColor]:"",a=n.bold?Ut:"",p=n.dim?Rt:"",i=n.italic?Ot:"",u=n.underline?Pt:"",g=n.strikethrough?kt:"";return`${r}${o}${a}${p}${i}${u}${g}${t}${Tt}`}if(c(this,P)==="mock"){let r=n.fgColor?`{${t}}@${n.fgColor}`:t,o=n.bgColor?`{${r}}#${n.bgColor}`:r,a=n.bold?`{${o}}+`:o,p=n.dim?`{${a}}-`:a,i=n.italic?`{${p}}*`:p,u=n.underline?`{${i}}_`:i;return n.strikethrough?`{${u}}~`:u}throw new Error(`Unknown TypoSupport kind: ${c(this,P)}`)}computeStyledErrorMessage(t){return[this.computeStyledString("Error:",dt),t instanceof d?t.computeStyledString(this):t instanceof Error?t.message:String(t)].join(" ")}};P=new WeakMap;var k=C,Tt="\x1B[0m",Ut="\x1B[1m",Rt="\x1B[2m",Ot="\x1B[3m",Pt="\x1B[4m",kt="\x1B[9m",Vt={darkBlack:"\x1B[30m",darkRed:"\x1B[31m",darkGreen:"\x1B[32m",darkYellow:"\x1B[33m",darkBlue:"\x1B[34m",darkMagenta:"\x1B[35m",darkCyan:"\x1B[36m",darkWhite:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m"},It={darkBlack:"\x1B[40m",darkRed:"\x1B[41m",darkGreen:"\x1B[42m",darkYellow:"\x1B[43m",darkBlue:"\x1B[44m",darkMagenta:"\x1B[45m",darkCyan:"\x1B[46m",darkWhite:"\x1B[47m",brightBlack:"\x1B[100m",brightRed:"\x1B[101m",brightGreen:"\x1B[102m",brightYellow:"\x1B[103m",brightBlue:"\x1B[104m",brightMagenta:"\x1B[105m",brightCyan:"\x1B[106m",brightWhite:"\x1B[107m"};function $t(e,t){return{getInformation(){return e},createFactory(n){function r(){let o=t.generateUsage();return{breadcrumbs:o.positionals.map(a=>v(a.label)),information:e,positionals:o.positionals,subcommands:[],options:o.options}}try{let o=t.createFactory(n),a=n.consumePositional();if(a!==void 0)throw new d(new l(new s("Unexpected argument: "),new s(`"${a}"`,f)));return{generateUsage:r,createInstance(){let p=o.createInstance();return{async executeWithContext(i){return await p.executeWithContext(i)}}}}}catch(o){return{generateUsage:r,createInstance(){throw o}}}}}}function At(e,t,n){return{getInformation(){return e},createFactory(r){try{let o=t.createFactory(r),a=r.consumePositional();if(a===void 0)throw new d(new l(new s("<SUBCOMMAND>",b),new s(": Is required, but was not provided")));let p=n[a];if(p===void 0)throw new d(new l(new s("<SUBCOMMAND>",b),new s(": Invalid value: "),new s(`"${a}"`,f)));let i=p.createFactory(r);return{generateUsage(){let u=t.generateUsage(),g=i.generateUsage();return{breadcrumbs:u.positionals.map(T=>v(T.label)).concat([Et(a)]).concat(g.breadcrumbs),information:g.information,positionals:u.positionals.concat(g.positionals),subcommands:g.subcommands,options:u.options.concat(g.options)}},createInstance(){let u=o.createInstance(),g=i.createInstance();return{async executeWithContext(T){return await g.executeWithContext(await u.executeWithContext(T))}}}}}catch(o){return{generateUsage(){let a=t.generateUsage();return{breadcrumbs:a.positionals.map(p=>v(p.label)).concat([v("<SUBCOMMAND>")]),information:e,positionals:a.positionals,subcommands:Object.entries(n).map(p=>{let i=p[1].getInformation();return{name:p[0],description:i.description,hint:i.hint}}),options:a.options}},createInstance(){throw o}}}}}}function vt(e,t,n){return{getInformation(){return e},createFactory(r){try{let o=t.createFactory(r),a=n.createFactory(r);return{generateUsage(){let p=t.generateUsage(),i=a.generateUsage();return{breadcrumbs:p.positionals.map(u=>v(u.label)).concat(i.breadcrumbs),information:i.information,positionals:p.positionals.concat(i.positionals),subcommands:i.subcommands,options:p.options.concat(i.options)}},createInstance(){let p=o.createInstance(),i=a.createInstance();return{async executeWithContext(u){return await i.executeWithContext(await p.executeWithContext(u))}}}}}catch(o){return{generateUsage(){let a=t.generateUsage();return{breadcrumbs:a.positionals.map(p=>v(p.label)).concat([v("[REST]...")]),information:e,positionals:a.positionals,subcommands:[],options:a.options}},createInstance(){throw o}}}}}}function v(e){return{positional:e}}function Et(e){return{command:e}}function Ft(e,t){return{generateUsage(){let n=new Array;for(let o in e.options){let a=e.options[o];a&&n.push(a.generateUsage())}let r=new Array;for(let o of e.positionals)r.push(o.generateUsage());return{options:n,positionals:r}},createFactory(n){let r={};for(let a in e.options){let p=e.options[a];r[a]=p.createParser(n)}let o=[];for(let a of e.positionals)o.push(a.createParser(n));return{createInstance(){let a={};for(let i in r)a[i]=r[i].parseValue();let p=[];for(let i of o)p.push(i.parseValue());return{executeWithContext(i){return t(i,{options:a,positionals:p})}}}}}}}var q={content:"Boolean",decoder(e){let t=e.toLowerCase();if(t==="true"||t==="yes")return!0;if(t==="false"||t==="no")return!1;throw new d(new l(new s("Invalid value: "),new s(`"${e}"`,f)))}},Bt={content:"Date",decoder(e){try{let t=Date.parse(e);if(isNaN(t))throw new Error;return new Date(t)}catch{throw new d(new l(new s("Not a valid ISO_8601: "),new s(`"${e}"`,f)))}}},Lt={content:"Number",decoder(e){try{let t=Number(e);if(isNaN(t))throw new Error;return t}catch{throw new d(new l(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Wt={content:"Integer",decoder(e){try{return BigInt(e)}catch{throw new d(new l(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Gt={content:"Url",decoder(e){try{return new URL(e)}catch{throw new d(new l(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Mt={content:"String",decoder(e){return e}};function Kt(e,t){return{content:t.content,decoder:n=>t.decoder(d.tryWithContext(()=>e.decoder(n),()=>new l(new s("from: "),new s(e.content,S))))}}function Dt(e,t){let n=new Set(t);return{content:e,decoder(r){if(n.has(r))return r;let o=[];for(let a of t){if(o.length>=5){o.push(new s("..."));break}o.length>0&&o.push(new s(" | ")),o.push(new s(`"${a}"`,f))}throw new d(new l(new s("Invalid value: "),new s(`"${r}"`,f),new s(" (expected one of: "),...o,new s(")")))}}}function Nt(e,t=","){return{content:e.map(n=>n.content).join(t),decoder(n){let r=n.split(t,e.length);if(r.length!==e.length)throw new d(new l(new s(`Found ${r.length} splits: `),new s(`Expected ${e.length} splits from: `),new s(`"${n}"`,f)));return r.map((o,a)=>{let p=e[a];return d.tryWithContext(()=>p.decoder(o),()=>new l(new s(`at ${a}: `),new s(p.content,S)))})}}}function jt(e,t=","){return{content:`${e.content}[${t}${e.content}]...`,decoder(n){return n.split(t).map((o,a)=>d.tryWithContext(()=>e.decoder(o),()=>new l(new s(`at ${a}: `),new s(e.content,S))))}}}function Yt(e){let t=`<${q.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,long:e.long,short:e.short,label:void 0}},createParser(n){let r=nt(n,{...e,valued:!1});return{parseValue(){let o=n.getOptionValues(r);if(o.length>1)throw new d(new l(new s(`--${e.long}`,x),new s(": Must not be set multiple times")));let a=o[0];if(a===void 0)try{return e.default?e.default():!1}catch(p){throw new d(new l(new s(`--${e.long}`,x),new s(": Failed to get default value")),p)}return et(e.long,t,q,a)}}}}}function qt(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,long:e.long,short:e.short,label:t}},createParser(n){let r=nt(n,{...e,valued:!0});return{parseValue(){let o=n.getOptionValues(r);if(o.length>1)throw new d(new l(new s(`--${e.long}`,x),new s(": Requires a single value, but got multiple")));let a=o[0];if(a===void 0)try{return e.default()}catch(p){throw new d(new l(new s(`--${e.long}`,x),new s(": Failed to get default value")),p)}return et(e.long,t,e.type,a)}}}}}function Ht(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,long:e.long,short:e.short,label:t}},createParser(n){let r=nt(n,{...e,valued:!0});return{parseValue(){return n.getOptionValues(r).map(a=>et(e.long,t,e.type,a))}}}}}function et(e,t,n,r){return d.tryWithContext(()=>n.decoder(r),()=>new l(new s(`--${e}`,x),new s(": "),new s(t,b),new s(": "),new s(n.content,S)))}function nt(e,t){let{long:n,short:r,aliases:o,valued:a}=t,p=n?[n]:[];o?.longs&&p.push(...o?.longs);let i=r?[r]:[];return o?.shorts&&i.push(...o?.shorts),e.registerOption({longs:p,shorts:i,valued:a})}function Qt(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},createParser(n){let r=n.consumePositional();if(r===void 0)throw new d(new l(new s(t,b),new s(": Is required, but was not provided")));return{parseValue(){return ot(t,e.type,r)}}}}}function Jt(e){let t=`[${e.label??e.type.content.toUpperCase()}]`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},createParser(n){let r=n.consumePositional();return{parseValue(){if(r===void 0)try{return e.default()}catch(o){throw new d(new l(new s(t,b),new s(": Failed to get default value")),o)}return ot(t,e.type,r)}}}}}function zt(e){let t=`[${e.label??e.type.content.toUpperCase()}]`;return{generateUsage(){return{description:e.description,hint:e.hint,label:`${t}...`+(e.endDelimiter?`["${e.endDelimiter}"]`:"")}},createParser(n){let r=new Array;for(;;){let o=n.consumePositional();if(o===void 0||o===e.endDelimiter)break;r.push(o)}return{parseValue(){return r.map(o=>ot(t,e.type,o))}}}}}function ot(e,t,n){return d.tryWithContext(()=>t.decoder(n),()=>new l(new s(e,b),new s(": "),new s(t.content,S)))}var j,W,I,E,R,F,G,y,H,yt,rt,mt,st,V,N=class{constructor(t){w(this,y);w(this,j);w(this,W);w(this,I);w(this,E);w(this,R);w(this,F);w(this,G);m(this,j,t),m(this,W,0),m(this,I,!1),m(this,E,new Map),m(this,R,new Map),m(this,F,new Map),m(this,G,new Map)}registerOption(t){let n=[...t.longs.map(r=>`--${r}`),...t.shorts.map(r=>`-${r}`)].join(", ");for(let r of t.longs){if(c(this,E).has(r))throw new Error(`Option already registered: --${r}`);c(this,E).set(r,n)}for(let r of t.shorts){if(c(this,R).has(r))throw new Error(`Option already registered: -${r}`);for(let o=0;o<r.length;o++){let a=r.slice(0,o);if(c(this,R).has(a))throw new Error(`Option -${r} overlap with shorter option: -${a}`)}for(let o of c(this,R).keys())if(o.startsWith(r))throw new Error(`Option -${r} overlap with longer option: -${o}`);c(this,R).set(r,n)}return c(this,F).set(n,t.valued),c(this,G).set(n,new Array),n}getOptionValues(t){let n=c(this,G).get(t);if(n===void 0)throw new Error(`Unregistered option: ${t}`);return n}consumePositional(){for(;;){let t=h(this,y,H).call(this);if(t===null)return;if(h(this,y,yt).call(this,t))return t}}};j=new WeakMap,W=new WeakMap,I=new WeakMap,E=new WeakMap,R=new WeakMap,F=new WeakMap,G=new WeakMap,y=new WeakSet,H=function(){let t=c(this,j)[c(this,W)];return t===void 0?null:(gt(this,W)._++,!c(this,I)&&t==="--"?(m(this,I,!0),h(this,y,H).call(this)):t)},yt=function(t){if(c(this,I))return!0;if(t.startsWith("--")){let n=t.indexOf("=");return n===-1?h(this,y,rt).call(this,t.slice(2),null):h(this,y,rt).call(this,t.slice(2,n),t.slice(n+1)),!1}if(t.startsWith("-")){let n=1,r=2;for(;r<=t.length;){let o=h(this,y,mt).call(this,t.slice(n,r),t.slice(r));if(o===!0)return!1;o===!1&&(n=r),r++}throw new d(new l(new s(`-${t.slice(n)}`,x),new s(": Unexpected unknown option")))}return!0},rt=function(t,n){let r=`--${t}`,o=c(this,E).get(t);if(o!==void 0)return n!==null?h(this,y,V).call(this,o,n):c(this,F).get(o)?h(this,y,V).call(this,o,h(this,y,st).call(this,r)):h(this,y,V).call(this,o,"true");throw new d(new l(new s(r,x),new s(": Unexpected unknown option")))},mt=function(t,n){let r=c(this,R).get(t);return r!==void 0?n.startsWith("=")?(h(this,y,V).call(this,r,n.slice(1)),!0):c(this,F).get(r)?(n===""?h(this,y,V).call(this,r,h(this,y,st).call(this,`-${t}`)):h(this,y,V).call(this,r,n),!0):(h(this,y,V).call(this,r,"true"),n===""):null},st=function(t){let n=h(this,y,H).call(this);if(n===null)throw new d(new l(new s(t,x),new s(": Requires a value, but got end of input")));if(c(this,I))throw new d(new l(new s(t,x),new s(": Requires a value before "),new s('"--"',f)));if(n.startsWith("-"))throw new d(new l(new s(t,x),new s(": Requires a value, but got: "),new s(`"${n}"`,f)));return n},V=function(t,n){this.getOptionValues(t).push(n)};function lt(e){let{cliName:t,commandUsage:n,typoSupport:r}=e,o=new Array,a=[Xt("Usage:").computeStyledString(r),M(t).computeStyledString(r)].concat(n.breadcrumbs.map(i=>{if("positional"in i)return pt(i.positional).computeStyledString(r);if("command"in i)return M(i.command).computeStyledString(r);throw new Error(`Unknown breadcrumb: ${JSON.stringify(i)}`)}));o.push(a.join(" ")),o.push("");let p=new l;p.pushString(Zt(n.information.description)),n.information.hint&&(p.pushString(O(" ")),p.pushString(Q(`(${n.information.hint})`))),o.push(p.computeStyledString(r));for(let i of n.information.details??[]){let u=new l;u.pushString(Q(i)),o.push(u.computeStyledString(r))}if(n.positionals.length>0){o.push(""),o.push(it("Positionals:").computeStyledString(r));let i=new A;for(let u of n.positionals){let g=new Array;g.push(new l(O(" "))),g.push(new l(pt(u.label))),g.push(...at(u)),i.pushRow(g)}o.push(...i.computeStyledGrid(r).map(u=>u.join("")))}if(n.subcommands.length>0){o.push(""),o.push(it("Subcommands:").computeStyledString(r));let i=new A;for(let u of n.subcommands){let g=new Array;g.push(new l(O(" "))),g.push(new l(M(u.name))),g.push(...at(u)),i.pushRow(g)}o.push(...i.computeStyledGrid(r).map(u=>u.join("")))}if(n.options.length>0){o.push(""),o.push(it("Options:").computeStyledString(r));let i=new A;for(let u of n.options){let g=new Array;g.push(new l(O(" "))),u.short?g.push(new l(M(`-${u.short}`),O(", "))):g.push(new l),u.label?g.push(new l(M(`--${u.long}`),O(" "),pt(u.label))):g.push(new l(M(`--${u.long}`),Q("[=no]"))),g.push(...at(u)),i.pushRow(g)}o.push(...i.computeStyledGrid(r).map(u=>u.join("")))}return o.push(""),o}function at(e){let t=[];return e.description&&(t.push(O(" ")),t.push(_t(e.description))),e.hint&&(t.push(O(" ")),t.push(Q(`(${e.hint})`))),t.length>0?[new l(O(" "),...t)]:[]}function Xt(e){return new s(e,S)}function Zt(e){return new s(e,Z)}function _t(e){return new s(e)}function it(e){return new s(e,X)}function Q(e){return new s(e,_)}function M(e){return new s(e,x)}function pt(e){return new s(e,b)}function O(e){return new s(e)}async function te(e,t,n,r,o){let a=new N(t),p=o?.usageOnHelp??!0;p&&a.registerOption({shorts:[],longs:["help"],valued:!1});let i=o?.buildVersion;i&&a.registerOption({shorts:[],longs:["version"],valued:!1});let u=r.createFactory(a);for(;;)try{if(a.consumePositional()===void 0)break}catch{}let g=o?.onExit??process.exit,T=o?.useTtyColors===void 0?k.inferFromProcess():o.useTtyColors==="mock"?k.mock():o.useTtyColors?k.tty():k.none();if(p&&a.getOptionValues("--help").length>0)return console.log(ht(e,u,T)),g(0);if(i&&a.getOptionValues("--version").length>0)return console.log([e,i].join(" ")),g(0);try{let K=u.createInstance();try{return await K.executeWithContext(n),g(0)}catch(ut){return o?.onError?o.onError(ut):console.error(T.computeStyledErrorMessage(ut)),g(1)}}catch(K){return(o?.usageOnError??!0)&&console.error(ht(e,u,T)),console.error(T.computeStyledErrorMessage(K)),g(1)}}function ht(e,t,n){return lt({cliName:e,commandUsage:t.generateUsage(),typoSupport:n}).join(`
|
|
2
|
-
`)}0&&(module.exports={ReaderArgs,TypoError,TypoGrid,TypoString,TypoSupport,TypoText,command,commandChained,commandWithSubcommands,operation,optionFlag,optionRepeatable,optionSingleValue,positionalOptional,positionalRequired,positionalVariadics,runAndExit,typeBoolean,
|
|
1
|
+
"use strict";var X=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var de=t=>{throw TypeError(t)};var Te=(t,e)=>{for(var n in e)X(t,n,{get:e[n],enumerable:!0})},ke=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Se(e))!Ce.call(t,r)&&r!==n&&X(t,r,{get:()=>e[r],enumerable:!(o=be(e,r))||o.enumerable});return t};var Ae=t=>ke(X({},"__esModule",{value:!0}),t);var Z=(t,e,n)=>e.has(t)||de("Cannot "+n);var d=(t,e,n)=>(Z(t,e,"read from private field"),n?n.call(t):e.get(t)),f=(t,e,n)=>e.has(t)?de("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),w=(t,e,n,o)=>(Z(t,e,"write to private field"),o?o.call(t,n):e.set(t,n),n),m=(t,e,n)=>(Z(t,e,"access private method"),n);var ge=(t,e,n,o)=>({set _(r){w(t,e,r,n)},get _(){return d(t,e,o)}});var rt={};Te(rt,{ReaderArgs:()=>F,TypoError:()=>g,TypoGrid:()=>P,TypoString:()=>s,TypoSupport:()=>$,TypoText:()=>u,command:()=>Pe,commandChained:()=>Ee,commandWithSubcommands:()=>ve,operation:()=>We,optionFlag:()=>Qe,optionRepeatable:()=>ze,optionSingleValue:()=>Je,positionalOptional:()=>Ze,positionalRequired:()=>Xe,positionalVariadics:()=>_e,runAndExit:()=>ot,typeBoolean:()=>Q,typeDate:()=>Be,typeInteger:()=>Ke,typeList:()=>He,typeMapped:()=>Fe,typeNumber:()=>Ge,typeOneOf:()=>Ye,typeString:()=>je,typeTuple:()=>qe,typeUrl:()=>Ne,typoStyleConstants:()=>b,typoStyleFailure:()=>he,typoStyleLogic:()=>R,typoStyleQuote:()=>x,typoStyleRegularStrong:()=>ee,typoStyleRegularWeaker:()=>te,typoStyleTitle:()=>_,typoStyleUserInput:()=>S,usageToStyledLines:()=>ce});module.exports=Ae(rt);var _={fgColor:"darkGreen",bold:!0},R={fgColor:"darkMagenta",bold:!0},x={fgColor:"darkYellow",bold:!0},he={fgColor:"darkRed",bold:!0},b={fgColor:"darkCyan",bold:!0},S={fgColor:"darkBlue",bold:!0},ee={bold:!0},te={italic:!0,dim:!0},L,j,s=class{constructor(e,n={}){f(this,L);f(this,j);w(this,L,e),w(this,j,n)}getRawString(){return d(this,L)}computeStyledString(e){return e.computeStyledString(d(this,L),d(this,j))}};L=new WeakMap,j=new WeakMap;var A,ne=class ne{constructor(...e){f(this,A);w(this,A,[]);for(let n of e)n instanceof ne?this.pushText(n):n instanceof s?this.pushString(n):typeof n=="string"&&this.pushString(new s(n))}pushString(e){typeof e=="string"?d(this,A).push(new s(e)):d(this,A).push(e)}pushText(e){if(typeof e=="string")this.pushString(e);else for(let n of d(e,A))d(this,A).push(n)}computeStyledString(e){return d(this,A).map(n=>n.computeStyledString(e)).join("")}computeRawString(){return d(this,A).map(e=>e.getRawString()).join("")}computeRawLength(){let e=0;for(let n of d(this,A))e+=n.getRawString().length;return e}};A=new WeakMap;var u=ne,M,P=class{constructor(){f(this,M);w(this,M,[])}pushRow(e){d(this,M).push(e)}computeStyledGrid(e){let n=new Array,o=new Array;for(let r of d(this,M))for(let i=0;i<r.length;i++){let a=r[i].computeRawLength();(n[i]===void 0||a>n[i])&&(n[i]=a)}for(let r of d(this,M)){let i=new Array;for(let l=0;l<r.length;l++){let a=r[l],c=a.computeStyledString(e);if(i.push(c),l<r.length-1){let p=a.computeRawLength(),y=" ".repeat(n[l]-p);i.push(y)}}o.push(i)}return o}};M=new WeakMap;var W,H=class H extends Error{constructor(n,o){let r=new u;r.pushText(n),o instanceof H?(r.pushString(new s(": ")),r.pushText(d(o,W))):o instanceof Error?r.pushString(new s(`: ${o.message}`)):o!==void 0&&r.pushString(new s(`: ${String(o)}`));super(r.computeRawString());f(this,W);w(this,W,r)}computeStyledString(n){return d(this,W).computeStyledString(n)}static tryWithContext(n,o){try{return n()}catch(r){throw new H(o(),r)}}};W=new WeakMap;var g=H,V,k=class k{constructor(e){f(this,V);w(this,V,e)}static none(){return new k("none")}static tty(){return new k("tty")}static mock(){return new k("mock")}static inferFromProcess(){if(!process)return k.none();if(process.env){if(process.env.FORCE_COLOR==="0")return k.none();if(process.env.FORCE_COLOR)return k.tty();if("NO_COLOR"in process.env)return k.none()}return process.stdout&&process.stdout.isTTY?k.tty():k.none()}computeStyledString(e,n){if(d(this,V)==="none")return e;if(d(this,V)==="tty"){let o=n.fgColor?De[n.fgColor]:"",r=n.bgColor?Me[n.bgColor]:"",i=n.bold?Ue:"",l=n.dim?Oe:"",a=n.italic?Ve:"",c=n.underline?$e:"",p=n.strikethrough?Ie:"";return`${o}${r}${i}${l}${a}${c}${p}${e}${Re}`}if(d(this,V)==="mock"){let o=n.fgColor?`{${e}}@${n.fgColor}`:e,r=n.bgColor?`{${o}}#${n.bgColor}`:o,i=n.bold?`{${r}}+`:r,l=n.dim?`{${i}}-`:i,a=n.italic?`{${l}}*`:l,c=n.underline?`{${a}}_`:a;return n.strikethrough?`{${c}}~`:c}throw new Error(`Unknown TypoSupport kind: ${d(this,V)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",he),e instanceof g?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};V=new WeakMap;var $=k,Re="\x1B[0m",Ue="\x1B[1m",Oe="\x1B[2m",Ve="\x1B[3m",$e="\x1B[4m",Ie="\x1B[9m",De={darkBlack:"\x1B[30m",darkRed:"\x1B[31m",darkGreen:"\x1B[32m",darkYellow:"\x1B[33m",darkBlue:"\x1B[34m",darkMagenta:"\x1B[35m",darkCyan:"\x1B[36m",darkWhite:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m"},Me={darkBlack:"\x1B[40m",darkRed:"\x1B[41m",darkGreen:"\x1B[42m",darkYellow:"\x1B[43m",darkBlue:"\x1B[44m",darkMagenta:"\x1B[45m",darkCyan:"\x1B[46m",darkWhite:"\x1B[47m",brightBlack:"\x1B[100m",brightRed:"\x1B[101m",brightGreen:"\x1B[102m",brightYellow:"\x1B[103m",brightBlue:"\x1B[104m",brightMagenta:"\x1B[105m",brightCyan:"\x1B[106m",brightWhite:"\x1B[107m"};function Pe(t,e){return{getInformation(){return t},consumeAndMakeDecoder(n){try{let o=e.consumeAndMakeDecoder(n),r=n.consumePositional();if(r!==void 0)throw new g(new u(new s("Unexpected argument: "),new s(`"${r}"`,x)));return{generateUsage:()=>B(t,e),decodeAndMakeInterpreter(){let i=o.decodeAndMakeInterpreter();return{async executeWithContext(l){return await i.executeWithContext(l)}}}}}catch(o){return{generateUsage:()=>B(t,e),decodeAndMakeInterpreter(){throw o}}}}}}function ve(t,e,n){return{getInformation(){return t},consumeAndMakeDecoder(o){try{let r=e.consumeAndMakeDecoder(o),i=o.consumePositional();if(i===void 0)throw new g(new u(new s("<SUBCOMMAND>",S),new s(": Is required, but was not provided")));let l=n[i];if(l===void 0)throw new g(new u(new s("<SUBCOMMAND>",S),new s(": Invalid value: "),new s(`"${i}"`,x)));let a=l.consumeAndMakeDecoder(o);return{generateUsage(){let c=a.generateUsage(),p=B(t,e);return p.segments.push(Le(i)),p.segments.push(...c.segments),p.information=c.information,p.positionals.push(...c.positionals),p.subcommands=c.subcommands,p.options.push(...c.options),p},decodeAndMakeInterpreter(){let c=r.decodeAndMakeInterpreter(),p=a.decodeAndMakeInterpreter();return{async executeWithContext(y){return await p.executeWithContext(await c.executeWithContext(y))}}}}}catch(r){return{generateUsage(){let i=B(t,e);i.segments.push(oe("<SUBCOMMAND>"));for(let[l,a]of Object.entries(n)){let{description:c,hint:p}=a.getInformation();i.subcommands.push({name:l,description:c,hint:p})}return i},decodeAndMakeInterpreter(){throw r}}}}}}function Ee(t,e,n){return{getInformation(){return t},consumeAndMakeDecoder(o){try{let r=e.consumeAndMakeDecoder(o),i=n.consumeAndMakeDecoder(o);return{generateUsage(){let l=i.generateUsage(),a=B(t,e);return a.segments.push(...l.segments),a.information=l.information,a.positionals.push(...l.positionals),a.subcommands=l.subcommands,a.options.push(...l.options),a},decodeAndMakeInterpreter(){let l=r.decodeAndMakeInterpreter(),a=i.decodeAndMakeInterpreter();return{async executeWithContext(c){return await a.executeWithContext(await l.executeWithContext(c))}}}}}catch(r){return{generateUsage(){let i=B(t,e);return i.segments.push(oe("[REST]...")),i},decodeAndMakeInterpreter(){throw r}}}}}}function oe(t){return{positional:t}}function Le(t){return{command:t}}function B(t,e){let{positionals:n,options:o}=e.generateUsage();return{segments:n.map(r=>oe(r.label)),information:t,positionals:n,subcommands:[],options:o}}function We(t,e){return{generateUsage(){let n=new Array;for(let r in t.options){let i=t.options[r];i&&n.push(i.generateUsage())}let o=new Array;for(let r of t.positionals)o.push(r.generateUsage());return{options:n,positionals:o}},consumeAndMakeDecoder(n){let o={};for(let i in t.options){let l=t.options[i];o[i]=l.registerAndMakeDecoder(n)}let r=[];for(let i of t.positionals)r.push(i.consumeAndMakeDecoder(n));return{decodeAndMakeInterpreter(){let i={};for(let a in o)i[a]=o[a].getAndDecodeValue();let l=[];for(let a of r)l.push(a.decodeValue());return{executeWithContext(a){return e(a,{options:i,positionals:l})}}}}}}}var Q={content:"Boolean",decoder(t){let e=t.toLowerCase();if(e==="true"||e==="yes")return!0;if(e==="false"||e==="no")return!1;throw new g(new u(new s("Invalid value: "),new s(`"${t}"`,x)))}},Be={content:"Date",decoder(t){try{let e=Date.parse(t);if(isNaN(e))throw new Error;return new Date(e)}catch{throw new g(new u(new s("Not a valid ISO_8601: "),new s(`"${t}"`,x)))}}},Ge={content:"Number",decoder(t){try{let e=Number(t);if(isNaN(e))throw new Error;return e}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${t}"`,x)))}}},Ke={content:"Integer",decoder(t){try{return BigInt(t)}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${t}"`,x)))}}},Ne={content:"Url",decoder(t){try{return new URL(t)}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${t}"`,x)))}}},je={content:"String",decoder(t){return t}};function Fe(t,e){return{content:e.content,decoder:n=>e.decoder(g.tryWithContext(()=>t.decoder(n),()=>new u(new s("from: "),new s(t.content,R))))}}function Ye(t,e){return{content:t,decoder(n){for(let r of e)if(n===r)return r;let o=[];for(let r of e){if(o.length>=5){o.push(new s("..."));break}o.length>0&&o.push(new s(" | ")),o.push(new s(`"${r}"`,x))}throw new g(new u(new s("Invalid value: "),new s(`"${n}"`,x),new s(" (expected one of: "),...o,new s(")")))}}}function qe(t,e=","){return{content:t.map(n=>n.content).join(e),decoder(n){let o=n.split(e,t.length);if(o.length!==t.length)throw new g(new u(new s(`Found ${o.length} splits: `),new s(`Expected ${t.length} splits from: `),new s(`"${n}"`,x)));return o.map((r,i)=>{let l=t[i];return g.tryWithContext(()=>l.decoder(r),()=>new u(new s(`at ${i}: `),new s(l.content,R)))})}}}function He(t,e=","){return{content:`${t.content}[${e}${t.content}]...`,decoder(n){return n.split(e).map((r,i)=>g.tryWithContext(()=>t.decoder(r),()=>new u(new s(`at ${i}: `),new s(t.content,R))))}}}function Qe(t){let e=`<${Q.content.toUpperCase()}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:void 0}},registerAndMakeDecoder(n){let o=se(n,{...t,valued:!1});return{getAndDecodeValue(){let r=n.getOptionValues(o);if(r.length>1)throw new g(new u(new s(`--${t.long}`,b),new s(": Must not be set multiple times")));let i=r[0];if(i===void 0)try{return t.default?t.default():!1}catch(l){throw new g(new u(new s(`--${t.long}`,b),new s(": Failed to get default value")),l)}return re({long:t.long,short:t.short,label:e,type:Q,input:i})}}}}}function Je(t){let e=`<${t.label??t.type.content.toUpperCase()}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:e}},registerAndMakeDecoder(n){let o=se(n,{...t,valued:!0});return{getAndDecodeValue(){let r=n.getOptionValues(o);if(r.length>1)throw new g(new u(new s(`--${t.long}`,b),new s(": Requires a single value, but got multiple")));let i=r[0];if(i===void 0)try{return t.default()}catch(l){throw new g(new u(new s(`--${t.long}`,b),new s(": Failed to get default value")),l)}return re({long:t.long,short:t.short,label:e,type:t.type,input:i})}}}}}function ze(t){let e=`<${t.label??t.type.content.toUpperCase()}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:e}},registerAndMakeDecoder(n){let o=se(n,{...t,valued:!0});return{getAndDecodeValue(){return n.getOptionValues(o).map(i=>re({long:t.long,short:t.short,label:e,type:t.type,input:i}))}}}}}function re(t){return g.tryWithContext(()=>t.type.decoder(t.input),()=>{let e=new u;return t.short&&(e.pushString(new s(`-${t.short}`,b)),e.pushString(new s(", "))),e.pushString(new s(`--${t.long}`,b)),e.pushString(new s(": ")),e.pushString(new s(t.label,S)),e.pushString(new s(": ")),e.pushString(new s(t.type.content,R)),e})}function se(t,e){let{long:n,short:o,aliases:r,valued:i}=e,l=n?[n]:[];r?.longs&&l.push(...r?.longs);let a=o?[o]:[];return r?.shorts&&a.push(...r?.shorts),t.registerOption({longs:l,shorts:a,valued:i})}function Xe(t){let e=`<${t.label??t.type.content.toUpperCase()}>`;return{generateUsage(){return{description:t.description,hint:t.hint,label:e}},consumeAndMakeDecoder(n){let o=n.consumePositional();if(o===void 0)throw new g(new u(new s(e,S),new s(": Is required, but was not provided")));return{decodeValue(){return ie(e,t.type,o)}}}}}function Ze(t){let e=`[${t.label??t.type.content.toUpperCase()}]`;return{generateUsage(){return{description:t.description,hint:t.hint,label:e}},consumeAndMakeDecoder(n){let o=n.consumePositional();return{decodeValue(){if(o===void 0)try{return t.default()}catch(r){throw new g(new u(new s(e,S),new s(": Failed to get default value")),r)}return ie(e,t.type,o)}}}}}function _e(t){let e=`[${t.label??t.type.content.toUpperCase()}]`;return{generateUsage(){return{description:t.description,hint:t.hint,label:`${e}...`+(t.endDelimiter?`["${t.endDelimiter}"]`:"")}},consumeAndMakeDecoder(n){let o=new Array;for(;;){let r=n.consumePositional();if(r===void 0||r===t.endDelimiter)break;o.push(r)}return{decodeValue(){return o.map(r=>ie(e,t.type,r))}}}}}function ie(t,e,n){return g.tryWithContext(()=>e.decoder(n),()=>new u(new s(t,S),new s(": "),new s(e.content,R)))}var Y,G,D,v,O,E,K,h,J,me,ae,ye,pe,I,ue,F=class{constructor(e){f(this,h);f(this,Y);f(this,G);f(this,D);f(this,v);f(this,O);f(this,E);f(this,K);w(this,Y,e),w(this,G,0),w(this,D,!1),w(this,v,new Map),w(this,O,new Map),w(this,E,new Map),w(this,K,new Map)}registerOption(e){let n=[...e.longs.map(o=>`--${o}`),...e.shorts.map(o=>`-${o}`)].join(", ");for(let o of e.longs){if(!m(this,h,ue).call(this,o))throw new Error(`Invalid option name: --${o}`);if(d(this,v).has(o))throw new Error(`Option already registered: --${o}`)}for(let o of e.shorts){if(!m(this,h,ue).call(this,o))throw new Error(`Invalid option name: -${o}`);if(d(this,O).has(o))throw new Error(`Option already registered: -${o}`);for(let r=0;r<o.length;r++){let i=o.slice(0,r);if(d(this,O).has(i))throw new Error(`Option -${o} overlap with shorter option: -${i}`)}for(let r of d(this,O).keys())if(r.startsWith(o))throw new Error(`Option -${o} overlap with longer option: -${r}`)}for(let o of e.longs)d(this,v).set(o,n);for(let o of e.shorts)d(this,O).set(o,n);return d(this,E).set(n,e.valued),d(this,K).set(n,new Array),n}getOptionValues(e){let n=d(this,K).get(e);if(n===void 0)throw new Error(`Unregistered option: ${e}`);return n}consumePositional(){for(;;){let e=m(this,h,J).call(this);if(e===null)return;if(m(this,h,me).call(this,e))return e}}};Y=new WeakMap,G=new WeakMap,D=new WeakMap,v=new WeakMap,O=new WeakMap,E=new WeakMap,K=new WeakMap,h=new WeakSet,J=function(){let e=d(this,Y)[d(this,G)];return e===void 0?null:(ge(this,G)._++,!d(this,D)&&e==="--"?(w(this,D,!0),m(this,h,J).call(this)):e)},me=function(e){if(d(this,D))return!0;if(e.startsWith("--")){let n=e.indexOf("=");return n===-1?m(this,h,ae).call(this,e.slice(2),null):m(this,h,ae).call(this,e.slice(2,n),e.slice(n+1)),!1}if(e.startsWith("-")){let n=1,o=2;for(;o<=e.length;){let r=m(this,h,ye).call(this,e.slice(n,o),e.slice(o));if(r===!0)return!1;r===!1&&(n=o),o++}throw new g(new u(new s(`-${e.slice(n)}`,b),new s(": Unexpected unknown option")))}return!0},ae=function(e,n){let o=`--${e}`,r=d(this,v).get(e);if(r!==void 0)return n!==null?m(this,h,I).call(this,r,n):d(this,E).get(r)?m(this,h,I).call(this,r,m(this,h,pe).call(this,o)):m(this,h,I).call(this,r,"true");throw new g(new u(new s(o,b),new s(": Unexpected unknown option")))},ye=function(e,n){let o=d(this,O).get(e);return o!==void 0?n.startsWith("=")?(m(this,h,I).call(this,o,n.slice(1)),!0):d(this,E).get(o)?(n===""?m(this,h,I).call(this,o,m(this,h,pe).call(this,`-${e}`)):m(this,h,I).call(this,o,n),!0):(m(this,h,I).call(this,o,"true"),n===""):null},pe=function(e){let n=m(this,h,J).call(this);if(n===null)throw new g(new u(new s(e,b),new s(": Requires a value, but got end of input")));if(d(this,D))throw new g(new u(new s(e,b),new s(": Requires a value before "),new s('"--"',x)));if(n.startsWith("-"))throw new g(new u(new s(e,b),new s(": Requires a value, but got: "),new s(`"${n}"`,x)));return n},I=function(e,n){this.getOptionValues(e).push(n)},ue=function(e){return e.length>0&&!e.includes("=")};function ce(t){let{cliName:e,commandUsage:n,typoSupport:o}=t,r=new Array,i=[et("Usage:").computeStyledString(o),U(e).computeStyledString(o)].concat(n.segments.map(a=>{if("positional"in a)return q(a.positional).computeStyledString(o);if("command"in a)return U(a.command).computeStyledString(o);throw new Error(`Unknown segment: ${JSON.stringify(a)}`)}));r.push(i.join(" ")),r.push("");let l=new u;l.pushString(tt(n.information.description)),n.information.hint&&(l.pushString(C(" ")),l.pushString(N(`(${n.information.hint})`))),r.push(l.computeStyledString(o));for(let a of n.information.details??[]){let c=new u;c.pushString(N(a)),r.push(c.computeStyledString(o))}if(n.positionals.length>0){r.push(""),r.push(z("Positionals:").computeStyledString(o));let a=new P;for(let c of n.positionals){let p=new Array;p.push(new u(C(" "))),p.push(new u(q(c.label))),p.push(...le(c)),a.pushRow(p)}r.push(...a.computeStyledGrid(o).map(c=>c.join("")))}if(n.subcommands.length>0){r.push(""),r.push(z("Subcommands:").computeStyledString(o));let a=new P;for(let c of n.subcommands){let p=new Array;p.push(new u(C(" "))),p.push(new u(U(c.name))),p.push(...le(c)),a.pushRow(p)}r.push(...a.computeStyledGrid(o).map(c=>c.join("")))}if(n.options.length>0){r.push(""),r.push(z("Options:").computeStyledString(o));let a=new P;for(let c of n.options){let p=new Array;p.push(new u(C(" "))),c.short?p.push(new u(U(`-${c.short}`),C(", "))):p.push(new u),c.label?p.push(new u(U(`--${c.long}`),C(" "),q(c.label))):p.push(new u(U(`--${c.long}`),N("[=no]"))),p.push(...le(c)),a.pushRow(p)}r.push(...a.computeStyledGrid(o).map(c=>c.join("")))}if(n.information.examples){r.push(""),r.push(z("Examples:").computeStyledString(o));for(let a of n.information.examples){let c=new u;c.pushString(C(" ")),c.pushString(N(`# ${a.explanation}`)),r.push(c.computeStyledString(o));let p=new u;p.pushString(C(" ")),p.pushString(U(e));for(let y of a.commandArgs)if(p.pushString(C(" ")),typeof y=="string")p.pushString(y);else if("positional"in y)p.pushString(q(y.positional));else if("subcommand"in y)p.pushString(U(y.subcommand));else if("option"in y){let T=y.option;"short"in T?p.pushString(U(`-${T.short}`)):p.pushString(U(`--${T.long}`)),T.value!==void 0&&(p.pushString(N("=")),p.pushString(q(T.value)))}r.push(p.computeStyledString(o))}}return r.push(""),r}function le(t){let e=[];return t.description&&(e.push(C(" ")),e.push(nt(t.description))),t.hint&&(e.push(C(" ")),e.push(N(`(${t.hint})`))),e.length>0?[new u(C(" "),...e)]:[]}function et(t){return new s(t,R)}function tt(t){return new s(t,ee)}function nt(t){return new s(t)}function z(t){return new s(t,_)}function N(t){return new s(t,te)}function U(t){return new s(t,b)}function q(t){return new s(t,S)}function C(t){return new s(t)}async function ot(t,e,n,o,r){let i=new F(e),l=r?.usageOnHelp??!0;l&&i.registerOption({shorts:[],longs:["help"],valued:!1});let a=r?.buildVersion;a&&i.registerOption({shorts:[],longs:["version"],valued:!1});let c=o.consumeAndMakeDecoder(i);for(;;)try{if(i.consumePositional()===void 0)break}catch{}let p=r?.onExit??process.exit,y=r?.useTtyColors===void 0?$.inferFromProcess():r.useTtyColors==="mock"?$.mock():r.useTtyColors?$.tty():$.none();if(l&&i.getOptionValues("--help").length>0)return console.log(fe(t,c,y)),p(0);if(a&&i.getOptionValues("--version").length>0)return console.log([t,a].join(" ")),p(0);try{let T=c.decodeAndMakeInterpreter();try{return await T.executeWithContext(n),p(0)}catch(xe){return we(r?.onError,xe,y),p(1)}}catch(T){return(r?.usageOnError??!0)&&console.error(fe(t,c,y)),we(r?.onError,T,y),p(1)}}function we(t,e,n){t!==void 0?t(e):console.error(n.computeStyledErrorMessage(e))}function fe(t,e,n){return ce({cliName:t,commandUsage:e.generateUsage(),typoSupport:n}).join(`
|
|
2
|
+
`)}0&&(module.exports={ReaderArgs,TypoError,TypoGrid,TypoString,TypoSupport,TypoText,command,commandChained,commandWithSubcommands,operation,optionFlag,optionRepeatable,optionSingleValue,positionalOptional,positionalRequired,positionalVariadics,runAndExit,typeBoolean,typeDate,typeInteger,typeList,typeMapped,typeNumber,typeOneOf,typeString,typeTuple,typeUrl,typoStyleConstants,typoStyleFailure,typoStyleLogic,typoStyleQuote,typoStyleRegularStrong,typoStyleRegularWeaker,typoStyleTitle,typoStyleUserInput,usageToStyledLines});
|
|
3
3
|
//# sourceMappingURL=index.js.map
|