cli-kiss 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +28 -13
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/Command.ts +75 -52
- package/src/lib/Operation.ts +16 -8
- package/src/lib/Option.ts +17 -12
- package/src/lib/Positional.ts +15 -8
- package/src/lib/Reader.ts +2 -5
- package/src/lib/Run.ts +32 -31
- package/src/lib/Type.ts +2 -2
- package/src/lib/Usage.ts +47 -41
- package/tests/unit.command.execute.ts +3 -2
- package/tests/unit.command.usage.ts +15 -20
- package/tests/{unit.runner.test1.ts → unit.runner.cycle.ts} +102 -68
package/dist/index.d.ts
CHANGED
|
@@ -103,6 +103,7 @@ type Option<Value> = {
|
|
|
103
103
|
};
|
|
104
104
|
type OptionUsage = {
|
|
105
105
|
description: string | undefined;
|
|
106
|
+
hint: string | undefined;
|
|
106
107
|
long: Lowercase<string>;
|
|
107
108
|
short: string | undefined;
|
|
108
109
|
label: Uppercase<string> | undefined;
|
|
@@ -114,6 +115,7 @@ declare function optionFlag(definition: {
|
|
|
114
115
|
long: Lowercase<string>;
|
|
115
116
|
short?: string;
|
|
116
117
|
description?: string;
|
|
118
|
+
hint?: string;
|
|
117
119
|
aliases?: {
|
|
118
120
|
longs?: Array<Lowercase<string>>;
|
|
119
121
|
shorts?: Array<string>;
|
|
@@ -124,6 +126,7 @@ declare function optionSingleValue<Value>(definition: {
|
|
|
124
126
|
long: Lowercase<string>;
|
|
125
127
|
short?: string;
|
|
126
128
|
description?: string;
|
|
129
|
+
hint?: string;
|
|
127
130
|
aliases?: {
|
|
128
131
|
longs?: Array<Lowercase<string>>;
|
|
129
132
|
shorts?: Array<string>;
|
|
@@ -136,6 +139,7 @@ declare function optionRepeatable<Value>(definition: {
|
|
|
136
139
|
long: Lowercase<string>;
|
|
137
140
|
short?: string;
|
|
138
141
|
description?: string;
|
|
142
|
+
hint?: string;
|
|
139
143
|
aliases?: {
|
|
140
144
|
longs?: Array<Lowercase<string>>;
|
|
141
145
|
shorts?: Array<string>;
|
|
@@ -150,15 +154,18 @@ type Positional<Value> = {
|
|
|
150
154
|
};
|
|
151
155
|
type PositionalUsage = {
|
|
152
156
|
description: string | undefined;
|
|
157
|
+
hint: string | undefined;
|
|
153
158
|
label: Uppercase<string>;
|
|
154
159
|
};
|
|
155
160
|
declare function positionalRequired<Value>(definition: {
|
|
156
161
|
description?: string;
|
|
162
|
+
hint?: string;
|
|
157
163
|
label?: Uppercase<string>;
|
|
158
164
|
type: Type<Value>;
|
|
159
165
|
}): Positional<Value>;
|
|
160
166
|
declare function positionalOptional<Value>(definition: {
|
|
161
167
|
description?: string;
|
|
168
|
+
hint?: string;
|
|
162
169
|
label?: Uppercase<string>;
|
|
163
170
|
type: Type<Value>;
|
|
164
171
|
default: () => Value;
|
|
@@ -166,15 +173,19 @@ declare function positionalOptional<Value>(definition: {
|
|
|
166
173
|
declare function positionalVariadics<Value>(definition: {
|
|
167
174
|
endDelimiter?: string;
|
|
168
175
|
description?: string;
|
|
176
|
+
hint?: string;
|
|
169
177
|
label?: Uppercase<string>;
|
|
170
178
|
type: Type<Value>;
|
|
171
179
|
}): Positional<Array<Value>>;
|
|
172
180
|
|
|
173
181
|
type Operation<Input, Output> = {
|
|
174
182
|
generateUsage(): OperationUsage;
|
|
175
|
-
|
|
183
|
+
createFactory(readerArgs: ReaderArgs): OperationFactory<Input, Output>;
|
|
176
184
|
};
|
|
177
|
-
type
|
|
185
|
+
type OperationFactory<Input, Output> = {
|
|
186
|
+
createInstance(): OperationInstance<Input, Output>;
|
|
187
|
+
};
|
|
188
|
+
type OperationInstance<Input, Output> = {
|
|
178
189
|
executeWithContext(input: Input): Promise<Output>;
|
|
179
190
|
};
|
|
180
191
|
type OperationUsage = {
|
|
@@ -196,20 +207,24 @@ declare function operation<Context, Result, Options extends {
|
|
|
196
207
|
}) => Promise<Result>): Operation<Context, Result>;
|
|
197
208
|
|
|
198
209
|
type Command<Context, Result> = {
|
|
199
|
-
|
|
200
|
-
|
|
210
|
+
getInformation(): CommandInformation;
|
|
211
|
+
createFactory(readerArgs: ReaderArgs): CommandFactory<Context, Result>;
|
|
201
212
|
};
|
|
202
|
-
type
|
|
213
|
+
type CommandFactory<Context, Result> = {
|
|
203
214
|
generateUsage(): CommandUsage;
|
|
215
|
+
createInstance(): CommandInstance<Context, Result>;
|
|
216
|
+
};
|
|
217
|
+
type CommandInstance<Context, Result> = {
|
|
204
218
|
executeWithContext(context: Context): Promise<Result>;
|
|
205
219
|
};
|
|
206
|
-
type
|
|
220
|
+
type CommandInformation = {
|
|
207
221
|
description: string;
|
|
222
|
+
hint?: string;
|
|
208
223
|
details?: string;
|
|
209
224
|
};
|
|
210
225
|
type CommandUsage = {
|
|
211
|
-
metadata: CommandMetadata;
|
|
212
226
|
breadcrumbs: Array<CommandUsageBreadcrumb>;
|
|
227
|
+
information: CommandInformation;
|
|
213
228
|
positionals: Array<PositionalUsage>;
|
|
214
229
|
subcommands: Array<CommandUsageSubcommand>;
|
|
215
230
|
options: Array<OptionUsage>;
|
|
@@ -222,22 +237,22 @@ type CommandUsageBreadcrumb = {
|
|
|
222
237
|
type CommandUsageSubcommand = {
|
|
223
238
|
name: string;
|
|
224
239
|
description: string | undefined;
|
|
240
|
+
hint: string | undefined;
|
|
225
241
|
};
|
|
226
|
-
declare function command<Context, Result>(
|
|
227
|
-
declare function commandWithSubcommands<Context, Payload, Result>(
|
|
242
|
+
declare function command<Context, Result>(information: CommandInformation, operation: Operation<Context, Result>): Command<Context, Result>;
|
|
243
|
+
declare function commandWithSubcommands<Context, Payload, Result>(information: CommandInformation, operation: Operation<Context, Payload>, subcommands: {
|
|
228
244
|
[subcommand: Lowercase<string>]: Command<Payload, Result>;
|
|
229
245
|
}): Command<Context, Result>;
|
|
230
|
-
declare function commandChained<Context, Payload, Result>(metadata:
|
|
246
|
+
declare function commandChained<Context, Payload, Result>(metadata: CommandInformation, operation: Operation<Context, Payload>, nextCommand: Command<Payload, Result>): Command<Context, Result>;
|
|
231
247
|
|
|
232
248
|
declare function runAsCliAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command: Command<Context, void>, application?: {
|
|
233
|
-
usageOnError?: boolean | undefined;
|
|
234
249
|
usageOnHelp?: boolean | undefined;
|
|
235
250
|
buildVersion?: string | undefined;
|
|
236
251
|
useColors?: boolean | undefined;
|
|
252
|
+
onExecutionError?: ((error: unknown) => void) | undefined;
|
|
237
253
|
onLogStdOut?: ((message: string) => void) | undefined;
|
|
238
254
|
onLogStdErr?: ((message: string) => void) | undefined;
|
|
239
255
|
onExit?: ((code: number) => never) | undefined;
|
|
240
|
-
onError?: ((error: unknown) => void) | undefined;
|
|
241
256
|
}): Promise<never>;
|
|
242
257
|
|
|
243
258
|
declare function usageToStyledLines(params: {
|
|
@@ -246,4 +261,4 @@ declare function usageToStyledLines(params: {
|
|
|
246
261
|
typoSupport: TypoSupport;
|
|
247
262
|
}): string[];
|
|
248
263
|
|
|
249
|
-
export { type Command, type
|
|
264
|
+
export { type Command, type CommandFactory, type CommandInformation, type CommandInstance, 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 q=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var he=Object.prototype.hasOwnProperty;var se=t=>{throw TypeError(t)};var we=(t,e)=>{for(var n in e)q(t,n,{get:e[n],enumerable:!0})},fe=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ye(e))!he.call(t,o)&&o!==n&&q(t,o,{get:()=>e[o],enumerable:!(r=me(e,o))||r.enumerable});return t};var be=t=>fe(q({},"__esModule",{value:!0}),t);var H=(t,e,n)=>e.has(t)||se("Cannot "+n);var c=(t,e,n)=>(H(t,e,"read from private field"),n?n.call(t):e.get(t)),f=(t,e,n)=>e.has(t)?se("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),h=(t,e,n,r)=>(H(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),w=(t,e,n)=>(H(t,e,"access private method"),n);var ie=(t,e,n,r)=>({set _(o){h(t,e,o,n)},get _(){return c(t,e,r)}});var Qe={};we(Qe,{ReaderArgs:()=>K,TypoError:()=>d,TypoGrid:()=>P,TypoString:()=>s,TypoSupport:()=>V,TypoText:()=>l,command:()=>ke,commandChained:()=>Pe,commandWithSubcommands:()=>$e,operation:()=>Ve,optionFlag:()=>Ke,optionRepeatable:()=>Ne,optionSingleValue:()=>Fe,positionalOptional:()=>Ye,positionalRequired:()=>je,positionalVariadics:()=>qe,runAsCliAndExit:()=>ze,typeBigInt:()=>Le,typeBoolean:()=>j,typeDate:()=>ve,typeDecode:()=>x,typeList:()=>De,typeMapped:()=>Ie,typeNumber:()=>Ge,typeOneOf:()=>Me,typeString:()=>Be,typeTuple:()=>We,typeUrl:()=>Ee,typoStyleConstants:()=>m,typoStyleFailure:()=>ae,typoStyleUserInput:()=>y,usageToStyledLines:()=>ne});module.exports=be(Qe);var m={fgColor:"darkCyan",bold:!0},y={fgColor:"darkBlue",bold:!0},ae={fgColor:"darkRed",bold:!0},B,D,s=class{constructor(e,n={}){f(this,B);f(this,D);h(this,B,e),h(this,D,n)}getRawString(){return c(this,B)}computeStyledString(e){return e.computeStyledString(c(this,B),c(this,D))}};B=new WeakMap,D=new WeakMap;var S,J=class J{constructor(...e){f(this,S);h(this,S,[]);for(let n of e)n instanceof J?this.pushText(n):n instanceof s?this.pushString(n):typeof n=="string"&&this.pushString(new s(n))}pushString(e){c(this,S).push(e)}pushText(e){for(let n of c(e,S))c(this,S).push(n)}computeStyledString(e){return c(this,S).map(n=>n.computeStyledString(e)).join("")}computeRawString(){return c(this,S).map(e=>e.getRawString()).join("")}computeRawLength(){let e=0;for(let n of c(this,S))e+=n.getRawString().length;return e}};S=new WeakMap;var l=J,$,P=class{constructor(){f(this,$);h(this,$,[])}pushRow(e){c(this,$).push(e)}computeStyledGrid(e){let n=new Array,r=new Array;for(let o of c(this,$))for(let i=0;i<o.length;i++){let p=o[i].computeRawLength();(n[i]===void 0||p>n[i])&&(n[i]=p)}for(let o of c(this,$)){let i=new Array;for(let a=0;a<o.length;a++){let p=o[a],u=p.computeStyledString(e);if(i.push(u),a<o.length-1){let b=p.computeRawLength(),O=" ".repeat(n[a]-b);i.push(O)}}r.push(i)}return r}};$=new WeakMap;var G,z=class z extends Error{constructor(n,r){let o=new l;o.pushText(n),r instanceof Error?o.pushString(new s(`: ${r.message}`)):r instanceof z?(o.pushString(new s(": ")),o.pushText(c(r,G))):r!==void 0&&o.pushString(new s(`: ${String(r)}`));super(o.computeRawString());f(this,G);h(this,G,o)}computeStyledString(n){return c(this,G).computeStyledString(n)}};G=new WeakMap;var d=z,T,C=class C{constructor(e){f(this,T);h(this,T,e)}static none(){return new C("none")}static tty(){return new C("tty")}static mock(){return new C("mock")}static inferFromProcess(){if(!process)return C.none();if(process.env){if(process.env.FORCE_COLOR==="0")return C.none();if(process.env.FORCE_COLOR)return C.tty();if("NO_COLOR"in process.env)return C.none()}return!process.stdout||!process.stdout.isTTY?C.none():C.tty()}computeStyledString(e,n){if(c(this,T)==="none")return e;if(c(this,T)==="tty"){let r=n.fgColor?Ue[n.fgColor]:"",o=n.bgColor?Ae[n.bgColor]:"",i=n.bold?Ce:"",a=n.dim?Se:"",p=n.italic?Re:"",u=n.underline?Oe:"",b=n.strikethrough?Te:"";return`${r}${o}${i}${a}${p}${u}${b}${e}${xe}`}if(c(this,T)==="mock"){let r=n.fgColor?`{${e}}@${n.fgColor}`:e,o=n.bgColor?`{${r}}#${n.bgColor}`:r,i=n.bold?`{${o}}+`:o,a=n.dim?`{${i}}-`:i,p=n.italic?`{${a}}*`:a,u=n.underline?`{${p}}_`:p;return n.strikethrough?`{${u}}~`:u}throw new Error(`Unknown TypoSupport kind: ${c(this,T)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",ae),e instanceof d?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};T=new WeakMap;var V=C,xe="\x1B[0m",Ce="\x1B[1m",Se="\x1B[2m",Re="\x1B[3m",Oe="\x1B[4m",Te="\x1B[9m",Ue={darkBlack:"\x1B[30m",darkRed:"\x1B[31m",darkGreen:"\x1B[32m",darkYellow:"\x1B[33m",darkBlue:"\x1B[34m",darkMagenta:"\x1B[35m",darkCyan:"\x1B[36m",darkWhite:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m"},Ae={darkBlack:"\x1B[40m",darkRed:"\x1B[41m",darkGreen:"\x1B[42m",darkYellow:"\x1B[43m",darkBlue:"\x1B[44m",darkMagenta:"\x1B[45m",darkCyan:"\x1B[46m",darkWhite:"\x1B[47m",brightBlack:"\x1B[100m",brightRed:"\x1B[101m",brightGreen:"\x1B[102m",brightYellow:"\x1B[103m",brightBlue:"\x1B[104m",brightMagenta:"\x1B[105m",brightCyan:"\x1B[106m",brightWhite:"\x1B[107m"};function ke(t,e){return{getDescription(){return t.description},createRunnerFromArgs(n){function r(){let o=e.generateUsage();return{metadata:t,breadcrumbs:o.positionals.map(i=>N(i.label)),positionals:o.positionals,subcommands:[],options:o.options}}try{let o=e.createRunnerFromArgs(n),i=n.consumePositional();if(i!==void 0)throw Error(`Unexpected argument: "${i}"`);return{generateUsage:r,async executeWithContext(a){return o.executeWithContext(a)}}}catch(o){return{generateUsage:r,async executeWithContext(){throw o}}}}}}function $e(t,e,n){return{getDescription(){return t.description},createRunnerFromArgs(r){try{let o=e.createRunnerFromArgs(r),i=r.consumePositional();if(i===void 0)throw new d(new l(new s("Missing required positional argument: "),new s("SUBCOMMAND",m)));let a=n[i];if(a===void 0)throw new d(new l(new s("Invalid value for positional argument: "),new s("SUBCOMMAND",m),new s(`: "${i}"`)));let p=a.createRunnerFromArgs(r);return{generateUsage(){let u=e.generateUsage(),b=p.generateUsage();return{metadata:b.metadata,breadcrumbs:u.positionals.map(O=>N(O.label)).concat([pe(i)]).concat(b.breadcrumbs),positionals:u.positionals.concat(b.positionals),subcommands:b.subcommands,options:u.options.concat(b.options)}},async executeWithContext(u){return await p.executeWithContext(await o.executeWithContext(u))}}}catch(o){return{generateUsage(){let i=e.generateUsage();return{metadata:t,breadcrumbs:i.positionals.map(a=>N(a.label)).concat([pe("<SUBCOMMAND>")]),positionals:i.positionals,subcommands:Object.entries(n).map(([a,p])=>({name:a,description:p.getDescription()})),options:i.options}},async executeWithContext(){throw o}}}}}}function Pe(t,e,n){return{getDescription(){return t.description},createRunnerFromArgs(r){let o=e.createRunnerFromArgs(r),i=n.createRunnerFromArgs(r);return{generateUsage(){let a=e.generateUsage(),p=i.generateUsage();return{metadata:p.metadata,breadcrumbs:a.positionals.map(u=>N(u.label)).concat(p.breadcrumbs),positionals:a.positionals.concat(p.positionals),subcommands:p.subcommands,options:a.options.concat(p.options)}},async executeWithContext(a){return await i.executeWithContext(await o.executeWithContext(a))}}}}}function N(t){return{positional:t}}function pe(t){return{command:t}}function Ve(t,e){return{generateUsage(){let n=new Array;for(let o in t.options){let i=t.options[o];i&&n.push(i.generateUsage())}let r=new Array;for(let o of t.positionals)r.push(o.generateUsage());return{options:n,positionals:r}},createRunnerFromArgs(n){let r={};for(let i in t.options){let a=t.options[i];r[i]=a.createGetter(n)}let o=[];for(let i of t.positionals)o.push(i.consumePositionals(n));return{executeWithContext(i){let a={};for(let p in r)a[p]=r[p].getValue();return e(i,{options:a,positionals:o})}}}}}var j={label:"BOOLEAN",decoder(t){let e=t.toLowerCase();if(e==="true"||e==="yes")return!0;if(e==="false"||e==="no")return!1;throw new Error(`Invalid value: "${t}"`)}},ve={label:"DATE",decoder(t){let e=Date.parse(t);if(isNaN(e))throw new Error(`Invalid ISO_8601 value: "${t}"`);return new Date(e)}},Ee={label:"URL",decoder(t){return new URL(t)}},Be={label:"STRING",decoder(t){return t}},Ge={label:"NUMBER",decoder(t){return Number(t)}},Le={label:"BIGINT",decoder(t){return BigInt(t)}};function Ie(t,e){return{label:e.label,decoder:n=>e.decoder(x(t,n,()=>new l(new s(t.label,y))))}}function Me(t,e){let n=new Set(e);return{label:t.label,decoder(r){let o=x(t,r,()=>new l(new s(t.label,y)));if(n.has(o))return o;let i=e.map(a=>`"${a}"`).join("|");throw new Error(`Unexpected value: "${r}" (expected: ${i})`)}}}function We(t,e=","){return{label:t.map(n=>n.label).join(e),decoder(n){let r=n.split(e,t.length);if(r.length!==t.length)throw new Error(`Invalid tuple parts: ${JSON.stringify(r)}`);return r.map((o,i)=>x(t[i],o,()=>new l(new s(t[i].label,y),new s(` at position ${i}`))))}}}function De(t,e=","){return{label:`${t.label}[${e}${t.label}]...`,decoder(n){return n.split(e).map((r,o)=>x(t,r,()=>new l(new s(t.label,y),new s(` at position ${o}`))))}}}function x(t,e,n){try{return t.decoder(e)}catch(r){throw new d(n(),r)}}function Ke(t){return{generateUsage(){return{description:t.description,long:t.long,short:t.short,label:void 0}},createGetter(e){let n=Q(e,{...t,valued:!1});return{getValue(){let r=e.getOptionValues(n);if(r.length>1)throw new d(new l(new s("Option value for: "),new s(`--${t.long}`,m),new s(": must not be set multiple times")));let o=r[0];if(o===void 0)try{return t.default?t.default():!1}catch(i){throw new d(new l(new s("Failed to compute default value for: "),new s(`--${t.long}`,m)),i)}return x(j,o,()=>new l(new s(`--${t.long}`,m),new s(": "),new s(j.label,y)))}}}}}function Fe(t){let e=t.label??t.type.label;return{generateUsage(){return{description:t.description,long:t.long,short:t.short,label:`<${e}>`}},createGetter(n){let r=Q(n,{...t,valued:!0});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new d(new l(new s("Option value for: "),new s(`--${t.long}`,m),new s(": must not be set multiple times")));let i=o[0];if(i===void 0)try{return t.default()}catch(a){throw new d(new l(new s("Failed to compute default value for: "),new s(`--${t.long}`,m)),a)}return x(t.type,i,()=>new l(new s(`--${t.long}`,m),new s(": "),new s(e,y)))}}}}}function Ne(t){let e=t.label??t.type.label;return{generateUsage(){return{description:t.description,long:t.long,short:t.short,label:`<${e}>`}},createGetter(n){let r=Q(n,{...t,valued:!0});return{getValue(){return n.getOptionValues(r).map(o=>x(t.type,o,()=>new l(new s(`--${t.long}`,m),new s(": "),new s(e,y))))}}}}}function Q(t,e){let{long:n,short:r,aliases:o,valued:i}=e,a=n?[n]:[];o?.longs&&a.push(...o?.longs);let p=r?[r]:[];return o?.shorts&&p.push(...o?.shorts),t.registerOption({longs:a,shorts:p,valued:i})}function je(t){let e=t.label??t.type.label;return{generateUsage(){return{description:t.description,label:`<${e}>`}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)throw new d(new l(new s("Missing required positional argument: "),new s(e,y)));return x(t.type,r,()=>new l(new s(e,y)))}}}function Ye(t){let e=t.label??t.type.label;return{generateUsage(){return{description:t.description,label:`[${e}]`}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)try{return t.default()}catch(o){throw new d(new l(new s("Failed to compute default value for: "),new s(e,y)),o)}return x(t.type,r,()=>new l(new s(e,y)))}}}function qe(t){let e=t.label??t.type.label;return{generateUsage(){return{description:t.description,label:`[${e}]...`+(t.endDelimiter?`["${t.endDelimiter}"]`:"")}},consumePositionals(n){let r=[];for(;;){let o=n.consumePositional();if(o===void 0||o===t.endDelimiter)break;r.push(x(t.type,o,()=>new l(new s(e,y))))}return r}}}var F,L,A,v,R,E,I,g,Y,le,X,ue,Z,U,K=class{constructor(e){f(this,g);f(this,F);f(this,L);f(this,A);f(this,v);f(this,R);f(this,E);f(this,I);h(this,F,e),h(this,L,0),h(this,A,!1),h(this,v,new Map),h(this,R,new Map),h(this,E,new Map),h(this,I,new Map)}registerOption(e){let n=[...e.longs.map(r=>`--${r}`),...e.shorts.map(r=>`-${r}`)].join(", ");for(let r of e.longs){if(c(this,v).has(r))throw new Error(`Option already registered: --${r}`);c(this,v).set(r,n)}for(let r of e.shorts){if(c(this,R).has(r))throw new Error(`Option already registered: -${r}`);for(let o=0;o<r.length;o++){let i=r.slice(0,o);if(c(this,R).has(i))throw new Error(`Option -${r} overlap with shorter option: -${i}`)}for(let o of c(this,R).keys())if(o.startsWith(r))throw new Error(`Option -${r} overlap with longer option: -${o}`);c(this,R).set(r,n)}return c(this,E).set(n,e.valued),c(this,I).set(n,new Array),n}getOptionValues(e){let n=c(this,I).get(e);if(n===void 0)throw new Error(`Unregistered option: ${e}`);return n}consumePositional(){for(;;){let e=w(this,g,Y).call(this);if(e===null)return;if(w(this,g,le).call(this,e))return e}}};F=new WeakMap,L=new WeakMap,A=new WeakMap,v=new WeakMap,R=new WeakMap,E=new WeakMap,I=new WeakMap,g=new WeakSet,Y=function(){let e=c(this,F)[c(this,L)];return e===void 0?null:(ie(this,L)._++,!c(this,A)&&e==="--"?(h(this,A,!0),w(this,g,Y).call(this)):e)},le=function(e){if(c(this,A))return!0;if(e.startsWith("--")){let n=e.indexOf("=");return n===-1?w(this,g,X).call(this,e.slice(2),null):w(this,g,X).call(this,e.slice(2,n),e.slice(n+1)),!1}if(e.startsWith("-")){let n=1,r=2;for(;r<=e.length;){let o=w(this,g,ue).call(this,e.slice(n,r),e.slice(r));if(o===!0)return!1;o===!1&&(n=r),r++}throw new d(new l(new s("Unknown option: "),new s(`-${e.slice(n)}`,m)))}return!0},X=function(e,n){let r=`--${e}`,o=c(this,v).get(e);if(o!==void 0)return n!==null?w(this,g,U).call(this,o,n):c(this,E).get(o)?w(this,g,U).call(this,o,w(this,g,Z).call(this,r)):w(this,g,U).call(this,o,"true");throw new d(new l(new s("Unknown option: "),new s(r,m)))},ue=function(e,n){let r=c(this,R).get(e);return r!==void 0?n.startsWith("=")?(w(this,g,U).call(this,r,n.slice(1)),!0):c(this,E).get(r)?(n===""?w(this,g,U).call(this,r,w(this,g,Z).call(this,`-${e}`)):w(this,g,U).call(this,r,n),!0):(w(this,g,U).call(this,r,"true"),n===""):null},Z=function(e){let n=w(this,g,Y).call(this);if(n===null)throw new d(new l(new s("Option parsing: "),new s(e,m),new s(": requires a value, but got end of input")));if(c(this,A))throw new d(new l(new s("Option parsing: "),new s(e,m),new s(': requires a value before "--"')));if(n.startsWith("-"))throw new d(new l(new s("Option parsing: "),new s(e,m),new s(`: requires a value, but got: "${n}"`)));return n},U=function(e,n){this.getOptionValues(e).push(n)};function ne(t){let{cliName:e,commandUsage:n,typoSupport:r}=t,o=new Array;o.push(He(n.metadata.description).computeStyledString(r)),n.metadata.details&&o.push(ce(n.metadata.details).computeStyledString(r)),o.push("");let i=[Je("Usage:").computeStyledString(r),M(e).computeStyledString(r)].concat(n.breadcrumbs.map(a=>{if("positional"in a)return te(a.positional).computeStyledString(r);if("command"in a)return M(a.command).computeStyledString(r);throw new Error(`Unknown breadcrumb: ${JSON.stringify(a)}`)}));if(o.push(i.join(" ")),n.positionals.length>0){o.push(""),o.push(ee("Positionals:").computeStyledString(r));let a=new P;for(let p of n.positionals){let u=new Array;u.push(new l(k())),u.push(new l(te(p.label))),p.description&&(u.push(new l(k())),u.push(new l(_(p.description)))),a.pushRow(u)}o.push(...a.computeStyledGrid(r).map(p=>p.join("")))}if(n.subcommands.length>0){o.push(""),o.push(ee("Subcommands:").computeStyledString(r));let a=new P;for(let p of n.subcommands){let u=new Array;u.push(new l(k())),u.push(new l(M(p.name))),p.description&&(u.push(new l(k())),u.push(new l(_(p.description)))),a.pushRow(u)}o.push(...a.computeStyledGrid(r).map(p=>p.join("")))}if(n.options.length>0){o.push(""),o.push(ee("Options:").computeStyledString(r));let a=new P;for(let p of n.options){let u=new Array;u.push(new l(k())),p.short?u.push(new l(M(`-${p.short}`),k(", "))):u.push(new l),p.label?u.push(new l(M(`--${p.long}`),k(" "),te(p.label))):u.push(new l(M(`--${p.long}`),ce("[=no]"))),p.description&&(u.push(new l(k())),u.push(new l(_(p.description)))),a.pushRow(u)}o.push(...a.computeStyledGrid(r).map(p=>p.join("")))}return o.push(""),o}function He(t){return new s(t,{bold:!0})}function _(t){return new s(t)}function ce(t){return new s(t,{italic:!0,dim:!0})}function Je(t){return new s(t,{fgColor:"darkMagenta",bold:!0})}function ee(t){return new s(t,{fgColor:"darkGreen",bold:!0})}function M(t){return new s(t,m)}function te(t){return new s(t,y)}function k(t){return new s(t??" ")}async function ze(t,e,n,r,o){let i=new K(e),a=o?.buildVersion;a&&i.registerOption({shorts:[],longs:["version"],valued:!1});let p=o?.usageOnHelp??!0;p&&i.registerOption({shorts:[],longs:["help"],valued:!1});let u=r.createRunnerFromArgs(i);for(;i.consumePositional()!==void 0;);let b=o?.onLogStdOut??console.log,O=o?.onExit??process.exit;if(a&&i.getOptionValues("--version").length>0)return b([t,a].join(" ")),O(0);if(p&&i.getOptionValues("--help").length>0){let W=de(o?.useColors);return b(ge(t,u,W)),O(0)}try{return await u.executeWithContext(n),O(0)}catch(W){if(o?.onError)o.onError(W);else{let oe=o?.onLogStdErr??console.error,re=de(o?.useColors);(o?.usageOnError??!0)&&oe(ge(t,u,re)),oe(re.computeStyledErrorMessage(W))}return O(1)}}function ge(t,e,n){return ne({cliName:t,commandUsage:e.generateUsage(),typoSupport:n}).join(`
|
|
2
|
-
`)}function
|
|
1
|
+
"use strict";var z=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var ht=Object.prototype.hasOwnProperty;var at=t=>{throw TypeError(t)};var ft=(t,e)=>{for(var n in e)z(t,n,{get:e[n],enumerable:!0})},wt=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of yt(e))!ht.call(t,r)&&r!==n&&z(t,r,{get:()=>e[r],enumerable:!(o=mt(e,r))||o.enumerable});return t};var bt=t=>wt(z({},"__esModule",{value:!0}),t);var Q=(t,e,n)=>e.has(t)||at("Cannot "+n);var c=(t,e,n)=>(Q(t,e,"read from private field"),n?n.call(t):e.get(t)),b=(t,e,n)=>e.has(t)?at("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),f=(t,e,n,o)=>(Q(t,e,"write to private field"),o?o.call(t,n):e.set(t,n),n),w=(t,e,n)=>(Q(t,e,"access private method"),n);var pt=(t,e,n,o)=>({set _(r){f(t,e,r,n)},get _(){return c(t,e,o)}});var Zt={};ft(Zt,{ReaderArgs:()=>K,TypoError:()=>m,TypoGrid:()=>$,TypoString:()=>i,TypoSupport:()=>P,TypoText:()=>l,command:()=>kt,commandChained:()=>$t,commandWithSubcommands:()=>At,operation:()=>Pt,optionFlag:()=>Kt,optionRepeatable:()=>Nt,optionSingleValue:()=>Dt,positionalOptional:()=>Yt,positionalRequired:()=>jt,positionalVariadics:()=>qt,runAsCliAndExit:()=>Qt,typeBigInt:()=>Gt,typeBoolean:()=>Y,typeDate:()=>Vt,typeDecode:()=>x,typeList:()=>Wt,typeMapped:()=>Lt,typeNumber:()=>Bt,typeOneOf:()=>Ft,typeString:()=>vt,typeTuple:()=>Mt,typeUrl:()=>Et,typoStyleConstants:()=>y,typoStyleFailure:()=>lt,typoStyleUserInput:()=>h,usageToStyledLines:()=>st});module.exports=bt(Zt);var y={fgColor:"darkCyan",bold:!0},h={fgColor:"darkBlue",bold:!0},lt={fgColor:"darkRed",bold:!0},v,W,i=class{constructor(e,n={}){b(this,v);b(this,W);f(this,v,e),f(this,W,n)}getRawString(){return c(this,v)}computeStyledString(e){return e.computeStyledString(c(this,v),c(this,W))}};v=new WeakMap,W=new WeakMap;var S,X=class X{constructor(...e){b(this,S);f(this,S,[]);for(let n of e)n instanceof X?this.pushText(n):n instanceof i?this.pushString(n):typeof n=="string"&&this.pushString(new i(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=X,A,$=class{constructor(){b(this,A);f(this,A,[])}pushRow(e){c(this,A).push(e)}computeStyledGrid(e){let n=new Array,o=new Array;for(let r of c(this,A))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,A)){let s=new Array;for(let a=0;a<r.length;a++){let p=r[a],u=p.computeStyledString(e);if(s.push(u),a<r.length-1){let g=p.computeRawLength(),O=" ".repeat(n[a]-g);s.push(O)}}o.push(s)}return o}};A=new WeakMap;var B,Z=class Z extends Error{constructor(n,o){let r=new l;r.pushText(n),o instanceof Error?r.pushString(new i(`: ${o.message}`)):o instanceof Z?(r.pushString(new i(": ")),r.pushText(c(o,B))):o!==void 0&&r.pushString(new i(`: ${String(o)}`));super(r.computeRawString());b(this,B);f(this,B,r)}computeStyledString(n){return c(this,B).computeStyledString(n)}};B=new WeakMap;var m=Z,R,C=class C{constructor(e){b(this,R);f(this,R,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,R)==="none")return e;if(c(this,R)==="tty"){let o=n.fgColor?Rt[n.fgColor]:"",r=n.bgColor?It[n.bgColor]:"",s=n.bold?Ct:"",a=n.dim?St:"",p=n.italic?Tt:"",u=n.underline?Ut:"",g=n.strikethrough?Ot:"";return`${o}${r}${s}${a}${p}${u}${g}${e}${xt}`}if(c(this,R)==="mock"){let o=n.fgColor?`{${e}}@${n.fgColor}`:e,r=n.bgColor?`{${o}}#${n.bgColor}`:o,s=n.bold?`{${r}}+`:r,a=n.dim?`{${s}}-`:s,p=n.italic?`{${a}}*`:a,u=n.underline?`{${p}}_`:p;return n.strikethrough?`{${u}}~`:u}throw new Error(`Unknown TypoSupport kind: ${c(this,R)}`)}computeStyledErrorMessage(e){return[this.computeStyledString("Error:",lt),e instanceof m?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};R=new WeakMap;var P=C,xt="\x1B[0m",Ct="\x1B[1m",St="\x1B[2m",Tt="\x1B[3m",Ut="\x1B[4m",Ot="\x1B[9m",Rt={darkBlack:"\x1B[30m",darkRed:"\x1B[31m",darkGreen:"\x1B[32m",darkYellow:"\x1B[33m",darkBlue:"\x1B[34m",darkMagenta:"\x1B[35m",darkCyan:"\x1B[36m",darkWhite:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m"},It={darkBlack:"\x1B[40m",darkRed:"\x1B[41m",darkGreen:"\x1B[42m",darkYellow:"\x1B[43m",darkBlue:"\x1B[44m",darkMagenta:"\x1B[45m",darkCyan:"\x1B[46m",darkWhite:"\x1B[47m",brightBlack:"\x1B[100m",brightRed:"\x1B[101m",brightGreen:"\x1B[102m",brightYellow:"\x1B[103m",brightBlue:"\x1B[104m",brightMagenta:"\x1B[105m",brightCyan:"\x1B[106m",brightWhite:"\x1B[107m"};function kt(t,e){return{getInformation(){return t},createFactory(n){function o(){let r=e.generateUsage();return{breadcrumbs:r.positionals.map(s=>j(s.label)),information:t,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 a=r.createInstance();return{async executeWithContext(p){return await a.executeWithContext(p)}}}}}catch(r){return{generateUsage:o,createInstance(){throw r}}}}}}function At(t,e,n){return{getInformation(){return t},createFactory(o){try{let r=e.createFactory(o),s=o.consumePositional();if(s===void 0)throw new m(new l(new i("<SUBCOMMAND>",y),new i(": Is required, but was not provided")));let a=n[s];if(a===void 0)throw new m(new l(new i("<SUBCOMMAND>",y),new i(`: Invalid value: "${s}"`)));let p=a.createFactory(o);return{generateUsage(){let u=e.generateUsage(),g=p.generateUsage();return{breadcrumbs:u.positionals.map(O=>j(O.label)).concat([ut(s)]).concat(g.breadcrumbs),information:g.information,positionals:u.positionals.concat(g.positionals),subcommands:g.subcommands,options:u.options.concat(g.options)}},createInstance(){let u=r.createInstance(),g=p.createInstance();return{async executeWithContext(O){return await g.executeWithContext(await u.executeWithContext(O))}}}}}catch(r){return{generateUsage(){let s=e.generateUsage();return{breadcrumbs:s.positionals.map(a=>j(a.label)).concat([ut("<SUBCOMMAND>")]),information:t,positionals:s.positionals,subcommands:Object.entries(n).map(a=>{let p=a[1].getInformation();return{name:a[0],description:p.description,hint:p.hint}}),options:s.options}},createInstance(){throw r}}}}}}function $t(t,e,n){return{getInformation(){return t},createFactory(o){let r=e.createFactory(o),s=n.createFactory(o);return{generateUsage(){let a=e.generateUsage(),p=s.generateUsage();return{information:p.information,breadcrumbs:a.positionals.map(u=>j(u.label)).concat(p.breadcrumbs),positionals:a.positionals.concat(p.positionals),subcommands:p.subcommands,options:a.options.concat(p.options)}},createInstance(){let a=r.createInstance(),p=s.createInstance();return{async executeWithContext(u){return await p.executeWithContext(await a.executeWithContext(u))}}}}}}}function j(t){return{positional:t}}function ut(t){return{command:t}}function Pt(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 a=t.options[s];o[s]=a.createGetter(n)}let r=[];for(let s of t.positionals)r.push(s.consumePositionals(n));return{createInstance(){let s={};for(let a in o)s[a]=o[a].getValue();return{executeWithContext(a){return e(a,{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}"`)}},Vt={label:"DATE",decoder(t){let e=Date.parse(t);if(isNaN(e))throw new Error(`Invalid ISO_8601 value: "${t}"`);return new Date(e)}},Et={label:"URL",decoder(t){return new URL(t)}},vt={label:"STRING",decoder(t){return t}},Bt={label:"NUMBER",decoder(t){return Number(t)}},Gt={label:"BIGINT",decoder(t){return BigInt(t)}};function Lt(t,e){return{label:e.label,decoder:n=>e.decoder(x(t,n,()=>new l(new i(t.label,h))))}}function Ft(t,e){let n=new Set(e);return{label:t.label,decoder(o){let r=x(t,o,()=>new l(new i(t.label,h)));if(n.has(r))return r;let s=e.map(a=>`"${a}"`).join("|");throw new Error(`Unexpected value: "${o}" (expected: ${s})`)}}}function Mt(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 i(t[s].label,h),new i(`@${s}`))))}}}function Wt(t,e=","){return{label:`${t.label}[${e}${t.label}]...`,decoder(n){return n.split(e).map((o,r)=>x(t,o,()=>new l(new i(t.label,h),new i(`@${r}`))))}}}function x(t,e,n){try{return t.decoder(e)}catch(o){throw new m(n(),o)}}function Kt(t){let e=`<${Y.label}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:void 0}},createGetter(n){let o=_(n,{...t,valued:!1});return{getValue(){let r=n.getOptionValues(o);if(r.length>1)throw new m(new l(new i(`--${t.long}`,y),new i(": Must not be set multiple times")));let s=r[0];if(s===void 0)try{return t.default?t.default():!1}catch(a){throw new m(new l(new i(`--${t.long}`,y),new i(": Failed to compute default value")),a)}return x(Y,s,()=>new l(new i(`--${t.long}`,y),new i(": "),new i(e,h)))}}}}}function Dt(t){let e=`<${t.label??t.type.label}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:e}},createGetter(n){let o=_(n,{...t,valued:!0});return{getValue(){let r=n.getOptionValues(o);if(r.length>1)throw new m(new l(new i(`--${t.long}`,y),new i(": Must not be set multiple times")));let s=r[0];if(s===void 0)try{return t.default()}catch(a){throw new m(new l(new i(`--${t.long}`,y),new i(": Failed to compute default value")),a)}return x(t.type,s,()=>new l(new i(`--${t.long}`,y),new i(": "),new i(e,h)))}}}}}function Nt(t){let e=`<${t.label??t.type.label}>`;return{generateUsage(){return{description:t.description,hint:t.hint,long:t.long,short:t.short,label:e}},createGetter(n){let o=_(n,{...t,valued:!0});return{getValue(){return n.getOptionValues(o).map(r=>x(t.type,r,()=>new l(new i(`--${t.long}`,y),new i(": "),new i(e,h))))}}}}}function _(t,e){let{long:n,short:o,aliases:r,valued:s}=e,a=n?[n]:[];r?.longs&&a.push(...r?.longs);let p=o?[o]:[];return r?.shorts&&p.push(...r?.shorts),t.registerOption({longs:a,shorts:p,valued:s})}function jt(t){let e=`<${t.label??t.type.label}>`;return{generateUsage(){return{description:t.description,hint:t.hint,label:e}},consumePositionals(n){let o=n.consumePositional();if(o===void 0)throw new m(new l(new i(e,h),new i(": Is required, but was not provided")));return x(t.type,o,()=>new l(new i(e,h)))}}}function Yt(t){let e=`[${t.label??t.type.label}]`;return{generateUsage(){return{description:t.description,hint:t.hint,label:e}},consumePositionals(n){let o=n.consumePositional();if(o===void 0)try{return t.default()}catch(r){throw new m(new l(new i(e,h),new i(": Failed to compute default value")),r)}return x(t.type,o,()=>new l(new i(e,h)))}}}function qt(t){let e=`[${t.label??t.type.label}]`;return{generateUsage(){return{description:t.description,hint:t.hint,label:`${e}...`+(t.endDelimiter?`["${t.endDelimiter}"]`:"")}},consumePositionals(n){let o=[];for(;;){let r=n.consumePositional();if(r===void 0||r===t.endDelimiter)break;o.push(x(t.type,r,()=>new l(new i(e,h))))}return o}}}var D,G,k,V,T,E,L,d,q,ct,tt,gt,et,I,K=class{constructor(e){b(this,d);b(this,D);b(this,G);b(this,k);b(this,V);b(this,T);b(this,E);b(this,L);f(this,D,e),f(this,G,0),f(this,k,!1),f(this,V,new Map),f(this,T,new Map),f(this,E,new Map),f(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,E).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=w(this,d,q).call(this);if(e===null)return;if(w(this,d,ct).call(this,e))return e}}};D=new WeakMap,G=new WeakMap,k=new WeakMap,V=new WeakMap,T=new WeakMap,E=new WeakMap,L=new WeakMap,d=new WeakSet,q=function(){let e=c(this,D)[c(this,G)];return e===void 0?null:(pt(this,G)._++,!c(this,k)&&e==="--"?(f(this,k,!0),w(this,d,q).call(this)):e)},ct=function(e){if(c(this,k))return!0;if(e.startsWith("--")){let n=e.indexOf("=");return n===-1?w(this,d,tt).call(this,e.slice(2),null):w(this,d,tt).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=w(this,d,gt).call(this,e.slice(n,o),e.slice(o));if(r===!0)return!1;r===!1&&(n=o),o++}throw new m(new l(new i(`-${e.slice(n)}`,y),new i(": Unexpected unknown option")))}return!0},tt=function(e,n){let o=`--${e}`,r=c(this,V).get(e);if(r!==void 0)return n!==null?w(this,d,I).call(this,r,n):c(this,E).get(r)?w(this,d,I).call(this,r,w(this,d,et).call(this,o)):w(this,d,I).call(this,r,"true");throw new m(new l(new i(o,y),new i(": Unexpected unknown option")))},gt=function(e,n){let o=c(this,T).get(e);return o!==void 0?n.startsWith("=")?(w(this,d,I).call(this,o,n.slice(1)),!0):c(this,E).get(o)?(n===""?w(this,d,I).call(this,o,w(this,d,et).call(this,`-${e}`)):w(this,d,I).call(this,o,n),!0):(w(this,d,I).call(this,o,"true"),n===""):null},et=function(e){let n=w(this,d,q).call(this);if(n===null)throw new m(new l(new i(e,y),new i(": requires a value, but got end of input")));if(c(this,k))throw new m(new l(new i(e,y),new i(': requires a value before "--"')));if(n.startsWith("-"))throw new m(new l(new i(e,y),new i(`: requires a value, but got: "${n}"`)));return n},I=function(e,n){this.getOptionValues(e).push(n)};function st(t){let{cliName:e,commandUsage:n,typoSupport:o}=t,r=new Array,s=[Jt("Usage:").computeStyledString(o),F(e).computeStyledString(o)].concat(n.breadcrumbs.map(p=>{if("positional"in p)return rt(p.positional).computeStyledString(o);if("command"in p)return F(p.command).computeStyledString(o);throw new Error(`Unknown breadcrumb: ${JSON.stringify(p)}`)}));r.push(s.join(" ")),r.push("");let a=new l;if(a.pushString(Ht(n.information.description)),n.information.hint&&(a.pushString(U(" ")),a.pushString(H(`(${n.information.hint})`))),r.push(a.computeStyledString(o)),n.information.details){let p=H(n.information.details);r.push(p.computeStyledString(o))}if(n.positionals.length>0){r.push(""),r.push(ot("Positionals:").computeStyledString(o));let p=new $;for(let u of n.positionals){let g=new Array;g.push(new l(U(" "))),g.push(new l(rt(u.label))),g.push(...nt(u)),p.pushRow(g)}r.push(...p.computeStyledGrid(o).map(u=>u.join("")))}if(n.subcommands.length>0){r.push(""),r.push(ot("Subcommands:").computeStyledString(o));let p=new $;for(let u of n.subcommands){let g=new Array;g.push(new l(U(" "))),g.push(new l(F(u.name))),g.push(...nt(u)),p.pushRow(g)}r.push(...p.computeStyledGrid(o).map(u=>u.join("")))}if(n.options.length>0){r.push(""),r.push(ot("Options:").computeStyledString(o));let p=new $;for(let u of n.options){let g=new Array;g.push(new l(U(" "))),u.short?g.push(new l(F(`-${u.short}`),U(", "))):g.push(new l),u.label?g.push(new l(F(`--${u.long}`),U(" "),rt(u.label))):g.push(new l(F(`--${u.long}`),H("[=no]"))),g.push(...nt(u)),p.pushRow(g)}r.push(...p.computeStyledGrid(o).map(u=>u.join("")))}return r.push(""),r}function nt(t){let e=[];return t.description&&(e.push(U(" ")),e.push(zt(t.description))),t.hint&&(e.push(U(" ")),e.push(H(`(${t.hint})`))),e.length>0?[new l(U(" "),...e)]:[]}function Ht(t){return new i(t,{bold:!0})}function Jt(t){return new i(t,{fgColor:"darkMagenta",bold:!0})}function zt(t){return new i(t)}function H(t){return new i(t,{italic:!0,dim:!0})}function ot(t){return new i(t,{fgColor:"darkGreen",bold:!0})}function F(t){return new i(t,y)}function rt(t){return new i(t,h)}function U(t){return new i(t)}async function Qt(t,e,n,o,r){let s=new K(e),a=r?.usageOnHelp??!0;a&&s.registerOption({shorts:[],longs:["help"],valued:!1});let p=r?.buildVersion;p&&s.registerOption({shorts:[],longs:["version"],valued:!1});let u=o.createFactory(s);for(;s.consumePositional()!==void 0;);let g=Xt(r?.useColors),O=r?.onLogStdOut??console.log,J=r?.onLogStdErr??console.error,M=r?.onExit??process.exit;if(a&&s.getOptionValues("--help").length>0)return O(dt(t,u,g)),M(0);if(p&&s.getOptionValues("--version").length>0)return O([t,p].join(" ")),M(0);try{let N=u.createInstance();try{return await N.executeWithContext(n),M(0)}catch(it){return r?.onExecutionError?r.onExecutionError(it):J(g.computeStyledErrorMessage(it)),M(1)}}catch(N){return J(dt(t,u,g)),J(g.computeStyledErrorMessage(N)),M(1)}}function dt(t,e,n){return st({cliName:t,commandUsage:e.generateUsage(),typoSupport:n}).join(`
|
|
2
|
+
`)}function Xt(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
|