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