cli-kiss 0.1.7 → 0.1.8

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 CHANGED
@@ -26,77 +26,25 @@ declare class ReaderArgs {
26
26
  consumePositional(): string | undefined;
27
27
  }
28
28
 
29
- type TypoColor = "darkBlack" | "darkRed" | "darkGreen" | "darkYellow" | "darkBlue" | "darkMagenta" | "darkCyan" | "darkWhite" | "brightBlack" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite";
30
- type TypoStyle = {
31
- fgColor?: TypoColor;
32
- bgColor?: TypoColor;
33
- dim?: boolean;
34
- bold?: boolean;
35
- italic?: boolean;
36
- underline?: boolean;
37
- strikethrough?: boolean;
38
- };
39
- declare const typoStyleFailure: TypoStyle;
40
- declare const typoStyleConstants: TypoStyle;
41
- declare const typoStyleUserInput: TypoStyle;
42
- declare const typoStyleQuote: TypoStyle;
43
- declare class TypoString {
44
- #private;
45
- constructor(value: string, typoStyle?: TypoStyle);
46
- getRawString(): string;
47
- computeStyledString(typoSupport: TypoSupport): string;
48
- }
49
- declare class TypoText {
50
- #private;
51
- constructor(...typoParts: Array<TypoText | TypoString | string>);
52
- pushString(typoString: TypoString): void;
53
- pushText(typoText: TypoText): void;
54
- computeStyledString(typoSupport: TypoSupport): string;
55
- computeRawString(): string;
56
- computeRawLength(): number;
57
- }
58
- declare class TypoGrid {
59
- #private;
60
- constructor();
61
- pushRow(cells: Array<TypoText>): void;
62
- computeStyledGrid(typoSupport: TypoSupport): Array<Array<string>>;
63
- }
64
- declare class TypoError extends Error {
65
- #private;
66
- constructor(currentTypoText: TypoText, source?: unknown);
67
- computeStyledString(typoSupport: TypoSupport): string;
68
- }
69
- declare class TypoSupport {
70
- #private;
71
- private constructor();
72
- static none(): TypoSupport;
73
- static tty(): TypoSupport;
74
- static mock(): TypoSupport;
75
- static inferFromProcess(): TypoSupport;
76
- computeStyledString(value: string, typoStyle: TypoStyle): string;
77
- computeStyledErrorMessage(error: unknown): string;
78
- }
79
-
80
29
  type Type<Value> = {
81
- label: Uppercase<string>;
30
+ content: string;
82
31
  decoder(value: string): Value;
83
32
  };
84
33
  declare const typeBoolean: Type<boolean>;
85
34
  declare const typeDate: Type<Date>;
35
+ declare const typeNumber: Type<number>;
36
+ declare const typeInteger: Type<bigint>;
86
37
  declare const typeUrl: Type<URL>;
87
38
  declare const typeString: Type<string>;
