cli-kiss 0.0.12 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.prettierrc CHANGED
@@ -9,5 +9,6 @@
9
9
  "tabWidth": 2,
10
10
  "trailingComma": "all",
11
11
  "useTabs": false,
12
+ "quoteProps": "consistent",
12
13
  "plugins": ["prettier-plugin-organize-imports"]
13
14
  }
package/dist/index.d.ts CHANGED
@@ -1,68 +1,105 @@
1
+ type ReaderOptionKey = (string | {
2
+ __brand: "ReaderOptionKey";
3
+ }) & {
4
+ __brand: "ReaderOptionKey";
5
+ };
6
+ type ReaderOptions = {
7
+ registerOption(definition: {
8
+ longs: Array<string>;
9
+ shorts: Array<string>;
10
+ valued: boolean;
11
+ }): ReaderOptionKey;
12
+ getOptionValues(key: ReaderOptionKey): Array<string>;
13
+ };
1
14
  type ReaderPositionals = {
2
15
  consumePositional(): string | undefined;
3
16
  };
4
17
  declare class ReaderArgs {
5
18
  #private;
6
- constructor(args: Array<string>);
7
- registerFlag(definition: {
8
- key: string;
9
- shorts: Array<string>;
10
- longs: Array<string>;
11
- }): void;
19
+ constructor(args: ReadonlyArray<string>);
12
20
  registerOption(definition: {
13
- key: string;
14
- shorts: Array<string>;
15
21
  longs: Array<string>;
16
- }): void;
17
- consumeFlag(key: string): boolean | undefined;
18
- consumeOption(key: string): Array<string>;
22
+ shorts: Array<string>;
23
+ valued: boolean;
24
+ }): ReaderOptionKey;
25
+ getOptionValues(key: ReaderOptionKey): Array<string>;
19
26
  consumePositional(): string | undefined;
20
27
  }
21
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 typoStyleConstants: TypoStyle;
40
+ declare const typoStyleUserInput: TypoStyle;
41
+ declare const typoStyleFailure: TypoStyle;
42
+ declare class TypoString {
43
+ #private;
44
+ constructor(value: string, typoStyle?: TypoStyle);
45
+ getRawString(): string;
46
+ computeStyledString(typoSupport: TypoSupport): string;
47
+ }
48
+ declare class TypoText {
49
+ #private;
50
+ constructor(...typoParts: Array<TypoText | TypoString | string>);
51
+ pushString(typoString: TypoString): void;
52
+ pushText(typoText: TypoText): void;
53
+ computeStyledString(typoSupport: TypoSupport): string;
54
+ computeRawString(): string;
55
+ computeRawLength(): number;
56
+ }
57
+ declare class TypoGrid {
58
+ #private;
59
+ constructor();
60
+ pushRow(cells: Array<TypoText>): void;
61
+ computeStyledGrid(typoSupport: TypoSupport): Array<Array<string>>;
62
+ }
63
+ declare class TypoError extends Error {
64
+ #private;
65
+ constructor(currentTypoText: TypoText, source?: unknown);
66
+ computeStyledString(typoSupport: TypoSupport): string;
67
+ }
68
+ declare class TypoSupport {
69
+ #private;
70
+ private constructor();
71
+ static none(): TypoSupport;
72
+ static tty(): TypoSupport;
73
+ static mock(): TypoSupport;
74
+ static inferFromProcess(): TypoSupport;
75
+ computeStyledString(value: string, typoStyle: TypoStyle): string;
76
+ computeStyledErrorMessage(error: unknown): string;
77
+ }
78
+
22
79
  type Type<Value> = {
23
80
  label: Uppercase<string>;
24
81
  decoder(value: string): Value;
25
82
  };
26
83
  declare const typeBoolean: Type<boolean>;
27
84
  declare const typeDate: Type<Date>;
85
+ declare const typeUrl: Type<URL>;
28
86
  declare const typeString: Type<string>;
29
87
  declare const typeNumber: Type<number>;
30
88
  declare const typeBigInt: Type<bigint>;
31
- declare function typeCommaTuple<const Elements extends Array<any>>(elementTypes: {
32
- [K in keyof Elements]: Type<Elements[K]>;
33
- }): Type<Elements>;
34
- declare function typeCommaList<Value>(elementType: Type<Value>): Type<Array<Value>>;
35
- declare function typeDecode<Value>(type: Type<Value>, value: string, context: string): Value;
36
-
37
- type Argument<Value> = {
38
- generateUsage(): ArgumentUsage;
39
- consumeValue(readerPositionals: ReaderPositionals): Value;
40
- };
41
- type ArgumentUsage = {
42
- description: string | undefined;
89
+ declare function typeMapped<Before, After>(before: Type<Before>, after: {
43
90
  label: Uppercase<string>;
44
- };
45
- declare function argumentRequired<Value>(definition: {
46
- description?: string;
47
- label?: Uppercase<string>;
48
- type: Type<Value>;
49
- }): Argument<Value>;
50
- declare function argumentOptional<Value>(definition: {
51
- description?: string;
52
- label?: Uppercase<string>;
53
- type: Type<Value>;
54
- default: () => Value;
55
- }): Argument<Value>;
56
- declare function argumentVariadics<Value>(definition: {
57
- endDelimiter?: string;
58
- description?: string;
59
- label?: Uppercase<string>;
60
- type: Type<Value>;
61
- }): Argument<Array<Value>>;
91
+ decoder: (value: Before) => After;
92
+ }): Type<After>;
93
+ declare function typeOneOf<Value>(type: Type<Value>, values: Array<Value>): Type<Value>;
94
+ declare function typeTuple<const Elements extends Array<any>>(elementTypes: {
95
+ [K in keyof Elements]: Type<Elements[K]>;
96
+ }, separator?: string): Type<Elements>;
97
+ declare function typeList<Value>(elementType: Type<Value>, separator?: string): Type<Array<Value>>;
98
+ declare function typeDecode<Value>(type: Type<Value>, value: string, context: () => TypoText): Value;
62
99
 
63
100
  type Option<Value> = {
64
101
  generateUsage(): OptionUsage;
65
- prepareConsumer(readerArgs: ReaderArgs): OptionConsumer<Value>;
102
+ createGetter(readerOptions: ReaderArgs): OptionGetter<Value>;
66
103
  };
