cli-kiss 0.2.8 → 0.2.9
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/README.md +8 -3
- package/dist/index.d.ts +89 -69
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/guide/01_getting_started.md +2 -2
- package/docs/guide/02_commands.md +2 -2
- package/docs/guide/04_positionals.md +9 -9
- package/docs/guide/05_input_types.md +8 -6
- package/package.json +1 -1
- package/src/lib/Command.ts +8 -3
- package/src/lib/Operation.ts +13 -5
- package/src/lib/Option.ts +22 -20
- package/src/lib/Positional.ts +17 -12
- package/src/lib/Reader.ts +14 -20
- package/src/lib/Run.ts +2 -2
- package/src/lib/Type.ts +145 -120
- package/src/lib/Typo.ts +1 -1
- package/tests/unit.Reader.commons.ts +29 -42
- package/tests/unit.Reader.parsings.ts +3 -3
- package/tests/unit.Reader.shortBig.ts +29 -40
- package/tests/unit.command.aliases.ts +10 -22
- package/tests/unit.command.execute.ts +5 -5
- package/tests/unit.command.usage.ts +8 -8
- package/tests/unit.runner.cycle.ts +31 -18
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
optionFlag,
|
|
26
26
|
positionalRequired,
|
|
27
27
|
runAndExit,
|
|
28
|
-
|
|
28
|
+
typeString,
|
|
29
29
|
} from "cli-kiss";
|
|
30
30
|
|
|
31
31
|
const greet = command(
|
|
@@ -35,7 +35,12 @@ const greet = command(
|
|
|
35
35
|
options: {
|
|
36
36
|
loud: optionFlag({ long: "loud", description: "Print in uppercase" }),
|
|
37
37
|
},
|
|
38
|
-
positionals: [
|
|
38
|
+
positionals: [
|
|
39
|
+
positionalRequired({
|
|
40
|
+
type: typeString("name"),
|
|
41
|
+
description: "The name of the person to greet",
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
39
44
|
},
|
|
40
45
|
async (_ctx, { options: { loud }, positionals: [name] }) => {
|
|
41
46
|
const text = `Hello, ${name}!`;
|
|
@@ -59,7 +64,7 @@ Usage: greet <name>
|
|
|
59
64
|
Greet someone
|
|
60
65
|
|
|
61
66
|
Positionals:
|
|
62
|
-
<name>
|
|
67
|
+
<name> The name of the person to greet
|
|
63
68
|
|
|
64
69
|
Options:
|
|
65
70
|
--loud[=no] Print in uppercase
|
package/dist/index.d.ts
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Represents the parsing specification for a long option
|
|
2
3
|
*/
|
|
3
4
|
type ReaderOptionLongSpec = {
|
|
4
5
|
key: string;
|
|
5
6
|
nextGuard: ReaderOptionNextGuard;
|
|
6
7
|
};
|
|
7
8
|
/**
|
|
9
|
+
* Represents the parsing specification for a short option
|
|
8
10
|
*/
|
|
9
|
-
type ReaderOptionShortSpec = {
|
|
10
|
-
|
|
11
|
-
restGuard: ReaderOptionRestGuard;
|
|
12
|
-
nextGuard: ReaderOptionNextGuard;
|
|
11
|
+
type ReaderOptionShortSpec = ReaderOptionLongSpec & {
|
|
12
|
+
consumeGroupRestAsValue: boolean;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
|
|
16
|
-
type ReaderOptionRestGuard = (rest: string) => boolean;
|
|
17
|
-
/**
|
|
15
|
+
* Determines whether the next token is valid for a given option.
|
|
18
16
|
*/
|
|
19
17
|
type ReaderOptionNextGuard = (value: ReaderOptionValue, next: string | undefined) => boolean;
|
|
20
18
|
/**
|
|
21
|
-
|
|
22
|
-
type ReaderOptionResult = {
|
|
23
|
-
identifier: string;
|
|
24
|
-
values: ReadonlyArray<ReaderOptionValue>;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
19
|
+
* Represents the values parsed for an option.
|
|
27
20
|
*/
|
|
28
21
|
type ReaderOptionValue = {
|
|
29
22
|
inlined: string | null;
|
|
30
23
|
separated: ReadonlyArray<string>;
|
|
31
24
|
};
|
|
32
25
|
/**
|
|
26
|
+
* Returns the parsed values for a registered option.
|
|
33
27
|
*/
|
|
34
|
-
type ReaderOptionGetter = () =>
|
|
28
|
+
type ReaderOptionGetter = () => ReadonlyArray<ReaderOptionValue>;
|
|
35
29
|
/**
|
|
36
30
|
* Option registration/query interface. Subset of {@link ReaderArgs}.
|
|
37
31
|
*/
|
|
@@ -67,9 +61,11 @@ declare class ReaderArgs {
|
|
|
67
61
|
*/
|
|
68
62
|
constructor(tokens: ReadonlyArray<string>);
|
|
69
63
|
/**
|
|
64
|
+
* Registers a long option and returns a getter for its parsed values.
|
|
70
65
|
*/
|
|
71
66
|
registerOptionLong(longSpec: ReaderOptionLongSpec): ReaderOptionGetter;
|
|
72
67
|
/**
|
|
68
|
+
* Registers a short option and returns a getter for its parsed values.
|
|
73
69
|
*/
|
|
74
70
|
registerOptionShort(shortSpec: ReaderOptionShortSpec): ReaderOptionGetter;
|
|
75
71
|
/**
|
|
@@ -86,9 +82,20 @@ declare class ReaderArgs {
|
|
|
86
82
|
* Decodes a raw CLI string into a typed value.
|
|
87
83
|
* A pair of a human-readable `content` name and a `decoder` function.
|
|
88
84
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
85
|
+
* Primitive Types:
|
|
86
|
+
* - {@link typeString}
|
|
87
|
+
* - {@link typeBoolean}
|
|
88
|
+
* - {@link typeNumber},
|
|
89
|
+
* - {@link typeInteger}
|
|
90
|
+
* - {@link typeDatetime}
|
|
91
|
+
* - {@link typeUrl}
|
|
92
|
+
* - {@link typePath}
|
|
93
|
+
* - {@link typeChoice}
|
|
94
|
+
*
|
|
95
|
+
* Composed Types:
|
|
96
|
+
* - {@link typeMapped}
|
|
97
|
+
* - {@link typeTuple}
|
|
98
|
+
* - {@link typeList}
|
|
92
99
|
*
|
|
93
100
|
* @typeParam Value - Type produced by the decoder.
|
|
94
101
|
*/
|
|
@@ -106,6 +113,16 @@ type Type<Value> = {
|
|
|
106
113
|
*/
|
|
107
114
|
decoder(input: string): Value;
|
|
108
115
|
};
|
|
116
|
+
/**
|
|
117
|
+
* A named type that accepts any string as input.
|
|
118
|
+
* @param name - Name shown in help and errors (e.g. `"my-value"`).
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* typeString("greeting").decoder("hello") // → "hello"
|
|
122
|
+
* typeString("greeting").decoder("") // → ""
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function typeString(name?: string): Type<string>;
|
|
109
126
|
/**
|
|
110
127
|
* Decodes a string to `boolean` (case-insensitive).
|
|
111
128
|
* Used by {@link optionFlag} for `--flag=<value>`.
|
|
@@ -114,25 +131,14 @@ type Type<Value> = {
|
|
|
114
131
|
* ```ts
|
|
115
132
|
* typeBoolean("flag").decoder("true") // → true
|
|
116
133
|
* typeBoolean("flag").decoder("yes") // → true
|
|
117
|
-
* typeBoolean("flag").decoder("
|
|
118
|
-
* typeBoolean("flag").decoder("
|
|
119
|
-
* typeBoolean("flag").decoder("
|
|
134
|
+
* typeBoolean("flag").decoder("Y") // → true
|
|
135
|
+
* typeBoolean("flag").decoder("FALSE") // → false
|
|
136
|
+
* typeBoolean("flag").decoder("NO") // → false
|
|
120
137
|
* typeBoolean("flag").decoder("n") // → false
|
|
138
|
+
* typeBoolean("flag").decoder("maybe") // throws
|
|
121
139
|
* ```
|
|
122
140
|
*/
|
|
123
141
|
declare function typeBoolean(name?: string): Type<boolean>;
|
|
124
|
-
/**
|
|
125
|
-
* Parses a date/time string via `Date.parse`.
|
|
126
|
-
* Accepts any format supported by `Date.parse`, including ISO 8601.
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* typeDatetime("my-datetime").decoder("2024-01-15") // → Date object for 2024-01-15
|
|
131
|
-
* typeDatetime("my-datetime").decoder("2024-01-15T13:45:30Z") // → Date object for 2024-01-15 13:45:30 UTC
|
|
132
|
-
* typeDatetime("my-datetime").decoder("not a date") // throws TypoError
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
declare function typeDatetime(name?: string): Type<Date>;
|
|
136
142
|
/**
|
|
137
143
|
* Parses a string to `number` via `Number()`; `NaN` throws.
|
|
138
144
|
*
|
|
@@ -156,6 +162,18 @@ declare function typeNumber(name?: string): Type<number>;
|
|
|
156
162
|
* ```
|
|
157
163
|
*/
|
|
158
164
|
declare function typeInteger(name?: string): Type<bigint>;
|
|
165
|
+
/**
|
|
166
|
+
* Parses a date/time string via `Date.parse`.
|
|
167
|
+
* Accepts any format supported by `Date.parse`, including ISO 8601.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* typeDatetime("start").decoder("2024-01-15") // → Date object for 2024-01-15
|
|
172
|
+
* typeDatetime("start").decoder("2024-01-15T13:45:30Z") // → Date object for 2024-01-15 13:45:30 UTC
|
|
173
|
+
* typeDatetime("start").decoder("not a date") // throws
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
declare function typeDatetime(name?: string): Type<Date>;
|
|
159
177
|
/**
|
|
160
178
|
* Parses an absolute URL string to a `URL` object.
|
|
161
179
|
* Relative or malformed URLs throws.
|
|
@@ -168,15 +186,36 @@ declare function typeInteger(name?: string): Type<bigint>;
|
|
|
168
186
|
*/
|
|
169
187
|
declare function typeUrl(name?: string): Type<URL>;
|
|
170
188
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
189
|
+
* Creates a {@link Type} for filesystem paths with optional existence checks.
|
|
190
|
+
*
|
|
191
|
+
* @param checks - Optional checks for path existence and type (file/directory).
|
|
192
|
+
* @returns A {@link Type}`<string>` representing the path.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* const typeInputFile = typePath("input-file", { checkSyncExistAs: "file" });
|
|
197
|
+
* typeInputFile.decoder("data.txt"); // → "data.txt" if it exists and is a file, otherwise throws
|
|
198
|
+
* typeInputFile.decoder("somedir"); // throws if "somedir" exists and is a directory
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
declare function typePath(name?: string, checks?: {
|
|
202
|
+
checkSyncExistAs?: "file" | "directory" | "anything";
|
|
203
|
+
}): Type<string>;
|
|
204
|
+
/**
|
|
205
|
+
* Creates a {@link Type}`<string>` that only accepts a fixed set of values.
|
|
206
|
+
*
|
|
207
|
+
* @param name - Name shown in help and errors.
|
|
208
|
+
* @param values - Ordered list of accepted values.
|
|
209
|
+
* @returns A {@link Type}`<string>`.
|
|
210
|
+
*
|
|
173
211
|
* @example
|
|
174
212
|
* ```ts
|
|
175
|
-
*
|
|
176
|
-
*
|
|
213
|
+
* const typeEnv = typeChoice("environment", ["dev", "staging", "prod"]);
|
|
214
|
+
* typeEnv.decoder("prod") // → "prod"
|
|
215
|
+
* typeEnv.decoder("unknown") // throws
|
|
177
216
|
* ```
|
|
178
217
|
*/
|
|
179
|
-
declare function
|
|
218
|
+
declare function typeChoice<const Value extends string>(name: string, values: Array<Value>, caseSensitive?: boolean): Type<Value>;
|
|
180
219
|
/**
|
|
181
220
|
* Chains `before`'s decoder with an `after` transformation.
|
|
182
221
|
* `before` errors are prefixed with `"from: <content>"` for traceability.
|
|
@@ -191,15 +230,17 @@ declare function type(name?: string): Type<string>;
|
|
|
191
230
|
*
|
|
192
231
|
* @example
|
|
193
232
|
* ```ts
|
|
194
|
-
* const typePort =
|
|
195
|
-
* if (n < 1 || n > 65535)
|
|
233
|
+
* const typePort = typeMapped("port", typeNumber(), (n) => {
|
|
234
|
+
* if (n < 1 || n > 65535) {
|
|
235
|
+
* throw new Error("Out of range");
|
|
236
|
+
* }
|
|
196
237
|
* return n;
|
|
197
238
|
* });
|
|
198
|
-
*
|
|
199
|
-
*
|
|
239
|
+
* typePort.decoder("8080"); // → 8080
|
|
240
|
+
* typePort.decoder("70000"); // throws
|
|
200
241
|
* ```
|
|
201
242
|
*/
|
|
202
|
-
declare function
|
|
243
|
+
declare function typeMapped<Before, After>(name: string, before: Type<Before>, mapper: (value: Before) => After): Type<After>;
|
|
203
244
|
/**
|
|
204
245
|
* Adds a name to a {@link Type} for clearer error messages and help text.
|
|
205
246
|
*
|
|
@@ -208,29 +249,6 @@ declare function typeConverted<Before, After>(name: string, before: Type<Before>
|
|
|
208
249
|
* @returns A {@link Type} with the given name.
|
|
209
250
|
*/
|
|
210
251
|
declare function typeRenamed<Value>(type: Type<Value>, name: string): Type<Value>;
|
|
211
|
-
/**
|
|
212
|
-
* Creates a {@link Type} for filesystem paths with optional existence checks.
|
|
213
|
-
* @param checks - Optional checks for path existence and type (file/directory).
|
|
214
|
-
* @returns A {@link Type}`<string>` representing the path.
|
|
215
|
-
*/
|
|
216
|
-
declare function typePath(name?: string, checks?: {
|
|
217
|
-
checkSyncExistAs?: "file" | "directory" | "anything";
|
|
218
|
-
}): Type<string>;
|
|
219
|
-
/**
|
|
220
|
-
* Creates a {@link Type}`<string>` that only accepts a fixed set of values.
|
|
221
|
-
*
|
|
222
|
-
* @param name - Name shown in help and errors.
|
|
223
|
-
* @param values - Ordered list of accepted values.
|
|
224
|
-
* @returns A {@link Type}`<string>`.
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* ```ts
|
|
228
|
-
* const typeEnv = typeChoice("environment", ["dev", "staging", "prod"]);
|
|
229
|
-
* typeEnv.decoder("prod") // → "prod"
|
|
230
|
-
* typeEnv.decoder("unknown") // throws
|
|
231
|
-
* ```
|
|
232
|
-
*/
|
|
233
|
-
declare function typeChoice<const Value extends string>(name: string, values: Array<Value>, caseSensitive?: boolean): Type<Value>;
|
|
234
252
|
/**
|
|
235
253
|
* Splits a delimited string into a typed tuple.
|
|
236
254
|
* Each part is decoded by the corresponding element type; wrong count or decode failure throws.
|
|
@@ -270,7 +288,9 @@ declare function typeTuple<const Elements extends Array<any>>(elementTypes: {
|
|
|
270
288
|
* typeNumbers.decoder("1,2,3") // → [1, 2, 3]
|
|
271
289
|
* typeNumbers.decoder("1,x,3") // throws
|
|
272
290
|
* const typePaths = typeList(typePath(), ":");
|
|
273
|
-
* typePaths.decoder("/
|
|
291
|
+
* typePaths.decoder("/bin:/usr") // → ["/bin", "/usr"]
|
|
292
|
+
* typePaths.decoder("/usr/bin") // → ["/usr/bin"]
|
|
293
|
+
* typePaths.decoder("") // → throws
|
|
274
294
|
* ```
|
|
275
295
|
*/
|
|
276
296
|
declare function typeList<Value>(elementType: Type<Value>, separator?: string): Type<Array<Value>>;
|
|
@@ -931,7 +951,7 @@ declare function positionalVariadics<Value>(definition: {
|
|
|
931
951
|
* @typeParam Context - Injected at execution; forwarded to handlers.
|
|
932
952
|
* @typeParam Result - Value produced on execution; typically `void`.
|
|
933
953
|
*/
|
|
934
|
-
type Operation<Context, Result> = {
|
|
954
|
+
type Operation<Context, Result = void> = {
|
|
935
955
|
/**
|
|
936
956
|
* Returns usage metadata without consuming any arguments.
|
|
937
957
|
*/
|
|
@@ -1034,7 +1054,7 @@ declare function operation<Context, Result, const Options extends {
|
|
|
1034
1054
|
* @typeParam Context - Injected at execution; forwarded to handlers.
|
|
1035
1055
|
* @typeParam Result - Produced on execution; typically `void`.
|
|
1036
1056
|
*/
|
|
1037
|
-
type Command<Context, Result> = {
|
|
1057
|
+
type Command<Context, Result = void> = {
|
|
1038
1058
|
/**
|
|
1039
1059
|
* Returns static metadata.
|
|
1040
1060
|
*/
|
|
@@ -1243,4 +1263,4 @@ declare function suggestTextPushMessage(text: TypoText, query: string, candidate
|
|
|
1243
1263
|
hint: TypoSegment;
|
|
1244
1264
|
}>): void;
|
|
1245
1265
|
|
|
1246
|
-
export { type Command, type CommandDecoder, type CommandInformation, type CommandInterpreter, type Operation, type OperationDecoder, type OperationInterpreter, type Option, type OptionDecoder, type Positional, type PositionalDecoder, ReaderArgs, type ReaderOptionGetter, type ReaderOptionLongSpec, type ReaderOptionNextGuard, type
|
|
1266
|
+
export { type Command, type CommandDecoder, type CommandInformation, type CommandInterpreter, type Operation, type OperationDecoder, type OperationInterpreter, type Option, type OptionDecoder, type Positional, type PositionalDecoder, ReaderArgs, type ReaderOptionGetter, type ReaderOptionLongSpec, type ReaderOptionNextGuard, type ReaderOptionShortSpec, type ReaderOptionValue, type ReaderOptions, type ReaderPositionals, type RunColorMode, type Type, type TypoColor, TypoError, TypoGrid, type TypoSegment, TypoString, type TypoStyle, TypoSupport, TypoText, type UsageCommand, type UsageOption, type UsagePositional, type UsageSubcommand, command, commandChained, commandWithSubcommands, operation, optionFlag, optionRepeatable, optionSingleValue, positionalOptional, positionalRequired, positionalVariadics, runAndExit, suggestTextPushMessage, typeBoolean, typeChoice, typeDatetime, typeInteger, typeList, typeMapped, typeNumber, typePath, typeRenamed, typeString, typeTuple, typeUrl, typoStyleConstants, typoStyleFailure, typoStyleLogic, typoStyleQuote, typoStyleRegularStrong, typoStyleRegularWeaker, typoStyleTitle, typoStyleUserInput, usageToStyledLines };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var se=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var be=n=>{throw TypeError(n)};var Ee=(n,e)=>{for(var t in e)se(n,t,{get:e[t],enumerable:!0})},Ke=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of $e(e))!Ge.call(n,r)&&r!==t&&se(n,r,{get:()=>e[r],enumerable:!(o=Me(e,r))||o.enumerable});return n};var Le=n=>Ke(se({},"__esModule",{value:!0}),n);var ie=(n,e,t)=>e.has(n)||be("Cannot "+t);var g=(n,e,t)=>(ie(n,e,"read from private field"),t?t.call(n):e.get(n)),C=(n,e,t)=>e.has(n)?be("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),w=(n,e,t,o)=>(ie(n,e,"write to private field"),o?o.call(n,t):e.set(n,t),t),b=(n,e,t)=>(ie(n,e,"access private method"),t);var Se=(n,e,t,o)=>({set _(r){w(n,e,r,t)},get _(){return g(n,e,o)}});var Ct={};Ee(Ct,{ReaderArgs:()=>X,TypoError:()=>h,TypoGrid:()=>G,TypoString:()=>u,TypoSupport:()=>k,TypoText:()=>c,command:()=>Xe,commandChained:()=>_e,commandWithSubcommands:()=>Ze,operation:()=>et,optionFlag:()=>ne,optionRepeatable:()=>gt,optionSingleValue:()=>ge,positionalOptional:()=>yt,positionalRequired:()=>ht,positionalVariadics:()=>mt,runAndExit:()=>Tt,suggestTextPushMessage:()=>E,type:()=>at,typeBoolean:()=>le,typeChoice:()=>ce,typeConverted:()=>ut,typeDatetime:()=>rt,typeInteger:()=>st,typeList:()=>ct,typeNumber:()=>ot,typePath:()=>dt,typeRenamed:()=>pt,typeTuple:()=>lt,typeUrl:()=>it,typoStyleConstants:()=>R,typoStyleFailure:()=>Te,typoStyleLogic:()=>V,typoStyleQuote:()=>m,typoStyleRegularStrong:()=>pe,typoStyleRegularWeaker:()=>B,typoStyleTitle:()=>ue,typoStyleUserInput:()=>O,usageToStyledLines:()=>we});module.exports=Le(Ct);var ue={fgColor:"darkGreen",bold:!0},V={fgColor:"darkMagenta",bold:!0},m={fgColor:"darkYellow",bold:!0},Te={fgColor:"darkRed",bold:!0},R={fgColor:"darkCyan",bold:!0},O={fgColor:"darkBlue",bold:!0},pe={bold:!0},B={italic:!0,dim:!0},L,Q,Z=class Z{constructor(e,t){C(this,L);C(this,Q);w(this,L,e),w(this,Q,t)}computeStyledString(e){return e.computeStyledString(g(this,L),g(this,Q))}getRawString(){return g(this,L)}};L=new WeakMap,Q=new WeakMap,Z.elipsis=new Z("...",B);var u=Z,A,de=class de{constructor(...e){C(this,A);w(this,A,[]);for(let t of e)this.push(t)}push(...e){for(let t of e)if(typeof t=="string")g(this,A).push(new u(t));else if(t instanceof u)g(this,A).push(t);else if(t instanceof de)g(this,A).push(...g(t,A));else if(Array.isArray(t))for(let o of t)this.push(o)}pushJoined(e,t,o){for(let r=0;r<e.length;r++){if(r>0&&this.push(t),o!==void 0&&r>=o){this.push(u.elipsis);break}this.push(e[r])}}computeStyledString(e){return g(this,A).map(t=>t.computeStyledString(e)).join("")}computeRawString(){return g(this,A).map(e=>e.getRawString()).join("")}computeRawLength(){let e=0;for(let t of g(this,A))e+=t.getRawString().length;return e}};A=new WeakMap;var c=de,$,G=class{constructor(){C(this,$);w(this,$,[])}pushRow(e){g(this,$).push(e)}computeStyledLines(e){let t=new Array,o=new Array;for(let r of g(this,$))for(let s=0;s<r.length;s++){let a=r[s].computeRawLength();(t[s]===void 0||a>t[s])&&(t[s]=a)}for(let r of g(this,$)){let s=new Array;for(let i=0;i<r.length;i++){let a=r[i];if(s.push(a.computeStyledString(e)),i<r.length-1){let d=a.computeRawLength(),p=" ".repeat(t[i]-d);s.push(p)}}o.push(s.join(""))}return o}};$=new WeakMap;var W,_=class _ extends Error{constructor(t,o){let r=new c;r.push(t),o instanceof _?(r.push(new u(": ")),r.push(g(o,W))):o instanceof Error?r.push(new u(`: ${o.message}`)):o!==void 0&&r.push(new u(`: ${String(o)}`));super(r.computeRawString());C(this,W);w(this,W,r)}computeStyledString(t){return g(this,W).computeStyledString(t)}static tryWithContext(t,o){try{return t()}catch(r){throw new _(o(),r)}}};W=new WeakMap;var h=_,D,S=class S{constructor(e){C(this,D);w(this,D,e)}static none(){return new S("none")}static tty(){return new S("tty")}static mock(){return new S("mock")}static inferFromEnv(){if(!process||!process.env||!process.stdout||ae("NO_COLOR"))return S.none();let e=ae("FORCE_COLOR");return e==="0"?S.none():e==="1"||e==="2"||e==="3"||e?S.tty():!process.stdout.isTTY||ae("TERM")?.toLowerCase()==="dumb"?S.none():S.tty()}computeStyledString(e,t){if(t===void 0)return e;let o=e;if(t.case==="upper"&&(o=o.toUpperCase()),t.case==="lower"&&(o=o.toLowerCase()),g(this,D)==="none")return o;if(g(this,D)==="tty"){let r=t.fgColor?Ye[t.fgColor]:"",s=t.bgColor?ze[t.bgColor]:"",i=t.bold?Be:"",a=t.dim?Ne:"",d=t.italic?Fe:"",p=t.underline?je:"",l=t.strikethrough?qe:"";return`${r}${s}${i}${a}${d}${p}${l}${o}${We}`}if(g(this,D)==="mock"){let r=t.fgColor?`{${o}}@${t.fgColor}`:o,s=t.bgColor?`{${r}}#${t.bgColor}`:r,i=t.bold?`{${s}}+`:s,a=t.dim?`{${i}}-`:i,d=t.italic?`{${a}}*`:a,p=t.underline?`{${d}}_`:d;return t.strikethrough?`{${p}}~`:p}throw new Error(`Unknown TypoSupport kind: ${g(this,D)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",Te),e instanceof h?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};D=new WeakMap;var k=S,We="\x1B[0m",Be="\x1B[1m",Ne="\x1B[2m",Fe="\x1B[3m",je="\x1B[4m",qe="\x1B[9m",Ye={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"},ze={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(n){if(n in process.env)return process.env[n]}function E(n,e,t){let o=He(e,t.map(({reference:r,hint:s})=>({reference:r,payload:s})));o.length!==0&&(n.push(new u(" Did you mean: ")),n.pushJoined(o,new u(", "),3),n.push(new u(" ?")))}function He(n,e){if(e.length===0)return[];let t=Qe(n,e),o=t[0].divergence+.25,r=new Array;for(let{divergence:s,payload:i}of t){if(s>o)break;r.push(i)}return r}function Qe(n,e){let t=n.toLowerCase().slice(0,100);return e.map(({reference:r,payload:s})=>{let i=r.toLowerCase().slice(0,100);return{divergence:Je(t,i)/Math.max(t.length,i.length),reference:r,payload:s}}).sort((r,s)=>r.divergence-s.divergence)}function Je(n,e){let t=n.length,o=e.length,r=Array.from({length:t+1},()=>Array(o+1).fill(0));for(let s=0;s<=t;s++)r[s][0]=s;for(let s=0;s<=o;s++)r[0][s]=s;for(let s=1;s<=t;s++)for(let i=1;i<=o;i++){let a=n[s-1]===e[i-1]?0:1;r[s][i]=Math.min(r[s-1][i]+1,r[s][i-1]+1,r[s-1][i-1]+a),s>1&&i>1&&n[s-1]===e[i-2]&&n[s-2]===e[i-1]&&(r[s][i]=Math.min(r[s][i],r[s-2][i-2]+a))}return r[t][o]}function Xe(n,e){return{getInformation(){return n},consumeAndMakeDecoder(t){try{let o=e.consumeAndMakeDecoder(t),r=t.consumePositional();if(r!==void 0){let s=new c;throw s.push(new u("Unexpected argument: ")),s.push(new u(`"${r}"`,m)),s.push(new u(".")),new h(s)}return{generateUsage:()=>N(n,e),decodeAndMakeInterpreter(){let s=o.decodeAndMakeInterpreter();return{async executeWithContext(i){return await s.executeWithContext(i)}}}}}catch(o){return{generateUsage:()=>N(n,e),decodeAndMakeInterpreter(){throw o}}}}}}function Ze(n,e,t){let o=Object.keys(t);if(o.length===0)throw new Error("At least one subcommand is required");return{getInformation(){return n},consumeAndMakeDecoder(r){try{let s=e.consumeAndMakeDecoder(r),i=r.consumePositional();if(i===void 0){let p=new c;throw p.push(new u("<subcommand>",O)),p.push(new u(": Missing argument.")),Ce(p,"",o),new h(p)}let a=t[i];if(a===void 0){let p=new c;throw p.push(new u("<subcommand>",O)),p.push(new u(": Unknown name: ")),p.push(new u(`"${i}"`,m)),p.push(new u(".")),Ce(p,i,o),new h(p)}let d=a.consumeAndMakeDecoder(r);return{generateUsage(){let p=d.generateUsage(),l=N(n,e);return l.segments.push({subcommand:i}),l.segments.push(...p.segments),l.information=p.information,l.positionals.push(...p.positionals),l.subcommands=p.subcommands,l.options.push(...p.options),l},decodeAndMakeInterpreter(){let p=s.decodeAndMakeInterpreter(),l=d.decodeAndMakeInterpreter();return{async executeWithContext(f){return await l.executeWithContext(await p.executeWithContext(f))}}}}}catch(s){return{generateUsage(){let i=N(n,e);i.segments.push({positional:"<subcommand>"});for(let[a,d]of Object.entries(t)){let{description:p,hint:l}=d.getInformation();i.subcommands.push({name:a,description:p,hint:l})}return i},decodeAndMakeInterpreter(){throw s}}}}}}function _e(n,e,t){return{getInformation(){return n},consumeAndMakeDecoder(o){try{let r=e.consumeAndMakeDecoder(o),s=t.consumeAndMakeDecoder(o);return{generateUsage(){let i=s.generateUsage(),a=N(n,e);return a.segments.push(...i.segments),a.information=i.information,a.positionals.push(...i.positionals),a.subcommands=i.subcommands,a.options.push(...i.options),a},decodeAndMakeInterpreter(){let i=r.decodeAndMakeInterpreter(),a=s.decodeAndMakeInterpreter();return{async executeWithContext(d){return await a.executeWithContext(await i.executeWithContext(d))}}}}}catch(r){return{generateUsage(){let s=N(n,e);return s.segments.push({positional:"[REST]..."}),s},decodeAndMakeInterpreter(){throw r}}}}}}function N(n,e){let{positionals:t,options:o}=e.generateUsage();return{segments:t.map(r=>({positional:r.label})),information:n,positionals:t,subcommands:[],options:o}}function Ce(n,e,t=[]){E(n,e,t.map(o=>({reference:o,hint:new u(o,R)})))}function et(n,e){return{generateUsage(){let t=new Array;if(n.options!==void 0)for(let r in n.options){let s=n.options[r];t.push(s.generateUsage())}let o=new Array;if(n.positionals!==void 0)for(let r of n.positionals)o.push(r.generateUsage());return{options:t,positionals:o}},consumeAndMakeDecoder(t){let o={};if(n.options!==void 0)for(let s in n.options){let i=n.options[s];o[s]=i.registerAndMakeDecoder(t)}let r=[];if(n.positionals!==void 0)for(let s of n.positionals)r.push(s.consumeAndMakeDecoder(t));return{decodeAndMakeInterpreter(){let s={};for(let a in o)s[a]=o[a].getAndDecodeValue();let i=[];for(let a of r)i.push(a.decodeValue());return{executeWithContext(a){return e(a,{options:s,positionals:i})}}}}}}}var Re=require("fs");function le(n){return{content:n??"boolean",decoder(e){let t=e.toLowerCase();if(tt.has(t))return!0;if(nt.has(t))return!1;J("a boolean",e)}}}var tt=new Set(["true","yes","on","y"]),nt=new Set(["false","no","off","n"]);function rt(n){return{content:n??"datetime",decoder(e){try{let t=Date.parse(e);if(isNaN(t))throw new Error;return new Date(t)}catch{J("a valid ISO_8601 datetime",e)}}}}function ot(n){return{content:n??"number",decoder(e){try{let t=Number(e);if(isNaN(t))throw new Error;return t}catch{J("a number",e)}}}}function st(n){return{content:n??"integer",decoder(e){try{return BigInt(e)}catch{J("an integer",e)}}}}function it(n){return{content:n??"url",decoder(e){try{return new URL(e)}catch{J("an URL",e)}}}}function at(n){return{content:n??"string",decoder:e=>e}}function ut(n,e,t){return{content:n,decoder:o=>t(h.tryWithContext(()=>e.decoder(o),()=>new c(new u("from: "),new u(e.content,V))))}}function pt(n,e){return{content:e,decoder:t=>h.tryWithContext(()=>n.decoder(t),()=>new c(new u("from: "),new u(n.content,V)))}}function dt(n,e){return{content:n??"path",decoder(t){if(t.length===0)throw new Error("Path cannot be empty");if(t.includes("\0"))throw new Error("Path cannot contain null characters");if(e?.checkSyncExistAs!==void 0){let r=function(a){try{return(0,Re.statSync)(a)}catch(d){throw new h(new c(new u("Path does not exist: "),new u(`"${a}"`,m)),d)}};var o=r;let s=r(t),i=s.isDirectory()?"directory":s.isFile()?"file":"unknown";if(e.checkSyncExistAs==="file"&&!s.isFile())throw new h(new c(new u(`Expected a file but found: ${i}: `),new u(`"${t}"`,m)));if(e.checkSyncExistAs==="directory"&&!s.isDirectory())throw new h(new c(new u(`Expected a directory but found: ${i}: `),new u(`"${t}"`,m)))}return t}}}function ce(n,e,t=!0){if(e.length===0)throw new Error("At least one value is required");let o=t?s=>s:s=>s.toLowerCase(),r=new Map(e.map(s=>[o(s),s]));return{content:n,decoder(s){let i=r.get(o(s));if(i!==void 0)return i;let a=new c;throw a.push(new u("Unknown value: ")),a.push(new u(`"${s}"`,m)),a.push(new u(".")),E(a,s,e.map(d=>({reference:d,hint:new u(`"${d}"`,m)}))),new h(a)}}}function lt(n,e=","){return{content:n.map(t=>t.content).join(e),decoder(t){let o=t.split(e,n.length);if(o.length!==n.length)throw new h(new c(new u(`Found ${o.length} splits: `),new u(`Expected ${n.length} splits from: `),new u(`"${t}"`,m),new u(".")));return o.map((r,s)=>{let i=n[s];return h.tryWithContext(()=>i.decoder(r),()=>new c(new u(`at ${s}: `),new u(i.content,V)))})}}}function ct(n,e=","){return{content:`${n.content}[${e}${n.content}]...`,decoder(t){return t.split(e).map((r,s)=>h.tryWithContext(()=>n.decoder(r),()=>new c(new u(`at ${s}: `),new u(n.content,V))))}}}function J(n,e){throw new h(new c(new u(`Not ${n}: `),new u(`"${e}"`,m),new u(".")))}function ne(n){let e=le("value"),{long:t,short:o,description:r,hint:s,aliases:i}=n;return{generateUsage(){return{short:o,long:t,annotation:"[=no]",description:r,hint:s}},registerAndMakeDecoder(a){let d=fe(a,{longKey:t,shortKey:o,aliasLongKeys:i?.longs,aliasShortKeys:i?.shorts,restGuard:()=>!1,nextGuard:()=>!1});return{getAndDecodeValue(){let p=d();if(p.length>1&&Ae(p.map(f=>f.identifier)),p.length===0)return n.default===void 0?!1:n.default;let l=p[0].value.inlined;return l===null?!0:te({long:t,label:void 0,type:e,input:l})}}}}}function ge(n){let{long:e,short:t,description:o,hint:r,aliases:s,type:i}=n,a=n.impliedValueIfNotInlined?void 0:`<${i.content}>`,d=n.impliedValueIfNotInlined?`[=${i.content}]`:void 0;return{generateUsage(){return{short:t,long:e,label:a,annotation:d,description:o,hint:r}},registerAndMakeDecoder(p){let l=fe(p,{longKey:e,shortKey:t,aliasLongKeys:s?.longs,aliasShortKeys:s?.shorts,restGuard:()=>n.impliedValueIfNotInlined===void 0,nextGuard:f=>!(n.impliedValueIfNotInlined!==void 0||f.inlined!==null||f.separated.length!==0)});return{getAndDecodeValue(){let f=l();f.length>1&&Ae(f.map(v=>v.identifier));let x=f[0];if(x===void 0){if(n.fallbackValueIfAbsent===void 0){let v=ee({long:e,label:a,type:i});throw v.push(new u(": Is required, but was not set.")),new h(v)}try{return n.fallbackValueIfAbsent()}catch(v){let H=ee({long:e,label:a,type:i});throw H.push(new u(": Failed to get fallback value.")),new h(H,v)}}let z=x.value.inlined;if(z!==null)return te({long:e,label:a,type:i,input:z});if(n.impliedValueIfNotInlined!==void 0)try{return n.impliedValueIfNotInlined()}catch(v){let H=ee({long:e,label:a,type:i});throw H.push(new u(": Failed to get implied value.")),new h(H,v)}let Pe=x.value.separated[0];return te({long:e,label:a,type:i,input:Pe})}}}}}function gt(n){let{long:e,short:t,description:o,hint:r,aliases:s,type:i}=n,a=`<${i.content}>`;return{generateUsage(){return{short:t,long:e,label:a,annotation:" [*]",description:o,hint:r}},registerAndMakeDecoder(d){let p=fe(d,{longKey:e,shortKey:t,aliasLongKeys:s?.longs,aliasShortKeys:s?.shorts,restGuard:()=>!0,nextGuard:l=>!(l.inlined!==null||l.separated.length!==0)});return{getAndDecodeValue(){return p().map(l=>{let f=l.value,x=f.inlined??f.separated[0];return te({long:e,label:a,type:i,input:x})})}}}}}function te(n){let{long:e,label:t,type:o,input:r}=n;return h.tryWithContext(()=>o.decoder(r),()=>ee({long:e,label:t,type:o}))}function ee(n){let e=new c;return e.push(new u(`--${n.long}`,R)),n.label!==void 0?(e.push(new u(": ")),e.push(new u(n.label,O))):(e.push(new u(": ")),e.push(new u(n.type.content,V))),e}function fe(n,e){let{longKey:t,shortKey:o,aliasLongKeys:r,aliasShortKeys:s}=e,i=[t];r!==void 0&&i.push(...r);let a=o?[o]:[];return s!==void 0&&a.push(...s),ft(n,{longKeys:i,shortKeys:a,restGuard:e.restGuard,nextGuard:e.nextGuard})}function ft(n,e){let{longKeys:t,shortKeys:o,restGuard:r,nextGuard:s}=e,i=new Array;for(let a of t)i.push(n.registerOptionLong({key:a,nextGuard:s}));for(let a of o)i.push(n.registerOptionShort({key:a,restGuard:r,nextGuard:s}));return()=>{let a=new Array;for(let d of i){let{identifier:p,values:l}=d();for(let f of l)a.push({identifier:p,value:f})}return a}}function Ae(n){let e=Array.from(new Set(n)).map(o=>new u(o,R)),t=new c;throw t.pushJoined(e,new u(", "),3),t.push(new u(": Must not be set multiple times.")),new h(t)}function ht(n){let{description:e,hint:t,type:o}=n,r=`<${o.content}>`;return{generateUsage(){return{description:e,hint:t,label:r}},consumeAndMakeDecoder(s){let i=s.consumePositional();if(i===void 0){let a=ke(r);throw a.push(new u(": Is required, but was not provided.")),e!==void 0&&a.push(new u(` (${e})`,B)),new h(a)}return{decodeValue(){return he(r,n.type,i)}}}}}function yt(n){let{description:e,hint:t,type:o}=n,r=`[${o.content}]`;return{generateUsage(){return{description:e,hint:t,label:r}},consumeAndMakeDecoder(s){let i=s.consumePositional();return{decodeValue(){if(i===void 0)try{return n.default()}catch{xt(r)}return he(r,n.type,i)}}}}}function mt(n){let{description:e,hint:t,type:o}=n,r=`[${o.content}]`,s=`${r}...`+(n.endDelimiter?` ["${n.endDelimiter}"]`:"");return{generateUsage(){return{description:e,hint:t,label:s}},consumeAndMakeDecoder(i){let a=new Array;for(;;){let d=i.consumePositional();if(d===void 0||d===n.endDelimiter)break;a.push(d)}return{decodeValue(){return a.map(d=>he(r,n.type,d))}}}}}function he(n,e,t){return h.tryWithContext(()=>e.decoder(t),()=>new c(new u(n,O)))}function ke(n){let e=new c;return e.push(new u(n,O)),e}function xt(n){let e=ke(n);throw e.push(new u(": Failed to get default value.")),new h(e)}var j,K,P,M,I,y,re,Ve,ye,Ie,F,me,X=class{constructor(e){C(this,y);C(this,j);C(this,K);C(this,P);C(this,M);C(this,I);w(this,j,e),w(this,K,0),w(this,P,!1),w(this,M,new Map),w(this,I,new Map)}registerOptionLong(e){let t=`--${e.key}`;if(!Oe(e.key))throw new Error(`Option identifier is invalid: ${t}.`);if(g(this,M).has(t))throw new Error(`Option already registered: ${t}.`);let o=new Array;return g(this,M).set(t,{identifier:t,spec:e,values:o}),()=>({identifier:t,values:o})}registerOptionShort(e){let t=`-${e.key}`;if(!Oe(e.key))throw new Error(`Option identifier is invalid: ${t}.`);if(g(this,I).has(t))throw new Error(`Option already registered: ${t}.`);for(let r=0;r<t.length;r++){let s=t.slice(0,1+r);if(g(this,I).has(s))throw new Error(`Option ${t} overlap with shorter option: ${s}.`)}for(let r of g(this,I).keys())if(r.startsWith(t))throw new Error(`Option ${t} overlap with longer option: ${r}.`);let o=new Array;return g(this,I).set(t,{identifier:t,spec:e,values:o}),()=>({identifier:t,values:o})}consumePositional(){for(;;){let e=b(this,y,re).call(this);if(e===void 0)return;if(!b(this,y,Ve).call(this,e))return e}}};j=new WeakMap,K=new WeakMap,P=new WeakMap,M=new WeakMap,I=new WeakMap,y=new WeakSet,re=function(){let e=g(this,j)[g(this,K)];if(e!==void 0)return Se(this,K)._++,!g(this,P)&&e==="--"?(w(this,P,!0),b(this,y,re).call(this)):e},Ve=function(e){if(g(this,P))return!1;if(e.startsWith("--")){let t=e.indexOf("=");return t===-1?b(this,y,ye).call(this,e,null):b(this,y,ye).call(this,e.slice(0,t),e.slice(t+1)),!0}if(e.startsWith("-")){let t=1,o=2;for(;o<=e.length;){let r=`-${e.slice(t,o)}`,s=g(this,I).get(r);if(s!==void 0){let i=e.slice(o);if(b(this,y,Ie).call(this,s,i))return!0;t=o}o++}b(this,y,me).call(this,`-${e.slice(t)}`)}return!1},ye=function(e,t){let o=g(this,M).get(e);if(o!==void 0)return b(this,y,F).call(this,o,t);b(this,y,me).call(this,e)},Ie=function(e,t){return t.startsWith("=")?(b(this,y,F).call(this,e,t.slice(1)),!0):t.length===0?(b(this,y,F).call(this,e,null),!0):e.spec.restGuard(t)?(b(this,y,F).call(this,e,t),!0):(b(this,y,F).call(this,e,null),!1)},F=function(e,t){let o={inlined:t,separated:new Array},{identifier:r,values:s,spec:i}=e;for(s.push(o);;){let a=g(this,j)[g(this,K)];if(!i.nextGuard(o,a))return;let d=b(this,y,re).call(this);if(g(this,P))throw new h(new c(new u(r,R),new u(": Requires a value but got: "),new u('"--"',m),new u(".")));if(d===void 0)throw new h(new c(new u(r,R),new u(": Requires a value, but got end of input.")));if(d.startsWith("-"))throw new h(new c(new u(r,R),new u(": Requires a value, but got: "),new u(`"${d}"`,m),new u(".")));o.separated.push(d)}},me=function(e){let t=[];for(let r of g(this,M).keys())t.push(r);for(let r of g(this,I).keys())t.push(r);let o=new c;throw o.push(new u("Unknown option: ")),o.push(new u(`"${e}"`,m)),t.length===0?o.push(new u(", no options are registered.")):(o.push(new u(".")),E(o,e,t.map(r=>({reference:r,hint:new u(r,R)})))),new h(o)};function Oe(n){return n.length>0&&!n.includes("=")&&!n.includes("\0")}function we(n){let{cliName:e,usage:t,typoSupport:o}=n,r=new Array,s=new c;s.push(wt("Usage:")),s.push(T(" ")),s.push(U(e));for(let a of t.segments)s.push(T(" ")),"positional"in a&&s.push(q(a.positional)),"subcommand"in a&&s.push(U(a.subcommand));r.push(s.computeStyledString(o)),r.push("");let i=new c;i.push(bt(t.information.description)),t.information.hint!==void 0&&(i.push(T(" ")),i.push(Y(`(${t.information.hint})`))),r.push(i.computeStyledString(o));for(let a of t.information.details??[]){let d=new c;d.push(Y(a)),r.push(d.computeStyledString(o))}if(t.positionals.length>0){r.push(""),r.push(oe("Positionals:").computeStyledString(o));let a=new G;for(let d of t.positionals){let p=new Array;p.push(new c(T(" "))),p.push(new c(q(d.label))),p.push(...xe(d)),a.pushRow(p)}r.push(...a.computeStyledLines(o))}if(t.subcommands.length>0){r.push(""),r.push(oe("Subcommands:").computeStyledString(o));let a=new G;for(let d of t.subcommands){let p=new Array;p.push(new c(T(" "))),p.push(new c(U(d.name))),p.push(...xe(d)),a.pushRow(p)}r.push(...a.computeStyledLines(o))}if(t.options.length>0){r.push(""),r.push(oe("Options:").computeStyledString(o));let a=new G;for(let d of t.options){let p=new Array;p.push(new c(T(" "))),d.short!==void 0?p.push(new c(U(`-${d.short}`),T(", "))):p.push(new c);let l=new c(U(`--${d.long}`));d.label!==void 0&&(l.push(T(" ")),l.push(q(d.label))),d.annotation!==void 0&&l.push(Y(d.annotation)),p.push(l),p.push(...xe(d)),a.pushRow(p)}r.push(...a.computeStyledLines(o))}if(t.information.examples!==void 0){r.push(""),r.push(oe("Examples:").computeStyledString(o));for(let a of t.information.examples){let d=new c;d.push(T(" ")),d.push(Y(`# ${a.explanation}`)),r.push(d.computeStyledString(o));let p=new c;p.push(T(" ")),p.push(U(e));for(let l of a.commandArgs)if(p.push(T(" ")),typeof l=="string")p.push(new u(l));else if("positional"in l)p.push(q(l.positional));else if("subcommand"in l)p.push(U(l.subcommand));else if("option"in l){let f=l.option;if("short"in f?p.push(U(`-${f.short}`)):p.push(U(`--${f.long}`)),f.inlined!==void 0&&(p.push(Y("=")),p.push(q(f.inlined))),f.separated!==void 0)for(let x of f.separated)p.push(T(" ")),p.push(q(x))}r.push(p.computeStyledString(o))}}return r.push(""),r}function xe(n){let e=[];return n.description!==void 0&&(e.push(T(" ")),e.push(St(n.description))),n.hint!==void 0&&(e.push(T(" ")),e.push(Y(`(${n.hint})`))),e.length>0?[new c(T(" "),...e)]:[]}function wt(n){return new u(n,V)}function bt(n){return new u(n,pe)}function St(n){return new u(n)}function oe(n){return new u(n,ue)}function Y(n){return new u(n,B)}function U(n){return new u(n,R)}function q(n){return new u(n,O)}function T(n){return new u(n)}async function Tt(n,e,t,o,r){let s=new X(e),i=new Array,a=k.none(),d=r?.colorSetup??"flag";if(d==="flag"){let f=ge({long:"color",type:ce("color-mode",["auto","always","never"]),fallbackValueIfAbsent:()=>"auto",impliedValueIfNotInlined:()=>"always"}).registerAndMakeDecoder(s);i.push(()=>{try{a=De(f.getAndDecodeValue())}catch(x){throw a=k.inferFromEnv(),x}})}else a=De(d);if(r?.usageOnHelp??!0){let f=ne({long:"help"}).registerAndMakeDecoder(s);i.push(x=>{if(f.getAndDecodeValue())return console.log(ve(n,x,a)),0})}if(r?.buildVersion!==void 0){let f=ne({long:"version"}).registerAndMakeDecoder(s);i.push(()=>{if(f.getAndDecodeValue())return console.log([n,r.buildVersion].join(" ")),0})}let p=o.consumeAndMakeDecoder(s);for(;;)try{if(s.consumePositional()===void 0)break}catch{}let l=r?.onExit??process.exit;try{for(let x of i){let z=x(p);if(z!==void 0)return l(z)}let f=p.decodeAndMakeInterpreter();try{return await f.executeWithContext(t),l(0)}catch(x){return Ue(n,r?.onError,x,a),l(1)}}catch(f){return(r?.usageOnError??!0)&&console.error(ve(n,p,a)),Ue(n,r?.onError,f,a),l(1)}}function Ue(n,e,t,o){let r=t;e!==void 0?e(r):console.error(o.computeStyledErrorMessage(r))}function ve(n,e,t){return we({cliName:n,usage:e.generateUsage(),typoSupport:t}).join(`
|
|
2
|
-
`)}function
|
|
1
|
+
"use strict";var se=Object.defineProperty;var De=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames;var Ee=Object.prototype.hasOwnProperty;var be=n=>{throw TypeError(n)};var Ge=(n,e)=>{for(var t in e)se(n,t,{get:e[t],enumerable:!0})},Ke=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ve(e))!Ee.call(n,o)&&o!==t&&se(n,o,{get:()=>e[o],enumerable:!(r=De(e,o))||r.enumerable});return n};var Le=n=>Ke(se({},"__esModule",{value:!0}),n);var ie=(n,e,t)=>e.has(n)||be("Cannot "+t);var g=(n,e,t)=>(ie(n,e,"read from private field"),t?t.call(n):e.get(n)),C=(n,e,t)=>e.has(n)?be("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,t),x=(n,e,t,r)=>(ie(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),b=(n,e,t)=>(ie(n,e,"access private method"),t);var Se=(n,e,t,r)=>({set _(o){x(n,e,o,t)},get _(){return g(n,e,r)}});var Tt={};Ge(Tt,{ReaderArgs:()=>X,TypoError:()=>f,TypoGrid:()=>E,TypoString:()=>u,TypoSupport:()=>k,TypoText:()=>c,command:()=>Xe,commandChained:()=>_e,commandWithSubcommands:()=>Ze,operation:()=>et,optionFlag:()=>ne,optionRepeatable:()=>gt,optionSingleValue:()=>ge,positionalOptional:()=>yt,positionalRequired:()=>ht,positionalVariadics:()=>mt,runAndExit:()=>St,suggestTextPushMessage:()=>G,typeBoolean:()=>le,typeChoice:()=>ce,typeDatetime:()=>rt,typeInteger:()=>ot,typeList:()=>dt,typeMapped:()=>at,typeNumber:()=>nt,typePath:()=>it,typeRenamed:()=>ut,typeString:()=>tt,typeTuple:()=>pt,typeUrl:()=>st,typoStyleConstants:()=>A,typoStyleFailure:()=>Te,typoStyleLogic:()=>V,typoStyleQuote:()=>m,typoStyleRegularStrong:()=>pe,typoStyleRegularWeaker:()=>B,typoStyleTitle:()=>ue,typoStyleUserInput:()=>O,usageToStyledLines:()=>xe});module.exports=Le(Tt);var ue={fgColor:"darkGreen",bold:!0},V={fgColor:"darkMagenta",bold:!0},m={fgColor:"darkYellow",bold:!0},Te={fgColor:"darkRed",bold:!0},A={fgColor:"darkCyan",bold:!0},O={fgColor:"darkBlue",bold:!0},pe={bold:!0},B={italic:!0,dim:!0},L,Q,Z=class Z{constructor(e,t){C(this,L);C(this,Q);x(this,L,e),x(this,Q,t)}computeStyledString(e){return e.computeStyledString(g(this,L),g(this,Q))}getRawString(){return g(this,L)}};L=new WeakMap,Q=new WeakMap,Z.elipsis=new Z("...",B);var u=Z,R,de=class de{constructor(...e){C(this,R);x(this,R,[]);for(let t of e)this.push(t)}push(...e){for(let t of e)if(typeof t=="string")g(this,R).push(new u(t));else if(t instanceof u)g(this,R).push(t);else if(t instanceof de)g(this,R).push(...g(t,R));else if(Array.isArray(t))for(let r of t)this.push(r)}pushJoined(e,t,r){for(let o=0;o<e.length;o++){if(o>0&&this.push(t),r!==void 0&&o>=r){this.push(u.elipsis);break}this.push(e[o])}}computeStyledString(e){return g(this,R).map(t=>t.computeStyledString(e)).join("")}computeRawString(){return g(this,R).map(e=>e.getRawString()).join("")}computeRawLength(){let e=0;for(let t of g(this,R))e+=t.getRawString().length;return e}};R=new WeakMap;var c=de,v,E=class{constructor(){C(this,v);x(this,v,[])}pushRow(e){g(this,v).push(e)}computeStyledLines(e){let t=new Array,r=new Array;for(let o of g(this,v))for(let s=0;s<o.length;s++){let a=o[s].computeRawLength();(t[s]===void 0||a>t[s])&&(t[s]=a)}for(let o of g(this,v)){let s=new Array;for(let i=0;i<o.length;i++){let a=o[i];if(s.push(a.computeStyledString(e)),i<o.length-1){let d=a.computeRawLength(),p=" ".repeat(t[i]-d);s.push(p)}}r.push(s.join(""))}return r}};v=new WeakMap;var W,_=class _ extends Error{constructor(t,r){let o=new c;o.push(t),r instanceof _?(o.push(new u(": ")),o.push(g(r,W))):r instanceof Error?o.push(new u(`: ${r.message}`)):r!==void 0&&o.push(new u(`: ${String(r)}`));super(o.computeRawString());C(this,W);x(this,W,o)}computeStyledString(t){return g(this,W).computeStyledString(t)}static tryWithContext(t,r){try{return t()}catch(o){throw new _(r(),o)}}};W=new WeakMap;var f=_,$,S=class S{constructor(e){C(this,$);x(this,$,e)}static none(){return new S("none")}static tty(){return new S("tty")}static mock(){return new S("mock")}static inferFromEnv(){if(!process||!process.env||!process.stdout||ae("NO_COLOR"))return S.none();let e=ae("FORCE_COLOR");return e==="0"?S.none():e==="1"||e==="2"||e==="3"||e?S.tty():!process.stdout.isTTY||ae("TERM")?.toLowerCase()==="dumb"?S.none():S.tty()}computeStyledString(e,t){if(t===void 0)return e;let r=e;if(t.case==="upper"&&(r=r.toUpperCase()),t.case==="lower"&&(r=r.toLowerCase()),g(this,$)==="none")return r;if(g(this,$)==="tty"){let o=t.fgColor?Ye[t.fgColor]:"",s=t.bgColor?ze[t.bgColor]:"",i=t.bold?Be:"",a=t.dim?Ne:"",d=t.italic?Fe:"",p=t.underline?je:"",l=t.strikethrough?qe:"";return`${o}${s}${i}${a}${d}${p}${l}${r}${We}`}if(g(this,$)==="mock"){let o=t.fgColor?`{${r}}@${t.fgColor}`:r,s=t.bgColor?`{${o}}#${t.bgColor}`:o,i=t.bold?`{${s}}+`:s,a=t.dim?`{${i}}-`:i,d=t.italic?`{${a}}*`:a,p=t.underline?`{${d}}_`:d;return t.strikethrough?`{${p}}~`:p}throw new Error(`Unknown TypoSupport kind: ${g(this,$)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",Te),e instanceof f?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};$=new WeakMap;var k=S,We="\x1B[0m",Be="\x1B[1m",Ne="\x1B[2m",Fe="\x1B[3m",je="\x1B[4m",qe="\x1B[9m",Ye={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"},ze={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(n){if(n in process.env)return process.env[n]}function G(n,e,t){let r=He(e,t.map(({reference:o,hint:s})=>({reference:o,payload:s})));r.length!==0&&(n.push(new u(" Did you mean: ")),n.pushJoined(r,new u(", "),3),n.push(new u(" ?")))}function He(n,e){if(e.length===0)return[];let t=Qe(n,e),r=t[0].divergence+.25,o=new Array;for(let{divergence:s,payload:i}of t){if(s>r)break;o.push(i)}return o}function Qe(n,e){let t=n.toLowerCase().slice(0,100);return e.map(({reference:o,payload:s})=>{let i=o.toLowerCase().slice(0,100);return{divergence:Je(t,i)/Math.max(t.length,i.length),reference:o,payload:s}}).sort((o,s)=>o.divergence-s.divergence)}function Je(n,e){let t=n.length,r=e.length,o=Array.from({length:t+1},()=>Array(r+1).fill(0));for(let s=0;s<=t;s++)o[s][0]=s;for(let s=0;s<=r;s++)o[0][s]=s;for(let s=1;s<=t;s++)for(let i=1;i<=r;i++){let a=n[s-1]===e[i-1]?0:1;o[s][i]=Math.min(o[s-1][i]+1,o[s][i-1]+1,o[s-1][i-1]+a),s>1&&i>1&&n[s-1]===e[i-2]&&n[s-2]===e[i-1]&&(o[s][i]=Math.min(o[s][i],o[s-2][i-2]+a))}return o[t][r]}function Xe(n,e){return{getInformation(){return n},consumeAndMakeDecoder(t){try{let r=e.consumeAndMakeDecoder(t),o=t.consumePositional();if(o!==void 0){let s=new c;throw s.push(new u("Unexpected argument: ")),s.push(new u(`"${o}"`,m)),s.push(new u(".")),new f(s)}return{generateUsage:()=>N(n,e),decodeAndMakeInterpreter(){let s=r.decodeAndMakeInterpreter();return{async executeWithContext(i){return await s.executeWithContext(i)}}}}}catch(r){return{generateUsage:()=>N(n,e),decodeAndMakeInterpreter(){throw r}}}}}}function Ze(n,e,t){let r=Object.keys(t);if(r.length===0)throw new Error("At least one subcommand is required");for(let o of r)if(o.startsWith("-"))throw new Error(`Subcommand name "${o}" cannot start with "-".`);return{getInformation(){return n},consumeAndMakeDecoder(o){try{let s=e.consumeAndMakeDecoder(o),i=o.consumePositional();if(i===void 0){let p=new c;throw p.push(new u("Missing argument: ")),p.push(new u("<subcommand>",O)),p.push(new u(".")),Ce(p,"",r),new f(p)}let a=t[i];if(a===void 0){let p=new c;throw p.push(new u("<subcommand>",O)),p.push(new u(": Unknown name: ")),p.push(new u(`"${i}"`,m)),p.push(new u(".")),Ce(p,i,r),new f(p)}let d=a.consumeAndMakeDecoder(o);return{generateUsage(){let p=d.generateUsage(),l=N(n,e);return l.segments.push({subcommand:i}),l.segments.push(...p.segments),l.information=p.information,l.positionals.push(...p.positionals),l.subcommands=p.subcommands,l.options.push(...p.options),l},decodeAndMakeInterpreter(){let p=s.decodeAndMakeInterpreter(),l=d.decodeAndMakeInterpreter();return{async executeWithContext(h){return await l.executeWithContext(await p.executeWithContext(h))}}}}}catch(s){return{generateUsage(){let i=N(n,e);i.segments.push({positional:"<subcommand>"});for(let[a,d]of Object.entries(t)){let{description:p,hint:l}=d.getInformation();i.subcommands.push({name:a,description:p,hint:l})}return i},decodeAndMakeInterpreter(){throw s}}}}}}function _e(n,e,t){return{getInformation(){return n},consumeAndMakeDecoder(r){try{let o=e.consumeAndMakeDecoder(r),s=t.consumeAndMakeDecoder(r);return{generateUsage(){let i=s.generateUsage(),a=N(n,e);return a.segments.push(...i.segments),a.information=i.information,a.positionals.push(...i.positionals),a.subcommands=i.subcommands,a.options.push(...i.options),a},decodeAndMakeInterpreter(){let i=o.decodeAndMakeInterpreter(),a=s.decodeAndMakeInterpreter();return{async executeWithContext(d){return await a.executeWithContext(await i.executeWithContext(d))}}}}}catch(o){return{generateUsage(){let s=N(n,e);return s.segments.push({positional:"[REST]..."}),s},decodeAndMakeInterpreter(){throw o}}}}}}function N(n,e){let{positionals:t,options:r}=e.generateUsage();return{segments:t.map(o=>({positional:o.label})),information:n,positionals:t,subcommands:[],options:r}}function Ce(n,e,t=[]){G(n,e,t.map(r=>({reference:r,hint:new u(r,A)})))}function et(n,e){return{generateUsage(){let t=new Array;if(n.options!==void 0)for(let o in n.options){let s=n.options[o];t.push(s.generateUsage())}let r=new Array;if(n.positionals!==void 0)for(let o of n.positionals)r.push(o.generateUsage());return{options:t,positionals:r}},consumeAndMakeDecoder(t){let r={};if(n.options!==void 0)for(let s in n.options){let i=n.options[s];r[s]=i.registerAndMakeDecoder(t)}let o=[];if(n.positionals!==void 0)for(let s of n.positionals)o.push(s.consumeAndMakeDecoder(t));return{decodeAndMakeInterpreter(){let s={};for(let a in r)s[a]=r[a].getAndDecodeValue();let i=[];for(let a of o)i.push(a.decodeValue());return{executeWithContext(a){return e(a,{options:s,positionals:i})}}}}}}}var Ae=require("fs");function tt(n){return{content:n??"string",decoder:e=>e}}function le(n){return{content:n??"boolean",decoder(e){let t=e.toLowerCase();if(lt.has(t))return!0;if(ct.has(t))return!1;J("a boolean",e)}}}function nt(n){return{content:n??"number",decoder(e){try{let t=Number(e);if(isNaN(t))throw new Error;return t}catch{J("a number",e)}}}}function ot(n){return{content:n??"integer",decoder(e){try{return BigInt(e)}catch{J("an integer",e)}}}}function rt(n){return{content:n??"datetime",decoder(e){try{let t=Date.parse(e);if(isNaN(t))throw new Error;return new Date(t)}catch{J("a valid ISO_8601 datetime",e)}}}}function st(n){return{content:n??"url",decoder(e){try{return new URL(e)}catch{J("an URL",e)}}}}function it(n,e){return{content:n??"path",decoder(t){if(t.length===0)throw new Error("Path cannot be empty");if(t.includes("\0"))throw new Error("Path cannot contain null characters");if(e?.checkSyncExistAs!==void 0){let o=function(a){try{return(0,Ae.statSync)(a)}catch(d){throw new f(new c(new u("Path does not exist: "),new u(`"${a}"`,m)),d)}};var r=o;let s=o(t),i=s.isDirectory()?"directory":s.isFile()?"file":"unknown";if(e.checkSyncExistAs==="file"&&!s.isFile())throw new f(new c(new u(`Expected a file but found: ${i}: `),new u(`"${t}"`,m)));if(e.checkSyncExistAs==="directory"&&!s.isDirectory())throw new f(new c(new u(`Expected a directory but found: ${i}: `),new u(`"${t}"`,m)))}return t}}}function ce(n,e,t=!0){if(e.length===0)throw new Error("At least one value is required");let r=t?s=>s:s=>s.toLowerCase(),o=new Map(e.map(s=>[r(s),s]));return{content:n,decoder(s){let i=o.get(r(s));if(i!==void 0)return i;let a=new c;throw a.push(new u("Unknown value: ")),a.push(new u(`"${s}"`,m)),a.push(new u(".")),G(a,s,e.map(d=>({reference:d,hint:new u(`"${d}"`,m)}))),new f(a)}}}function at(n,e,t){return{content:n,decoder:r=>t(f.tryWithContext(()=>e.decoder(r),()=>new c(new u("from: "),new u(e.content,V))))}}function ut(n,e){return{content:e,decoder:t=>f.tryWithContext(()=>n.decoder(t),()=>new c(new u("from: "),new u(n.content,V)))}}function pt(n,e=","){return{content:n.map(t=>t.content).join(e),decoder(t){let r=t.split(e,n.length);if(r.length!==n.length)throw new f(new c(new u(`Found ${r.length} splits: `),new u(`Expected ${n.length} splits from: `),new u(`"${t}"`,m),new u(".")));return r.map((o,s)=>{let i=n[s];return f.tryWithContext(()=>i.decoder(o),()=>new c(new u(`at ${s}: `),new u(i.content,V)))})}}}function dt(n,e=","){return{content:`${n.content}[${e}${n.content}]...`,decoder(t){return t.split(e).map((o,s)=>f.tryWithContext(()=>n.decoder(o),()=>new c(new u(`at ${s}: `),new u(n.content,V))))}}}function J(n,e){throw new f(new c(new u(`Not ${n}: `),new u(`"${e}"`,m),new u(".")))}var lt=new Set(["true","yes","on","y"]),ct=new Set(["false","no","off","n"]);function ne(n){let e=le("value"),{long:t,short:r,description:o,hint:s,aliases:i}=n;return{generateUsage(){return{short:r,long:t,annotation:"[=no]",description:o,hint:s}},registerAndMakeDecoder(a){let d=fe(a,{longKey:t,shortKey:r,aliasLongKeys:i?.longs,aliasShortKeys:i?.shorts,nextGuard:()=>!1,consumeGroupRestAsValue:!1});return{getAndDecodeValue(){let p=d();if(p.length>1&&Re(p.map(h=>h.identifier)),p.length===0)return n.default===void 0?!1:n.default;let l=p[0].value.inlined;return l===null?!0:te({long:t,label:void 0,type:e,input:l})}}}}}function ge(n){let{long:e,short:t,description:r,hint:o,aliases:s,type:i}=n,a=n.impliedValueIfNotInlined?void 0:`<${i.content}>`,d=n.impliedValueIfNotInlined?`[=${i.content}]`:void 0;return{generateUsage(){return{short:t,long:e,label:a,annotation:d,description:r,hint:o}},registerAndMakeDecoder(p){let l=fe(p,{longKey:e,shortKey:t,aliasLongKeys:s?.longs,aliasShortKeys:s?.shorts,nextGuard:h=>!(n.impliedValueIfNotInlined!==void 0||h.inlined!==null||h.separated.length!==0),consumeGroupRestAsValue:n.impliedValueIfNotInlined===void 0});return{getAndDecodeValue(){let h=l();h.length>1&&Re(h.map(P=>P.identifier));let w=h[0];if(w===void 0){if(n.fallbackValueIfAbsent===void 0){let P=ee({long:e,label:a,type:i});throw P.push(new u(": Is required, but was not set.")),new f(P)}try{return n.fallbackValueIfAbsent()}catch(P){let H=ee({long:e,label:a,type:i});throw H.push(new u(": Failed to get fallback value.")),new f(H,P)}}let z=w.value.inlined;if(z!==null)return te({long:e,label:a,type:i,input:z});if(n.impliedValueIfNotInlined!==void 0)try{return n.impliedValueIfNotInlined()}catch(P){let H=ee({long:e,label:a,type:i});throw H.push(new u(": Failed to get implied value.")),new f(H,P)}let Me=w.value.separated[0];return te({long:e,label:a,type:i,input:Me})}}}}}function gt(n){let{long:e,short:t,description:r,hint:o,aliases:s,type:i}=n,a=`<${i.content}>`;return{generateUsage(){return{short:t,long:e,label:a,annotation:" [*]",description:r,hint:o}},registerAndMakeDecoder(d){let p=fe(d,{longKey:e,shortKey:t,aliasLongKeys:s?.longs,aliasShortKeys:s?.shorts,nextGuard:l=>!(l.inlined!==null||l.separated.length!==0),consumeGroupRestAsValue:!0});return{getAndDecodeValue(){return p().map(l=>{let h=l.value,w=h.inlined??h.separated[0];return te({long:e,label:a,type:i,input:w})})}}}}}function te(n){let{long:e,label:t,type:r,input:o}=n;return f.tryWithContext(()=>r.decoder(o),()=>ee({long:e,label:t,type:r}))}function ee(n){let e=new c;return e.push(new u(`--${n.long}`,A)),n.label!==void 0?(e.push(new u(": ")),e.push(new u(n.label,O))):(e.push(new u(": ")),e.push(new u(n.type.content,V))),e}function fe(n,e){let{longKey:t,shortKey:r,aliasLongKeys:o,aliasShortKeys:s}=e,i=[t];o!==void 0&&i.push(...o);let a=r?[r]:[];return s!==void 0&&a.push(...s),ft(n,{longKeys:i,shortKeys:a,nextGuard:e.nextGuard,consumeGroupRestAsValue:e.consumeGroupRestAsValue})}function ft(n,e){let{longKeys:t,shortKeys:r,nextGuard:o,consumeGroupRestAsValue:s}=e,i=new Map;for(let a of t)i.set(`--${a}`,n.registerOptionLong({key:a,nextGuard:o}));for(let a of r)i.set(`-${a}`,n.registerOptionShort({key:a,nextGuard:o,consumeGroupRestAsValue:s}));return()=>{let a=new Array;for(let[d,p]of i.entries())for(let l of p())a.push({identifier:d,value:l});return a}}function Re(n){let e=Array.from(new Set(n)).map(r=>new u(r,A)),t=new c;throw t.pushJoined(e,new u(", "),3),t.push(new u(": Must not be set multiple times.")),new f(t)}function ht(n){let{description:e,hint:t,type:r}=n,o=`<${r.content}>`;return{generateUsage(){return{description:e,hint:t,label:o}},consumeAndMakeDecoder(s){let i=s.consumePositional();if(i===void 0){let a=ke("Missing argument",o);throw e!==void 0&&a.push(new u(": "),new u(`${e}`)),t!==void 0&&a.push(new u(" "),new u(`(${t})`,B)),new f(a)}return{decodeValue(){return he(o,n.type,i)}}}}}function yt(n){let{description:e,hint:t,type:r}=n,o=`[${r.content}]`;return{generateUsage(){return{description:e,hint:t,label:o}},consumeAndMakeDecoder(s){let i=s.consumePositional();return{decodeValue(){if(i===void 0)try{return n.default()}catch(a){let d=ke("Failed to get default value",o);throw d.push(new u(".")),new f(d,a)}return he(o,n.type,i)}}}}}function mt(n){let{description:e,hint:t,type:r}=n,o=`[${r.content}]`,s=`${o}...`+(n.endDelimiter?` ["${n.endDelimiter}"]`:"");return{generateUsage(){return{description:e,hint:t,label:s}},consumeAndMakeDecoder(i){let a=new Array;for(;;){let d=i.consumePositional();if(d===void 0||d===n.endDelimiter)break;a.push(d)}return{decodeValue(){return a.map(d=>he(o,n.type,d))}}}}}function he(n,e,t){return f.tryWithContext(()=>e.decoder(t),()=>new c(new u(n,O)))}function ke(n,e){let t=new c;return t.push(new u(`${n}: `)),t.push(new u(e,O)),t}var j,K,M,D,I,y,oe,Ve,ye,Ie,F,me,X=class{constructor(e){C(this,y);C(this,j);C(this,K);C(this,M);C(this,D);C(this,I);x(this,j,e),x(this,K,0),x(this,M,!1),x(this,D,new Map),x(this,I,new Map)}registerOptionLong(e){let t=`--${e.key}`;if(!Oe(e.key))throw new Error(`Option identifier is invalid: ${t}.`);if(g(this,D).has(t))throw new Error(`Option already registered: ${t}.`);let r=new Array;return g(this,D).set(t,{identifier:t,spec:e,values:r}),()=>r}registerOptionShort(e){let t=`-${e.key}`;if(!Oe(e.key))throw new Error(`Option identifier is invalid: ${t}.`);if(g(this,I).has(t))throw new Error(`Option already registered: ${t}.`);for(let o=0;o<t.length;o++){let s=t.slice(0,1+o);if(g(this,I).has(s))throw new Error(`Option ${t} overlap with shorter option: ${s}.`)}for(let o of g(this,I).keys())if(o.startsWith(t))throw new Error(`Option ${t} overlap with longer option: ${o}.`);let r=new Array;return g(this,I).set(t,{identifier:t,spec:e,values:r}),()=>r}consumePositional(){for(;;){let e=b(this,y,oe).call(this);if(e===void 0)return;if(!b(this,y,Ve).call(this,e))return e}}};j=new WeakMap,K=new WeakMap,M=new WeakMap,D=new WeakMap,I=new WeakMap,y=new WeakSet,oe=function(){let e=g(this,j)[g(this,K)];if(e!==void 0)return Se(this,K)._++,!g(this,M)&&e==="--"?(x(this,M,!0),b(this,y,oe).call(this)):e},Ve=function(e){if(g(this,M))return!1;if(e.startsWith("--")){let t=e.indexOf("=");return t===-1?b(this,y,ye).call(this,e,null):b(this,y,ye).call(this,e.slice(0,t),e.slice(t+1)),!0}if(e.startsWith("-")){let t=1,r=2;for(;r<=e.length;){let o=`-${e.slice(t,r)}`,s=g(this,I).get(o);if(s!==void 0){let i=e.slice(r);if(b(this,y,Ie).call(this,s,i))return!0;t=r}r++}b(this,y,me).call(this,`-${e.slice(t)}`)}return!1},ye=function(e,t){let r=g(this,D).get(e);if(r!==void 0)return b(this,y,F).call(this,r,t);b(this,y,me).call(this,e)},Ie=function(e,t){return t.startsWith("=")?(b(this,y,F).call(this,e,t.slice(1)),!0):t.length===0?(b(this,y,F).call(this,e,null),!0):e.spec.consumeGroupRestAsValue?(b(this,y,F).call(this,e,t),!0):(b(this,y,F).call(this,e,null),!1)},F=function(e,t){let r={inlined:t,separated:new Array},{identifier:o,values:s,spec:i}=e;for(s.push(r);;){let a=g(this,j)[g(this,K)];if(!i.nextGuard(r,a))return;let d=b(this,y,oe).call(this);if(g(this,M))throw new f(new c(new u(o,A),new u(": Requires a value but got: "),new u('"--"',m),new u(".")));if(d===void 0)throw new f(new c(new u(o,A),new u(": Requires a value, but got end of input.")));if(d.startsWith("-"))throw new f(new c(new u(o,A),new u(": Requires a value, but got: "),new u(`"${d}"`,m),new u(".")));r.separated.push(d)}},me=function(e){let t=[];for(let o of g(this,D).keys())t.push(o);for(let o of g(this,I).keys())t.push(o);let r=new c;throw r.push(new u("Unknown option: ")),r.push(new u(`"${e}"`,m)),t.length===0?r.push(new u(", no options are registered.")):(r.push(new u(".")),G(r,e,t.map(o=>({reference:o,hint:new u(o,A)})))),new f(r)};function Oe(n){return n.length>0&&!n.includes("=")&&!n.includes("\0")}function xe(n){let{cliName:e,usage:t,typoSupport:r}=n,o=new Array,s=new c;s.push(wt("Usage:")),s.push(T(" ")),s.push(U(e));for(let a of t.segments)s.push(T(" ")),"positional"in a&&s.push(q(a.positional)),"subcommand"in a&&s.push(U(a.subcommand));o.push(s.computeStyledString(r)),o.push("");let i=new c;i.push(xt(t.information.description)),t.information.hint!==void 0&&(i.push(T(" ")),i.push(Y(`(${t.information.hint})`))),o.push(i.computeStyledString(r));for(let a of t.information.details??[]){let d=new c;d.push(Y(a)),o.push(d.computeStyledString(r))}if(t.positionals.length>0){o.push(""),o.push(re("Positionals:").computeStyledString(r));let a=new E;for(let d of t.positionals){let p=new Array;p.push(new c(T(" "))),p.push(new c(q(d.label))),p.push(...we(d)),a.pushRow(p)}o.push(...a.computeStyledLines(r))}if(t.subcommands.length>0){o.push(""),o.push(re("Subcommands:").computeStyledString(r));let a=new E;for(let d of t.subcommands){let p=new Array;p.push(new c(T(" "))),p.push(new c(U(d.name))),p.push(...we(d)),a.pushRow(p)}o.push(...a.computeStyledLines(r))}if(t.options.length>0){o.push(""),o.push(re("Options:").computeStyledString(r));let a=new E;for(let d of t.options){let p=new Array;p.push(new c(T(" "))),d.short!==void 0?p.push(new c(U(`-${d.short}`),T(", "))):p.push(new c);let l=new c(U(`--${d.long}`));d.label!==void 0&&(l.push(T(" ")),l.push(q(d.label))),d.annotation!==void 0&&l.push(Y(d.annotation)),p.push(l),p.push(...we(d)),a.pushRow(p)}o.push(...a.computeStyledLines(r))}if(t.information.examples!==void 0){o.push(""),o.push(re("Examples:").computeStyledString(r));for(let a of t.information.examples){let d=new c;d.push(T(" ")),d.push(Y(`# ${a.explanation}`)),o.push(d.computeStyledString(r));let p=new c;p.push(T(" ")),p.push(U(e));for(let l of a.commandArgs)if(p.push(T(" ")),typeof l=="string")p.push(new u(l));else if("positional"in l)p.push(q(l.positional));else if("subcommand"in l)p.push(U(l.subcommand));else if("option"in l){let h=l.option;if("short"in h?p.push(U(`-${h.short}`)):p.push(U(`--${h.long}`)),h.inlined!==void 0&&(p.push(Y("=")),p.push(q(h.inlined))),h.separated!==void 0)for(let w of h.separated)p.push(T(" ")),p.push(q(w))}o.push(p.computeStyledString(r))}}return o.push(""),o}function we(n){let e=[];return n.description!==void 0&&(e.push(T(" ")),e.push(bt(n.description))),n.hint!==void 0&&(e.push(T(" ")),e.push(Y(`(${n.hint})`))),e.length>0?[new c(T(" "),...e)]:[]}function wt(n){return new u(n,V)}function xt(n){return new u(n,pe)}function bt(n){return new u(n)}function re(n){return new u(n,ue)}function Y(n){return new u(n,B)}function U(n){return new u(n,A)}function q(n){return new u(n,O)}function T(n){return new u(n)}async function St(n,e,t,r,o){let s=new X(e),i=new Array,a=k.none(),d=o?.colorSetup??"flag";if(d==="flag"){let h=ge({long:"color",type:ce("color-mode",["auto","always","never"]),fallbackValueIfAbsent:()=>"auto",impliedValueIfNotInlined:()=>"always"}).registerAndMakeDecoder(s);i.push(()=>{try{a=$e(h.getAndDecodeValue())}catch(w){throw a=k.inferFromEnv(),w}})}else a=$e(d);if(o?.usageOnHelp??!0){let h=ne({long:"help"}).registerAndMakeDecoder(s);i.push(w=>{if(h.getAndDecodeValue())return console.log(Pe(n,w,a)),0})}if(o?.buildVersion!==void 0){let h=ne({long:"version"}).registerAndMakeDecoder(s);i.push(()=>{if(h.getAndDecodeValue())return console.log([n,o.buildVersion].join(" ")),0})}let p=r.consumeAndMakeDecoder(s);for(;;)try{if(s.consumePositional()===void 0)break}catch{}let l=o?.onExit??process.exit;try{for(let w of i){let z=w(p);if(z!==void 0)return l(z)}let h=p.decodeAndMakeInterpreter();try{return await h.executeWithContext(t),l(0)}catch(w){return Ue(n,o?.onError,w,a),l(1)}}catch(h){return(o?.usageOnError??!0)&&console.error(Pe(n,p,a)),Ue(n,o?.onError,h,a),l(1)}}function Ue(n,e,t,r){let o=t;e!==void 0?e(o):console.error(r.computeStyledErrorMessage(o))}function Pe(n,e,t){return xe({cliName:n,usage:e.generateUsage(),typoSupport:t}).join(`
|
|
2
|
+
`)}function $e(n){switch(n){case"auto":return k.inferFromEnv();case"env":return k.inferFromEnv();case"always":return k.tty();case"never":return k.none();case"mock":return k.mock()}}0&&(module.exports={ReaderArgs,TypoError,TypoGrid,TypoString,TypoSupport,TypoText,command,commandChained,commandWithSubcommands,operation,optionFlag,optionRepeatable,optionSingleValue,positionalOptional,positionalRequired,positionalVariadics,runAndExit,suggestTextPushMessage,typeBoolean,typeChoice,typeDatetime,typeInteger,typeList,typeMapped,typeNumber,typePath,typeRenamed,typeString,typeTuple,typeUrl,typoStyleConstants,typoStyleFailure,typoStyleLogic,typoStyleQuote,typoStyleRegularStrong,typoStyleRegularWeaker,typoStyleTitle,typoStyleUserInput,usageToStyledLines});
|
|
3
3
|
//# sourceMappingURL=index.js.map
|