88
- declare const typeNumber: Type<number>;
89
- declare const typeBigInt: Type<bigint>;
90
- declare function typeMapped<Before, After>(before: Type<Before>, after: {
91
- label: Uppercase<string>;
39
+ declare function typeConverted<Before, After>(before: Type<Before>, after: {
40
+ content: string;
92
41
  decoder: (value: Before) => After;
93
42
  }): Type<After>;
94
- declare function typeOneOf<Value>(type: Type<Value>, values: Array<Value>): Type<Value>;
43
+ declare function typeOneOf(content: string, values: Array<string>): Type<string>;
95
44
  declare function typeTuple<const Elements extends Array<any>>(elementTypes: {
96
45
  [K in keyof Elements]: Type<Elements[K]>;
97
46
  }, separator?: string): Type<Elements>;
98
47
  declare function typeList<Value>(elementType: Type<Value>, separator?: string): Type<Array<Value>>;
99
- declare function typeDecode<Value>(type: Type<Value>, value: string, context: () => TypoText): Value;
100
48
 
101
49
  type Option<Value> = {
102
50
  generateUsage(): OptionUsage;
@@ -247,7 +195,7 @@ declare function commandWithSubcommands<Context, Payload, Result>(information: C
247
195
  declare function commandChained<Context, Payload, Result>(information: CommandInformation, operation: OperationDescriptor<Context, Payload>, nextCommand: CommandDescriptor<Payload, Result>): CommandDescriptor<Context, Result>;
248
196
 
249
197
  declare function runAsCliAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command: CommandDescriptor<Context, void>, options?: {
250
- useColors?: boolean | undefined;
198
+ useTtyColors?: boolean | undefined | "mock";
251
199
  usageOnHelp?: boolean | undefined;
252
200
  usageOnError?: boolean | undefined;
253
201
  buildVersion?: string | undefined;
@@ -257,10 +205,66 @@ declare function runAsCliAndExit<Context>(cliName: Lowercase<string>, cliArgs: R
257
205
  onExit?: ((code: number) => never) | undefined;
258
206
  }): Promise<never>;
259
207
 
208
+ type TypoColor = "darkBlack" | "darkRed" | "darkGreen" | "darkYellow" | "darkBlue" | "darkMagenta" | "darkCyan" | "darkWhite" | "brightBlack" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite";
209
+ type TypoStyle = {
210
+ fgColor?: TypoColor;
211
+ bgColor?: TypoColor;
212
+ dim?: boolean;
213
+ bold?: boolean;
214
+ italic?: boolean;
215
+ underline?: boolean;
216
+ strikethrough?: boolean;
217
+ };
218
+ declare const typoStyleTitle: TypoStyle;
219
+ declare const typoStyleLogic: TypoStyle;
220
+ declare const typoStyleQuote: TypoStyle;
221
+ declare const typoStyleFailure: TypoStyle;
222
+ declare const typoStyleConstants: TypoStyle;
223
+ declare const typoStyleUserInput: TypoStyle;
224
+ declare const typoStyleRegularStrong: TypoStyle;
225
+ declare const typoStyleRegularWeaker: TypoStyle;
226
+ declare class TypoString {
227
+ #private;
228
+ constructor(value: string, typoStyle?: TypoStyle);
229
+ getRawString(): string;
230
+ computeStyledString(typoSupport: TypoSupport): string;
231
+ }
232
+ declare class TypoText {
233
+ #private;
234
+ constructor(...typoParts: Array<TypoText | TypoString | string>);
235
+ pushString(typoString: TypoString): void;
236
+ pushText(typoText: TypoText): void;
237
+ computeStyledString(typoSupport: TypoSupport): string;
238
+ computeRawString(): string;
239
+ computeRawLength(): number;
240
+ }
241
+ declare class TypoGrid {
242
+ #private;
243
+ constructor();
244
+ pushRow(cells: Array<TypoText>): void;
245
+ computeStyledGrid(typoSupport: TypoSupport): Array<Array<string>>;
246
+ }
247
+ declare class TypoError extends Error {
248
+ #private;
249
+ constructor(currentTypoText: TypoText, source?: unknown);
250
+ computeStyledString(typoSupport: TypoSupport): string;
251
+ static tryWithContext<Value>(thrower: () => Value, context: () => TypoText): Value;
252
+ }
253
+ declare class TypoSupport {
254
+ #private;
255
+ private constructor();
256
+ static none(): TypoSupport;
257
+ static tty(): TypoSupport;
258
+ static mock(): TypoSupport;
259
+ static inferFromProcess(): TypoSupport;
260
+ computeStyledString(value: string, typoStyle: TypoStyle): string;
261
+ computeStyledErrorMessage(error: unknown): string;
262
+ }
263
+
260
264
  declare function usageToStyledLines(params: {
261
265
  cliName: Lowercase<string>;
262
266
  commandUsage: CommandUsage;
263
267
  typoSupport: TypoSupport;
264
268
  }): string[];
265
269
 
266
- export { type CommandDescriptor, type CommandFactory, type CommandInformation, type CommandInstance, type CommandUsage, type CommandUsageBreadcrumb, type CommandUsageSubcommand, type OperationDescriptor, type OperationFactory, type OperationInstance, type OperationUsage, type Option, type OptionGetter, type OptionUsage, type Positional, type PositionalUsage, ReaderArgs, type ReaderOptionKey, type ReaderOptions, type ReaderPositionals, type Type, type TypoColor, TypoError, TypoGrid, TypoString, type TypoStyle, TypoSupport, TypoText, command, commandChained, commandWithSubcommands, operation, optionFlag, optionRepeatable, optionSingleValue, positionalOptional, positionalRequired, positionalVariadics, runAsCliAndExit, typeBigInt, typeBoolean, typeDate, typeDecode, typeList, typeMapped, typeNumber, typeOneOf, typeString, typeTuple, typeUrl, typoStyleConstants, typoStyleFailure, typoStyleQuote, typoStyleUserInput, usageToStyledLines };
270
+ export { type CommandDescriptor, type CommandFactory, type CommandInformation, type CommandInstance, type CommandUsage, type CommandUsageBreadcrumb, type CommandUsageSubcommand, type OperationDescriptor, type OperationFactory, type OperationInstance, type OperationUsage, type Option, type OptionGetter, type OptionUsage, type Positional, type PositionalUsage, ReaderArgs, type ReaderOptionKey, type ReaderOptions, type ReaderPositionals, type Type, type TypoColor, TypoError, TypoGrid, TypoString, type TypoStyle, TypoSupport, TypoText, command, commandChained, commandWithSubcommands, operation, optionFlag, optionRepeatable, optionSingleValue, positionalOptional, positionalRequired, positionalVariadics, runAsCliAndExit, typeBoolean, typeConverted, typeDate, typeInteger, typeList, typeNumber, typeOneOf, typeString, typeTuple, typeUrl, typoStyleConstants, typoStyleFailure, typoStyleLogic, typoStyleQuote, typoStyleRegularStrong, typoStyleRegularWeaker, typoStyleTitle, typoStyleUserInput, usageToStyledLines };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var z=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var ht=Object.prototype.hasOwnProperty;var pt=t=>{throw TypeError(t)};var wt=(t,e)=>{for(var n in e)z(t,n,{get:e[n],enumerable:!0})},ft=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of yt(e))!ht.call(t,o)&&o!==n&&z(t,o,{get:()=>e[o],enumerable:!(r=mt(e,o))||r.enumerable});return t};var bt=t=>ft(z({},"__esModule",{value:!0}),t);var X=(t,e,n)=>e.has(t)||pt("Cannot "+n);var c=(t,e,n)=>(X(t,e,"read from private field"),n?n.call(t):e.get(t)),b=(t,e,n)=>e.has(t)?pt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),h=(t,e,n,r)=>(X(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),w=(t,e,n)=>(X(t,e,"access private method"),n);var lt=(t,e,n,r)=>({set _(o){h(t,e,o,n)},get _(){return c(t,e,r)}});var _t={};wt(_t,{ReaderArgs:()=>j,TypoError:()=>d,TypoGrid:()=>P,TypoString:()=>s,TypoSupport:()=>V,TypoText:()=>p,command:()=>kt,commandChained:()=>At,commandWithSubcommands:()=>$t,operation:()=>Vt,optionFlag:()=>Kt,optionRepeatable:()=>jt,optionSingleValue:()=>Nt,positionalOptional:()=>qt,positionalRequired:()=>Yt,positionalVariadics:()=>Ht,runAsCliAndExit:()=>Xt,typeBigInt:()=>Lt,typeBoolean:()=>q,typeDate:()=>Et,typeDecode:()=>C,typeList:()=>Wt,typeMapped:()=>Ft,typeNumber:()=>Gt,typeOneOf:()=>Dt,typeString:()=>Bt,typeTuple:()=>Mt,typeUrl:()=>vt,typoStyleConstants:()=>f,typoStyleFailure:()=>ut,typoStyleQuote:()=>x,typoStyleUserInput:()=>y,usageToStyledLines:()=>it});module.exports=bt(_t);var ut={fgColor:"darkRed",bold:!0},f={fgColor:"darkCyan",bold:!0},y={fgColor:"darkBlue",bold:!0},x={fgColor:"darkYellow",bold:!0},G,N,s=class{constructor(e,n={}){b(this,G);b(this,N);h(this,G,e),h(this,N,n)}getRawString(){return c(this,G)}computeStyledString(e){return e.computeStyledString(c(this,G),c(this,N))}};G=new WeakMap,N=new WeakMap;var T,Z=class Z{constructor(...e){b(this,T);h(this,T,[]);for(let n of e)n instanceof Z?this.pushText(n):n instanceof s?this.pushString(n):typeof n=="string"&&this.pushString(new s(n))}pushString(e){c(this,T).push(e)}pushText(e){for(let n of c(e,T))c(this,T).push(n)}computeStyledString(e){return c(this,T).map(n=>n.computeStyledString(e)).join("")}computeRawString(){return c(this,T).map(e=>e.getRawString()).join("")}computeRawLength(){let e=0;for(let n of c(this,T))e+=n.getRawString().length;return e}};T=new WeakMap;var p=Z,A,P=class{constructor(){b(this,A);h(this,A,[])}pushRow(e){c(this,A).push(e)}computeStyledGrid(e){let n=new Array,r=new Array;for(let o of c(this,A))for(let i=0;i<o.length;i++){let l=o[i].computeRawLength();(n[i]===void 0||l>n[i])&&(n[i]=l)}for(let o of c(this,A)){let i=new Array;for(let a=0;a<o.length;a++){let l=o[a],u=l.computeStyledString(e);if(i.push(u),a<o.length-1){let g=l.computeRawLength(),U=" ".repeat(n[a]-g);i.push(U)}}r.push(i)}return r}};A=new WeakMap;var L,_=class _ extends Error{constructor(n,r){let o=new p;o.pushText(n),r instanceof _?(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());b(this,L);h(this,L,o)}computeStyledString(n){return c(this,L).computeStyledString(n)}};L=new WeakMap;var d=_,I,S=class S{constructor(e){b(this,I);h(this,I,e)}static none(){return new S("none")}static tty(){return new S("tty")}static mock(){return new S("mock")}static inferFromProcess(){if(!process)return S.none();if(process.env){if(process.env.FORCE_COLOR==="0")return S.none();if(process.env.FORCE_COLOR)return S.tty();if("NO_COLOR"in process.env)return S.none()}return!process.stdout||!process.stdout.isTTY?S.none():S.tty()}computeStyledString(e,n){if(c(this,I)==="none")return e;if(c(this,I)==="tty"){let r=n.fgColor?Rt[n.fgColor]:"",o=n.bgColor?It[n.bgColor]:"",i=n.bold?Ct:"",a=n.dim?St:"",l=n.italic?Tt:"",u=n.underline?Ut:"",g=n.strikethrough?Ot:"";return`${r}${o}${i}${a}${l}${u}${g}${e}${xt}`}if(c(this,I)==="mock"){let r=n.fgColor?`{${e}}@${n.fgColor}`:e,o=n.bgColor?`{${r}}#${n.bgColor}`:r,i=n.bold?`{${o}}+`:o,a=n.dim?`{${i}}-`:i,l=n.italic?`{${a}}*`:a,u=n.underline?`{${l}}_`:l;return n.strikethrough?`{${u}}~`:u}throw new Error(`Unknown TypoSupport kind: ${c(this,I)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",ut),e instanceof d?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};I=new WeakMap;var V=S,xt="\x1B[0m",Ct="\x1B[1m",St="\x1B[2m",Tt="\x1B[3m",Ut="\x1B[4m",Ot="\x1B[9m",Rt={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 kt(t,e){return{getInformation(){return t},createFactory(n){function r(){let o=e.generateUsage();return{breadcrumbs:o.positionals.map(i=>E(i.label)),information:t,positionals:o.positionals,subcommands:[],options:o.options}}try{let o=e.createFactory(n),i=n.consumePositional();if(i!==void 0)throw Error(`Unexpected argument: "${i}"`);return{generateUsage:r,createInstance(){let a=o.createInstance();return{async executeWithContext(l){return await a.executeWithContext(l)}}}}}catch(o){return{generateUsage:r,createInstance(){throw o}}}}}}function $t(t,e,n){return{getInformation(){return t},createFactory(r){try{let o=e.createFactory(r),i=r.consumePositional();if(i===void 0)throw new d(new p(new s("<SUBCOMMAND>",y),new s(": Is required, but was not provided")));let a=n[i];if(a===void 0)throw new d(new p(new s("<SUBCOMMAND>",y),new s(": Invalid value: "),new s(`"${i}"`,x)));let l=a.createFactory(r);return{generateUsage(){let u=e.generateUsage(),g=l.generateUsage();return{breadcrumbs:u.positionals.map(U=>E(U.label)).concat([Pt(i)]).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=l.createInstance();return{async executeWithContext(U){return await g.executeWithContext(await u.executeWithContext(U))}}}}}catch(o){return{generateUsage(){let i=e.generateUsage();return{breadcrumbs:i.positionals.map(a=>E(a.label)).concat([E("<SUBCOMMAND>")]),information:t,positionals:i.positionals,subcommands:Object.entries(n).map(a=>{let l=a[1].getInformation();return{name:a[0],description:l.description,hint:l.hint}}),options:i.options}},createInstance(){throw o}}}}}}function At(t,e,n){return{getInformation(){return t},createFactory(r){try{let o=e.createFactory(r),i=n.createFactory(r);return{generateUsage(){let a=e.generateUsage(),l=i.generateUsage();return{breadcrumbs:a.positionals.map(u=>E(u.label)).concat(l.breadcrumbs),information:l.information,positionals:a.positionals.concat(l.positionals),subcommands:l.subcommands,options:a.options.concat(l.options)}},createInstance(){let a=o.createInstance(),l=i.createInstance();return{async executeWithContext(u){return await l.executeWithContext(await a.executeWithContext(u))}}}}}catch(o){return{generateUsage(){let i=e.generateUsage();return{breadcrumbs:i.positionals.map(a=>E(a.label)).concat([E("[REST]...")]),information:t,positionals:i.positionals,subcommands:[],options:i.options}},createInstance(){throw o}}}}}}function E(t){return{positional:t}}function Pt(t){return{command:t}}function Vt(t,e){return{generateUsage(){let n=new Array;for(let o in t.options){let i=t.options[o];i&&n.push(i.generateUsage())}let r=new Array;for(let o of t.positionals)r.push(o.generateUsage());return{options:n,positionals:r}},createFactory(n){let r={};for(let i in t.options){let a=t.options[i];r[i]=a.createGetter(n)}let o=[];for(let i of t.positionals)o.push(i.consumePositionals(n));return{createInstance(){let i={};for(let a in r)i[a]=r[a].getValue();return{executeWithContext(a){return e(a,{options:i,positionals:o})}}}}}}}var q={label:"BOOLEAN",decoder(t){let e=t.toLowerCase();if(e==="true"||e==="yes")return!0;if(e==="false"||e==="no")return!1;throw new d(new p(new s("Invalid boolean: "),new s(`"${t}"`,x)))}},Et={label:"DATE",decoder(t){let e=Date.parse(t);if(isNaN(e))throw new d(new p(new s("Invalid date (ISO_8601): "),new s(`"${t}"`,x)));return new Date(e)}},vt={label:"URL",decoder(t){try{return new URL(t)}catch{throw new d(new p(new s("Invalid URL: "),new s(`"${t}"`,x)))}}},Bt={label:"STRING",decoder(t){return t}},Gt={label:"NUMBER",decoder(t){try{let e=Number(t);if(isNaN(e))throw new Error;return e}catch{throw new d(new p(new s("Invalid number: "),new s(`"${t}"`,x)))}}},Lt={label:"BIGINT",decoder(t){try{return BigInt(t)}catch{throw new d(new p(new s("Invalid integer: "),new s(`"${t}"`,x)))}}};function Ft(t,e){return{label:e.label,decoder:n=>e.decoder(C(t,n,()=>new p(new s(t.label,y))))}}function Dt(t,e){let n=new Set(e);return{label:t.label,decoder(r){let o=C(t,r,()=>new p(new s(t.label,y)));if(n.has(o))return o;let i=[];for(let a of e){if(i.length>=5){i.push(new s("..."));break}i.length>0&&i.push(new s(" | ")),i.push(new s(`"${a}"`,x))}throw new d(new p(new s("Invalid value: "),new s(`"${r}"`,x),new s(" (expected one of: "),...i,new s(")")))}}}function Mt(t,e=","){return{label:t.map(n=>n.label).join(e),decoder(n){let r=n.split(e,t.length);if(r.length!==t.length)throw new d(new p(new s("Invalid tuple: "),new s(`"${n}"`,x),new s(` (expected ${t.length} parts)`)));return r.map((o,i)=>C(t[i],o,()=>new p(new s(t[i].label,y),new s(`@${i}`))))}}}function Wt(t,e=","){return{label:`${t.label}[${e}${t.label}]...`,decoder(n){return n.split(e).map((r,o)=>C(t,r,()=>new p(new s(t.label,y),new s(`@${o}`))))}}}function C(t,e,n){try{return t.decoder(e)}catch(r){throw new d(n(),r)}}function Kt(t){let e=`<${q.label}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:void 0}},createGetter(n){let r=tt(n,{...t,valued:!1});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new d(new p(new s(`--${t.long}`,f),new s(": Must not be set multiple times")));let i=o[0];if(i===void 0)try{return t.default?t.default():!1}catch(a){throw new d(new p(new s(`--${t.long}`,f),new s(": Failed to get default value")),a)}return C(q,i,()=>new p(new s(`--${t.long}`,f),new s(": "),new s(e,y)))}}}}}function Nt(t){let e=`<${t.label??t.type.label}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:e}},createGetter(n){let r=tt(n,{...t,valued:!0});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new d(new p(new s(`--${t.long}`,f),new s(": Requires a single value, but got multiple")));let i=o[0];if(i===void 0)try{return t.default()}catch(a){throw new d(new p(new s(`--${t.long}`,f),new s(": Failed to get default value")),a)}return C(t.type,i,()=>new p(new s(`--${t.long}`,f),new s(": "),new s(e,y)))}}}}}function jt(t){let e=`<${t.label??t.type.label}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:e}},createGetter(n){let r=tt(n,{...t,valued:!0});return{getValue(){return n.getOptionValues(r).map(o=>C(t.type,o,()=>new p(new s(`--${t.long}`,f),new s(": "),new s(e,y))))}}}}}function tt(t,e){let{long:n,short:r,aliases:o,valued:i}=e,a=n?[n]:[];o?.longs&&a.push(...o?.longs);let l=r?[r]:[];return o?.shorts&&l.push(...o?.shorts),t.registerOption({longs:a,shorts:l,valued:i})}function Yt(t){let e=`<${t.label??t.type.label}>`;return{generateUsage(){return{description:t.description,hint:t.hint,label:e}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)throw new d(new p(new s(e,y),new s(": Is required, but was not provided")));return C(t.type,r,()=>new p(new s(e,y)))}}}function qt(t){let e=`[${t.label??t.type.label}]`;return{generateUsage(){return{description:t.description,hint:t.hint,label:e}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)try{return t.default()}catch(o){throw new d(new p(new s(e,y),new s(": Failed to get default value")),o)}return C(t.type,r,()=>new p(new s(e,y)))}}}function Ht(t){let e=`[${t.label??t.type.label}]`;return{generateUsage(){return{description:t.description,hint:t.hint,label:`${e}...`+(t.endDelimiter?`["${t.endDelimiter}"]`:"")}},consumePositionals(n){let r=[];for(;;){let o=n.consumePositional();if(o===void 0||o===t.endDelimiter)break;r.push(C(t.type,o,()=>new p(new s(e,y))))}return r}}}var Y,F,$,v,O,B,D,m,H,ct,et,gt,nt,k,j=class{constructor(e){b(this,m);b(this,Y);b(this,F);b(this,$);b(this,v);b(this,O);b(this,B);b(this,D);h(this,Y,e),h(this,F,0),h(this,$,!1),h(this,v,new Map),h(this,O,new Map),h(this,B,new Map),h(this,D,new Map)}registerOption(e){let n=[...e.longs.map(r=>`--${r}`),...e.shorts.map(r=>`-${r}`)].join(", ");for(let r of e.longs){if(c(this,v).has(r))throw new Error(`Option already registered: --${r}`);c(this,v).set(r,n)}for(let r of e.shorts){if(c(this,O).has(r))throw new Error(`Option already registered: -${r}`);for(let o=0;o<r.length;o++){let i=r.slice(0,o);if(c(this,O).has(i))throw new Error(`Option -${r} overlap with shorter option: -${i}`)}for(let o of c(this,O).keys())if(o.startsWith(r))throw new Error(`Option -${r} overlap with longer option: -${o}`);c(this,O).set(r,n)}return c(this,B).set(n,e.valued),c(this,D).set(n,new Array),n}getOptionValues(e){let n=c(this,D).get(e);if(n===void 0)throw new Error(`Unregistered option: ${e}`);return n}consumePositional(){for(;;){let e=w(this,m,H).call(this);if(e===null)return;if(w(this,m,ct).call(this,e))return e}}};Y=new WeakMap,F=new WeakMap,$=new WeakMap,v=new WeakMap,O=new WeakMap,B=new WeakMap,D=new WeakMap,m=new WeakSet,H=function(){let e=c(this,Y)[c(this,F)];return e===void 0?null:(lt(this,F)._++,!c(this,$)&&e==="--"?(h(this,$,!0),w(this,m,H).call(this)):e)},ct=function(e){if(c(this,$))return!0;if(e.startsWith("--")){let n=e.indexOf("=");return n===-1?w(this,m,et).call(this,e.slice(2),null):w(this,m,et).call(this,e.slice(2,n),e.slice(n+1)),!1}if(e.startsWith("-")){let n=1,r=2;for(;r<=e.length;){let o=w(this,m,gt).call(this,e.slice(n,r),e.slice(r));if(o===!0)return!1;o===!1&&(n=r),r++}throw new d(new p(new s(`-${e.slice(n)}`,f),new s(": Unexpected unknown option")))}return!0},et=function(e,n){let r=`--${e}`,o=c(this,v).get(e);if(o!==void 0)return n!==null?w(this,m,k).call(this,o,n):c(this,B).get(o)?w(this,m,k).call(this,o,w(this,m,nt).call(this,r)):w(this,m,k).call(this,o,"true");throw new d(new p(new s(r,f),new s(": Unexpected unknown option")))},gt=function(e,n){let r=c(this,O).get(e);return r!==void 0?n.startsWith("=")?(w(this,m,k).call(this,r,n.slice(1)),!0):c(this,B).get(r)?(n===""?w(this,m,k).call(this,r,w(this,m,nt).call(this,`-${e}`)):w(this,m,k).call(this,r,n),!0):(w(this,m,k).call(this,r,"true"),n===""):null},nt=function(e){let n=w(this,m,H).call(this);if(n===null)throw new d(new p(new s(e,f),new s(": Requires a value, but got end of input")));if(c(this,$))throw new d(new p(new s(e,f),new s(": Requires a value before "),new s('"--"',x)));if(n.startsWith("-"))throw new d(new p(new s(e,f),new s(": Requires a value, but got: "),new s(`"${n}"`,x)));return n},k=function(e,n){this.getOptionValues(e).push(n)};function it(t){let{cliName:e,commandUsage:n,typoSupport:r}=t,o=new Array,i=[Qt("Usage:").computeStyledString(r),M(e).computeStyledString(r)].concat(n.breadcrumbs.map(l=>{if("positional"in l)return st(l.positional).computeStyledString(r);if("command"in l)return M(l.command).computeStyledString(r);throw new Error(`Unknown breadcrumb: ${JSON.stringify(l)}`)}));o.push(i.join(" ")),o.push("");let a=new p;a.pushString(Jt(n.information.description)),n.information.hint&&(a.pushString(R(" ")),a.pushString(Q(`(${n.information.hint})`))),o.push(a.computeStyledString(r));for(let l of n.information.details??[]){let u=new p;u.pushString(Q(l)),o.push(u.computeStyledString(r))}if(n.positionals.length>0){o.push(""),o.push(rt("Positionals:").computeStyledString(r));let l=new P;for(let u of n.positionals){let g=new Array;g.push(new p(R(" "))),g.push(new p(st(u.label))),g.push(...ot(u)),l.pushRow(g)}o.push(...l.computeStyledGrid(r).map(u=>u.join("")))}if(n.subcommands.length>0){o.push(""),o.push(rt("Subcommands:").computeStyledString(r));let l=new P;for(let u of n.subcommands){let g=new Array;g.push(new p(R(" "))),g.push(new p(M(u.name))),g.push(...ot(u)),l.pushRow(g)}o.push(...l.computeStyledGrid(r).map(u=>u.join("")))}if(n.options.length>0){o.push(""),o.push(rt("Options:").computeStyledString(r));let l=new P;for(let u of n.options){let g=new Array;g.push(new p(R(" "))),u.short?g.push(new p(M(`-${u.short}`),R(", "))):g.push(new p),u.label?g.push(new p(M(`--${u.long}`),R(" "),st(u.label))):g.push(new p(M(`--${u.long}`),Q("[=no]"))),g.push(...ot(u)),l.pushRow(g)}o.push(...l.computeStyledGrid(r).map(u=>u.join("")))}return o.push(""),o}function ot(t){let e=[];return t.description&&(e.push(R(" ")),e.push(zt(t.description))),t.hint&&(e.push(R(" ")),e.push(Q(`(${t.hint})`))),e.length>0?[new p(R(" "),...e)]:[]}function Qt(t){return new s(t,{fgColor:"darkMagenta",bold:!0})}function Jt(t){return new s(t,{bold:!0})}function zt(t){return new s(t)}function rt(t){return new s(t,{fgColor:"darkGreen",bold:!0})}function Q(t){return new s(t,{italic:!0,dim:!0})}function M(t){return new s(t,f)}function st(t){return new s(t,y)}function R(t){return new s(t)}async function Xt(t,e,n,r,o){let i=new j(e),a=o?.usageOnHelp??!0;a&&i.registerOption({shorts:[],longs:["help"],valued:!1});let l=o?.buildVersion;l&&i.registerOption({shorts:[],longs:["version"],valued:!1});let u=Zt(o?.useColors),g=o?.onLogStdOut??console.log,U=o?.onLogStdErr??console.error,W=o?.onExit??process.exit,J=r.createFactory(i);for(;;)try{if(i.consumePositional()===void 0)break}catch{}if(a&&i.getOptionValues("--help").length>0)return g(dt(t,J,u)),W(0);if(l&&i.getOptionValues("--version").length>0)return g([t,l].join(" ")),W(0);try{let K=J.createInstance();try{return await K.executeWithContext(n),W(0)}catch(at){return o?.onExecutionError?o.onExecutionError(at):U(u.computeStyledErrorMessage(at)),W(1)}}catch(K){return(o?.usageOnError??!0)&&U(dt(t,J,u)),U(u.computeStyledErrorMessage(K)),W(1)}}function dt(t,e,n){return it({cliName:t,commandUsage:e.generateUsage(),typoSupport:n}).join(`
2
- `)}function Zt(t){return t===void 0?V.inferFromProcess():t?V.tty():V.none()}0&&(module.exports={ReaderArgs,TypoError,TypoGrid,TypoString,TypoSupport,TypoText,command,commandChained,commandWithSubcommands,operation,optionFlag,optionRepeatable,optionSingleValue,positionalOptional,positionalRequired,positionalVariadics,runAsCliAndExit,typeBigInt,typeBoolean,typeDate,typeDecode,typeList,typeMapped,typeNumber,typeOneOf,typeString,typeTuple,typeUrl,typoStyleConstants,typoStyleFailure,typoStyleQuote,typoStyleUserInput,usageToStyledLines});
1
+ "use strict";var X=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var bt=Object.getOwnPropertyNames;var Ct=Object.prototype.hasOwnProperty;var dt=e=>{throw TypeError(e)};var St=(e,t)=>{for(var n in t)X(e,n,{get:t[n],enumerable:!0})},Tt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of bt(t))!Ct.call(e,o)&&o!==n&&X(e,o,{get:()=>t[o],enumerable:!(r=xt(t,o))||r.enumerable});return e};var Ut=e=>Tt(X({},"__esModule",{value:!0}),e);var Z=(e,t,n)=>t.has(e)||dt("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)?dt("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 yt=(e,t,n,r)=>({set _(o){m(e,t,o,n)},get _(){return c(e,t,r)}});var oe={};St(oe,{ReaderArgs:()=>j,TypoError:()=>g,TypoGrid:()=>P,TypoString:()=>s,TypoSupport:()=>I,TypoText:()=>u,command:()=>Et,commandChained:()=>Lt,commandWithSubcommands:()=>vt,operation:()=>Gt,optionFlag:()=>Ht,optionRepeatable:()=>Jt,optionSingleValue:()=>Qt,positionalOptional:()=>Xt,positionalRequired:()=>zt,positionalVariadics:()=>Zt,runAsCliAndExit:()=>ne,typeBoolean:()=>H,typeConverted:()=>Nt,typeDate:()=>Bt,typeInteger:()=>Dt,typeList:()=>qt,typeNumber:()=>Wt,typeOneOf:()=>jt,typeString:()=>Kt,typeTuple:()=>Yt,typeUrl:()=>Mt,typoStyleConstants:()=>x,typoStyleFailure:()=>mt,typoStyleLogic:()=>S,typoStyleQuote:()=>f,typoStyleRegularStrong:()=>tt,typoStyleRegularWeaker:()=>et,typoStyleTitle:()=>_,typoStyleUserInput:()=>b,usageToStyledLines:()=>ct});module.exports=Ut(oe);var _={fgColor:"darkGreen",bold:!0},S={fgColor:"darkMagenta",bold:!0},f={fgColor:"darkYellow",bold:!0},mt={fgColor:"darkRed",bold:!0},x={fgColor:"darkCyan",bold:!0},b={fgColor:"darkBlue",bold:!0},tt={bold:!0},et={italic:!0,dim:!0},F,N,s=class{constructor(t,n={}){w(this,F);w(this,N);m(this,F,t),m(this,N,n)}getRawString(){return c(this,F)}computeStyledString(t){return t.computeStyledString(c(this,F),c(this,N))}};F=new WeakMap,N=new WeakMap;var T,nt=class nt{constructor(...t){w(this,T);m(this,T,[]);for(let n of t)n instanceof nt?this.pushText(n):n instanceof s?this.pushString(n):typeof n=="string"&&this.pushString(new s(n))}pushString(t){c(this,T).push(t)}pushText(t){for(let n of c(t,T))c(this,T).push(n)}computeStyledString(t){return c(this,T).map(n=>n.computeStyledString(t)).join("")}computeRawString(){return c(this,T).map(t=>t.getRawString()).join("")}computeRawLength(){let t=0;for(let n of c(this,T))t+=n.getRawString().length;return t}};T=new WeakMap;var u=nt,V,P=class{constructor(){w(this,V);m(this,V,[])}pushRow(t){c(this,V).push(t)}computeStyledGrid(t){let n=new Array,r=new Array;for(let o of c(this,V))for(let i=0;i<o.length;i++){let p=o[i].computeRawLength();(n[i]===void 0||p>n[i])&&(n[i]=p)}for(let o of c(this,V)){let i=new Array;for(let a=0;a<o.length;a++){let p=o[a],l=p.computeStyledString(t);if(i.push(l),a<o.length-1){let d=p.computeRawLength(),U=" ".repeat(n[a]-d);i.push(U)}}r.push(i)}return r}};V=new WeakMap;var G,q=class q extends Error{constructor(n,r){let o=new u;o.pushText(n),r instanceof q?(o.pushString(new s(": ")),o.pushText(c(r,G))):r instanceof Error?o.pushString(new s(`: ${r.message}`)):r!==void 0&&o.pushString(new s(`: ${String(r)}`));super(o.computeRawString());w(this,G);m(this,G,o)}computeStyledString(n){return c(this,G).computeStyledString(n)}static tryWithContext(n,r){try{return n()}catch(o){throw new q(r(),o)}}};G=new WeakMap;var g=q,k,C=class C{constructor(t){w(this,k);m(this,k,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,k)==="none")return t;if(c(this,k)==="tty"){let r=n.fgColor?Vt[n.fgColor]:"",o=n.bgColor?Pt[n.bgColor]:"",i=n.bold?Rt:"",a=n.dim?kt:"",p=n.italic?It:"",l=n.underline?$t:"",d=n.strikethrough?At:"";return`${r}${o}${i}${a}${p}${l}${d}${t}${Ot}`}if(c(this,k)==="mock"){let r=n.fgColor?`{${t}}@${n.fgColor}`:t,o=n.bgColor?`{${r}}#${n.bgColor}`:r,i=n.bold?`{${o}}+`:o,a=n.dim?`{${i}}-`:i,p=n.italic?`{${a}}*`:a,l=n.underline?`{${p}}_`:p;return n.strikethrough?`{${l}}~`:l}throw new Error(`Unknown TypoSupport kind: ${c(this,k)}`)}computeStyledErrorMessage(t){return[this.computeStyledString("Error:",mt),t instanceof g?t.computeStyledString(this):t instanceof Error?t.message:String(t)].join(" ")}};k=new WeakMap;var I=C,Ot="\x1B[0m",Rt="\x1B[1m",kt="\x1B[2m",It="\x1B[3m",$t="\x1B[4m",At="\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"},Pt={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 Et(e,t){return{getInformation(){return e},createFactory(n){function r(){let o=t.generateUsage();return{breadcrumbs:o.positionals.map(i=>E(i.label)),information:e,positionals:o.positionals,subcommands:[],options:o.options}}try{let o=t.createFactory(n),i=n.consumePositional();if(i!==void 0)throw new g(new u(new s("Unexpected argument: "),new s(`"${i}"`,f)));return{generateUsage:r,createInstance(){let a=o.createInstance();return{async executeWithContext(p){return await a.executeWithContext(p)}}}}}catch(o){return{generateUsage:r,createInstance(){throw o}}}}}}function vt(e,t,n){return{getInformation(){return e},createFactory(r){try{let o=t.createFactory(r),i=r.consumePositional();if(i===void 0)throw new g(new u(new s("<SUBCOMMAND>",b),new s(": Is required, but was not provided")));let a=n[i];if(a===void 0)throw new g(new u(new s("<SUBCOMMAND>",b),new s(": Invalid value: "),new s(`"${i}"`,f)));let p=a.createFactory(r);return{generateUsage(){let l=t.generateUsage(),d=p.generateUsage();return{breadcrumbs:l.positionals.map(U=>E(U.label)).concat([Ft(i)]).concat(d.breadcrumbs),information:d.information,positionals:l.positionals.concat(d.positionals),subcommands:d.subcommands,options:l.options.concat(d.options)}},createInstance(){let l=o.createInstance(),d=p.createInstance();return{async executeWithContext(U){return await d.executeWithContext(await l.executeWithContext(U))}}}}}catch(o){return{generateUsage(){let i=t.generateUsage();return{breadcrumbs:i.positionals.map(a=>E(a.label)).concat([E("<SUBCOMMAND>")]),information:e,positionals:i.positionals,subcommands:Object.entries(n).map(a=>{let p=a[1].getInformation();return{name:a[0],description:p.description,hint:p.hint}}),options:i.options}},createInstance(){throw o}}}}}}function Lt(e,t,n){return{getInformation(){return e},createFactory(r){try{let o=t.createFactory(r),i=n.createFactory(r);return{generateUsage(){let a=t.generateUsage(),p=i.generateUsage();return{breadcrumbs:a.positionals.map(l=>E(l.label)).concat(p.breadcrumbs),information:p.information,positionals:a.positionals.concat(p.positionals),subcommands:p.subcommands,options:a.options.concat(p.options)}},createInstance(){let a=o.createInstance(),p=i.createInstance();return{async executeWithContext(l){return await p.executeWithContext(await a.executeWithContext(l))}}}}}catch(o){return{generateUsage(){let i=t.generateUsage();return{breadcrumbs:i.positionals.map(a=>E(a.label)).concat([E("[REST]...")]),information:e,positionals:i.positionals,subcommands:[],options:i.options}},createInstance(){throw o}}}}}}function E(e){return{positional:e}}function Ft(e){return{command:e}}function Gt(e,t){return{generateUsage(){let n=new Array;for(let o in e.options){let i=e.options[o];i&&n.push(i.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 i in e.options){let a=e.options[i];r[i]=a.createGetter(n)}let o=[];for(let i of e.positionals)o.push(i.consumePositionals(n));return{createInstance(){let i={};for(let a in r)i[a]=r[a].getValue();return{executeWithContext(a){return t(a,{options:i,positionals:o})}}}}}}}var H={content:"Boolean",decoder(e){let t=e.toLowerCase();if(t==="true"||t==="yes")return!0;if(t==="false"||t==="no")return!1;throw new g(new u(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 g(new u(new s("Not a valid ISO_8601: "),new s(`"${e}"`,f)))}}},Wt={content:"Number",decoder(e){try{let t=Number(e);if(isNaN(t))throw new Error;return t}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Dt={content:"Integer",decoder(e){try{return BigInt(e)}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Mt={content:"Url",decoder(e){try{return new URL(e)}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Kt={content:"String",decoder(e){return e}};function Nt(e,t){return{content:t.content,decoder:n=>t.decoder(g.tryWithContext(()=>e.decoder(n),()=>new u(new s("from: "),new s(e.content,S))))}}function jt(e,t){let n=new Set(t);return{content:e,decoder(r){if(n.has(r))return r;let o=[];for(let i of t){if(o.length>=5){o.push(new s("..."));break}o.length>0&&o.push(new s(" | ")),o.push(new s(`"${i}"`,f))}throw new g(new u(new s("Invalid value: "),new s(`"${r}"`,f),new s(" (expected one of: "),...o,new s(")")))}}}function Yt(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 g(new u(new s(`Found ${r.length} splits: `),new s(`Expected ${e.length} splits from: `),new s(`"${n}"`,f)));return r.map((o,i)=>{let a=e[i];return g.tryWithContext(()=>a.decoder(o),()=>new u(new s(`at ${i}: `),new s(a.content,S)))})}}}function qt(e,t=","){return{content:`${e.content}[${t}${e.content}]...`,decoder(n){return n.split(t).map((o,i)=>g.tryWithContext(()=>e.decoder(o),()=>new u(new s(`at ${i}: `),new s(e.content,S))))}}}function Ht(e){let t=`<${H.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,long:e.long,short:e.short,label:void 0}},createGetter(n){let r=rt(n,{...e,valued:!1});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new g(new u(new s(`--${e.long}`,x),new s(": Must not be set multiple times")));let i=o[0];if(i===void 0)try{return e.default?e.default():!1}catch(a){throw new g(new u(new s(`--${e.long}`,x),new s(": Failed to get default value")),a)}return ot(e.long,t,H,i)}}}}}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}},createGetter(n){let r=rt(n,{...e,valued:!0});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new g(new u(new s(`--${e.long}`,x),new s(": Requires a single value, but got multiple")));let i=o[0];if(i===void 0)try{return e.default()}catch(a){throw new g(new u(new s(`--${e.long}`,x),new s(": Failed to get default value")),a)}return ot(e.long,t,e.type,i)}}}}}function Jt(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}},createGetter(n){let r=rt(n,{...e,valued:!0});return{getValue(){return n.getOptionValues(r).map(i=>ot(e.long,t,e.type,i))}}}}}function ot(e,t,n,r){return g.tryWithContext(()=>n.decoder(r),()=>new u(new s(`--${e}`,x),new s(": "),new s(t,b),new s(": "),new s(n.content,S)))}function rt(e,t){let{long:n,short:r,aliases:o,valued:i}=t,a=n?[n]:[];o?.longs&&a.push(...o?.longs);let p=r?[r]:[];return o?.shorts&&p.push(...o?.shorts),e.registerOption({longs:a,shorts:p,valued:i})}function zt(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)throw new g(new u(new s(t,b),new s(": Is required, but was not provided")));return st(t,e.type,r)}}}function Xt(e){let t=`[${e.label??e.type.content.toUpperCase()}]`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)try{return e.default()}catch(o){throw new g(new u(new s(t,b),new s(": Failed to get default value")),o)}return st(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}"]`:"")}},consumePositionals(n){let r=[];for(;;){let o=n.consumePositional();if(o===void 0||o===e.endDelimiter)break;r.push(st(t,e.type,o))}return r}}}function st(e,t,n){return g.tryWithContext(()=>t.decoder(n),()=>new u(new s(e,b),new s(": "),new s(t.content,S)))}var Y,B,A,v,O,L,W,y,Q,ht,it,wt,at,$,j=class{constructor(t){w(this,y);w(this,Y);w(this,B);w(this,A);w(this,v);w(this,O);w(this,L);w(this,W);m(this,Y,t),m(this,B,0),m(this,A,!1),m(this,v,new Map),m(this,O,new Map),m(this,L,new Map),m(this,W,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,v).has(r))throw new Error(`Option already registered: --${r}`);c(this,v).set(r,n)}for(let r of t.shorts){if(c(this,O).has(r))throw new Error(`Option already registered: -${r}`);for(let o=0;o<r.length;o++){let i=r.slice(0,o);if(c(this,O).has(i))throw new Error(`Option -${r} overlap with shorter option: -${i}`)}for(let o of c(this,O).keys())if(o.startsWith(r))throw new Error(`Option -${r} overlap with longer option: -${o}`);c(this,O).set(r,n)}return c(this,L).set(n,t.valued),c(this,W).set(n,new Array),n}getOptionValues(t){let n=c(this,W).get(t);if(n===void 0)throw new Error(`Unregistered option: ${t}`);return n}consumePositional(){for(;;){let t=h(this,y,Q).call(this);if(t===null)return;if(h(this,y,ht).call(this,t))return t}}};Y=new WeakMap,B=new WeakMap,A=new WeakMap,v=new WeakMap,O=new WeakMap,L=new WeakMap,W=new WeakMap,y=new WeakSet,Q=function(){let t=c(this,Y)[c(this,B)];return t===void 0?null:(yt(this,B)._++,!c(this,A)&&t==="--"?(m(this,A,!0),h(this,y,Q).call(this)):t)},ht=function(t){if(c(this,A))return!0;if(t.startsWith("--")){let n=t.indexOf("=");return n===-1?h(this,y,it).call(this,t.slice(2),null):h(this,y,it).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,wt).call(this,t.slice(n,r),t.slice(r));if(o===!0)return!1;o===!1&&(n=r),r++}throw new g(new u(new s(`-${t.slice(n)}`,x),new s(": Unexpected unknown option")))}return!0},it=function(t,n){let r=`--${t}`,o=c(this,v).get(t);if(o!==void 0)return n!==null?h(this,y,$).call(this,o,n):c(this,L).get(o)?h(this,y,$).call(this,o,h(this,y,at).call(this,r)):h(this,y,$).call(this,o,"true");throw new g(new u(new s(r,x),new s(": Unexpected unknown option")))},wt=function(t,n){let r=c(this,O).get(t);return r!==void 0?n.startsWith("=")?(h(this,y,$).call(this,r,n.slice(1)),!0):c(this,L).get(r)?(n===""?h(this,y,$).call(this,r,h(this,y,at).call(this,`-${t}`)):h(this,y,$).call(this,r,n),!0):(h(this,y,$).call(this,r,"true"),n===""):null},at=function(t){let n=h(this,y,Q).call(this);if(n===null)throw new g(new u(new s(t,x),new s(": Requires a value, but got end of input")));if(c(this,A))throw new g(new u(new s(t,x),new s(": Requires a value before "),new s('"--"',f)));if(n.startsWith("-"))throw new g(new u(new s(t,x),new s(": Requires a value, but got: "),new s(`"${n}"`,f)));return n},$=function(t,n){this.getOptionValues(t).push(n)};function ct(e){let{cliName:t,commandUsage:n,typoSupport:r}=e,o=new Array,i=[_t("Usage:").computeStyledString(r),D(t).computeStyledString(r)].concat(n.breadcrumbs.map(p=>{if("positional"in p)return lt(p.positional).computeStyledString(r);if("command"in p)return D(p.command).computeStyledString(r);throw new Error(`Unknown breadcrumb: ${JSON.stringify(p)}`)}));o.push(i.join(" ")),o.push("");let a=new u;a.pushString(te(n.information.description)),n.information.hint&&(a.pushString(R(" ")),a.pushString(J(`(${n.information.hint})`))),o.push(a.computeStyledString(r));for(let p of n.information.details??[]){let l=new u;l.pushString(J(p)),o.push(l.computeStyledString(r))}if(n.positionals.length>0){o.push(""),o.push(ut("Positionals:").computeStyledString(r));let p=new P;for(let l of n.positionals){let d=new Array;d.push(new u(R(" "))),d.push(new u(lt(l.label))),d.push(...pt(l)),p.pushRow(d)}o.push(...p.computeStyledGrid(r).map(l=>l.join("")))}if(n.subcommands.length>0){o.push(""),o.push(ut("Subcommands:").computeStyledString(r));let p=new P;for(let l of n.subcommands){let d=new Array;d.push(new u(R(" "))),d.push(new u(D(l.name))),d.push(...pt(l)),p.pushRow(d)}o.push(...p.computeStyledGrid(r).map(l=>l.join("")))}if(n.options.length>0){o.push(""),o.push(ut("Options:").computeStyledString(r));let p=new P;for(let l of n.options){let d=new Array;d.push(new u(R(" "))),l.short?d.push(new u(D(`-${l.short}`),R(", "))):d.push(new u),l.label?d.push(new u(D(`--${l.long}`),R(" "),lt(l.label))):d.push(new u(D(`--${l.long}`),J("[=no]"))),d.push(...pt(l)),p.pushRow(d)}o.push(...p.computeStyledGrid(r).map(l=>l.join("")))}return o.push(""),o}function pt(e){let t=[];return e.description&&(t.push(R(" ")),t.push(ee(e.description))),e.hint&&(t.push(R(" ")),t.push(J(`(${e.hint})`))),t.length>0?[new u(R(" "),...t)]:[]}function _t(e){return new s(e,S)}function te(e){return new s(e,tt)}function ee(e){return new s(e)}function ut(e){return new s(e,_)}function J(e){return new s(e,et)}function D(e){return new s(e,x)}function lt(e){return new s(e,b)}function R(e){return new s(e)}async function ne(e,t,n,r,o){let i=new j(t),a=o?.usageOnHelp??!0;a&&i.registerOption({shorts:[],longs:["help"],valued:!1});let p=o?.buildVersion;p&&i.registerOption({shorts:[],longs:["version"],valued:!1});let l=o?.useTtyColors===void 0?I.inferFromProcess():o.useTtyColors==="mock"?I.mock():o.useTtyColors?I.tty():I.none(),d=o?.onLogStdOut??console.log,U=o?.onLogStdErr??console.error,M=o?.onExit??process.exit,z=r.createFactory(i);for(;;)try{if(i.consumePositional()===void 0)break}catch{}if(a&&i.getOptionValues("--help").length>0)return d(ft(e,z,l)),M(0);if(p&&i.getOptionValues("--version").length>0)return d([e,p].join(" ")),M(0);try{let K=z.createInstance();try{return await K.executeWithContext(n),M(0)}catch(gt){return o?.onExecutionError?o.onExecutionError(gt):U(l.computeStyledErrorMessage(gt)),M(1)}}catch(K){return(o?.usageOnError??!0)&&U(ft(e,z,l)),U(l.computeStyledErrorMessage(K)),M(1)}}function ft(e,t,n){return ct({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,runAsCliAndExit,typeBoolean,typeConverted,typeDate,typeInteger,typeList,typeNumber,typeOneOf,typeString,typeTuple,typeUrl,typoStyleConstants,typoStyleFailure,typoStyleLogic,typoStyleQuote,typoStyleRegularStrong,typoStyleRegularWeaker,typoStyleTitle,typoStyleUserInput,usageToStyledLines});
3
3
  //# sourceMappingURL=index.js.map