cli-kiss 0.0.12 → 0.1.1
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 +1 -0
- package/dist/index.d.ts +145 -98
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -3
- package/src/lib/Command.ts +113 -65
- package/src/lib/Operation.ts +81 -0
- package/src/lib/Option.ts +147 -72
- package/src/lib/Positional.ts +123 -0
- package/src/lib/Reader.ts +137 -201
- package/src/lib/Run.ts +54 -69
- package/src/lib/Type.ts +85 -25
- package/src/lib/Typo.ts +220 -60
- package/src/lib/Usage.ts +91 -72
- package/tests/unit.Reader.aliases.ts +12 -11
- package/tests/unit.Reader.commons.ts +85 -45
- package/tests/unit.Reader.shortBig.ts +57 -33
- package/tests/unit.command.execute.ts +30 -27
- package/tests/unit.command.usage.ts +75 -96
- package/tests/unit.runner.cycle.ts +362 -0
- package/src/lib/Argument.ts +0 -93
- package/src/lib/Execution.ts +0 -84
- package/src/lib/Grid.ts +0 -60
package/.prettierrc
CHANGED
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:
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}):
|
|
50
|
-
declare function
|
|
51
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
95
|
-
|
|
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,71 @@ declare function optionSingleValue<Value>(definition: {
|
|
|
102
142
|
};
|
|
103
143
|
label?: Uppercase<string>;
|
|
104
144
|
type: Type<Value>;
|
|
145
|
+
}): Option<Array<Value>>;
|
|
146
|
+
|
|
147
|
+
type Positional<Value> = {
|
|
148
|
+
generateUsage(): PositionalUsage;
|
|
149
|
+
consumePositionals(readerPositionals: ReaderPositionals): Value;
|
|
150
|
+
};
|
|
151
|
+
type PositionalUsage = {
|
|
152
|
+
description: string | undefined;
|
|
153
|
+
label: Uppercase<string>;
|
|
154
|
+
};
|
|
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>;
|
|
105
164
|
default: () => Value;
|
|
106
|
-
}):
|
|
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>>;
|
|
107
172
|
|
|
108
|
-
type
|
|
109
|
-
generateUsage():
|
|
110
|
-
|
|
173
|
+
type Operation<Input, Output> = {
|
|
174
|
+
generateUsage(): OperationUsage;
|
|
175
|
+
createFactory(readerArgs: ReaderArgs): OperationFactory<Input, Output>;
|
|
111
176
|
};
|
|
112
|
-
type
|
|
113
|
-
|
|
177
|
+
type OperationFactory<Input, Output> = {
|
|
178
|
+
createInstance(): OperationInstance<Input, Output>;
|
|
114
179
|
};
|
|
115
|
-
type
|
|
116
|
-
executeWithContext(
|
|
180
|
+
type OperationInstance<Input, Output> = {
|
|
181
|
+
executeWithContext(input: Input): Promise<Output>;
|
|
117
182
|
};
|
|
118
|
-
type
|
|
183
|
+
type OperationUsage = {
|
|
119
184
|
options: Array<OptionUsage>;
|
|
120
|
-
|
|
185
|
+
positionals: Array<PositionalUsage>;
|
|
121
186
|
};
|
|
122
|
-
declare function
|
|
187
|
+
declare function operation<Context, Result, Options extends {
|
|
123
188
|
[option: string]: any;
|
|
124
|
-
}, const
|
|
189
|
+
}, const Positionals extends Array<any>>(inputs: {
|
|
125
190
|
options: {
|
|
126
191
|
[K in keyof Options]: Option<Options[K]>;
|
|
127
192
|
};
|
|
128
|
-
|
|
129
|
-
[K in keyof
|
|
193
|
+
positionals: {
|
|
194
|
+
[K in keyof Positionals]: Positional<Positionals[K]>;
|
|
130
195
|
};
|
|
131
196
|
}, handler: (context: Context, inputs: {
|
|
132
197
|
options: Options;
|
|
133
|
-
|
|
134
|
-
}) => Promise<Result>):
|
|
198
|
+
positionals: Positionals;
|
|
199
|
+
}) => Promise<Result>): Operation<Context, Result>;
|
|
135
200
|
|
|
136
201
|
type Command<Context, Result> = {
|
|
137
202
|
getDescription(): string | undefined;
|
|
138
|
-
|
|
203
|
+
createFactory(readerArgs: ReaderArgs): CommandFactory<Context, Result>;
|
|
139
204
|
};
|
|
140
|
-
type
|
|
205
|
+
type CommandFactory<Context, Result> = {
|
|
141
206
|
generateUsage(): CommandUsage;
|
|
142
|
-
|
|
207
|
+
createInstance(): CommandInstance<Context, Result>;
|
|
143
208
|
};
|
|
144
|
-
type
|
|
209
|
+
type CommandInstance<Context, Result> = {
|
|
145
210
|
executeWithContext(context: Context): Promise<Result>;
|
|
146
211
|
};
|
|
147
212
|
type CommandMetadata = {
|
|
@@ -151,57 +216,39 @@ type CommandMetadata = {
|
|
|
151
216
|
type CommandUsage = {
|
|
152
217
|
metadata: CommandMetadata;
|
|
153
218
|
breadcrumbs: Array<CommandUsageBreadcrumb>;
|
|
219
|
+
positionals: Array<PositionalUsage>;
|
|
220
|
+
subcommands: Array<CommandUsageSubcommand>;
|
|
154
221
|
options: Array<OptionUsage>;
|
|
155
|
-
arguments: Array<ArgumentUsage>;
|
|
156
|
-
subcommands: Array<{
|
|
157
|
-
name: string;
|
|
158
|
-
description: string | undefined;
|
|
159
|
-
}>;
|
|
160
222
|
};
|
|
161
223
|
type CommandUsageBreadcrumb = {
|
|
162
|
-
|
|
224
|
+
positional: string;
|
|
163
225
|
} | {
|
|
164
226
|
command: string;
|
|
165
227
|
};
|
|
166
|
-
|
|
167
|
-
|
|
228
|
+
type CommandUsageSubcommand = {
|
|
229
|
+
name: string;
|
|
230
|
+
description: string | undefined;
|
|
231
|
+
};
|
|
232
|
+
declare function command<Context, Result>(metadata: CommandMetadata, operation: Operation<Context, Result>): Command<Context, Result>;
|
|
233
|
+
declare function commandWithSubcommands<Context, Payload, Result>(metadata: CommandMetadata, operation: Operation<Context, Payload>, subcommands: {
|
|
168
234
|
[subcommand: Lowercase<string>]: Command<Payload, Result>;
|
|
169
235
|
}): Command<Context, Result>;
|
|
236
|
+
declare function commandChained<Context, Payload, Result>(metadata: CommandMetadata, operation: Operation<Context, Payload>, nextCommand: Command<Payload, Result>): Command<Context, Result>;
|
|
170
237
|
|
|
171
|
-
|
|
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?: {
|
|
191
|
-
usageOnError?: boolean | undefined;
|
|
238
|
+
declare function runAsCliAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command: Command<Context, void>, application?: {
|
|
192
239
|
usageOnHelp?: boolean | undefined;
|
|
193
240
|
buildVersion?: string | undefined;
|
|
194
241
|
useColors?: boolean | undefined;
|
|
195
242
|
onLogStdOut?: ((message: string) => void) | undefined;
|
|
196
243
|
onLogStdErr?: ((message: string) => void) | undefined;
|
|
197
244
|
onExit?: ((code: number) => never) | undefined;
|
|
198
|
-
|
|
245
|
+
onExecutionError?: ((error: unknown) => void) | undefined;
|
|
199
246
|
}): Promise<never>;
|
|
200
247
|
|
|
201
|
-
declare function
|
|
248
|
+
declare function usageToStyledLines(params: {
|
|
202
249
|
cliName: Lowercase<string>;
|
|
203
250
|
commandUsage: CommandUsage;
|
|
204
251
|
typoSupport: TypoSupport;
|
|
205
252
|
}): string[];
|
|
206
253
|
|
|
207
|
-
export { type
|
|
254
|
+
export { type Command, type CommandFactory, type CommandInstance, type CommandMetadata, type CommandUsage, type CommandUsageBreadcrumb, type CommandUsageSubcommand, type Operation, 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, 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
|
|
1
|
+
"use strict";var J=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var he=Object.prototype.hasOwnProperty;var ae=t=>{throw TypeError(t)};var we=(t,e)=>{for(var n in e)J(t,n,{get:e[n],enumerable:!0})},fe=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ye(e))!he.call(t,r)&&r!==n&&J(t,r,{get:()=>e[r],enumerable:!(o=me(e,r))||o.enumerable});return t};var be=t=>fe(J({},"__esModule",{value:!0}),t);var z=(t,e,n)=>e.has(t)||ae("Cannot "+n);var c=(t,e,n)=>(z(t,e,"read from private field"),n?n.call(t):e.get(t)),b=(t,e,n)=>e.has(t)?ae("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),w=(t,e,n,o)=>(z(t,e,"write to private field"),o?o.call(t,n):e.set(t,n),n),f=(t,e,n)=>(z(t,e,"access private method"),n);var ie=(t,e,n,o)=>({set _(r){w(t,e,r,n)},get _(){return c(t,e,o)}});var Xe={};we(Xe,{ReaderArgs:()=>W,TypoError:()=>d,TypoGrid:()=>I,TypoString:()=>a,TypoSupport:()=>P,TypoText:()=>l,command:()=>Ae,commandChained:()=>Ie,commandWithSubcommands:()=>$e,operation:()=>Pe,optionFlag:()=>We,optionRepeatable:()=>Ne,optionSingleValue:()=>Ke,positionalOptional:()=>Ye,positionalRequired:()=>je,positionalVariadics:()=>qe,runAsCliAndExit:()=>ze,typeBigInt:()=>Ge,typeBoolean:()=>Y,typeDate:()=>Ve,typeDecode:()=>x,typeList:()=>De,typeMapped:()=>Le,typeNumber:()=>Be,typeOneOf:()=>Fe,typeString:()=>Ee,typeTuple:()=>Me,typeUrl:()=>ve,typoStyleConstants:()=>m,typoStyleFailure:()=>pe,typoStyleUserInput:()=>y,usageToStyledLines:()=>re});module.exports=be(Xe);var m={fgColor:"darkCyan",bold:!0},y={fgColor:"darkBlue",bold:!0},pe={fgColor:"darkRed",bold:!0},E,D,a=class{constructor(e,n={}){b(this,E);b(this,D);w(this,E,e),w(this,D,n)}getRawString(){return c(this,E)}computeStyledString(e){return e.computeStyledString(c(this,E),c(this,D))}};E=new WeakMap,D=new WeakMap;var S,Q=class Q{constructor(...e){b(this,S);w(this,S,[]);for(let n of e)n instanceof Q?this.pushText(n):n instanceof a?this.pushString(n):typeof n=="string"&&this.pushString(new a(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=Q,$,I=class{constructor(){b(this,$);w(this,$,[])}pushRow(e){c(this,$).push(e)}computeStyledGrid(e){let n=new Array,o=new Array;for(let r of c(this,$))for(let s=0;s<r.length;s++){let p=r[s].computeRawLength();(n[s]===void 0||p>n[s])&&(n[s]=p)}for(let r of c(this,$)){let s=new Array;for(let i=0;i<r.length;i++){let p=r[i],u=p.computeStyledString(e);if(s.push(u),i<r.length-1){let h=p.computeRawLength(),O=" ".repeat(n[i]-h);s.push(O)}}o.push(s)}return o}};$=new WeakMap;var B,X=class X extends Error{constructor(n,o){let r=new l;r.pushText(n),o instanceof Error?r.pushString(new a(`: ${o.message}`)):o instanceof X?(r.pushString(new a(": ")),r.pushText(c(o,B))):o!==void 0&&r.pushString(new a(`: ${String(o)}`));super(r.computeRawString());b(this,B);w(this,B,r)}computeStyledString(n){return c(this,B).computeStyledString(n)}};B=new WeakMap;var d=X,U,C=class C{constructor(e){b(this,U);w(this,U,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,U)==="none")return e;if(c(this,U)==="tty"){let o=n.fgColor?Re[n.fgColor]:"",r=n.bgColor?ke[n.bgColor]:"",s=n.bold?Ce:"",i=n.dim?Se:"",p=n.italic?Te:"",u=n.underline?Oe:"",h=n.strikethrough?Ue:"";return`${o}${r}${s}${i}${p}${u}${h}${e}${xe}`}if(c(this,U)==="mock"){let o=n.fgColor?`{${e}}@${n.fgColor}`:e,r=n.bgColor?`{${o}}#${n.bgColor}`:o,s=n.bold?`{${r}}+`:r,i=n.dim?`{${s}}-`:s,p=n.italic?`{${i}}*`:i,u=n.underline?`{${p}}_`:p;return n.strikethrough?`{${u}}~`:u}throw new Error(`Unknown TypoSupport kind: ${c(this,U)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",pe),e instanceof d?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};U=new WeakMap;var P=C,xe="\x1B[0m",Ce="\x1B[1m",Se="\x1B[2m",Te="\x1B[3m",Oe="\x1B[4m",Ue="\x1B[9m",Re={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"},ke={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 Ae(t,e){return{getDescription(){return t.description},createFactory(n){function o(){let r=e.generateUsage();return{metadata:t,breadcrumbs:r.positionals.map(s=>j(s.label)),positionals:r.positionals,subcommands:[],options:r.options}}try{let r=e.createFactory(n),s=n.consumePositional();if(s!==void 0)throw Error(`Unexpected argument: "${s}"`);return{generateUsage:o,createInstance(){let i=r.createInstance();return{async executeWithContext(p){return await i.executeWithContext(p)}}}}}catch(r){return{generateUsage:o,createInstance(){throw r}}}}}}function $e(t,e,n){return{getDescription(){return t.description},createFactory(o){try{let r=e.createFactory(o),s=o.consumePositional();if(s===void 0)throw new d(new l(new a("<SUBCOMMAND>",m),new a(": Is required, but was not provided")));let i=n[s];if(i===void 0)throw new d(new l(new a("<SUBCOMMAND>",m),new a(`: Invalid value: "${s}"`)));let p=i.createFactory(o);return{generateUsage(){let u=e.generateUsage(),h=p.generateUsage();return{metadata:h.metadata,breadcrumbs:u.positionals.map(O=>j(O.label)).concat([le(s)]).concat(h.breadcrumbs),positionals:u.positionals.concat(h.positionals),subcommands:h.subcommands,options:u.options.concat(h.options)}},createInstance(){let u=r.createInstance(),h=p.createInstance();return{async executeWithContext(O){return await h.executeWithContext(await u.executeWithContext(O))}}}}}catch(r){return{generateUsage(){let s=e.generateUsage();return{metadata:t,breadcrumbs:s.positionals.map(i=>j(i.label)).concat([le("<SUBCOMMAND>")]),positionals:s.positionals,subcommands:Object.entries(n).map(([i,p])=>({name:i,description:p.getDescription()})),options:s.options}},createInstance(){throw r}}}}}}function Ie(t,e,n){return{getDescription(){return t.description},createFactory(o){let r=e.createFactory(o),s=n.createFactory(o);return{generateUsage(){let i=e.generateUsage(),p=s.generateUsage();return{metadata:p.metadata,breadcrumbs:i.positionals.map(u=>j(u.label)).concat(p.breadcrumbs),positionals:i.positionals.concat(p.positionals),subcommands:p.subcommands,options:i.options.concat(p.options)}},createInstance(){let i=r.createInstance(),p=s.createInstance();return{async executeWithContext(u){return await p.executeWithContext(await i.executeWithContext(u))}}}}}}}function j(t){return{positional:t}}function le(t){return{command:t}}function Pe(t,e){return{generateUsage(){let n=new Array;for(let r in t.options){let s=t.options[r];s&&n.push(s.generateUsage())}let o=new Array;for(let r of t.positionals)o.push(r.generateUsage());return{options:n,positionals:o}},createFactory(n){let o={};for(let s in t.options){let i=t.options[s];o[s]=i.createGetter(n)}let r=[];for(let s of t.positionals)r.push(s.consumePositionals(n));return{createInstance(){let s={};for(let i in o)s[i]=o[i].getValue();return{executeWithContext(i){return e(i,{options:s,positionals:r})}}}}}}}var Y={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)}},ve={label:"URL",decoder(t){return new URL(t)}},Ee={label:"STRING",decoder(t){return t}},Be={label:"NUMBER",decoder(t){return Number(t)}},Ge={label:"BIGINT",decoder(t){return BigInt(t)}};function Le(t,e){return{label:e.label,decoder:n=>e.decoder(x(t,n,()=>new l(new a(t.label,y))))}}function Fe(t,e){let n=new Set(e);return{label:t.label,decoder(o){let r=x(t,o,()=>new l(new a(t.label,y)));if(n.has(r))return r;let s=e.map(i=>`"${i}"`).join("|");throw new Error(`Unexpected value: "${o}" (expected: ${s})`)}}}function Me(t,e=","){return{label:t.map(n=>n.label).join(e),decoder(n){let o=n.split(e,t.length);if(o.length!==t.length)throw new Error(`Invalid tuple parts: ${JSON.stringify(o)}`);return o.map((r,s)=>x(t[s],r,()=>new l(new a(t[s].label,y),new a(` at position ${s}`))))}}}function De(t,e=","){return{label:`${t.label}[${e}${t.label}]...`,decoder(n){return n.split(e).map((o,r)=>x(t,o,()=>new l(new a(t.label,y),new a(` at position ${r}`))))}}}function x(t,e,n){try{return t.decoder(e)}catch(o){throw new d(n(),o)}}function We(t){let e=`<${Y.label}>`;return{generateUsage(){return{description:t.description,long:t.long,short:t.short,label:void 0}},createGetter(n){let o=Z(n,{...t,valued:!1});return{getValue(){let r=n.getOptionValues(o);if(r.length>1)throw new d(new l(new a(`--${t.long}`,m),new a(": Must not be set multiple times")));let s=r[0];if(s===void 0)try{return t.default?t.default():!1}catch(i){throw new d(new l(new a(`--${t.long}`,m),new a(": Failed to compute default value")),i)}return x(Y,s,()=>new l(new a(`--${t.long}`,m),new a(": "),new a(e,y)))}}}}}function Ke(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 o=Z(n,{...t,valued:!0});return{getValue(){let r=n.getOptionValues(o);if(r.length>1)throw new d(new l(new a(`--${t.long}`,m),new a(": Must not be set multiple times")));let s=r[0];if(s===void 0)try{return t.default()}catch(i){throw new d(new l(new a(`--${t.long}`,m),new a(": Failed to compute default value")),i)}return x(t.type,s,()=>new l(new a(`--${t.long}`,m),new a(": "),new a(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 o=Z(n,{...t,valued:!0});return{getValue(){return n.getOptionValues(o).map(r=>x(t.type,r,()=>new l(new a(`--${t.long}`,m),new a(": "),new a(e,y))))}}}}}function Z(t,e){let{long:n,short:o,aliases:r,valued:s}=e,i=n?[n]:[];r?.longs&&i.push(...r?.longs);let p=o?[o]:[];return r?.shorts&&p.push(...r?.shorts),t.registerOption({longs:i,shorts:p,valued:s})}function je(t){let e=`<${t.label??t.type.label}>`;return{generateUsage(){return{description:t.description,label:e}},consumePositionals(n){let o=n.consumePositional();if(o===void 0)throw new d(new l(new a(e,y),new a(": Is required, but was not provided")));return x(t.type,o,()=>new l(new a(e,y)))}}}function Ye(t){let e=`[${t.label??t.type.label}]`;return{generateUsage(){return{description:t.description,label:e}},consumePositionals(n){let o=n.consumePositional();if(o===void 0)try{return t.default()}catch(r){throw new d(new l(new a(e,y),new a(": Failed to compute default value")),r)}return x(t.type,o,()=>new l(new a(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 o=[];for(;;){let r=n.consumePositional();if(r===void 0||r===t.endDelimiter)break;o.push(x(t.type,r,()=>new l(new a(e,y))))}return o}}}var K,G,k,V,T,v,L,g,q,ue,_,ce,ee,R,W=class{constructor(e){b(this,g);b(this,K);b(this,G);b(this,k);b(this,V);b(this,T);b(this,v);b(this,L);w(this,K,e),w(this,G,0),w(this,k,!1),w(this,V,new Map),w(this,T,new Map),w(this,v,new Map),w(this,L,new Map)}registerOption(e){let n=[...e.longs.map(o=>`--${o}`),...e.shorts.map(o=>`-${o}`)].join(", ");for(let o of e.longs){if(c(this,V).has(o))throw new Error(`Option already registered: --${o}`);c(this,V).set(o,n)}for(let o of e.shorts){if(c(this,T).has(o))throw new Error(`Option already registered: -${o}`);for(let r=0;r<o.length;r++){let s=o.slice(0,r);if(c(this,T).has(s))throw new Error(`Option -${o} overlap with shorter option: -${s}`)}for(let r of c(this,T).keys())if(r.startsWith(o))throw new Error(`Option -${o} overlap with longer option: -${r}`);c(this,T).set(o,n)}return c(this,v).set(n,e.valued),c(this,L).set(n,new Array),n}getOptionValues(e){let n=c(this,L).get(e);if(n===void 0)throw new Error(`Unregistered option: ${e}`);return n}consumePositional(){for(;;){let e=f(this,g,q).call(this);if(e===null)return;if(f(this,g,ue).call(this,e))return e}}};K=new WeakMap,G=new WeakMap,k=new WeakMap,V=new WeakMap,T=new WeakMap,v=new WeakMap,L=new WeakMap,g=new WeakSet,q=function(){let e=c(this,K)[c(this,G)];return e===void 0?null:(ie(this,G)._++,!c(this,k)&&e==="--"?(w(this,k,!0),f(this,g,q).call(this)):e)},ue=function(e){if(c(this,k))return!0;if(e.startsWith("--")){let n=e.indexOf("=");return n===-1?f(this,g,_).call(this,e.slice(2),null):f(this,g,_).call(this,e.slice(2,n),e.slice(n+1)),!1}if(e.startsWith("-")){let n=1,o=2;for(;o<=e.length;){let r=f(this,g,ce).call(this,e.slice(n,o),e.slice(o));if(r===!0)return!1;r===!1&&(n=o),o++}throw new d(new l(new a(`-${e.slice(n)}`,m),new a(": Unexpected unknown option")))}return!0},_=function(e,n){let o=`--${e}`,r=c(this,V).get(e);if(r!==void 0)return n!==null?f(this,g,R).call(this,r,n):c(this,v).get(r)?f(this,g,R).call(this,r,f(this,g,ee).call(this,o)):f(this,g,R).call(this,r,"true");throw new d(new l(new a(o,m),new a(": Unexpected unknown option")))},ce=function(e,n){let o=c(this,T).get(e);return o!==void 0?n.startsWith("=")?(f(this,g,R).call(this,o,n.slice(1)),!0):c(this,v).get(o)?(n===""?f(this,g,R).call(this,o,f(this,g,ee).call(this,`-${e}`)):f(this,g,R).call(this,o,n),!0):(f(this,g,R).call(this,o,"true"),n===""):null},ee=function(e){let n=f(this,g,q).call(this);if(n===null)throw new d(new l(new a(e,m),new a(": requires a value, but got end of input")));if(c(this,k))throw new d(new l(new a(e,m),new a(': requires a value before "--"')));if(n.startsWith("-"))throw new d(new l(new a(e,m),new a(`: requires a value, but got: "${n}"`)));return n},R=function(e,n){this.getOptionValues(e).push(n)};function re(t){let{cliName:e,commandUsage:n,typoSupport:o}=t,r=new Array;r.push(He(n.metadata.description).computeStyledString(o)),n.metadata.details&&r.push(ge(n.metadata.details).computeStyledString(o)),r.push("");let s=[Je("Usage:").computeStyledString(o),F(e).computeStyledString(o)].concat(n.breadcrumbs.map(i=>{if("positional"in i)return oe(i.positional).computeStyledString(o);if("command"in i)return F(i.command).computeStyledString(o);throw new Error(`Unknown breadcrumb: ${JSON.stringify(i)}`)}));if(r.push(s.join(" ")),n.positionals.length>0){r.push(""),r.push(ne("Positionals:").computeStyledString(o));let i=new I;for(let p of n.positionals){let u=new Array;u.push(new l(A())),u.push(new l(oe(p.label))),p.description&&(u.push(new l(A())),u.push(new l(te(p.description)))),i.pushRow(u)}r.push(...i.computeStyledGrid(o).map(p=>p.join("")))}if(n.subcommands.length>0){r.push(""),r.push(ne("Subcommands:").computeStyledString(o));let i=new I;for(let p of n.subcommands){let u=new Array;u.push(new l(A())),u.push(new l(F(p.name))),p.description&&(u.push(new l(A())),u.push(new l(te(p.description)))),i.pushRow(u)}r.push(...i.computeStyledGrid(o).map(p=>p.join("")))}if(n.options.length>0){r.push(""),r.push(ne("Options:").computeStyledString(o));let i=new I;for(let p of n.options){let u=new Array;u.push(new l(A())),p.short?u.push(new l(F(`-${p.short}`),A(", "))):u.push(new l),p.label?u.push(new l(F(`--${p.long}`),A(" "),oe(p.label))):u.push(new l(F(`--${p.long}`),ge("[=no]"))),p.description&&(u.push(new l(A())),u.push(new l(te(p.description)))),i.pushRow(u)}r.push(...i.computeStyledGrid(o).map(p=>p.join("")))}return r.push(""),r}function He(t){return new a(t,{bold:!0})}function te(t){return new a(t)}function ge(t){return new a(t,{italic:!0,dim:!0})}function Je(t){return new a(t,{fgColor:"darkMagenta",bold:!0})}function ne(t){return new a(t,{fgColor:"darkGreen",bold:!0})}function F(t){return new a(t,m)}function oe(t){return new a(t,y)}function A(t){return new a(t??" ")}async function ze(t,e,n,o,r){let s=new W(e),i=r?.buildVersion;i&&s.registerOption({shorts:[],longs:["version"],valued:!1});let p=r?.usageOnHelp??!0;p&&s.registerOption({shorts:[],longs:["help"],valued:!1});let u=o.createFactory(s);for(;s.consumePositional()!==void 0;);let h=Qe(r?.useColors),O=r?.onLogStdOut??console.log,H=r?.onLogStdErr??console.error,M=r?.onExit??process.exit;if(i&&s.getOptionValues("--version").length>0)return O([t,i].join(" ")),M(0);if(p&&s.getOptionValues("--help").length>0)return O(de(t,u,h)),M(0);try{let N=u.createInstance();try{return await N.executeWithContext(n),M(0)}catch(se){return r?.onExecutionError?r.onExecutionError(se):H(h.computeStyledErrorMessage(se)),M(1)}}catch(N){return H(de(t,u,h)),H(h.computeStyledErrorMessage(N)),M(1)}}function de(t,e,n){return re({cliName:t,commandUsage:e.generateUsage(),typoSupport:n}).join(`
|
|
2
|
+
`)}function Qe(t){return t===void 0?P.inferFromProcess():t?P.tty():P.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
|