67
104
  type OptionUsage = {
68
105
  description: string | undefined;
@@ -70,7 +107,9 @@ type OptionUsage = {
70
107
  short: string | undefined;
71
108
  label: Uppercase<string> | undefined;
72
109
  };
73
- type OptionConsumer<Value> = () => Value;
110
+ type OptionGetter<Value> = {
111
+ getValue(): Value;
112
+ };
74
113
  declare function optionFlag(definition: {
75
114
  long: Lowercase<string>;
76
115
  short?: string;
@@ -81,7 +120,7 @@ declare function optionFlag(definition: {
81
120
  };
82
121
  default?: () => boolean;
83
122
  }): Option<boolean>;
84
- declare function optionRepeatable<Value>(definition: {
123
+ declare function optionSingleValue<Value>(definition: {
85
124
  long: Lowercase<string>;
86
125
  short?: string;
87
126
  description?: string;
@@ -91,8 +130,9 @@ declare function optionRepeatable<Value>(definition: {
91
130
  };
92
131
  label?: Uppercase<string>;
93
132
  type: Type<Value>;
94
- }): Option<Array<Value>>;
95
- declare function optionSingleValue<Value>(definition: {
133
+ default: () => Value;
134
+ }): Option<Value>;
135
+ declare function optionRepeatable<Value>(definition: {
96
136
  long: Lowercase<string>;
97
137
  short?: string;
98
138
  description?: string;
@@ -102,46 +142,65 @@ declare function optionSingleValue<Value>(definition: {
102
142
  };
103
143
  label?: Uppercase<string>;
104
144
  type: Type<Value>;
105
- default: () => Value;
106
- }): Option<Value>;
145
+ }): Option<Array<Value>>;
107
146
 
108
- type Execution<Context, Result> = {
109
- generateUsage(): ExecutionUsage;
110
- createInterpreterFactory(readerArgs: ReaderArgs): ExecutionInterpreterFactory<Context, Result>;
147
+ type Positional<Value> = {
148
+ generateUsage(): PositionalUsage;
149
+ consumePositionals(readerPositionals: ReaderPositionals): Value;
111
150
  };
112
- type ExecutionInterpreterFactory<Context, Result> = {
113
- createInterpreterInstance(): ExecutionInterpreterInstance<Context, Result>;
151
+ type PositionalUsage = {
152
+ description: string | undefined;
153
+ label: Uppercase<string>;
114
154
  };
115
- type ExecutionInterpreterInstance<Context, Result> = {
116
- executeWithContext(context: Context): Promise<Result>;
155
+ declare function positionalRequired<Value>(definition: {
156
+ description?: string;
157
+ label?: Uppercase<string>;
158
+ type: Type<Value>;
159
+ }): Positional<Value>;
160
+ declare function positionalOptional<Value>(definition: {
161
+ description?: string;
162
+ label?: Uppercase<string>;
163
+ type: Type<Value>;
164
+ default: () => Value;
165
+ }): Positional<Value>;
166
+ declare function positionalVariadics<Value>(definition: {
167
+ endDelimiter?: string;
168
+ description?: string;
169
+ label?: Uppercase<string>;
170
+ type: Type<Value>;
171
+ }): Positional<Array<Value>>;
172
+
173
+ type Operation<Input, Output> = {
174
+ generateUsage(): OperationUsage;
175
+ createRunnerFromArgs(readerArgs: ReaderArgs): OperationRunner<Input, Output>;
117
176
  };
118
- type ExecutionUsage = {
177
+ type OperationRunner<Input, Output> = {
178
+ executeWithContext(input: Input): Promise<Output>;
179
+ };
180
+ type OperationUsage = {
119
181
  options: Array<OptionUsage>;
120
- arguments: Array<ArgumentUsage>;
182
+ positionals: Array<PositionalUsage>;
121
183
  };
122
- declare function execution<Context, Result, Options extends {
184
+ declare function operation<Context, Result, Options extends {
123
185
  [option: string]: any;
124
- }, const Arguments extends Array<any>>(inputs: {
186
+ }, const Positionals extends Array<any>>(inputs: {
125
187
  options: {
126
188
  [K in keyof Options]: Option<Options[K]>;
127
189
  };
128
- arguments: {
129
- [K in keyof Arguments]: Argument<Arguments[K]>;
190
+ positionals: {
191
+ [K in keyof Positionals]: Positional<Positionals[K]>;
130
192
  };
131
193
  }, handler: (context: Context, inputs: {
132
194
  options: Options;
133
- arguments: Arguments;
134
- }) => Promise<Result>): Execution<Context, Result>;
195
+ positionals: Positionals;
196
+ }) => Promise<Result>): Operation<Context, Result>;
135
197
 
136
198
  type Command<Context, Result> = {
137
199
  getDescription(): string | undefined;
138
- createInterpreterFactory(readerArgs: ReaderArgs): CommandInterpreterFactory<Context, Result>;
200
+ createRunnerFromArgs(readerArgs: ReaderArgs): CommandRunner<Context, Result>;
139
201
  };
140
- type CommandInterpreterFactory<Context, Result> = {
202
+ type CommandRunner<Context, Result> = {
141
203
  generateUsage(): CommandUsage;
142
- createInterpreterInstance(): CommandInterpreterInstance<Context, Result>;
143
- };
144
- type CommandInterpreterInstance<Context, Result> = {
145
204
  executeWithContext(context: Context): Promise<Result>;
146
205
  };
147
206
  type CommandMetadata = {
@@ -151,43 +210,26 @@ type CommandMetadata = {
151
210
  type CommandUsage = {
152
211
  metadata: CommandMetadata;
153
212
  breadcrumbs: Array<CommandUsageBreadcrumb>;
213
+ positionals: Array<PositionalUsage>;
214
+ subcommands: Array<CommandUsageSubcommand>;
154
215
  options: Array<OptionUsage>;
155
- arguments: Array<ArgumentUsage>;
156
- subcommands: Array<{
157
- name: string;
158
- description: string | undefined;
159
- }>;
160
216
  };
161
217
  type CommandUsageBreadcrumb = {
162
- argument: string;
218
+ positional: string;
163
219
  } | {
164
220
  command: string;
165
221
  };
166
- declare function command<Context, Result>(metadata: CommandMetadata, execution: Execution<Context, Result>): Command<Context, Result>;
167
- declare function commandWithSubcommands<Context, Payload, Result>(metadata: CommandMetadata, execution: Execution<Context, Payload>, subcommands: {
222
+ type CommandUsageSubcommand = {
223
+ name: string;
224
+ description: string | undefined;
225
+ };
226
+ declare function command<Context, Result>(metadata: CommandMetadata, operation: Operation<Context, Result>): Command<Context, Result>;
227
+ declare function commandWithSubcommands<Context, Payload, Result>(metadata: CommandMetadata, operation: Operation<Context, Payload>, subcommands: {
168
228
  [subcommand: Lowercase<string>]: Command<Payload, Result>;
169
229
  }): Command<Context, Result>;
230
+ declare function commandChained<Context, Payload, Result>(metadata: CommandMetadata, operation: Operation<Context, Payload>, nextCommand: Command<Payload, Result>): Command<Context, Result>;
170
231
 
171
- type TypoSupport = "none" | "tty" | "mock";
172
- type TypoColor = "darkBlack" | "darkRed" | "darkGreen" | "darkYellow" | "darkBlue" | "darkMagenta" | "darkCyan" | "darkWhite" | "brightBlack" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite";
173
- type TypoText = {
174
- value: string;
175
- foregroundColor?: TypoColor;
176
- backgroundColor?: TypoColor;
177
- bold?: boolean;
178
- italic?: boolean;
179
- underline?: boolean;
180
- strikethrough?: boolean;
181
- };
182
- declare function typoPrintableString(typoSupport: TypoSupport, typoText: TypoText): string;
183
- declare function typoInferProcessSupport(): TypoSupport;
184
-
185
- type Grid = Array<GridRow>;
186
- type GridRow = Array<GridCell>;
187
- type GridCell = Array<TypoText>;
188
- declare function gridToPrintableLines(grid: Grid, typoSupport: TypoSupport, delimiter?: string): Array<string>;
189
-
190
- declare function runAndExit<Context>(cliName: Lowercase<string>, cliArgs: Array<string>, context: Context, command: Command<Context, void>, application?: {
232
+ declare function runAsCliAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command: Command<Context, void>, application?: {
191
233
  usageOnError?: boolean | undefined;
192
234
  usageOnHelp?: boolean | undefined;
193
235
  buildVersion?: string | undefined;
@@ -198,10 +240,10 @@ declare function runAndExit<Context>(cliName: Lowercase<string>, cliArgs: Array<
198
240
  onError?: ((error: unknown) => void) | undefined;
199
241
  }): Promise<never>;
200
242
 
201
- declare function usageToPrintableLines(params: {
243
+ declare function usageToStyledLines(params: {
202
244
  cliName: Lowercase<string>;
203
245
  commandUsage: CommandUsage;
204
246
  typoSupport: TypoSupport;
205
247
  }): string[];
206
248
 
207
- export { type Argument, type ArgumentUsage, type Command, type CommandInterpreterFactory, type CommandInterpreterInstance, type CommandMetadata, type CommandUsage, type CommandUsageBreadcrumb, type Execution, type ExecutionInterpreterFactory, type ExecutionInterpreterInstance, type ExecutionUsage, type Grid, type GridCell, type GridRow, type Option, type OptionConsumer, type OptionUsage, ReaderArgs, type ReaderPositionals, type Type, type TypoColor, type TypoSupport, type TypoText, argumentOptional, argumentRequired, argumentVariadics, command, commandWithSubcommands, execution, gridToPrintableLines, optionFlag, optionRepeatable, optionSingleValue, runAndExit, typeBigInt, typeBoolean, typeCommaList, typeCommaTuple, typeDate, typeDecode, typeNumber, typeString, typoInferProcessSupport, typoPrintableString, usageToPrintableLines };
249
+ export { type Command, type CommandMetadata, type CommandRunner, type CommandUsage, type CommandUsageBreadcrumb, type CommandUsageSubcommand, type Operation, type OperationRunner, 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, typoStyleUserInput, usageToStyledLines };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var L=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var ue=Object.prototype.hasOwnProperty;var z=r=>{throw TypeError(r)};var le=(r,e)=>{for(var t in e)L(r,t,{get:e[t],enumerable:!0})},ge=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ie(e))!ue.call(r,n)&&n!==t&&L(r,n,{get:()=>e[n],enumerable:!(o=ae(e,n))||o.enumerable});return r};var pe=r=>ge(L({},"__esModule",{value:!0}),r);var G=(r,e,t)=>e.has(r)||z("Cannot "+t);var l=(r,e,t)=>(G(r,e,"read from private field"),t?t.call(r):e.get(r)),m=(r,e,t)=>e.has(r)?z("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),d=(r,e,t,o)=>(G(r,e,"write to private field"),o?o.call(r,t):e.set(r,t),t),p=(r,e,t)=>(G(r,e,"access private method"),t);var Q=(r,e,t,o)=>({set _(n){d(r,e,n,t)},get _(){return l(r,e,o)}});var Ke={};le(Ke,{ReaderArgs:()=>P,argumentOptional:()=>Ce,argumentRequired:()=>xe,argumentVariadics:()=>we,command:()=>Ie,commandWithSubcommands:()=>Ue,execution:()=>Ae,gridToPrintableLines:()=>v,optionFlag:()=>Te,optionRepeatable:()=>Fe,optionSingleValue:()=>Pe,runAndExit:()=>Le,typeBigInt:()=>fe,typeBoolean:()=>ce,typeCommaList:()=>be,typeCommaTuple:()=>ye,typeDate:()=>de,typeDecode:()=>f,typeNumber:()=>he,typeString:()=>me,typoInferProcessSupport:()=>W,typoPrintableString:()=>c,usageToPrintableLines:()=>J});module.exports=pe(Ke);var ce={label:"BOOLEAN",decoder(r){if(r==="true")return!0;if(r==="false")return!1;throw new Error(`Invalid boolean: ${r} (expected: "true"|"false")`)}},de={label:"DATE",decoder(r){let e=Date.parse(r);if(isNaN(e))throw new Error(`Invalid date: ${r} (expected: ISO_8601 format)`);return new Date(e)}},me={label:"STRING",decoder(r){return r}},he={label:"NUMBER",decoder(r){return Number(r)}},fe={label:"BIGINT",decoder(r){return BigInt(r)}};function ye(r){return{label:r.map(e=>e.label).join(","),decoder(e){let t=e.split(",",r.length);if(t.length!==r.length)throw new Error(`Invalid tuple value: "${e}", expected ${r.length} comma-separated parts`);return t.map((o,n)=>f(r[n],o,`[${n}].${r[n].label}`))}}}function be(r){return{label:`${r.label}[,${r.label}...]`,decoder(e){return e.split(",").map((t,o)=>f(r,t,`[${o}].${r.label}`))}}}function f(r,e,t){try{return r.decoder(e)}catch(o){throw new Error(`Failed to decode value "${e}" for ${t}: ${o instanceof Error?o.message:String(o)}`)}}function xe(r){let e=r.label??r.type.label;return{generateUsage(){return{description:r.description,label:`<${e}>`}},consumeValue(t){let o=t.consumePositional();if(o===void 0)throw new Error(`Missing required argument: ${e}`);return f(r.type,o,e)}}}function Ce(r){let e=r.label??r.type.label;return{generateUsage(){return{description:r.description,label:`[${e}]`}},consumeValue(t){let o=t.consumePositional();return o===void 0?r.default():f(r.type,o,e)}}}function we(r){let e=r.label??r.type.label;return{generateUsage(){return{description:r.description,label:`[${e}]...`+(r.endDelimiter?`["${r.endDelimiter}"]`:"")}},consumeValue(t){let o=[];for(;;){let n=t.consumePositional();if(n===void 0||n===r.endDelimiter)break;o.push(f(r.type,n,e))}return o}}}function Ie(r,e){return{getDescription(){return r.description},createInterpreterFactory(t){function o(){let n=e.generateUsage();return{metadata:r,breadcrumbs:n.arguments.map(s=>K(s.label)),options:n.options,arguments:n.arguments,subcommands:[]}}try{let n=e.createInterpreterFactory(t);return{generateUsage:o,createInterpreterInstance(){let s=t.consumePositional();if(s!==void 0)throw Error(`Unexpected argument: "${s}"`);let a=n.createInterpreterInstance();return{async executeWithContext(i){return a.executeWithContext(i)}}}}}catch(n){return{generateUsage:o,createInterpreterInstance(){throw n}}}}}}function Ue(r,e,t){return{getDescription(){return r.description},createInterpreterFactory(o){try{let n=e.createInterpreterFactory(o),s=o.consumePositional();if(s===void 0)throw new Error("Missing required argument: SUBCOMMAND");let a=t[s];if(a===void 0)throw new Error(`Invalid SUBCOMMAND: "${s}"`);let i=a.createInterpreterFactory(o);return{generateUsage(){let u=e.generateUsage(),h=i.generateUsage();return{metadata:h.metadata,breadcrumbs:u.arguments.map(C=>K(C.label)).concat([X(s)]).concat(h.breadcrumbs),options:u.options.concat(h.options),arguments:u.arguments.concat(h.arguments),subcommands:h.subcommands}},createInterpreterInstance(){let u=i.createInterpreterInstance(),h=n.createInterpreterInstance();return{async executeWithContext(C){let S=await h.executeWithContext(C);return await u.executeWithContext(S)}}}}}catch(n){return{generateUsage(){let s=e.generateUsage();return{metadata:r,breadcrumbs:s.arguments.map(a=>K(a.label)).concat([X("<SUBCOMMAND>")]),options:s.options,arguments:s.arguments,subcommands:Object.entries(t).map(([a,i])=>({name:a,description:i.getDescription()}))}},createInterpreterInstance(){throw n}}}}}}function K(r){return{argument:r}}function X(r){return{command:r}}function Ae(r,e){return{generateUsage(){let t=new Array;for(let n in r.options){let s=r.options[n];t.push(s.generateUsage())}let o=new Array;for(let n of r.arguments)o.push(n.generateUsage());return{options:t,arguments:o}},createInterpreterFactory(t){let o={};for(let s in r.options){let a=r.options[s];o[s]=a.prepareConsumer(t)}let n=[];for(let s of r.arguments)n.push(s.consumeValue(t));return{createInterpreterInstance(){let s={};for(let a in o)s[a]=o[a]();return{executeWithContext(a){return e(a,{options:s,arguments:n})}}}}}}}function c(r,e){if(r==="none")return e.value;if(r==="tty"){let t=e.foregroundColor?Ve[e.foregroundColor]:"",o=e.backgroundColor?ve[e.backgroundColor]:"",n=e.bold?Re:"",s=e.italic?Ee:"",a=e.underline?Oe:"",i=e.strikethrough?ke:"";return`${t}${o}${n}${s}${a}${i}${e.value}${$e}`}if(r==="mock"){let t=e.foregroundColor?`{${e.value}}@${e.foregroundColor}`:e.value,o=e.backgroundColor?`{${t}}#${e.backgroundColor}`:t,n=e.bold?`{${o}}+`:o,s=e.italic?`{${n}}*`:n,a=e.underline?`{${s}}_`:s;return e.strikethrough?`{${a}}~`:a}throw new Error(`Unknown typo support: ${r}`)}function W(){if(!process)return"none";if(process.env){if(process.env.FORCE_COLOR==="0")return"none";if(process.env.FORCE_COLOR)return"tty";if("NO_COLOR"in process.env)return"none"}return!process.stdout||!process.stdout.isTTY?"none":"tty"}var $e="\x1B[0m",Re="\x1B[1m",Ee="\x1B[3m",Oe="\x1B[4m",ke="\x1B[9m",Ve={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"},ve={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 v(r,e,t=""){let o=new Array,n=new Array;for(let s of r)for(let a=0;a<s.length;a++){let i=s[a],u=Z(i);(n[a]===void 0||u>n[a])&&(n[a]=u)}for(let s of r){let a=new Array;for(let i=0;i<s.length;i++){let u=s[i],h=u.map(C=>c(e,C));if(i<s.length-1){let C=Z(u),S=" ".repeat(n[i]-C);a.push(h.join("")+S)}else a.push(h.join(""))}o.push(a.join(t))}return o}function Z(r){let e=0;for(let t of r)e+=t.value.length;return e}function Te(r){return{generateUsage(){return{description:r.description,long:r.long,short:r.short,label:void 0}},prepareConsumer(e){let t=D(r.long,r.short),o=[r.long];r.aliases?.longs&&o.push(...r.aliases?.longs);let n=r.short?[r.short]:[];return r.aliases?.shorts&&n.push(...r.aliases?.shorts),e.registerFlag({key:t,longs:o,shorts:n}),()=>{let s=e.consumeFlag(t);return s===void 0?r.default?r.default():!1:s}}}}function Fe(r){let e=r.label??r.type.label;return{generateUsage(){return{description:r.description,long:r.long,short:r.short,label:`<${e}>`}},prepareConsumer(t){let o=D(r.long,r.short),n=r.long?[r.long]:[];r.aliases?.longs&&n.push(...r.aliases?.longs);let s=r.short?[r.short]:[];return r.aliases?.shorts&&s.push(...r.aliases?.shorts),t.registerOption({key:o,longs:n,shorts:s}),()=>t.consumeOption(o).map(a=>f(r.type,a,`${o}: ${e}`))}}}function Pe(r){let e=r.label??r.type.label;return{generateUsage(){return{description:r.description,long:r.long,short:r.short,label:`<${e}>`}},prepareConsumer(t){let o=D(r.long,r.short),n=[r.long];r.aliases?.longs&&n.push(...r.aliases?.longs);let s=r.short?[r.short]:[];return r.aliases?.shorts&&s.push(...r.aliases?.shorts),t.registerOption({key:o,longs:n,shorts:s}),()=>{let a=t.consumeOption(o);if(a.length>1)throw new Error(`Multiple values provided for option: ${o}, expected only one. Found: ${a.map(u=>`"${u}"`).join(", ")}`);let i=a[0];return i===void 0?r.default():f(r.type,i,`${o}: ${e}`)}}}}function D(r,e){return e?`-${e}, --${r}`:`--${r}`}var B,k,x,w,I,U,y,A,$,R,b,g,M,N,te,j,ne,T,O,q,F,P=class{constructor(e){m(this,g);m(this,B);m(this,k);m(this,x);m(this,w);m(this,I);m(this,U);m(this,y);m(this,A);m(this,$);m(this,R);m(this,b);d(this,B,e),d(this,k,0),d(this,x,!1),d(this,w,new Map),d(this,I,new Map),d(this,U,new Map),d(this,y,new Map),d(this,A,new Map),d(this,$,new Map),d(this,R,new Map),d(this,b,new Map)}registerFlag(e){p(this,g,q).call(this,e.key),l(this,U).set(e.key,{});for(let t of e.shorts)p(this,g,F).call(this,t),l(this,w).set(t,e.key);for(let t of e.longs)p(this,g,F).call(this,t),l(this,I).set(t,e.key)}registerOption(e){p(this,g,q).call(this,e.key),l(this,R).set(e.key,{});for(let t of e.shorts)p(this,g,F).call(this,t),l(this,A).set(t,e.key);for(let t of e.longs)p(this,g,F).call(this,t),l(this,$).set(t,e.key)}consumeFlag(e){if(l(this,U).get(e)===void 0)throw new Error(`Flag not registered: ${e}`);let o=l(this,y).get(e);if(o===void 0){l(this,y).set(e,null);return}if(o===null)throw new Error(`Flag already consumed: ${e}`);return l(this,y).set(e,null),o}consumeOption(e){if(l(this,R).get(e)===void 0)throw new Error(`Option not registered: ${e}`);let o=l(this,b).get(e);if(o===void 0)return l(this,b).set(e,null),new Array;if(o===null)throw new Error(`Option already consumed: ${e}`);return l(this,b).set(e,null),o}consumePositional(){for(;;){let e=p(this,g,M).call(this);if(e===null)return;let t=p(this,g,te).call(this,e);if(t!==null)return t}}};B=new WeakMap,k=new WeakMap,x=new WeakMap,w=new WeakMap,I=new WeakMap,U=new WeakMap,y=new WeakMap,A=new WeakMap,$=new WeakMap,R=new WeakMap,b=new WeakMap,g=new WeakSet,M=function(){let e=l(this,B)[l(this,k)];return e===void 0?null:(Q(this,k)._++,!l(this,x)&&e==="--"?(d(this,x,!0),p(this,g,M).call(this)):e)},N=function(e){let t=p(this,g,M).call(this);if(t===null)throw new Error(`Option ${e} requires a value but none was provided`);if(l(this,x))throw new Error(`Option ${e} requires a value before "--"`);if(t.startsWith("-"))throw new Error(`Option ${e} requires a value, got: "${t}"`);return t},te=function(e){if(l(this,x))return e;if(e.startsWith("--")){let t=e.indexOf("=");return t===-1?p(this,g,j).call(this,e.slice(2),null):p(this,g,j).call(this,e.slice(2,t),e.slice(t+1)),null}if(e.startsWith("-")){let t=1,o=2;for(;o<=e.length;){let s=e.slice(t,o),a=e.slice(o),i=p(this,g,ne).call(this,s,a);if(i===!0)return null;i===!1&&(t=o),o++}let n=e.slice(t);throw new Error(`Unknown flag or option: -${n}`)}return e},j=function(e,t){let o=l(this,I).get(e);if(o!==void 0){if(t!==null){let s=re.get(t.toLowerCase());if(s!==void 0)return p(this,g,T).call(this,o,s);throw new Error(`Invalid value for flag: --${e}: "${t}" (expected: ${ee})`)}return p(this,g,T).call(this,o,!0)}let n=l(this,$).get(e);if(n!==void 0)return t!==null?p(this,g,O).call(this,n,t):p(this,g,O).call(this,n,p(this,g,N).call(this,`--${e}`));throw new Error(`Unknown flag or option: --${e}`)},ne=function(e,t){let o=l(this,w).get(e);if(o!==void 0){if(t.startsWith("=")){let s=re.get(t.slice(1).toLowerCase());if(s!==void 0)return p(this,g,T).call(this,o,s),!0;throw new Error(`Invalid value for flag: -${e}: "${t}" (expected: ${ee})`)}return p(this,g,T).call(this,o,!0),t===""}let n=l(this,A).get(e);return n!==void 0?t===""?(p(this,g,O).call(this,n,p(this,g,N).call(this,`-${e}`)),!0):(t.startsWith("=")?p(this,g,O).call(this,n,t.slice(1)):p(this,g,O).call(this,n,t),!0):null},T=function(e,t){if(l(this,y).has(e))throw new Error(`Flag already set: ${e}`);l(this,y).set(e,t)},O=function(e,t){let o=l(this,b).get(e)??new Array;o.push(t),l(this,b).set(e,o)},q=function(e){if(l(this,U).has(e))throw new Error(`Flag already registered: ${e}`);if(l(this,R).has(e))throw new Error(`Option already registered: ${e}`)},F=function(e){if(l(this,w).has(e))throw new Error(`Flag already registered: -${e}`);if(l(this,I).has(e))throw new Error(`Flag already registered: --${e}`);if(l(this,A).has(e))throw new Error(`Option already registered: -${e}`);if(l(this,$).has(e))throw new Error(`Option already registered: --${e}`)};var ee='"yes"|"no"',re=new Map([["true",!0],["false",!1],["yes",!0],["no",!1],["t",!0],["f",!1],["y",!0],["n",!1]]);function J(r){let{cliName:e,commandUsage:t,typoSupport:o}=r,n=new Array;n.push(c(o,Be(t.metadata.description))),t.metadata.details&&n.push(c(o,Me(t.metadata.details))),n.push("");let s=[c(o,Se("Usage:")),c(o,V(e))].concat(t.breadcrumbs.map(a=>{if("argument"in a)return c(o,H(a.argument));if("command"in a)return c(o,V(a.command));throw new Error(`Unknown breadcrumb: ${JSON.stringify(a)}`)}));if(n.push(s.join(" ")),t.arguments.length>0){n.push(""),n.push(c(o,_("Arguments:")));let a=new Array;for(let i of t.arguments){let u=new Array;u.push([E()]),u.push([H(i.label)]),i.description&&(u.push([E()]),u.push([Y(i.description)])),a.push(u)}n.push(...v(a,o))}if(t.subcommands.length>0){n.push(""),n.push(c(o,_("Subcommands:")));let a=new Array;for(let i of t.subcommands){let u=new Array;u.push([E()]),u.push([V(i.name)]),i.description&&(u.push([E()]),u.push([Y(i.description)])),a.push(u)}n.push(...v(a,o))}if(t.options.length>0){n.push(""),n.push(c(o,_("Options:")));let a=new Array;for(let i of t.options){let u=new Array;u.push([E()]),i.short?u.push([V(`-${i.short}`),E(", ")]):u.push([]),i.label?u.push([V(`--${i.long} `),H(i.label)]):u.push([V(`--${i.long}`)]),i.description&&(u.push([E()]),u.push([Y(i.description)])),a.push(u)}n.push(...v(a,o))}return n.push(""),n}function Be(r){return{value:r,bold:!0}}function Me(r){return{value:r,foregroundColor:"brightBlack",italic:!0}}function Y(r){return{value:r}}function Se(r){return{value:r,foregroundColor:"brightMagenta",bold:!0}}function _(r){return{value:r,foregroundColor:"brightGreen",bold:!0}}function V(r){return{value:r,foregroundColor:"brightCyan",bold:!0}}function H(r){return{value:r,foregroundColor:"brightBlue",italic:!0}}function E(r){return{value:r??" "}}async function Le(r,e,t,o,n){let s=new P(e);n?.buildVersion&&s.registerFlag({key:"version",shorts:[],longs:["version"]}),(n?.usageOnHelp??!0)&&s.registerFlag({key:"help",shorts:[],longs:["help"]});let a=o.createInterpreterFactory(s);if(n?.buildVersion&&s.consumeFlag("version"))return(n?.onLogStdOut??console.log)([r,n.buildVersion].join(" ")),(n?.onExit??process.exit)(0);if((n?.usageOnHelp??!0)&&s.consumeFlag("help")){let i=se(n?.useColors);return(n?.onLogStdOut??console.log)(oe(r,a,i)),(n?.onExit??process.exit)(0)}try{return await a.createInterpreterInstance().executeWithContext(t),(n?.onExit??process.exit)(0)}catch(i){if(n?.onError)n.onError(i);else{let u=se(n?.useColors);(n?.usageOnError??!0)&&(n?.onLogStdErr??console.error)(oe(r,a,u)),(n?.onLogStdErr??console.error)(Ge(i,u))}return(n?.onExit??process.exit)(1)}}function Ge(r,e){return[c(e,{value:"Error:",foregroundColor:"brightRed",bold:!0}),c(e,{value:r instanceof Error?r.message:String(r),bold:!0})].join(" ")}function oe(r,e,t){return J({cliName:r,commandUsage:e.generateUsage(),typoSupport:t}).join(`
2
- `)}function se(r){return r===void 0?W():r?"tty":"none"}0&&(module.exports={ReaderArgs,argumentOptional,argumentRequired,argumentVariadics,command,commandWithSubcommands,execution,gridToPrintableLines,optionFlag,optionRepeatable,optionSingleValue,runAndExit,typeBigInt,typeBoolean,typeCommaList,typeCommaTuple,typeDate,typeDecode,typeNumber,typeString,typoInferProcessSupport,typoPrintableString,usageToPrintableLines});
1
+ "use strict";var q=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var he=Object.prototype.hasOwnProperty;var se=t=>{throw TypeError(t)};var we=(t,e)=>{for(var n in e)q(t,n,{get:e[n],enumerable:!0})},fe=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ye(e))!he.call(t,o)&&o!==n&&q(t,o,{get:()=>e[o],enumerable:!(r=me(e,o))||r.enumerable});return t};var be=t=>fe(q({},"__esModule",{value:!0}),t);var H=(t,e,n)=>e.has(t)||se("Cannot "+n);var c=(t,e,n)=>(H(t,e,"read from private field"),n?n.call(t):e.get(t)),f=(t,e,n)=>e.has(t)?se("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),h=(t,e,n,r)=>(H(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),w=(t,e,n)=>(H(t,e,"access private method"),n);var ie=(t,e,n,r)=>({set _(o){h(t,e,o,n)},get _(){return c(t,e,r)}});var Qe={};we(Qe,{ReaderArgs:()=>K,TypoError:()=>d,TypoGrid:()=>P,TypoString:()=>s,TypoSupport:()=>V,TypoText:()=>l,command:()=>ke,commandChained:()=>Pe,commandWithSubcommands:()=>$e,operation:()=>Ve,optionFlag:()=>Ke,optionRepeatable:()=>Ne,optionSingleValue:()=>Fe,positionalOptional:()=>Ye,positionalRequired:()=>je,positionalVariadics:()=>qe,runAsCliAndExit:()=>ze,typeBigInt:()=>Le,typeBoolean:()=>j,typeDate:()=>ve,typeDecode:()=>x,typeList:()=>De,typeMapped:()=>Ie,typeNumber:()=>Ge,typeOneOf:()=>Me,typeString:()=>Be,typeTuple:()=>We,typeUrl:()=>Ee,typoStyleConstants:()=>m,typoStyleFailure:()=>ae,typoStyleUserInput:()=>y,usageToStyledLines:()=>ne});module.exports=be(Qe);var m={fgColor:"darkCyan",bold:!0},y={fgColor:"darkBlue",bold:!0},ae={fgColor:"darkRed",bold:!0},B,D,s=class{constructor(e,n={}){f(this,B);f(this,D);h(this,B,e),h(this,D,n)}getRawString(){return c(this,B)}computeStyledString(e){return e.computeStyledString(c(this,B),c(this,D))}};B=new WeakMap,D=new WeakMap;var S,J=class J{constructor(...e){f(this,S);h(this,S,[]);for(let n of e)n instanceof J?this.pushText(n):n instanceof s?this.pushString(n):typeof n=="string"&&this.pushString(new s(n))}pushString(e){c(this,S).push(e)}pushText(e){for(let n of c(e,S))c(this,S).push(n)}computeStyledString(e){return c(this,S).map(n=>n.computeStyledString(e)).join("")}computeRawString(){return c(this,S).map(e=>e.getRawString()).join("")}computeRawLength(){let e=0;for(let n of c(this,S))e+=n.getRawString().length;return e}};S=new WeakMap;var l=J,$,P=class{constructor(){f(this,$);h(this,$,[])}pushRow(e){c(this,$).push(e)}computeStyledGrid(e){let n=new Array,r=new Array;for(let o of c(this,$))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,$)){let i=new Array;for(let a=0;a<o.length;a++){let p=o[a],u=p.computeStyledString(e);if(i.push(u),a<o.length-1){let b=p.computeRawLength(),O=" ".repeat(n[a]-b);i.push(O)}}r.push(i)}return r}};$=new WeakMap;var G,z=class z extends Error{constructor(n,r){let o=new l;o.pushText(n),r instanceof Error?o.pushString(new s(`: ${r.message}`)):r instanceof z?(o.pushString(new s(": ")),o.pushText(c(r,G))):r!==void 0&&o.pushString(new s(`: ${String(r)}`));super(o.computeRawString());f(this,G);h(this,G,o)}computeStyledString(n){return c(this,G).computeStyledString(n)}};G=new WeakMap;var d=z,T,C=class C{constructor(e){f(this,T);h(this,T,e)}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.none():C.tty()}computeStyledString(e,n){if(c(this,T)==="none")return e;if(c(this,T)==="tty"){let r=n.fgColor?Ue[n.fgColor]:"",o=n.bgColor?Ae[n.bgColor]:"",i=n.bold?Ce:"",a=n.dim?Se:"",p=n.italic?Re:"",u=n.underline?Oe:"",b=n.strikethrough?Te:"";return`${r}${o}${i}${a}${p}${u}${b}${e}${xe}`}if(c(this,T)==="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,p=n.italic?`{${a}}*`:a,u=n.underline?`{${p}}_`:p;return n.strikethrough?`{${u}}~`:u}throw new Error(`Unknown TypoSupport kind: ${c(this,T)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",ae),e instanceof d?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};T=new WeakMap;var V=C,xe="\x1B[0m",Ce="\x1B[1m",Se="\x1B[2m",Re="\x1B[3m",Oe="\x1B[4m",Te="\x1B[9m",Ue={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"},Ae={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 ke(t,e){return{getDescription(){return t.description},createRunnerFromArgs(n){function r(){let o=e.generateUsage();return{metadata:t,breadcrumbs:o.positionals.map(i=>N(i.label)),positionals:o.positionals,subcommands:[],options:o.options}}try{let o=e.createRunnerFromArgs(n),i=n.consumePositional();if(i!==void 0)throw Error(`Unexpected argument: "${i}"`);return{generateUsage:r,async executeWithContext(a){return o.executeWithContext(a)}}}catch(o){return{generateUsage:r,async executeWithContext(){throw o}}}}}}function $e(t,e,n){return{getDescription(){return t.description},createRunnerFromArgs(r){try{let o=e.createRunnerFromArgs(r),i=r.consumePositional();if(i===void 0)throw new d(new l(new s("Missing required positional argument: "),new s("SUBCOMMAND",m)));let a=n[i];if(a===void 0)throw new d(new l(new s("Invalid value for positional argument: "),new s("SUBCOMMAND",m),new s(`: "${i}"`)));let p=a.createRunnerFromArgs(r);return{generateUsage(){let u=e.generateUsage(),b=p.generateUsage();return{metadata:b.metadata,breadcrumbs:u.positionals.map(O=>N(O.label)).concat([pe(i)]).concat(b.breadcrumbs),positionals:u.positionals.concat(b.positionals),subcommands:b.subcommands,options:u.options.concat(b.options)}},async executeWithContext(u){return await p.executeWithContext(await o.executeWithContext(u))}}}catch(o){return{generateUsage(){let i=e.generateUsage();return{metadata:t,breadcrumbs:i.positionals.map(a=>N(a.label)).concat([pe("<SUBCOMMAND>")]),positionals:i.positionals,subcommands:Object.entries(n).map(([a,p])=>({name:a,description:p.getDescription()})),options:i.options}},async executeWithContext(){throw o}}}}}}function Pe(t,e,n){return{getDescription(){return t.description},createRunnerFromArgs(r){let o=e.createRunnerFromArgs(r),i=n.createRunnerFromArgs(r);return{generateUsage(){let a=e.generateUsage(),p=i.generateUsage();return{metadata:p.metadata,breadcrumbs:a.positionals.map(u=>N(u.label)).concat(p.breadcrumbs),positionals:a.positionals.concat(p.positionals),subcommands:p.subcommands,options:a.options.concat(p.options)}},async executeWithContext(a){return await i.executeWithContext(await o.executeWithContext(a))}}}}}function N(t){return{positional:t}}function pe(t){return{command:t}}function Ve(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}},createRunnerFromArgs(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{executeWithContext(i){let a={};for(let p in r)a[p]=r[p].getValue();return e(i,{options:a,positionals:o})}}}}}var j={label:"BOOLEAN",decoder(t){let e=t.toLowerCase();if(e==="true"||e==="yes")return!0;if(e==="false"||e==="no")return!1;throw new Error(`Invalid value: "${t}"`)}},ve={label:"DATE",decoder(t){let e=Date.parse(t);if(isNaN(e))throw new Error(`Invalid ISO_8601 value: "${t}"`);return new Date(e)}},Ee={label:"URL",decoder(t){return new URL(t)}},Be={label:"STRING",decoder(t){return t}},Ge={label:"NUMBER",decoder(t){return Number(t)}},Le={label:"BIGINT",decoder(t){return BigInt(t)}};function Ie(t,e){return{label:e.label,decoder:n=>e.decoder(x(t,n,()=>new l(new s(t.label,y))))}}function Me(t,e){let n=new Set(e);return{label:t.label,decoder(r){let o=x(t,r,()=>new l(new s(t.label,y)));if(n.has(o))return o;let i=e.map(a=>`"${a}"`).join("|");throw new Error(`Unexpected value: "${r}" (expected: ${i})`)}}}function We(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 Error(`Invalid tuple parts: ${JSON.stringify(r)}`);return r.map((o,i)=>x(t[i],o,()=>new l(new s(t[i].label,y),new s(` at position ${i}`))))}}}function De(t,e=","){return{label:`${t.label}[${e}${t.label}]...`,decoder(n){return n.split(e).map((r,o)=>x(t,r,()=>new l(new s(t.label,y),new s(` at position ${o}`))))}}}function x(t,e,n){try{return t.decoder(e)}catch(r){throw new d(n(),r)}}function Ke(t){return{generateUsage(){return{description:t.description,long:t.long,short:t.short,label:void 0}},createGetter(e){let n=Q(e,{...t,valued:!1});return{getValue(){let r=e.getOptionValues(n);if(r.length>1)throw new d(new l(new s("Option value for: "),new s(`--${t.long}`,m),new s(": must not be set multiple times")));let o=r[0];if(o===void 0)try{return t.default?t.default():!1}catch(i){throw new d(new l(new s("Failed to compute default value for: "),new s(`--${t.long}`,m)),i)}return x(j,o,()=>new l(new s(`--${t.long}`,m),new s(": "),new s(j.label,y)))}}}}}function Fe(t){let e=t.label??t.type.label;return{generateUsage(){return{description:t.description,long:t.long,short:t.short,label:`<${e}>`}},createGetter(n){let r=Q(n,{...t,valued:!0});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new d(new l(new s("Option value for: "),new s(`--${t.long}`,m),new s(": must not be set multiple times")));let i=o[0];if(i===void 0)try{return t.default()}catch(a){throw new d(new l(new s("Failed to compute default value for: "),new s(`--${t.long}`,m)),a)}return x(t.type,i,()=>new l(new s(`--${t.long}`,m),new s(": "),new s(e,y)))}}}}}function Ne(t){let e=t.label??t.type.label;return{generateUsage(){return{description:t.description,long:t.long,short:t.short,label:`<${e}>`}},createGetter(n){let r=Q(n,{...t,valued:!0});return{getValue(){return n.getOptionValues(r).map(o=>x(t.type,o,()=>new l(new s(`--${t.long}`,m),new s(": "),new s(e,y))))}}}}}function Q(t,e){let{long:n,short:r,aliases:o,valued:i}=e,a=n?[n]:[];o?.longs&&a.push(...o?.longs);let p=r?[r]:[];return o?.shorts&&p.push(...o?.shorts),t.registerOption({longs:a,shorts:p,valued:i})}function je(t){let e=t.label??t.type.label;return{generateUsage(){return{description:t.description,label:`<${e}>`}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)throw new d(new l(new s("Missing required positional argument: "),new s(e,y)));return x(t.type,r,()=>new l(new s(e,y)))}}}function Ye(t){let e=t.label??t.type.label;return{generateUsage(){return{description:t.description,label:`[${e}]`}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)try{return t.default()}catch(o){throw new d(new l(new s("Failed to compute default value for: "),new s(e,y)),o)}return x(t.type,r,()=>new l(new s(e,y)))}}}function qe(t){let e=t.label??t.type.label;return{generateUsage(){return{description:t.description,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(x(t.type,o,()=>new l(new s(e,y))))}return r}}}var F,L,A,v,R,E,I,g,Y,le,X,ue,Z,U,K=class{constructor(e){f(this,g);f(this,F);f(this,L);f(this,A);f(this,v);f(this,R);f(this,E);f(this,I);h(this,F,e),h(this,L,0),h(this,A,!1),h(this,v,new Map),h(this,R,new Map),h(this,E,new Map),h(this,I,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,R).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,R).has(i))throw new Error(`Option -${r} overlap with shorter option: -${i}`)}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,E).set(n,e.valued),c(this,I).set(n,new Array),n}getOptionValues(e){let n=c(this,I).get(e);if(n===void 0)throw new Error(`Unregistered option: ${e}`);return n}consumePositional(){for(;;){let e=w(this,g,Y).call(this);if(e===null)return;if(w(this,g,le).call(this,e))return e}}};F=new WeakMap,L=new WeakMap,A=new WeakMap,v=new WeakMap,R=new WeakMap,E=new WeakMap,I=new WeakMap,g=new WeakSet,Y=function(){let e=c(this,F)[c(this,L)];return e===void 0?null:(ie(this,L)._++,!c(this,A)&&e==="--"?(h(this,A,!0),w(this,g,Y).call(this)):e)},le=function(e){if(c(this,A))return!0;if(e.startsWith("--")){let n=e.indexOf("=");return n===-1?w(this,g,X).call(this,e.slice(2),null):w(this,g,X).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,g,ue).call(this,e.slice(n,r),e.slice(r));if(o===!0)return!1;o===!1&&(n=r),r++}throw new d(new l(new s("Unknown option: "),new s(`-${e.slice(n)}`,m)))}return!0},X=function(e,n){let r=`--${e}`,o=c(this,v).get(e);if(o!==void 0)return n!==null?w(this,g,U).call(this,o,n):c(this,E).get(o)?w(this,g,U).call(this,o,w(this,g,Z).call(this,r)):w(this,g,U).call(this,o,"true");throw new d(new l(new s("Unknown option: "),new s(r,m)))},ue=function(e,n){let r=c(this,R).get(e);return r!==void 0?n.startsWith("=")?(w(this,g,U).call(this,r,n.slice(1)),!0):c(this,E).get(r)?(n===""?w(this,g,U).call(this,r,w(this,g,Z).call(this,`-${e}`)):w(this,g,U).call(this,r,n),!0):(w(this,g,U).call(this,r,"true"),n===""):null},Z=function(e){let n=w(this,g,Y).call(this);if(n===null)throw new d(new l(new s("Option parsing: "),new s(e,m),new s(": requires a value, but got end of input")));if(c(this,A))throw new d(new l(new s("Option parsing: "),new s(e,m),new s(': requires a value before "--"')));if(n.startsWith("-"))throw new d(new l(new s("Option parsing: "),new s(e,m),new s(`: requires a value, but got: "${n}"`)));return n},U=function(e,n){this.getOptionValues(e).push(n)};function ne(t){let{cliName:e,commandUsage:n,typoSupport:r}=t,o=new Array;o.push(He(n.metadata.description).computeStyledString(r)),n.metadata.details&&o.push(ce(n.metadata.details).computeStyledString(r)),o.push("");let i=[Je("Usage:").computeStyledString(r),M(e).computeStyledString(r)].concat(n.breadcrumbs.map(a=>{if("positional"in a)return te(a.positional).computeStyledString(r);if("command"in a)return M(a.command).computeStyledString(r);throw new Error(`Unknown breadcrumb: ${JSON.stringify(a)}`)}));if(o.push(i.join(" ")),n.positionals.length>0){o.push(""),o.push(ee("Positionals:").computeStyledString(r));let a=new P;for(let p of n.positionals){let u=new Array;u.push(new l(k())),u.push(new l(te(p.label))),p.description&&(u.push(new l(k())),u.push(new l(_(p.description)))),a.pushRow(u)}o.push(...a.computeStyledGrid(r).map(p=>p.join("")))}if(n.subcommands.length>0){o.push(""),o.push(ee("Subcommands:").computeStyledString(r));let a=new P;for(let p of n.subcommands){let u=new Array;u.push(new l(k())),u.push(new l(M(p.name))),p.description&&(u.push(new l(k())),u.push(new l(_(p.description)))),a.pushRow(u)}o.push(...a.computeStyledGrid(r).map(p=>p.join("")))}if(n.options.length>0){o.push(""),o.push(ee("Options:").computeStyledString(r));let a=new P;for(let p of n.options){let u=new Array;u.push(new l(k())),p.short?u.push(new l(M(`-${p.short}`),k(", "))):u.push(new l),p.label?u.push(new l(M(`--${p.long}`),k(" "),te(p.label))):u.push(new l(M(`--${p.long}`),ce("[=no]"))),p.description&&(u.push(new l(k())),u.push(new l(_(p.description)))),a.pushRow(u)}o.push(...a.computeStyledGrid(r).map(p=>p.join("")))}return o.push(""),o}function He(t){return new s(t,{bold:!0})}function _(t){return new s(t)}function ce(t){return new s(t,{italic:!0,dim:!0})}function Je(t){return new s(t,{fgColor:"darkMagenta",bold:!0})}function ee(t){return new s(t,{fgColor:"darkGreen",bold:!0})}function M(t){return new s(t,m)}function te(t){return new s(t,y)}function k(t){return new s(t??" ")}async function ze(t,e,n,r,o){let i=new K(e),a=o?.buildVersion;a&&i.registerOption({shorts:[],longs:["version"],valued:!1});let p=o?.usageOnHelp??!0;p&&i.registerOption({shorts:[],longs:["help"],valued:!1});let u=r.createRunnerFromArgs(i);for(;i.consumePositional()!==void 0;);let b=o?.onLogStdOut??console.log,O=o?.onExit??process.exit;if(a&&i.getOptionValues("--version").length>0)return b([t,a].join(" ")),O(0);if(p&&i.getOptionValues("--help").length>0){let W=de(o?.useColors);return b(ge(t,u,W)),O(0)}try{return await u.executeWithContext(n),O(0)}catch(W){if(o?.onError)o.onError(W);else{let oe=o?.onLogStdErr??console.error,re=de(o?.useColors);(o?.usageOnError??!0)&&oe(ge(t,u,re)),oe(re.computeStyledErrorMessage(W))}return O(1)}}function ge(t,e,n){return ne({cliName:t,commandUsage:e.generateUsage(),typoSupport:n}).join(`
2
+ `)}function de(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,typoStyleUserInput,usageToStyledLines});
3
3
  //# sourceMappingURL=index.js.map