cli-kiss 0.1.3 → 0.1.4
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 +11 -11
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/Command.ts +16 -14
- package/src/lib/Operation.ts +2 -2
- package/src/lib/Option.ts +0 -1
- package/src/lib/Run.ts +9 -15
- package/src/lib/Type.ts +0 -1
- package/tests/unit.command.execute.ts +2 -2
- package/tests/unit.command.usage.ts +3 -3
- package/tests/unit.runner.cycle.ts +10 -11
package/dist/index.d.ts
CHANGED
|
@@ -178,7 +178,7 @@ declare function positionalVariadics<Value>(definition: {
|
|
|
178
178
|
type: Type<Value>;
|
|
179
179
|
}): Positional<Array<Value>>;
|
|
180
180
|
|
|
181
|
-
type
|
|
181
|
+
type OperationDescriptor<Input, Output> = {
|
|
182
182
|
generateUsage(): OperationUsage;
|
|
183
183
|
createFactory(readerArgs: ReaderArgs): OperationFactory<Input, Output>;
|
|
184
184
|
};
|
|
@@ -204,9 +204,9 @@ declare function operation<Context, Result, Options extends {
|
|
|
204
204
|
}, handler: (context: Context, inputs: {
|
|
205
205
|
options: Options;
|
|
206
206
|
positionals: Positionals;
|
|
207
|
-
}) => Promise<Result>):
|
|
207
|
+
}) => Promise<Result>): OperationDescriptor<Context, Result>;
|
|
208
208
|
|
|
209
|
-
type
|
|
209
|
+
type CommandDescriptor<Context, Result> = {
|
|
210
210
|
getInformation(): CommandInformation;
|
|
211
211
|
createFactory(readerArgs: ReaderArgs): CommandFactory<Context, Result>;
|
|
212
212
|
};
|
|
@@ -239,20 +239,20 @@ type CommandUsageSubcommand = {
|
|
|
239
239
|
description: string | undefined;
|
|
240
240
|
hint: string | undefined;
|
|
241
241
|
};
|
|
242
|
-
declare function command<Context, Result>(information: CommandInformation, operation:
|
|
243
|
-
declare function commandWithSubcommands<Context, Payload, Result>(information: CommandInformation, operation:
|
|
244
|
-
[subcommand: Lowercase<string>]:
|
|
245
|
-
}):
|
|
246
|
-
declare function commandChained<Context, Payload, Result>(information: CommandInformation, operation:
|
|
242
|
+
declare function command<Context, Result>(information: CommandInformation, operation: OperationDescriptor<Context, Result>): CommandDescriptor<Context, Result>;
|
|
243
|
+
declare function commandWithSubcommands<Context, Payload, Result>(information: CommandInformation, operation: OperationDescriptor<Context, Payload>, subcommands: {
|
|
244
|
+
[subcommand: Lowercase<string>]: CommandDescriptor<Payload, Result>;
|
|
245
|
+
}): CommandDescriptor<Context, Result>;
|
|
246
|
+
declare function commandChained<Context, Payload, Result>(information: CommandInformation, operation: OperationDescriptor<Context, Payload>, nextCommand: CommandDescriptor<Payload, Result>): CommandDescriptor<Context, Result>;
|
|
247
247
|
|
|
248
|
-
declare function runAsCliAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command:
|
|
248
|
+
declare function runAsCliAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command: CommandDescriptor<Context, void>, application?: {
|
|
249
249
|
usageOnHelp?: boolean | undefined;
|
|
250
250
|
buildVersion?: string | undefined;
|
|
251
251
|
useColors?: boolean | undefined;
|
|
252
|
-
onExecutionError?: ((error: unknown) => void) | undefined;
|
|
253
252
|
onLogStdOut?: ((message: string) => void) | undefined;
|
|
254
253
|
onLogStdErr?: ((message: string) => void) | undefined;
|
|
255
254
|
onExit?: ((code: number) => never) | undefined;
|
|
255
|
+
onExecutionError?: ((error: unknown) => void) | undefined;
|
|
256
256
|
}): Promise<never>;
|
|
257
257
|
|
|
258
258
|
declare function usageToStyledLines(params: {
|
|
@@ -261,4 +261,4 @@ declare function usageToStyledLines(params: {
|
|
|
261
261
|
typoSupport: TypoSupport;
|
|
262
262
|
}): string[];
|
|
263
263
|
|
|
264
|
-
export { type
|
|
264
|
+
export { type CommandDescriptor, type CommandFactory, type CommandInformation, type CommandInstance, type CommandUsage, type CommandUsageBreadcrumb, type CommandUsageSubcommand, type OperationDescriptor, 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 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
|
|
1
|
+
"use strict";var z=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var yt=Object.prototype.hasOwnProperty;var at=t=>{throw TypeError(t)};var ht=(t,e)=>{for(var n in e)z(t,n,{get:e[n],enumerable:!0})},ft=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of mt(e))!yt.call(t,o)&&o!==n&&z(t,o,{get:()=>e[o],enumerable:!(r=dt(e,o))||r.enumerable});return t};var wt=t=>ft(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),h=(t,e,n,r)=>(Q(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),f=(t,e,n)=>(Q(t,e,"access private method"),n);var pt=(t,e,n,r)=>({set _(o){h(t,e,o,n)},get _(){return c(t,e,r)}});var Zt={};ht(Zt,{ReaderArgs:()=>N,TypoError:()=>m,TypoGrid:()=>$,TypoString:()=>i,TypoSupport:()=>P,TypoText:()=>l,command:()=>It,commandChained:()=>At,commandWithSubcommands:()=>kt,operation:()=>Pt,optionFlag:()=>Wt,optionRepeatable:()=>Nt,optionSingleValue:()=>Kt,positionalOptional:()=>Yt,positionalRequired:()=>jt,positionalVariadics:()=>qt,runAsCliAndExit:()=>Qt,typeBigInt:()=>Gt,typeBoolean:()=>Y,typeDate:()=>Vt,typeDecode:()=>x,typeList:()=>Mt,typeMapped:()=>Lt,typeNumber:()=>Bt,typeOneOf:()=>Ft,typeString:()=>vt,typeTuple:()=>Dt,typeUrl:()=>Et,typoStyleConstants:()=>w,typoStyleFailure:()=>lt,typoStyleUserInput:()=>y,usageToStyledLines:()=>st});module.exports=wt(Zt);var w={fgColor:"darkCyan",bold:!0},y={fgColor:"darkBlue",bold:!0},lt={fgColor:"darkRed",bold:!0},B,K,i=class{constructor(e,n={}){b(this,B);b(this,K);h(this,B,e),h(this,K,n)}getRawString(){return c(this,B)}computeStyledString(e){return e.computeStyledString(c(this,B),c(this,K))}};B=new WeakMap,K=new WeakMap;var S,X=class X{constructor(...e){b(this,S);h(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);h(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(),U=" ".repeat(n[a]-g);s.push(U)}}r.push(s)}return r}};A=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 i(`: ${r.message}`)):r instanceof Z?(o.pushString(new i(": ")),o.pushText(c(r,G))):r!==void 0&&o.pushString(new i(`: ${String(r)}`));super(o.computeRawString());b(this,G);h(this,G,o)}computeStyledString(n){return c(this,G).computeStyledString(n)}};G=new WeakMap;var m=Z,R,C=class C{constructor(e){b(this,R);h(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?Ot[n.fgColor]:"",o=n.bgColor?Rt[n.bgColor]:"",s=n.bold?xt:"",a=n.dim?Ct:"",p=n.italic?St:"",u=n.underline?Ut:"",g=n.strikethrough?Tt:"";return`${r}${o}${s}${a}${p}${u}${g}${e}${bt}`}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:",lt),e instanceof m?e.computeStyledString(this):e instanceof Error?e.message:String(e)].join(" ")}};R=new WeakMap;var P=C,bt="\x1B[0m",xt="\x1B[1m",Ct="\x1B[2m",St="\x1B[3m",Ut="\x1B[4m",Tt="\x1B[9m",Ot={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"},Rt={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 It(t,e){return{getInformation(){return t},createFactory(n){function r(){let o=e.generateUsage();return{breadcrumbs:o.positionals.map(s=>V(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 kt(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(U=>V(U.label)).concat([$t(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(U){return await g.executeWithContext(await u.executeWithContext(U))}}}}}catch(o){return{generateUsage(){let s=e.generateUsage();return{breadcrumbs:s.positionals.map(a=>V(a.label)).concat([V("<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 At(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=>V(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=>V(a.label)).concat([V("[REST]...")]),information:t,positionals:s.positionals,subcommands:[],options:s.options}},createInstance(){throw o}}}}}}function V(t){return{positional:t}}function $t(t){return{command:t}}function Pt(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 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,y))))}}function Ft(t,e){let n=new Set(e);return{label:t.label,decoder(r){let o=x(t,r,()=>new l(new i(t.label,y)));if(n.has(o))return o;let s=e.map(a=>`"${a}"`).join("|");throw new Error(`Unexpected value: "${r}" (expected: ${s})`)}}}function Dt(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,y),new i(`@${s}`))))}}}function Mt(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,y),new i(`@${o}`))))}}}function x(t,e,n){try{return t.decoder(e)}catch(r){throw new m(n(),r)}}function Wt(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 r=_(n,{...t,valued:!1});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new m(new l(new i(`--${t.long}`,w),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}`,w),new i(": Failed to compute default value")),a)}return x(Y,s,()=>new l(new i(`--${t.long}`,w),new i(": "),new i(e,y)))}}}}}function Kt(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=_(n,{...t,valued:!0});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new m(new l(new i(`--${t.long}`,w),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}`,w),new i(": Failed to compute default value")),a)}return x(t.type,s,()=>new l(new i(`--${t.long}`,w),new i(": "),new i(e,y)))}}}}}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=_(n,{...t,valued:!0});return{getValue(){return n.getOptionValues(r).map(o=>x(t.type,o,()=>new l(new i(`--${t.long}`,w),new i(": "),new i(e,y))))}}}}}function _(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 jt(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,y),new i(": Is required, but was not provided")));return x(t.type,r,()=>new l(new i(e,y)))}}}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)try{return t.default()}catch(o){throw new m(new l(new i(e,y),new i(": Failed to compute default value")),o)}return x(t.type,r,()=>new l(new i(e,y)))}}}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 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,y))))}return r}}}var j,L,k,E,T,v,F,d,q,ut,tt,ct,et,I,N=class{constructor(e){b(this,d);b(this,j);b(this,L);b(this,k);b(this,E);b(this,T);b(this,v);b(this,F);h(this,j,e),h(this,L,0),h(this,k,!1),h(this,E,new Map),h(this,T,new Map),h(this,v,new Map),h(this,F,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,E).has(r))throw new Error(`Option already registered: --${r}`);c(this,E).set(r,n)}for(let r of e.shorts){if(c(this,T).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,T).has(s))throw new Error(`Option -${r} overlap with shorter option: -${s}`)}for(let o of c(this,T).keys())if(o.startsWith(r))throw new Error(`Option -${r} overlap with longer option: -${o}`);c(this,T).set(r,n)}return c(this,v).set(n,e.valued),c(this,F).set(n,new Array),n}getOptionValues(e){let n=c(this,F).get(e);if(n===void 0)throw new Error(`Unregistered option: ${e}`);return n}consumePositional(){for(;;){let e=f(this,d,q).call(this);if(e===null)return;if(f(this,d,ut).call(this,e))return e}}};j=new WeakMap,L=new WeakMap,k=new WeakMap,E=new WeakMap,T=new WeakMap,v=new WeakMap,F=new WeakMap,d=new WeakSet,q=function(){let e=c(this,j)[c(this,L)];return e===void 0?null:(pt(this,L)._++,!c(this,k)&&e==="--"?(h(this,k,!0),f(this,d,q).call(this)):e)},ut=function(e){if(c(this,k))return!0;if(e.startsWith("--")){let n=e.indexOf("=");return n===-1?f(this,d,tt).call(this,e.slice(2),null):f(this,d,tt).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=f(this,d,ct).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)}`,w),new i(": Unexpected unknown option")))}return!0},tt=function(e,n){let r=`--${e}`,o=c(this,E).get(e);if(o!==void 0)return n!==null?f(this,d,I).call(this,o,n):c(this,v).get(o)?f(this,d,I).call(this,o,f(this,d,et).call(this,r)):f(this,d,I).call(this,o,"true");throw new m(new l(new i(r,w),new i(": Unexpected unknown option")))},ct=function(e,n){let r=c(this,T).get(e);return r!==void 0?n.startsWith("=")?(f(this,d,I).call(this,r,n.slice(1)),!0):c(this,v).get(r)?(n===""?f(this,d,I).call(this,r,f(this,d,et).call(this,`-${e}`)):f(this,d,I).call(this,r,n),!0):(f(this,d,I).call(this,r,"true"),n===""):null},et=function(e){let n=f(this,d,q).call(this);if(n===null)throw new m(new l(new i(e,w),new i(": Requires a value, but got end of input")));if(c(this,k))throw new m(new l(new i(e,w),new i(': Requires a value before "--"')));if(n.startsWith("-"))throw new m(new l(new i(e,w),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:r}=t,o=new Array,s=[Jt("Usage:").computeStyledString(r),D(e).computeStyledString(r)].concat(n.breadcrumbs.map(p=>{if("positional"in p)return rt(p.positional).computeStyledString(r);if("command"in p)return D(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(Ht(n.information.description)),n.information.hint&&(a.pushString(O(" ")),a.pushString(H(`(${n.information.hint})`))),o.push(a.computeStyledString(r)),n.information.details){let p=H(n.information.details);o.push(p.computeStyledString(r))}if(n.positionals.length>0){o.push(""),o.push(ot("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(rt(u.label))),g.push(...nt(u)),p.pushRow(g)}o.push(...p.computeStyledGrid(r).map(u=>u.join("")))}if(n.subcommands.length>0){o.push(""),o.push(ot("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(D(u.name))),g.push(...nt(u)),p.pushRow(g)}o.push(...p.computeStyledGrid(r).map(u=>u.join("")))}if(n.options.length>0){o.push(""),o.push(ot("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(D(`-${u.short}`),O(", "))):g.push(new l),u.label?g.push(new l(D(`--${u.long}`),O(" "),rt(u.label))):g.push(new l(D(`--${u.long}`),H("[=no]"))),g.push(...nt(u)),p.pushRow(g)}o.push(...p.computeStyledGrid(r).map(u=>u.join("")))}return o.push(""),o}function nt(t){let e=[];return t.description&&(e.push(O(" ")),e.push(zt(t.description))),t.hint&&(e.push(O(" ")),e.push(H(`(${t.hint})`))),e.length>0?[new l(O(" "),...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 D(t){return new i(t,w)}function rt(t){return new i(t,y)}function O(t){return new i(t)}async function Qt(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=Xt(o?.useColors),g=o?.onLogStdOut??console.log,U=o?.onLogStdErr??console.error,M=o?.onExit??process.exit,J=r.createFactory(s);for(;;)try{if(s.consumePositional()===void 0)break}catch{}if(a&&s.getOptionValues("--help").length>0)return g(gt(t,J,u)),M(0);if(p&&s.getOptionValues("--version").length>0)return g([t,p].join(" ")),M(0);try{let W=J.createInstance();try{return await W.executeWithContext(n),M(0)}catch(it){return o?.onExecutionError?o.onExecutionError(it):U(u.computeStyledErrorMessage(it)),M(1)}}catch(W){return U(gt(t,J,u)),U(u.computeStyledErrorMessage(W)),M(1)}}function gt(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
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/lib/Typo.ts","../src/lib/Command.ts","../src/lib/Operation.ts","../src/lib/Type.ts","../src/lib/Option.ts","../src/lib/Positional.ts","../src/lib/Reader.ts","../src/lib/Usage.ts","../src/lib/Run.ts"],"sourcesContent":["export * from \"./lib/Command\";\nexport * from \"./lib/Operation\";\nexport * from \"./lib/Option\";\nexport * from \"./lib/Positional\";\nexport * from \"./lib/Reader\";\nexport * from \"./lib/Run\";\nexport * from \"./lib/Type\";\nexport * from \"./lib/Typo\";\nexport * from \"./lib/Usage\";\n","export type TypoColor =\n | \"darkBlack\"\n | \"darkRed\"\n | \"darkGreen\"\n | \"darkYellow\"\n | \"darkBlue\"\n | \"darkMagenta\"\n | \"darkCyan\"\n | \"darkWhite\"\n | \"brightBlack\"\n | \"brightRed\"\n | \"brightGreen\"\n | \"brightYellow\"\n | \"brightBlue\"\n | \"brightMagenta\"\n | \"brightCyan\"\n | \"brightWhite\";\n\nexport type TypoStyle = {\n fgColor?: TypoColor;\n bgColor?: TypoColor;\n dim?: boolean;\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n strikethrough?: boolean;\n};\n\nexport const typoStyleConstants: TypoStyle = {\n fgColor: \"darkCyan\",\n bold: true,\n};\nexport const typoStyleUserInput: TypoStyle = {\n fgColor: \"darkBlue\",\n bold: true,\n};\nexport const typoStyleFailure: TypoStyle = {\n fgColor: \"darkRed\",\n bold: true,\n};\n\nexport class TypoString {\n #value: string;\n #typoStyle: TypoStyle;\n constructor(value: string, typoStyle: TypoStyle = {}) {\n this.#value = value;\n this.#typoStyle = typoStyle;\n }\n getRawString(): string {\n return this.#value;\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return typoSupport.computeStyledString(this.#value, this.#typoStyle);\n }\n}\n\nexport class TypoText {\n #typoStrings: Array<TypoString>;\n constructor(...typoParts: Array<TypoText | TypoString | string>) {\n this.#typoStrings = [];\n for (const typoPart of typoParts) {\n if (typoPart instanceof TypoText) {\n this.pushText(typoPart);\n } else if (typoPart instanceof TypoString) {\n this.pushString(typoPart);\n } else if (typeof typoPart === \"string\") {\n this.pushString(new TypoString(typoPart));\n }\n }\n }\n pushString(typoString: TypoString) {\n this.#typoStrings.push(typoString);\n }\n pushText(typoText: TypoText) {\n for (const typoString of typoText.#typoStrings) {\n this.#typoStrings.push(typoString);\n }\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoStrings\n .map((t) => t.computeStyledString(typoSupport))\n .join(\"\");\n }\n computeRawString(): string {\n return this.#typoStrings.map((t) => t.getRawString()).join(\"\");\n }\n computeRawLength(): number {\n let length = 0;\n for (const typoString of this.#typoStrings) {\n length += typoString.getRawString().length;\n }\n return length;\n }\n}\n\nexport class TypoGrid {\n #typoRows: Array<Array<TypoText>>;\n constructor() {\n this.#typoRows = [];\n }\n pushRow(cells: Array<TypoText>) {\n this.#typoRows.push(cells);\n }\n computeStyledGrid(typoSupport: TypoSupport): Array<Array<string>> {\n const widths = new Array<number>();\n const printableGrid = new Array<Array<string>>();\n for (const typoGridRow of this.#typoRows) {\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const width = typoGridCell.computeRawLength();\n if (\n widths[typoGridColumnIndex] === undefined ||\n width > widths[typoGridColumnIndex]!\n ) {\n widths[typoGridColumnIndex] = width;\n }\n }\n }\n for (const typoGridRow of this.#typoRows) {\n const printableGridRow = new Array<string>();\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const printableGridCell = typoGridCell.computeStyledString(typoSupport);\n printableGridRow.push(printableGridCell);\n if (typoGridColumnIndex < typoGridRow.length - 1) {\n const width = typoGridCell.computeRawLength();\n const padding = \" \".repeat(widths[typoGridColumnIndex]! - width);\n printableGridRow.push(padding);\n }\n }\n printableGrid.push(printableGridRow);\n }\n return printableGrid;\n }\n}\n\nexport class TypoError extends Error {\n #typoText: TypoText;\n constructor(currentTypoText: TypoText, source?: unknown) {\n const typoText = new TypoText();\n typoText.pushText(currentTypoText);\n if (source instanceof Error) {\n typoText.pushString(new TypoString(`: ${source.message}`));\n } else if (source instanceof TypoError) {\n typoText.pushString(new TypoString(\": \"));\n typoText.pushText(source.#typoText);\n } else if (source !== undefined) {\n typoText.pushString(new TypoString(`: ${String(source)}`));\n }\n super(typoText.computeRawString());\n this.#typoText = typoText;\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoText.computeStyledString(typoSupport);\n }\n}\n\nexport class TypoSupport {\n #kind: \"none\" | \"tty\" | \"mock\";\n private constructor(kind: \"none\" | \"tty\" | \"mock\") {\n this.#kind = kind;\n }\n static none(): TypoSupport {\n return new TypoSupport(\"none\");\n }\n static tty(): TypoSupport {\n return new TypoSupport(\"tty\");\n }\n static mock(): TypoSupport {\n return new TypoSupport(\"mock\");\n }\n static inferFromProcess(): TypoSupport {\n if (!process) {\n return TypoSupport.none();\n }\n if (process.env) {\n if (process.env[\"FORCE_COLOR\"] === \"0\") {\n return TypoSupport.none();\n }\n if (process.env[\"FORCE_COLOR\"]) {\n return TypoSupport.tty();\n }\n if (\"NO_COLOR\" in process.env) {\n return TypoSupport.none();\n }\n }\n if (!process.stdout || !process.stdout.isTTY) {\n return TypoSupport.none();\n }\n return TypoSupport.tty();\n }\n computeStyledString(value: string, typoStyle: TypoStyle): string {\n if (this.#kind === \"none\") {\n return value;\n }\n if (this.#kind === \"tty\") {\n const fgColorCode = typoStyle.fgColor\n ? ttyCodeFgColors[typoStyle.fgColor]\n : \"\";\n const bgColorCode = typoStyle.bgColor\n ? ttyCodeBgColors[typoStyle.bgColor]\n : \"\";\n const boldCode = typoStyle.bold ? ttyCodeBold : \"\";\n const dimCode = typoStyle.dim ? ttyCodeDim : \"\";\n const italicCode = typoStyle.italic ? ttyCodeItalic : \"\";\n const underlineCode = typoStyle.underline ? ttyCodeUnderline : \"\";\n const strikethroughCode = typoStyle.strikethrough\n ? ttyCodeStrikethrough\n : \"\";\n return `${fgColorCode}${bgColorCode}${boldCode}${dimCode}${italicCode}${underlineCode}${strikethroughCode}${value}${ttyCodeReset}`;\n }\n if (this.#kind === \"mock\") {\n const fgColorPart = typoStyle.fgColor\n ? `{${value}}@${typoStyle.fgColor}`\n : value;\n const bgColorPart = typoStyle.bgColor\n ? `{${fgColorPart}}#${typoStyle.bgColor}`\n : fgColorPart;\n const boldPart = typoStyle.bold ? `{${bgColorPart}}+` : bgColorPart;\n const dimPart = typoStyle.dim ? `{${boldPart}}-` : boldPart;\n const italicPart = typoStyle.italic ? `{${dimPart}}*` : dimPart;\n const underlinePart = typoStyle.underline\n ? `{${italicPart}}_`\n : italicPart;\n const strikethroughPart = typoStyle.strikethrough\n ? `{${underlinePart}}~`\n : underlinePart;\n return strikethroughPart;\n }\n throw new Error(`Unknown TypoSupport kind: ${this.#kind}`);\n }\n computeStyledErrorMessage(error: unknown): string {\n return [\n this.computeStyledString(\"Error:\", typoStyleFailure),\n error instanceof TypoError\n ? error.computeStyledString(this)\n : error instanceof Error\n ? error.message\n : String(error),\n ].join(\" \");\n }\n}\n\nconst ttyCodeReset = \"\\x1b[0m\";\nconst ttyCodeBold = \"\\x1b[1m\";\nconst ttyCodeDim = \"\\x1b[2m\";\nconst ttyCodeItalic = \"\\x1b[3m\";\nconst ttyCodeUnderline = \"\\x1b[4m\";\nconst ttyCodeStrikethrough = \"\\x1b[9m\";\nconst ttyCodeFgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[30m\",\n darkRed: \"\\x1b[31m\",\n darkGreen: \"\\x1b[32m\",\n darkYellow: \"\\x1b[33m\",\n darkBlue: \"\\x1b[34m\",\n darkMagenta: \"\\x1b[35m\",\n darkCyan: \"\\x1b[36m\",\n darkWhite: \"\\x1b[37m\",\n brightBlack: \"\\x1b[90m\",\n brightRed: \"\\x1b[91m\",\n brightGreen: \"\\x1b[92m\",\n brightYellow: \"\\x1b[93m\",\n brightBlue: \"\\x1b[94m\",\n brightMagenta: \"\\x1b[95m\",\n brightCyan: \"\\x1b[96m\",\n brightWhite: \"\\x1b[97m\",\n};\nconst ttyCodeBgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[40m\",\n darkRed: \"\\x1b[41m\",\n darkGreen: \"\\x1b[42m\",\n darkYellow: \"\\x1b[43m\",\n darkBlue: \"\\x1b[44m\",\n darkMagenta: \"\\x1b[45m\",\n darkCyan: \"\\x1b[46m\",\n darkWhite: \"\\x1b[47m\",\n brightBlack: \"\\x1b[100m\",\n brightRed: \"\\x1b[101m\",\n brightGreen: \"\\x1b[102m\",\n brightYellow: \"\\x1b[103m\",\n brightBlue: \"\\x1b[104m\",\n brightMagenta: \"\\x1b[105m\",\n brightCyan: \"\\x1b[106m\",\n brightWhite: \"\\x1b[107m\",\n};\n","import { Operation } from \"./Operation\";\nimport { OptionUsage } from \"./Option\";\nimport { PositionalUsage } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\nimport { TypoError, TypoString, typoStyleConstants, TypoText } from \"./Typo\";\n\nexport type Command<Context, Result> = {\n getInformation(): CommandInformation;\n createFactory(readerArgs: ReaderArgs): CommandFactory<Context, Result>;\n};\n\nexport type CommandFactory<Context, Result> = {\n generateUsage(): CommandUsage;\n createInstance(): CommandInstance<Context, Result>;\n};\n\nexport type CommandInstance<Context, Result> = {\n executeWithContext(context: Context): Promise<Result>;\n};\n\nexport type CommandInformation = {\n description: string;\n hint?: string;\n details?: string;\n // TODO - printable examples ?\n};\n\nexport type CommandUsage = {\n breadcrumbs: Array<CommandUsageBreadcrumb>;\n information: CommandInformation;\n positionals: Array<PositionalUsage>;\n subcommands: Array<CommandUsageSubcommand>;\n options: Array<OptionUsage>;\n};\n\nexport type CommandUsageBreadcrumb =\n | { positional: string }\n | { command: string };\n\nexport type CommandUsageSubcommand = {\n name: string;\n description: string | undefined;\n hint: string | undefined;\n};\n\nexport function command<Context, Result>(\n information: CommandInformation,\n operation: Operation<Context, Result>,\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n createFactory(readerArgs: ReaderArgs) {\n function generateUsage(): CommandUsage {\n const operationUsage = operation.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals.map((positional) =>\n breadcrumbPositional(positional.label),\n ),\n information: information,\n positionals: operationUsage.positionals,\n subcommands: [],\n options: operationUsage.options,\n };\n }\n try {\n const operationFactory = operation.createFactory(readerArgs);\n const endPositional = readerArgs.consumePositional();\n if (endPositional !== undefined) {\n throw Error(`Unexpected argument: \"${endPositional}\"`);\n }\n return {\n generateUsage,\n createInstance() {\n const operationInstance = operationFactory.createInstance();\n return {\n async executeWithContext(context: Context) {\n return await operationInstance.executeWithContext(context);\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage,\n createInstance() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nexport function commandWithSubcommands<Context, Payload, Result>(\n information: CommandInformation,\n operation: Operation<Context, Payload>,\n subcommands: { [subcommand: Lowercase<string>]: Command<Payload, Result> },\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n createFactory(readerArgs: ReaderArgs) {\n try {\n const operationFactory = operation.createFactory(readerArgs);\n const subcommandName = readerArgs.consumePositional();\n if (subcommandName === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`<SUBCOMMAND>`, typoStyleConstants),\n new TypoString(`: Is required, but was not provided`),\n ),\n );\n }\n const subcommandInput =\n subcommands[subcommandName as Lowercase<string>];\n if (subcommandInput === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`<SUBCOMMAND>`, typoStyleConstants),\n new TypoString(`: Invalid value: \"${subcommandName}\"`),\n ),\n );\n }\n const subcommandFactory = subcommandInput.createFactory(readerArgs);\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n const subcommandUsage = subcommandFactory.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat([breadcrumbCommand(subcommandName)])\n .concat(subcommandUsage.breadcrumbs),\n information: subcommandUsage.information,\n positionals: operationUsage.positionals.concat(\n subcommandUsage.positionals,\n ),\n subcommands: subcommandUsage.subcommands,\n options: operationUsage.options.concat(subcommandUsage.options),\n };\n },\n createInstance() {\n const operationInstance = operationFactory.createInstance();\n const subcommandInstance = subcommandFactory.createInstance();\n return {\n async executeWithContext(context: Context) {\n return await subcommandInstance.executeWithContext(\n await operationInstance.executeWithContext(context),\n );\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat([breadcrumbCommand(\"<SUBCOMMAND>\")]),\n information: information,\n positionals: operationUsage.positionals,\n subcommands: Object.entries(subcommands).map((subcommand) => {\n const metadata = subcommand[1].getInformation();\n return {\n name: subcommand[0],\n description: metadata.description,\n hint: metadata.hint,\n };\n }),\n options: operationUsage.options,\n };\n },\n createInstance() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nexport function commandChained<Context, Payload, Result>(\n information: CommandInformation,\n operation: Operation<Context, Payload>,\n nextCommand: Command<Payload, Result>,\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n createFactory(readerArgs: ReaderArgs) {\n try {\n const operationFactory = operation.createFactory(readerArgs);\n const nextCommandFactory = nextCommand.createFactory(readerArgs);\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n const nextCommandUsage = nextCommandFactory.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat(nextCommandUsage.breadcrumbs),\n information: nextCommandUsage.information,\n positionals: operationUsage.positionals.concat(\n nextCommandUsage.positionals,\n ),\n subcommands: nextCommandUsage.subcommands,\n options: operationUsage.options.concat(nextCommandUsage.options),\n };\n },\n createInstance() {\n const operationInstance = operationFactory.createInstance();\n const nextCommandInstance = nextCommandFactory.createInstance();\n return {\n async executeWithContext(context: Context) {\n return await nextCommandInstance.executeWithContext(\n await operationInstance.executeWithContext(context),\n );\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat([breadcrumbPositional(\"[REST]...\")]),\n information: information,\n positionals: operationUsage.positionals,\n subcommands: [],\n options: operationUsage.options,\n };\n },\n createInstance() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nfunction breadcrumbPositional(value: string): CommandUsageBreadcrumb {\n return { positional: value };\n}\n\nfunction breadcrumbCommand(value: string): CommandUsageBreadcrumb {\n return { command: value };\n}\n","import { Option, OptionUsage } from \"./Option\";\nimport { Positional, PositionalUsage } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\n\nexport type Operation<Input, Output> = {\n generateUsage(): OperationUsage;\n createFactory(readerArgs: ReaderArgs): OperationFactory<Input, Output>;\n};\n\nexport type OperationFactory<Input, Output> = {\n createInstance(): OperationInstance<Input, Output>;\n};\n\nexport type OperationInstance<Input, Output> = {\n executeWithContext(input: Input): Promise<Output>;\n};\n\nexport type OperationUsage = {\n options: Array<OptionUsage>;\n positionals: Array<PositionalUsage>;\n};\n\nexport function operation<\n Context,\n Result,\n Options extends { [option: string]: any },\n const Positionals extends Array<any>,\n>(\n inputs: {\n options: { [K in keyof Options]: Option<Options[K]> };\n positionals: { [K in keyof Positionals]: Positional<Positionals[K]> };\n },\n handler: (\n context: Context,\n inputs: { options: Options; positionals: Positionals },\n ) => Promise<Result>,\n): Operation<Context, Result> {\n return {\n generateUsage() {\n const optionsUsage = new Array<OptionUsage>();\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n if (optionInput) {\n optionsUsage.push(optionInput.generateUsage());\n }\n }\n const positionalsUsage = new Array<PositionalUsage>();\n for (const positionalInput of inputs.positionals) {\n positionalsUsage.push(positionalInput.generateUsage());\n }\n return { options: optionsUsage, positionals: positionalsUsage };\n },\n createFactory(readerArgs: ReaderArgs) {\n const optionsGetters: any = {};\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n optionsGetters[optionKey] = optionInput.createGetter(readerArgs);\n }\n const positionalsValues: any = [];\n for (const positionalInput of inputs.positionals) {\n positionalsValues.push(positionalInput.consumePositionals(readerArgs));\n }\n return {\n createInstance() {\n const optionsValues: any = {};\n for (const optionKey in optionsGetters) {\n optionsValues[optionKey] = optionsGetters[optionKey]!.getValue();\n }\n return {\n executeWithContext(context: Context) {\n return handler(context, {\n options: optionsValues,\n positionals: positionalsValues,\n });\n },\n };\n },\n };\n },\n };\n}\n","import { TypoError, TypoString, typoStyleUserInput, TypoText } from \"./Typo\";\n\nexport type Type<Value> = {\n // TODO - maybe include an optional hint ??\n label: Uppercase<string>; // TODO - is there a better way to enforce uppercase labels?\n decoder(value: string): Value;\n};\n\nexport const typeBoolean: Type<boolean> = {\n label: \"BOOLEAN\",\n decoder(value: string) {\n const lowerValue = value.toLowerCase();\n if (lowerValue === \"true\" || lowerValue === \"yes\") {\n return true;\n }\n if (lowerValue === \"false\" || lowerValue === \"no\") {\n return false;\n }\n throw new Error(`Invalid value: \"${value}\"`);\n },\n};\n\nexport const typeDate: Type<Date> = {\n label: \"DATE\",\n decoder(value: string) {\n const timestamp = Date.parse(value);\n if (isNaN(timestamp)) {\n throw new Error(`Invalid ISO_8601 value: \"${value}\"`);\n }\n return new Date(timestamp);\n },\n};\n\nexport const typeUrl: Type<URL> = {\n label: \"URL\",\n decoder(value: string) {\n return new URL(value);\n },\n};\n\nexport const typeString: Type<string> = {\n label: \"STRING\",\n decoder(value: string) {\n return value;\n },\n};\n\nexport const typeNumber: Type<number> = {\n label: \"NUMBER\",\n decoder(value: string) {\n return Number(value);\n },\n};\n\nexport const typeBigInt: Type<bigint> = {\n label: \"BIGINT\",\n decoder(value: string) {\n return BigInt(value);\n },\n};\n\nexport function typeMapped<Before, After>(\n before: Type<Before>,\n after: {\n label: Uppercase<string>;\n decoder: (value: Before) => After;\n },\n): Type<After> {\n return {\n label: after.label,\n decoder: (value: string) => {\n return after.decoder(\n typeDecode(\n before,\n value,\n () => new TypoText(new TypoString(before.label, typoStyleUserInput)),\n ),\n );\n },\n };\n}\n\nexport function typeOneOf<Value>(\n type: Type<Value>,\n values: Array<Value>,\n): Type<Value> {\n const valuesSet = new Set(values);\n return {\n label: type.label,\n decoder(value: string) {\n const decoded = typeDecode(\n type,\n value,\n () => new TypoText(new TypoString(type.label, typoStyleUserInput)),\n );\n if (valuesSet.has(decoded)) {\n return decoded;\n }\n const valuesDesc = values.map((v) => `\"${v}\"`).join(\"|\");\n throw new Error(`Unexpected value: \"${value}\" (expected: ${valuesDesc})`);\n },\n };\n}\n\nexport function typeTuple<const Elements extends Array<any>>(\n elementTypes: { [K in keyof Elements]: Type<Elements[K]> },\n separator: string = \",\",\n): Type<Elements> {\n return {\n label: elementTypes\n .map((elementType) => elementType.label)\n .join(separator) as Uppercase<string>,\n decoder(value: string) {\n const parts = value.split(separator, elementTypes.length);\n if (parts.length !== elementTypes.length) {\n throw new Error(`Invalid tuple parts: ${JSON.stringify(parts)}`);\n }\n return parts.map((part, index) =>\n typeDecode(\n elementTypes[index]!,\n part,\n () =>\n new TypoText(\n new TypoString(elementTypes[index]!.label, typoStyleUserInput),\n new TypoString(`@${index}`),\n ),\n ),\n ) as Elements;\n },\n };\n}\n\nexport function typeList<Value>(\n elementType: Type<Value>,\n separator: string = \",\",\n): Type<Array<Value>> {\n return {\n label:\n `${elementType.label}[${separator}${elementType.label}]...` as Uppercase<string>,\n decoder(value: string) {\n return value\n .split(separator)\n .map((part, index) =>\n typeDecode(\n elementType,\n part,\n () =>\n new TypoText(\n new TypoString(elementType.label, typoStyleUserInput),\n new TypoString(`@${index}`),\n ),\n ),\n );\n },\n };\n}\n\nexport function typeDecode<Value>(\n type: Type<Value>,\n value: string,\n context: () => TypoText,\n): Value {\n try {\n return type.decoder(value);\n } catch (error) {\n throw new TypoError(context(), error);\n }\n}\n","import { ReaderArgs as ReaderOptions } from \"./Reader\";\nimport { Type, typeBoolean, typeDecode } from \"./Type\";\nimport {\n TypoError,\n TypoString,\n typoStyleConstants,\n typoStyleUserInput,\n TypoText,\n} from \"./Typo\";\n\nexport type Option<Value> = {\n generateUsage(): OptionUsage;\n createGetter(readerOptions: ReaderOptions): OptionGetter<Value>;\n};\n\nexport type OptionUsage = {\n description: string | undefined;\n hint: string | undefined;\n long: Lowercase<string>; // TODO - better type for long option names ?\n short: string | undefined;\n label: Uppercase<string> | undefined;\n};\n\nexport type OptionGetter<Value> = {\n getValue(): Value;\n};\n\nexport function optionFlag(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n default?: () => boolean;\n}): Option<boolean> {\n const label = `<${typeBoolean.label}>` as Uppercase<string>;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: undefined,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: false,\n });\n return {\n getValue() {\n const optionValues = readerOptions.getOptionValues(key);\n if (optionValues.length > 1) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Must not be set multiple times`),\n ),\n );\n }\n const optionValue = optionValues[0];\n if (optionValue === undefined) {\n // TODO - scoped error util\n try {\n return definition.default ? definition.default() : false;\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Failed to compute default value`),\n ),\n error,\n );\n }\n }\n return typeDecode(\n typeBoolean,\n optionValue,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n );\n },\n };\n },\n };\n}\n\nexport function optionSingleValue<Value>(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n label?: Uppercase<string>;\n type: Type<Value>;\n default: () => Value;\n}): Option<Value> {\n const label = `<${definition.label ?? definition.type.label}>`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: label as Uppercase<string>,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: true,\n });\n return {\n getValue() {\n const optionValues = readerOptions.getOptionValues(key);\n if (optionValues.length > 1) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Must not be set multiple times`),\n ),\n );\n }\n const optionValue = optionValues[0];\n if (optionValue === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Failed to compute default value`),\n ),\n error,\n );\n }\n }\n return typeDecode(\n definition.type,\n optionValue,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n );\n },\n };\n },\n };\n}\n\nexport function optionRepeatable<Value>(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Option<Array<Value>> {\n const label = `<${definition.label ?? definition.type.label}>`;\n return {\n generateUsage() {\n // TODO - showcase that it can be repeated ?\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: label as Uppercase<string>,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: true,\n });\n return {\n getValue() {\n return readerOptions\n .getOptionValues(key)\n .map((value) =>\n typeDecode(\n definition.type,\n value,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n ),\n );\n },\n };\n },\n };\n}\n\nfunction registerOption(\n readerOptions: ReaderOptions,\n definition: {\n long: Lowercase<string>;\n short?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n valued: boolean;\n },\n) {\n const { long, short, aliases, valued } = definition;\n const longs = long ? [long] : [];\n if (aliases?.longs) {\n longs.push(...aliases?.longs);\n }\n const shorts = short ? [short] : [];\n if (aliases?.shorts) {\n shorts.push(...aliases?.shorts);\n }\n return readerOptions.registerOption({ longs, shorts, valued });\n}\n","import { ReaderPositionals } from \"./Reader\";\nimport { Type, typeDecode } from \"./Type\";\nimport { TypoError, TypoString, typoStyleUserInput, TypoText } from \"./Typo\";\n\nexport type Positional<Value> = {\n generateUsage(): PositionalUsage;\n consumePositionals(readerPositionals: ReaderPositionals): Value;\n};\n\nexport type PositionalUsage = {\n description: string | undefined;\n hint: string | undefined;\n label: Uppercase<string>;\n};\n\nexport function positionalRequired<Value>(definition: {\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Positional<Value> {\n const label = `<${definition.label ?? definition.type.label}>`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: label as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n if (positional === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: Is required, but was not provided`),\n ),\n );\n }\n return typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n );\n },\n };\n}\n\nexport function positionalOptional<Value>(definition: {\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n default: () => Value;\n}): Positional<Value> {\n const label = `[${definition.label ?? definition.type.label}]`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: label as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n if (positional === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: Failed to compute default value`),\n ),\n error,\n );\n }\n }\n return typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n );\n },\n };\n}\n\nexport function positionalVariadics<Value>(definition: {\n endDelimiter?: string;\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Positional<Array<Value>> {\n const label = `[${definition.label ?? definition.type.label}]`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: (`${label}...` +\n (definition.endDelimiter\n ? `[\"${definition.endDelimiter}\"]`\n : \"\")) as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positionals: Array<Value> = [];\n while (true) {\n const positional = readerPositionals.consumePositional();\n if (\n positional === undefined ||\n positional === definition.endDelimiter\n ) {\n break;\n }\n positionals.push(\n typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n ),\n );\n }\n return positionals;\n },\n };\n}\n","import { TypoError, TypoString, typoStyleConstants, TypoText } from \"./Typo\";\n\nexport type ReaderOptionKey = (string | { __brand: \"ReaderOptionKey\" }) & {\n __brand: \"ReaderOptionKey\";\n};\n\nexport type ReaderOptions = {\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n valued: boolean;\n }): ReaderOptionKey;\n getOptionValues(key: ReaderOptionKey): Array<string>;\n};\n\nexport type ReaderPositionals = {\n consumePositional(): string | undefined;\n};\n\nexport class ReaderArgs {\n #args: ReadonlyArray<string>;\n #parsedIndex: number;\n #parsedDouble: boolean;\n #keyByLong: Map<string, ReaderOptionKey>;\n #keyByShort: Map<string, ReaderOptionKey>;\n #valuedByKey: Map<ReaderOptionKey, boolean>;\n #resultByKey: Map<ReaderOptionKey, Array<string>>;\n\n constructor(args: ReadonlyArray<string>) {\n this.#args = args;\n this.#parsedIndex = 0;\n this.#parsedDouble = false;\n this.#keyByLong = new Map();\n this.#keyByShort = new Map();\n this.#valuedByKey = new Map();\n this.#resultByKey = new Map();\n }\n\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n valued: boolean;\n }) {\n const key = [\n ...definition.longs.map((long) => `--${long}`),\n ...definition.shorts.map((short) => `-${short}`),\n ].join(\", \") as ReaderOptionKey;\n for (const long of definition.longs) {\n if (this.#keyByLong.has(long)) {\n throw new Error(`Option already registered: --${long}`);\n }\n this.#keyByLong.set(long, key);\n }\n for (const short of definition.shorts) {\n if (this.#keyByShort.has(short)) {\n throw new Error(`Option already registered: -${short}`);\n }\n for (let i = 0; i < short.length; i++) {\n const shortSlice = short.slice(0, i);\n if (this.#keyByShort.has(shortSlice)) {\n throw new Error(\n `Option -${short} overlap with shorter option: -${shortSlice}`,\n );\n }\n }\n for (const shortOther of this.#keyByShort.keys()) {\n if (shortOther.startsWith(short)) {\n throw new Error(\n `Option -${short} overlap with longer option: -${shortOther}`,\n );\n }\n }\n this.#keyByShort.set(short, key);\n }\n this.#valuedByKey.set(key, definition.valued);\n this.#resultByKey.set(key, new Array<string>());\n return key;\n }\n\n getOptionValues(key: ReaderOptionKey): Array<string> {\n const optionResult = this.#resultByKey.get(key);\n if (optionResult === undefined) {\n throw new Error(`Unregistered option: ${key}`);\n }\n return optionResult;\n }\n\n consumePositional(): string | undefined {\n while (true) {\n const arg = this.#consumeArg();\n if (arg === null) {\n return undefined;\n }\n if (this.#processedAsPositional(arg)) {\n return arg;\n }\n }\n }\n\n #consumeArg(): string | null {\n const arg = this.#args[this.#parsedIndex];\n if (arg === undefined) {\n return null;\n }\n this.#parsedIndex++;\n if (!this.#parsedDouble) {\n if (arg === \"--\") {\n this.#parsedDouble = true;\n return this.#consumeArg();\n }\n }\n return arg;\n }\n\n #processedAsPositional(arg: string): boolean {\n if (this.#parsedDouble) {\n return true;\n }\n if (arg.startsWith(\"--\")) {\n const valueIndexStart = arg.indexOf(\"=\");\n if (valueIndexStart === -1) {\n this.#consumeOptionLong(arg.slice(2), null);\n } else {\n this.#consumeOptionLong(\n arg.slice(2, valueIndexStart),\n arg.slice(valueIndexStart + 1),\n );\n }\n return false;\n }\n if (arg.startsWith(\"-\")) {\n let shortIndexStart = 1;\n let shortIndexEnd = 2;\n while (shortIndexEnd <= arg.length) {\n const result = this.#tryConsumeOptionShort(\n arg.slice(shortIndexStart, shortIndexEnd),\n arg.slice(shortIndexEnd),\n );\n if (result === true) {\n return false;\n }\n if (result === false) {\n shortIndexStart = shortIndexEnd;\n }\n shortIndexEnd++;\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`-${arg.slice(shortIndexStart)}`, typoStyleConstants),\n new TypoString(`: Unexpected unknown option`),\n ),\n );\n }\n return true;\n }\n\n #consumeOptionLong(long: string, direct: string | null): void {\n const constant = `--${long}`;\n const key = this.#keyByLong.get(long);\n if (key !== undefined) {\n if (direct !== null) {\n return this.#acknowledgeOption(key, direct);\n }\n const valued = this.#valuedByKey.get(key);\n if (valued) {\n return this.#acknowledgeOption(key, this.#consumeOptionValue(constant));\n }\n return this.#acknowledgeOption(key, \"true\");\n }\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Unexpected unknown option`),\n ),\n );\n }\n\n #tryConsumeOptionShort(short: string, rest: string): boolean | null {\n const key = this.#keyByShort.get(short);\n if (key !== undefined) {\n if (rest.startsWith(\"=\")) {\n this.#acknowledgeOption(key, rest.slice(1));\n return true;\n }\n const valued = this.#valuedByKey.get(key);\n if (valued) {\n if (rest === \"\") {\n this.#acknowledgeOption(key, this.#consumeOptionValue(`-${short}`));\n } else {\n this.#acknowledgeOption(key, rest);\n }\n return true;\n }\n this.#acknowledgeOption(key, \"true\");\n return rest === \"\";\n }\n return null;\n }\n\n #consumeOptionValue(constant: string) {\n const arg = this.#consumeArg();\n if (arg === null) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value, but got end of input`),\n ),\n );\n }\n if (this.#parsedDouble) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value before \"--\"`),\n ),\n );\n }\n // TODO - is that weird, could a valid value start with dash ?\n if (arg.startsWith(\"-\")) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value, but got: \"${arg}\"`),\n ),\n );\n }\n return arg;\n }\n\n #acknowledgeOption(key: ReaderOptionKey, value: string) {\n this.getOptionValues(key).push(value);\n }\n}\n","import { CommandUsage } from \"./Command\";\nimport {\n TypoGrid,\n TypoString,\n typoStyleConstants,\n typoStyleUserInput,\n TypoSupport,\n TypoText,\n} from \"./Typo\";\n\nexport function usageToStyledLines(params: {\n cliName: Lowercase<string>;\n commandUsage: CommandUsage;\n typoSupport: TypoSupport;\n}) {\n const { cliName, commandUsage, typoSupport } = params;\n\n const lines = new Array<string>();\n\n const breadcrumbs = [\n textUsageTitle(\"Usage:\").computeStyledString(typoSupport),\n textConstants(cliName).computeStyledString(typoSupport),\n ].concat(\n commandUsage.breadcrumbs.map((breadcrumb) => {\n if (\"positional\" in breadcrumb) {\n return textUserInput(breadcrumb.positional).computeStyledString(\n typoSupport,\n );\n }\n if (\"command\" in breadcrumb) {\n return textConstants(breadcrumb.command).computeStyledString(\n typoSupport,\n );\n }\n throw new Error(`Unknown breadcrumb: ${JSON.stringify(breadcrumb)}`);\n }),\n );\n lines.push(breadcrumbs.join(\" \"));\n\n lines.push(\"\");\n const infoText = new TypoText();\n infoText.pushString(textUsageIntro(commandUsage.information.description));\n if (commandUsage.information.hint) {\n infoText.pushString(textDelimiter(\" \"));\n infoText.pushString(textSubtleInfo(`(${commandUsage.information.hint})`));\n }\n lines.push(infoText.computeStyledString(typoSupport));\n if (commandUsage.information.details) {\n const detailsString = textSubtleInfo(commandUsage.information.details);\n lines.push(detailsString.computeStyledString(typoSupport));\n }\n\n if (commandUsage.positionals.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Positionals:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const positionalUsage of commandUsage.positionals) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n typoGridRow.push(new TypoText(textUserInput(positionalUsage.label)));\n typoGridRow.push(...createInformationals(positionalUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.subcommands.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Subcommands:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const subcommandUsage of commandUsage.subcommands) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n typoGridRow.push(new TypoText(textConstants(subcommandUsage.name)));\n typoGridRow.push(...createInformationals(subcommandUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.options.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Options:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const optionUsage of commandUsage.options) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n if (optionUsage.short) {\n typoGridRow.push(\n new TypoText(\n textConstants(`-${optionUsage.short}`),\n textDelimiter(\", \"),\n ),\n );\n } else {\n typoGridRow.push(new TypoText());\n }\n if (optionUsage.label) {\n typoGridRow.push(\n new TypoText(\n textConstants(`--${optionUsage.long}`),\n textDelimiter(\" \"),\n textUserInput(optionUsage.label),\n ),\n );\n } else {\n typoGridRow.push(\n new TypoText(\n textConstants(`--${optionUsage.long}`),\n textSubtleInfo(\"[=no]\"),\n ),\n );\n }\n typoGridRow.push(...createInformationals(optionUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n lines.push(\"\");\n return lines;\n}\n\nfunction createInformationals(usage: {\n description: string | undefined;\n hint: string | undefined;\n}): Array<TypoText> {\n const informationals = [];\n if (usage.description) {\n informationals.push(textDelimiter(\" \"));\n informationals.push(textUsefulInfo(usage.description));\n }\n if (usage.hint) {\n informationals.push(textDelimiter(\" \"));\n informationals.push(textSubtleInfo(`(${usage.hint})`));\n }\n if (informationals.length > 0) {\n return [new TypoText(textDelimiter(\" \"), ...informationals)];\n }\n return [];\n}\n\nfunction textUsageIntro(value: string): TypoString {\n return new TypoString(value, { bold: true });\n}\n\nfunction textUsageTitle(value: string): TypoString {\n return new TypoString(value, { fgColor: \"darkMagenta\", bold: true });\n}\n\nfunction textUsefulInfo(value: string): TypoString {\n return new TypoString(value);\n}\n\nfunction textSubtleInfo(value: string): TypoString {\n return new TypoString(value, { italic: true, dim: true });\n}\n\nfunction textBlockTitle(value: string): TypoString {\n return new TypoString(value, { fgColor: \"darkGreen\", bold: true });\n}\n\nfunction textConstants(value: string): TypoString {\n return new TypoString(value, typoStyleConstants);\n}\n\nfunction textUserInput(value: string): TypoString {\n return new TypoString(value, typoStyleUserInput);\n}\n\nfunction textDelimiter(value: string): TypoString {\n return new TypoString(value);\n}\n","import { Command, CommandFactory } from \"./Command\";\nimport { ReaderArgs } from \"./Reader\";\nimport { TypoSupport } from \"./Typo\";\nimport { usageToStyledLines } from \"./Usage\";\n\nexport async function runAsCliAndExit<Context>(\n cliName: Lowercase<string>,\n cliArgs: ReadonlyArray<string>,\n context: Context,\n command: Command<Context, void>,\n application?: {\n usageOnHelp?: boolean | undefined;\n buildVersion?: string | undefined;\n useColors?: boolean | undefined;\n onExecutionError?: ((error: unknown) => void) | undefined;\n onLogStdOut?: ((message: string) => void) | undefined; // TODO - this is a problem, deep commands use console\n onLogStdErr?: ((message: string) => void) | undefined;\n onExit?: ((code: number) => never) | undefined;\n },\n): Promise<never> {\n const readerArgs = new ReaderArgs(cliArgs);\n const usageOnHelp = application?.usageOnHelp ?? true;\n if (usageOnHelp) {\n readerArgs.registerOption({\n shorts: [],\n longs: [\"help\"],\n valued: false,\n });\n }\n const buildVersion = application?.buildVersion;\n if (buildVersion) {\n readerArgs.registerOption({\n shorts: [],\n longs: [\"version\"],\n valued: false,\n });\n }\n /*\n // TODO - handle completions ?\n readerArgs.registerFlag({\n key: \"completion\",\n shorts: [],\n longs: [\"completion\"],\n });\n */\n const typoSupport = chooseTypoSupport(application?.useColors);\n const onLogStdOut = application?.onLogStdOut ?? console.log;\n const onLogStdErr = application?.onLogStdErr ?? console.error;\n const onExit = application?.onExit ?? process.exit;\n const commandFactory = command.createFactory(readerArgs);\n const errors = [];\n while (true) {\n try {\n const positional = readerArgs.consumePositional();\n if (positional === undefined) {\n break;\n }\n } catch (error) {\n errors.push(error);\n }\n }\n if (usageOnHelp) {\n if (readerArgs.getOptionValues(\"--help\" as any).length > 0) {\n onLogStdOut(computeUsageString(cliName, commandFactory, typoSupport));\n return onExit(0);\n }\n }\n if (buildVersion) {\n if (readerArgs.getOptionValues(\"--version\" as any).length > 0) {\n onLogStdOut([cliName, buildVersion].join(\" \"));\n return onExit(0);\n }\n }\n try {\n const commandInstance = commandFactory.createInstance();\n try {\n await commandInstance.executeWithContext(context);\n return onExit(0);\n } catch (error) {\n if (application?.onExecutionError) {\n application.onExecutionError(error);\n } else {\n onLogStdErr(typoSupport.computeStyledErrorMessage(error));\n }\n return onExit(1);\n }\n } catch (error) {\n errors.unshift(error);\n onLogStdErr(computeUsageString(cliName, commandFactory, typoSupport));\n for (const error of errors) {\n onLogStdErr(typoSupport.computeStyledErrorMessage(error));\n }\n return onExit(1);\n }\n}\n\nfunction computeUsageString<Context, Result>(\n cliName: Lowercase<string>,\n commandFactory: CommandFactory<Context, Result>,\n typoSupport: TypoSupport,\n) {\n return usageToStyledLines({\n cliName,\n commandUsage: commandFactory.generateUsage(),\n typoSupport,\n }).join(\"\\n\");\n}\n\nfunction chooseTypoSupport(useColors?: boolean): TypoSupport {\n if (useColors === undefined) {\n return TypoSupport.inferFromProcess();\n }\n return useColors ? TypoSupport.tty() : TypoSupport.none();\n}\n"],"mappings":"m3BAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,gBAAAE,EAAA,cAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,gBAAAC,EAAA,aAAAC,EAAA,YAAAC,GAAA,mBAAAC,GAAA,2BAAAC,GAAA,cAAAC,GAAA,eAAAC,GAAA,qBAAAC,GAAA,sBAAAC,GAAA,uBAAAC,GAAA,uBAAAC,GAAA,wBAAAC,GAAA,oBAAAC,GAAA,eAAAC,GAAA,gBAAAC,EAAA,aAAAC,GAAA,eAAAC,EAAA,aAAAC,GAAA,eAAAC,GAAA,eAAAC,GAAA,cAAAC,GAAA,eAAAC,GAAA,cAAAC,GAAA,YAAAC,GAAA,uBAAAC,EAAA,qBAAAC,GAAA,uBAAAC,EAAA,uBAAAC,KAAA,eAAAC,GAAAlC,IC4BO,IAAMmC,EAAgC,CAC3C,QAAS,WACT,KAAM,EACR,EACaC,EAAgC,CAC3C,QAAS,WACT,KAAM,EACR,EACaC,GAA8B,CACzC,QAAS,UACT,KAAM,EACR,EAvCAC,EAAAC,EAyCaC,EAAN,KAAiB,CAGtB,YAAYC,EAAeC,EAAuB,CAAC,EAAG,CAFtDC,EAAA,KAAAL,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H,EAAY,0BAA0BO,CAAK,CAAC,EAEnDH,EAAO,CAAC,CACjB,CACF,OAASG,EAAO,CACdD,EAAO,QAAQC,CAAK,EACpBJ,EAAYK,GAAmBjB,EAASc,EAAgBL,CAAW,CAAC,EACpE,QAAWO,KAASD,EAClBH,EAAYH,EAAY,0BAA0BO,CAAK,CAAC,EAE1D,OAAOH,EAAO,CAAC,CACjB,CACF,CAEA,SAASI,GACPjB,EACAc,EACAL,EACA,CACA,OAAOU,GAAmB,CACxB,QAAAnB,EACA,aAAcc,EAAe,cAAc,EAC3C,YAAAL,CACF,CAAC,EAAE,KAAK;AAAA,CAAI,CACd,CAEA,SAASC,GAAkBU,EAAkC,CAC3D,OAAIA,IAAc,OACTC,EAAY,iBAAiB,EAE/BD,EAAYC,EAAY,IAAI,EAAIA,EAAY,KAAK,CAC1D","names":["index_exports","__export","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","__toCommonJS","typoStyleConstants","typoStyleUserInput","typoStyleFailure","_value","_typoStyle","TypoString","value","typoStyle","__privateAdd","__privateSet","__privateGet","typoSupport","_typoStrings","_TypoText","typoParts","typoPart","typoString","typoText","t","length","TypoText","_typoRows","TypoGrid","cells","widths","printableGrid","typoGridRow","typoGridColumnIndex","width","printableGridRow","typoGridCell","printableGridCell","padding","_typoText","_TypoError","currentTypoText","source","TypoError","_kind","_TypoSupport","kind","fgColorCode","ttyCodeFgColors","bgColorCode","ttyCodeBgColors","boldCode","ttyCodeBold","dimCode","ttyCodeDim","italicCode","ttyCodeItalic","underlineCode","ttyCodeUnderline","strikethroughCode","ttyCodeStrikethrough","ttyCodeReset","fgColorPart","bgColorPart","boldPart","dimPart","italicPart","underlinePart","error","TypoSupport","command","information","operation","readerArgs","generateUsage","operationUsage","positional","breadcrumbPositional","operationFactory","endPositional","operationInstance","context","error","commandWithSubcommands","subcommands","subcommandName","TypoError","TypoText","TypoString","typoStyleConstants","subcommandInput","subcommandFactory","subcommandUsage","breadcrumbCommand","subcommandInstance","subcommand","metadata","commandChained","nextCommand","nextCommandFactory","nextCommandUsage","nextCommandInstance","value","operation","inputs","handler","optionsUsage","optionKey","optionInput","positionalsUsage","positionalInput","readerArgs","optionsGetters","positionalsValues","optionsValues","context","typeBoolean","value","lowerValue","typeDate","timestamp","typeUrl","typeString","typeNumber","typeBigInt","typeMapped","before","after","typeDecode","TypoText","TypoString","typoStyleUserInput","typeOneOf","type","values","valuesSet","decoded","valuesDesc","v","typeTuple","elementTypes","separator","elementType","parts","part","index","typeList","context","error","TypoError","optionFlag","definition","label","typeBoolean","readerOptions","key","registerOption","optionValues","TypoError","TypoText","TypoString","typoStyleConstants","optionValue","error","typeDecode","typoStyleUserInput","optionSingleValue","optionRepeatable","value","long","short","aliases","valued","longs","shorts","positionalRequired","definition","label","readerPositionals","positional","TypoError","TypoText","TypoString","typoStyleUserInput","typeDecode","positionalOptional","error","positionalVariadics","positionals","_args","_parsedIndex","_parsedDouble","_keyByLong","_keyByShort","_valuedByKey","_resultByKey","_ReaderArgs_instances","consumeArg_fn","processedAsPositional_fn","consumeOptionLong_fn","tryConsumeOptionShort_fn","consumeOptionValue_fn","acknowledgeOption_fn","ReaderArgs","args","__privateAdd","__privateSet","definition","key","long","short","__privateGet","i","shortSlice","shortOther","optionResult","arg","__privateMethod","__privateWrapper","valueIndexStart","shortIndexStart","shortIndexEnd","result","TypoError","TypoText","TypoString","typoStyleConstants","direct","constant","rest","value","usageToStyledLines","params","cliName","commandUsage","typoSupport","lines","breadcrumbs","textUsageTitle","textConstants","breadcrumb","textUserInput","infoText","TypoText","textUsageIntro","textDelimiter","textSubtleInfo","detailsString","textBlockTitle","typoGrid","TypoGrid","positionalUsage","typoGridRow","createInformationals","row","subcommandUsage","optionUsage","usage","informationals","textUsefulInfo","value","TypoString","typoStyleConstants","typoStyleUserInput","runAsCliAndExit","cliName","cliArgs","context","command","application","readerArgs","ReaderArgs","usageOnHelp","buildVersion","typoSupport","chooseTypoSupport","onLogStdOut","onLogStdErr","onExit","commandFactory","errors","error","computeUsageString","commandInstance","usageToStyledLines","useColors","TypoSupport"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/Typo.ts","../src/lib/Command.ts","../src/lib/Operation.ts","../src/lib/Type.ts","../src/lib/Option.ts","../src/lib/Positional.ts","../src/lib/Reader.ts","../src/lib/Usage.ts","../src/lib/Run.ts"],"sourcesContent":["export * from \"./lib/Command\";\nexport * from \"./lib/Operation\";\nexport * from \"./lib/Option\";\nexport * from \"./lib/Positional\";\nexport * from \"./lib/Reader\";\nexport * from \"./lib/Run\";\nexport * from \"./lib/Type\";\nexport * from \"./lib/Typo\";\nexport * from \"./lib/Usage\";\n","export type TypoColor =\n | \"darkBlack\"\n | \"darkRed\"\n | \"darkGreen\"\n | \"darkYellow\"\n | \"darkBlue\"\n | \"darkMagenta\"\n | \"darkCyan\"\n | \"darkWhite\"\n | \"brightBlack\"\n | \"brightRed\"\n | \"brightGreen\"\n | \"brightYellow\"\n | \"brightBlue\"\n | \"brightMagenta\"\n | \"brightCyan\"\n | \"brightWhite\";\n\nexport type TypoStyle = {\n fgColor?: TypoColor;\n bgColor?: TypoColor;\n dim?: boolean;\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n strikethrough?: boolean;\n};\n\nexport const typoStyleConstants: TypoStyle = {\n fgColor: \"darkCyan\",\n bold: true,\n};\nexport const typoStyleUserInput: TypoStyle = {\n fgColor: \"darkBlue\",\n bold: true,\n};\nexport const typoStyleFailure: TypoStyle = {\n fgColor: \"darkRed\",\n bold: true,\n};\n\nexport class TypoString {\n #value: string;\n #typoStyle: TypoStyle;\n constructor(value: string, typoStyle: TypoStyle = {}) {\n this.#value = value;\n this.#typoStyle = typoStyle;\n }\n getRawString(): string {\n return this.#value;\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return typoSupport.computeStyledString(this.#value, this.#typoStyle);\n }\n}\n\nexport class TypoText {\n #typoStrings: Array<TypoString>;\n constructor(...typoParts: Array<TypoText | TypoString | string>) {\n this.#typoStrings = [];\n for (const typoPart of typoParts) {\n if (typoPart instanceof TypoText) {\n this.pushText(typoPart);\n } else if (typoPart instanceof TypoString) {\n this.pushString(typoPart);\n } else if (typeof typoPart === \"string\") {\n this.pushString(new TypoString(typoPart));\n }\n }\n }\n pushString(typoString: TypoString) {\n this.#typoStrings.push(typoString);\n }\n pushText(typoText: TypoText) {\n for (const typoString of typoText.#typoStrings) {\n this.#typoStrings.push(typoString);\n }\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoStrings\n .map((t) => t.computeStyledString(typoSupport))\n .join(\"\");\n }\n computeRawString(): string {\n return this.#typoStrings.map((t) => t.getRawString()).join(\"\");\n }\n computeRawLength(): number {\n let length = 0;\n for (const typoString of this.#typoStrings) {\n length += typoString.getRawString().length;\n }\n return length;\n }\n}\n\nexport class TypoGrid {\n #typoRows: Array<Array<TypoText>>;\n constructor() {\n this.#typoRows = [];\n }\n pushRow(cells: Array<TypoText>) {\n this.#typoRows.push(cells);\n }\n computeStyledGrid(typoSupport: TypoSupport): Array<Array<string>> {\n const widths = new Array<number>();\n const printableGrid = new Array<Array<string>>();\n for (const typoGridRow of this.#typoRows) {\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const width = typoGridCell.computeRawLength();\n if (\n widths[typoGridColumnIndex] === undefined ||\n width > widths[typoGridColumnIndex]!\n ) {\n widths[typoGridColumnIndex] = width;\n }\n }\n }\n for (const typoGridRow of this.#typoRows) {\n const printableGridRow = new Array<string>();\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const printableGridCell = typoGridCell.computeStyledString(typoSupport);\n printableGridRow.push(printableGridCell);\n if (typoGridColumnIndex < typoGridRow.length - 1) {\n const width = typoGridCell.computeRawLength();\n const padding = \" \".repeat(widths[typoGridColumnIndex]! - width);\n printableGridRow.push(padding);\n }\n }\n printableGrid.push(printableGridRow);\n }\n return printableGrid;\n }\n}\n\nexport class TypoError extends Error {\n #typoText: TypoText;\n constructor(currentTypoText: TypoText, source?: unknown) {\n const typoText = new TypoText();\n typoText.pushText(currentTypoText);\n if (source instanceof Error) {\n typoText.pushString(new TypoString(`: ${source.message}`));\n } else if (source instanceof TypoError) {\n typoText.pushString(new TypoString(\": \"));\n typoText.pushText(source.#typoText);\n } else if (source !== undefined) {\n typoText.pushString(new TypoString(`: ${String(source)}`));\n }\n super(typoText.computeRawString());\n this.#typoText = typoText;\n }\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoText.computeStyledString(typoSupport);\n }\n}\n\nexport class TypoSupport {\n #kind: \"none\" | \"tty\" | \"mock\";\n private constructor(kind: \"none\" | \"tty\" | \"mock\") {\n this.#kind = kind;\n }\n static none(): TypoSupport {\n return new TypoSupport(\"none\");\n }\n static tty(): TypoSupport {\n return new TypoSupport(\"tty\");\n }\n static mock(): TypoSupport {\n return new TypoSupport(\"mock\");\n }\n static inferFromProcess(): TypoSupport {\n if (!process) {\n return TypoSupport.none();\n }\n if (process.env) {\n if (process.env[\"FORCE_COLOR\"] === \"0\") {\n return TypoSupport.none();\n }\n if (process.env[\"FORCE_COLOR\"]) {\n return TypoSupport.tty();\n }\n if (\"NO_COLOR\" in process.env) {\n return TypoSupport.none();\n }\n }\n if (!process.stdout || !process.stdout.isTTY) {\n return TypoSupport.none();\n }\n return TypoSupport.tty();\n }\n computeStyledString(value: string, typoStyle: TypoStyle): string {\n if (this.#kind === \"none\") {\n return value;\n }\n if (this.#kind === \"tty\") {\n const fgColorCode = typoStyle.fgColor\n ? ttyCodeFgColors[typoStyle.fgColor]\n : \"\";\n const bgColorCode = typoStyle.bgColor\n ? ttyCodeBgColors[typoStyle.bgColor]\n : \"\";\n const boldCode = typoStyle.bold ? ttyCodeBold : \"\";\n const dimCode = typoStyle.dim ? ttyCodeDim : \"\";\n const italicCode = typoStyle.italic ? ttyCodeItalic : \"\";\n const underlineCode = typoStyle.underline ? ttyCodeUnderline : \"\";\n const strikethroughCode = typoStyle.strikethrough\n ? ttyCodeStrikethrough\n : \"\";\n return `${fgColorCode}${bgColorCode}${boldCode}${dimCode}${italicCode}${underlineCode}${strikethroughCode}${value}${ttyCodeReset}`;\n }\n if (this.#kind === \"mock\") {\n const fgColorPart = typoStyle.fgColor\n ? `{${value}}@${typoStyle.fgColor}`\n : value;\n const bgColorPart = typoStyle.bgColor\n ? `{${fgColorPart}}#${typoStyle.bgColor}`\n : fgColorPart;\n const boldPart = typoStyle.bold ? `{${bgColorPart}}+` : bgColorPart;\n const dimPart = typoStyle.dim ? `{${boldPart}}-` : boldPart;\n const italicPart = typoStyle.italic ? `{${dimPart}}*` : dimPart;\n const underlinePart = typoStyle.underline\n ? `{${italicPart}}_`\n : italicPart;\n const strikethroughPart = typoStyle.strikethrough\n ? `{${underlinePart}}~`\n : underlinePart;\n return strikethroughPart;\n }\n throw new Error(`Unknown TypoSupport kind: ${this.#kind}`);\n }\n computeStyledErrorMessage(error: unknown): string {\n return [\n this.computeStyledString(\"Error:\", typoStyleFailure),\n error instanceof TypoError\n ? error.computeStyledString(this)\n : error instanceof Error\n ? error.message\n : String(error),\n ].join(\" \");\n }\n}\n\nconst ttyCodeReset = \"\\x1b[0m\";\nconst ttyCodeBold = \"\\x1b[1m\";\nconst ttyCodeDim = \"\\x1b[2m\";\nconst ttyCodeItalic = \"\\x1b[3m\";\nconst ttyCodeUnderline = \"\\x1b[4m\";\nconst ttyCodeStrikethrough = \"\\x1b[9m\";\nconst ttyCodeFgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[30m\",\n darkRed: \"\\x1b[31m\",\n darkGreen: \"\\x1b[32m\",\n darkYellow: \"\\x1b[33m\",\n darkBlue: \"\\x1b[34m\",\n darkMagenta: \"\\x1b[35m\",\n darkCyan: \"\\x1b[36m\",\n darkWhite: \"\\x1b[37m\",\n brightBlack: \"\\x1b[90m\",\n brightRed: \"\\x1b[91m\",\n brightGreen: \"\\x1b[92m\",\n brightYellow: \"\\x1b[93m\",\n brightBlue: \"\\x1b[94m\",\n brightMagenta: \"\\x1b[95m\",\n brightCyan: \"\\x1b[96m\",\n brightWhite: \"\\x1b[97m\",\n};\nconst ttyCodeBgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[40m\",\n darkRed: \"\\x1b[41m\",\n darkGreen: \"\\x1b[42m\",\n darkYellow: \"\\x1b[43m\",\n darkBlue: \"\\x1b[44m\",\n darkMagenta: \"\\x1b[45m\",\n darkCyan: \"\\x1b[46m\",\n darkWhite: \"\\x1b[47m\",\n brightBlack: \"\\x1b[100m\",\n brightRed: \"\\x1b[101m\",\n brightGreen: \"\\x1b[102m\",\n brightYellow: \"\\x1b[103m\",\n brightBlue: \"\\x1b[104m\",\n brightMagenta: \"\\x1b[105m\",\n brightCyan: \"\\x1b[106m\",\n brightWhite: \"\\x1b[107m\",\n};\n","import { OperationDescriptor } from \"./Operation\";\nimport { OptionUsage } from \"./Option\";\nimport { PositionalUsage } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\nimport { TypoError, TypoString, typoStyleUserInput, TypoText } from \"./Typo\";\n\nexport type CommandDescriptor<Context, Result> = {\n getInformation(): CommandInformation;\n createFactory(readerArgs: ReaderArgs): CommandFactory<Context, Result>;\n};\n\nexport type CommandFactory<Context, Result> = {\n generateUsage(): CommandUsage;\n createInstance(): CommandInstance<Context, Result>;\n};\n\nexport type CommandInstance<Context, Result> = {\n executeWithContext(context: Context): Promise<Result>;\n};\n\nexport type CommandInformation = {\n description: string;\n hint?: string;\n details?: string;\n // TODO - printable examples ?\n};\n\nexport type CommandUsage = {\n breadcrumbs: Array<CommandUsageBreadcrumb>;\n information: CommandInformation;\n positionals: Array<PositionalUsage>;\n subcommands: Array<CommandUsageSubcommand>;\n options: Array<OptionUsage>;\n};\n\nexport type CommandUsageBreadcrumb =\n | { positional: string }\n | { command: string };\n\nexport type CommandUsageSubcommand = {\n name: string;\n description: string | undefined;\n hint: string | undefined;\n};\n\nexport function command<Context, Result>(\n information: CommandInformation,\n operation: OperationDescriptor<Context, Result>,\n): CommandDescriptor<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n createFactory(readerArgs: ReaderArgs) {\n function generateUsage(): CommandUsage {\n const operationUsage = operation.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals.map((positional) =>\n breadcrumbPositional(positional.label),\n ),\n information: information,\n positionals: operationUsage.positionals,\n subcommands: [],\n options: operationUsage.options,\n };\n }\n try {\n const operationFactory = operation.createFactory(readerArgs);\n const endPositional = readerArgs.consumePositional();\n if (endPositional !== undefined) {\n throw Error(`Unexpected argument: \"${endPositional}\"`);\n }\n return {\n generateUsage,\n createInstance() {\n const operationInstance = operationFactory.createInstance();\n return {\n async executeWithContext(context: Context) {\n return await operationInstance.executeWithContext(context);\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage,\n createInstance() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nexport function commandWithSubcommands<Context, Payload, Result>(\n information: CommandInformation,\n operation: OperationDescriptor<Context, Payload>,\n subcommands: {\n [subcommand: Lowercase<string>]: CommandDescriptor<Payload, Result>;\n },\n): CommandDescriptor<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n createFactory(readerArgs: ReaderArgs) {\n try {\n const operationFactory = operation.createFactory(readerArgs);\n const subcommandName = readerArgs.consumePositional();\n if (subcommandName === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`<SUBCOMMAND>`, typoStyleUserInput),\n new TypoString(`: Is required, but was not provided`),\n ),\n );\n }\n const subcommandInput =\n subcommands[subcommandName as Lowercase<string>];\n if (subcommandInput === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`<SUBCOMMAND>`, typoStyleUserInput),\n new TypoString(`: Invalid value: \"${subcommandName}\"`),\n ),\n );\n }\n const subcommandFactory = subcommandInput.createFactory(readerArgs);\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n const subcommandUsage = subcommandFactory.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat([breadcrumbCommand(subcommandName)])\n .concat(subcommandUsage.breadcrumbs),\n information: subcommandUsage.information,\n positionals: operationUsage.positionals.concat(\n subcommandUsage.positionals,\n ),\n subcommands: subcommandUsage.subcommands,\n options: operationUsage.options.concat(subcommandUsage.options),\n };\n },\n createInstance() {\n const operationInstance = operationFactory.createInstance();\n const subcommandInstance = subcommandFactory.createInstance();\n return {\n async executeWithContext(context: Context) {\n return await subcommandInstance.executeWithContext(\n await operationInstance.executeWithContext(context),\n );\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat([breadcrumbPositional(\"<SUBCOMMAND>\")]),\n information: information,\n positionals: operationUsage.positionals,\n subcommands: Object.entries(subcommands).map((subcommand) => {\n const metadata = subcommand[1].getInformation();\n return {\n name: subcommand[0],\n description: metadata.description,\n hint: metadata.hint,\n };\n }),\n options: operationUsage.options,\n };\n },\n createInstance() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nexport function commandChained<Context, Payload, Result>(\n information: CommandInformation,\n operation: OperationDescriptor<Context, Payload>,\n nextCommand: CommandDescriptor<Payload, Result>,\n): CommandDescriptor<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n createFactory(readerArgs: ReaderArgs) {\n try {\n const operationFactory = operation.createFactory(readerArgs);\n const nextCommandFactory = nextCommand.createFactory(readerArgs);\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n const nextCommandUsage = nextCommandFactory.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat(nextCommandUsage.breadcrumbs),\n information: nextCommandUsage.information,\n positionals: operationUsage.positionals.concat(\n nextCommandUsage.positionals,\n ),\n subcommands: nextCommandUsage.subcommands,\n options: operationUsage.options.concat(nextCommandUsage.options),\n };\n },\n createInstance() {\n const operationInstance = operationFactory.createInstance();\n const nextCommandInstance = nextCommandFactory.createInstance();\n return {\n async executeWithContext(context: Context) {\n return await nextCommandInstance.executeWithContext(\n await operationInstance.executeWithContext(context),\n );\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage() {\n const operationUsage = operation.generateUsage();\n return {\n breadcrumbs: operationUsage.positionals\n .map((positional) => breadcrumbPositional(positional.label))\n .concat([breadcrumbPositional(\"[REST]...\")]),\n information: information,\n positionals: operationUsage.positionals,\n subcommands: [],\n options: operationUsage.options,\n };\n },\n createInstance() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nfunction breadcrumbPositional(value: string): CommandUsageBreadcrumb {\n return { positional: value };\n}\n\nfunction breadcrumbCommand(value: string): CommandUsageBreadcrumb {\n return { command: value };\n}\n","import { Option, OptionUsage } from \"./Option\";\nimport { Positional, PositionalUsage } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\n\nexport type OperationDescriptor<Input, Output> = {\n generateUsage(): OperationUsage;\n createFactory(readerArgs: ReaderArgs): OperationFactory<Input, Output>;\n};\n\nexport type OperationFactory<Input, Output> = {\n createInstance(): OperationInstance<Input, Output>;\n};\n\nexport type OperationInstance<Input, Output> = {\n executeWithContext(input: Input): Promise<Output>;\n};\n\nexport type OperationUsage = {\n options: Array<OptionUsage>;\n positionals: Array<PositionalUsage>;\n};\n\nexport function operation<\n Context,\n Result,\n Options extends { [option: string]: any },\n const Positionals extends Array<any>,\n>(\n inputs: {\n options: { [K in keyof Options]: Option<Options[K]> };\n positionals: { [K in keyof Positionals]: Positional<Positionals[K]> };\n },\n handler: (\n context: Context,\n inputs: { options: Options; positionals: Positionals },\n ) => Promise<Result>,\n): OperationDescriptor<Context, Result> {\n return {\n generateUsage() {\n const optionsUsage = new Array<OptionUsage>();\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n if (optionInput) {\n optionsUsage.push(optionInput.generateUsage());\n }\n }\n const positionalsUsage = new Array<PositionalUsage>();\n for (const positionalInput of inputs.positionals) {\n positionalsUsage.push(positionalInput.generateUsage());\n }\n return { options: optionsUsage, positionals: positionalsUsage };\n },\n createFactory(readerArgs: ReaderArgs) {\n const optionsGetters: any = {};\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n optionsGetters[optionKey] = optionInput.createGetter(readerArgs);\n }\n const positionalsValues: any = [];\n for (const positionalInput of inputs.positionals) {\n positionalsValues.push(positionalInput.consumePositionals(readerArgs));\n }\n return {\n createInstance() {\n const optionsValues: any = {};\n for (const optionKey in optionsGetters) {\n optionsValues[optionKey] = optionsGetters[optionKey]!.getValue();\n }\n return {\n executeWithContext(context: Context) {\n return handler(context, {\n options: optionsValues,\n positionals: positionalsValues,\n });\n },\n };\n },\n };\n },\n };\n}\n","import { TypoError, TypoString, typoStyleUserInput, TypoText } from \"./Typo\";\n\nexport type Type<Value> = {\n label: Uppercase<string>; // TODO - is there a better way to enforce uppercase labels?\n decoder(value: string): Value;\n};\n\nexport const typeBoolean: Type<boolean> = {\n label: \"BOOLEAN\",\n decoder(value: string) {\n const lowerValue = value.toLowerCase();\n if (lowerValue === \"true\" || lowerValue === \"yes\") {\n return true;\n }\n if (lowerValue === \"false\" || lowerValue === \"no\") {\n return false;\n }\n throw new Error(`Invalid value: \"${value}\"`);\n },\n};\n\nexport const typeDate: Type<Date> = {\n label: \"DATE\",\n decoder(value: string) {\n const timestamp = Date.parse(value);\n if (isNaN(timestamp)) {\n throw new Error(`Invalid ISO_8601 value: \"${value}\"`);\n }\n return new Date(timestamp);\n },\n};\n\nexport const typeUrl: Type<URL> = {\n label: \"URL\",\n decoder(value: string) {\n return new URL(value);\n },\n};\n\nexport const typeString: Type<string> = {\n label: \"STRING\",\n decoder(value: string) {\n return value;\n },\n};\n\nexport const typeNumber: Type<number> = {\n label: \"NUMBER\",\n decoder(value: string) {\n return Number(value);\n },\n};\n\nexport const typeBigInt: Type<bigint> = {\n label: \"BIGINT\",\n decoder(value: string) {\n return BigInt(value);\n },\n};\n\nexport function typeMapped<Before, After>(\n before: Type<Before>,\n after: {\n label: Uppercase<string>;\n decoder: (value: Before) => After;\n },\n): Type<After> {\n return {\n label: after.label,\n decoder: (value: string) => {\n return after.decoder(\n typeDecode(\n before,\n value,\n () => new TypoText(new TypoString(before.label, typoStyleUserInput)),\n ),\n );\n },\n };\n}\n\nexport function typeOneOf<Value>(\n type: Type<Value>,\n values: Array<Value>,\n): Type<Value> {\n const valuesSet = new Set(values);\n return {\n label: type.label,\n decoder(value: string) {\n const decoded = typeDecode(\n type,\n value,\n () => new TypoText(new TypoString(type.label, typoStyleUserInput)),\n );\n if (valuesSet.has(decoded)) {\n return decoded;\n }\n const valuesDesc = values.map((v) => `\"${v}\"`).join(\"|\");\n throw new Error(`Unexpected value: \"${value}\" (expected: ${valuesDesc})`);\n },\n };\n}\n\nexport function typeTuple<const Elements extends Array<any>>(\n elementTypes: { [K in keyof Elements]: Type<Elements[K]> },\n separator: string = \",\",\n): Type<Elements> {\n return {\n label: elementTypes\n .map((elementType) => elementType.label)\n .join(separator) as Uppercase<string>,\n decoder(value: string) {\n const parts = value.split(separator, elementTypes.length);\n if (parts.length !== elementTypes.length) {\n throw new Error(`Invalid tuple parts: ${JSON.stringify(parts)}`);\n }\n return parts.map((part, index) =>\n typeDecode(\n elementTypes[index]!,\n part,\n () =>\n new TypoText(\n new TypoString(elementTypes[index]!.label, typoStyleUserInput),\n new TypoString(`@${index}`),\n ),\n ),\n ) as Elements;\n },\n };\n}\n\nexport function typeList<Value>(\n elementType: Type<Value>,\n separator: string = \",\",\n): Type<Array<Value>> {\n return {\n label:\n `${elementType.label}[${separator}${elementType.label}]...` as Uppercase<string>,\n decoder(value: string) {\n return value\n .split(separator)\n .map((part, index) =>\n typeDecode(\n elementType,\n part,\n () =>\n new TypoText(\n new TypoString(elementType.label, typoStyleUserInput),\n new TypoString(`@${index}`),\n ),\n ),\n );\n },\n };\n}\n\nexport function typeDecode<Value>(\n type: Type<Value>,\n value: string,\n context: () => TypoText,\n): Value {\n try {\n return type.decoder(value);\n } catch (error) {\n throw new TypoError(context(), error);\n }\n}\n","import { ReaderArgs as ReaderOptions } from \"./Reader\";\nimport { Type, typeBoolean, typeDecode } from \"./Type\";\nimport {\n TypoError,\n TypoString,\n typoStyleConstants,\n typoStyleUserInput,\n TypoText,\n} from \"./Typo\";\n\nexport type Option<Value> = {\n generateUsage(): OptionUsage;\n createGetter(readerOptions: ReaderOptions): OptionGetter<Value>;\n};\n\nexport type OptionUsage = {\n description: string | undefined;\n hint: string | undefined;\n long: Lowercase<string>; // TODO - better type for long option names ?\n short: string | undefined;\n label: Uppercase<string> | undefined;\n};\n\nexport type OptionGetter<Value> = {\n getValue(): Value;\n};\n\nexport function optionFlag(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n default?: () => boolean;\n}): Option<boolean> {\n const label = `<${typeBoolean.label}>` as Uppercase<string>;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: undefined,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: false,\n });\n return {\n getValue() {\n const optionValues = readerOptions.getOptionValues(key);\n if (optionValues.length > 1) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Must not be set multiple times`),\n ),\n );\n }\n const optionValue = optionValues[0];\n if (optionValue === undefined) {\n try {\n return definition.default ? definition.default() : false;\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Failed to compute default value`),\n ),\n error,\n );\n }\n }\n return typeDecode(\n typeBoolean,\n optionValue,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n );\n },\n };\n },\n };\n}\n\nexport function optionSingleValue<Value>(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n label?: Uppercase<string>;\n type: Type<Value>;\n default: () => Value;\n}): Option<Value> {\n const label = `<${definition.label ?? definition.type.label}>`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: label as Uppercase<string>,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: true,\n });\n return {\n getValue() {\n const optionValues = readerOptions.getOptionValues(key);\n if (optionValues.length > 1) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Must not be set multiple times`),\n ),\n );\n }\n const optionValue = optionValues[0];\n if (optionValue === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Failed to compute default value`),\n ),\n error,\n );\n }\n }\n return typeDecode(\n definition.type,\n optionValue,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n );\n },\n };\n },\n };\n}\n\nexport function optionRepeatable<Value>(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Option<Array<Value>> {\n const label = `<${definition.label ?? definition.type.label}>`;\n return {\n generateUsage() {\n // TODO - showcase that it can be repeated ?\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: label as Uppercase<string>,\n };\n },\n createGetter(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: true,\n });\n return {\n getValue() {\n return readerOptions\n .getOptionValues(key)\n .map((value) =>\n typeDecode(\n definition.type,\n value,\n () =>\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: `),\n new TypoString(label, typoStyleUserInput),\n ),\n ),\n );\n },\n };\n },\n };\n}\n\nfunction registerOption(\n readerOptions: ReaderOptions,\n definition: {\n long: Lowercase<string>;\n short?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n valued: boolean;\n },\n) {\n const { long, short, aliases, valued } = definition;\n const longs = long ? [long] : [];\n if (aliases?.longs) {\n longs.push(...aliases?.longs);\n }\n const shorts = short ? [short] : [];\n if (aliases?.shorts) {\n shorts.push(...aliases?.shorts);\n }\n return readerOptions.registerOption({ longs, shorts, valued });\n}\n","import { ReaderPositionals } from \"./Reader\";\nimport { Type, typeDecode } from \"./Type\";\nimport { TypoError, TypoString, typoStyleUserInput, TypoText } from \"./Typo\";\n\nexport type Positional<Value> = {\n generateUsage(): PositionalUsage;\n consumePositionals(readerPositionals: ReaderPositionals): Value;\n};\n\nexport type PositionalUsage = {\n description: string | undefined;\n hint: string | undefined;\n label: Uppercase<string>;\n};\n\nexport function positionalRequired<Value>(definition: {\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Positional<Value> {\n const label = `<${definition.label ?? definition.type.label}>`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: label as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n if (positional === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: Is required, but was not provided`),\n ),\n );\n }\n return typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n );\n },\n };\n}\n\nexport function positionalOptional<Value>(definition: {\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n default: () => Value;\n}): Positional<Value> {\n const label = `[${definition.label ?? definition.type.label}]`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: label as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n if (positional === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: Failed to compute default value`),\n ),\n error,\n );\n }\n }\n return typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n );\n },\n };\n}\n\nexport function positionalVariadics<Value>(definition: {\n endDelimiter?: string;\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Positional<Array<Value>> {\n const label = `[${definition.label ?? definition.type.label}]`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: (`${label}...` +\n (definition.endDelimiter\n ? `[\"${definition.endDelimiter}\"]`\n : \"\")) as Uppercase<string>,\n };\n },\n consumePositionals(readerPositionals: ReaderPositionals) {\n const positionals: Array<Value> = [];\n while (true) {\n const positional = readerPositionals.consumePositional();\n if (\n positional === undefined ||\n positional === definition.endDelimiter\n ) {\n break;\n }\n positionals.push(\n typeDecode(\n definition.type,\n positional,\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n ),\n );\n }\n return positionals;\n },\n };\n}\n","import { TypoError, TypoString, typoStyleConstants, TypoText } from \"./Typo\";\n\nexport type ReaderOptionKey = (string | { __brand: \"ReaderOptionKey\" }) & {\n __brand: \"ReaderOptionKey\";\n};\n\nexport type ReaderOptions = {\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n valued: boolean;\n }): ReaderOptionKey;\n getOptionValues(key: ReaderOptionKey): Array<string>;\n};\n\nexport type ReaderPositionals = {\n consumePositional(): string | undefined;\n};\n\nexport class ReaderArgs {\n #args: ReadonlyArray<string>;\n #parsedIndex: number;\n #parsedDouble: boolean;\n #keyByLong: Map<string, ReaderOptionKey>;\n #keyByShort: Map<string, ReaderOptionKey>;\n #valuedByKey: Map<ReaderOptionKey, boolean>;\n #resultByKey: Map<ReaderOptionKey, Array<string>>;\n\n constructor(args: ReadonlyArray<string>) {\n this.#args = args;\n this.#parsedIndex = 0;\n this.#parsedDouble = false;\n this.#keyByLong = new Map();\n this.#keyByShort = new Map();\n this.#valuedByKey = new Map();\n this.#resultByKey = new Map();\n }\n\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n valued: boolean;\n }) {\n const key = [\n ...definition.longs.map((long) => `--${long}`),\n ...definition.shorts.map((short) => `-${short}`),\n ].join(\", \") as ReaderOptionKey;\n for (const long of definition.longs) {\n if (this.#keyByLong.has(long)) {\n throw new Error(`Option already registered: --${long}`);\n }\n this.#keyByLong.set(long, key);\n }\n for (const short of definition.shorts) {\n if (this.#keyByShort.has(short)) {\n throw new Error(`Option already registered: -${short}`);\n }\n for (let i = 0; i < short.length; i++) {\n const shortSlice = short.slice(0, i);\n if (this.#keyByShort.has(shortSlice)) {\n throw new Error(\n `Option -${short} overlap with shorter option: -${shortSlice}`,\n );\n }\n }\n for (const shortOther of this.#keyByShort.keys()) {\n if (shortOther.startsWith(short)) {\n throw new Error(\n `Option -${short} overlap with longer option: -${shortOther}`,\n );\n }\n }\n this.#keyByShort.set(short, key);\n }\n this.#valuedByKey.set(key, definition.valued);\n this.#resultByKey.set(key, new Array<string>());\n return key;\n }\n\n getOptionValues(key: ReaderOptionKey): Array<string> {\n const optionResult = this.#resultByKey.get(key);\n if (optionResult === undefined) {\n throw new Error(`Unregistered option: ${key}`);\n }\n return optionResult;\n }\n\n consumePositional(): string | undefined {\n while (true) {\n const arg = this.#consumeArg();\n if (arg === null) {\n return undefined;\n }\n if (this.#processedAsPositional(arg)) {\n return arg;\n }\n }\n }\n\n #consumeArg(): string | null {\n const arg = this.#args[this.#parsedIndex];\n if (arg === undefined) {\n return null;\n }\n this.#parsedIndex++;\n if (!this.#parsedDouble) {\n if (arg === \"--\") {\n this.#parsedDouble = true;\n return this.#consumeArg();\n }\n }\n return arg;\n }\n\n #processedAsPositional(arg: string): boolean {\n if (this.#parsedDouble) {\n return true;\n }\n if (arg.startsWith(\"--\")) {\n const valueIndexStart = arg.indexOf(\"=\");\n if (valueIndexStart === -1) {\n this.#consumeOptionLong(arg.slice(2), null);\n } else {\n this.#consumeOptionLong(\n arg.slice(2, valueIndexStart),\n arg.slice(valueIndexStart + 1),\n );\n }\n return false;\n }\n if (arg.startsWith(\"-\")) {\n let shortIndexStart = 1;\n let shortIndexEnd = 2;\n while (shortIndexEnd <= arg.length) {\n const result = this.#tryConsumeOptionShort(\n arg.slice(shortIndexStart, shortIndexEnd),\n arg.slice(shortIndexEnd),\n );\n if (result === true) {\n return false;\n }\n if (result === false) {\n shortIndexStart = shortIndexEnd;\n }\n shortIndexEnd++;\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`-${arg.slice(shortIndexStart)}`, typoStyleConstants),\n new TypoString(`: Unexpected unknown option`),\n ),\n );\n }\n return true;\n }\n\n #consumeOptionLong(long: string, direct: string | null): void {\n const constant = `--${long}`;\n const key = this.#keyByLong.get(long);\n if (key !== undefined) {\n if (direct !== null) {\n return this.#acknowledgeOption(key, direct);\n }\n const valued = this.#valuedByKey.get(key);\n if (valued) {\n return this.#acknowledgeOption(key, this.#consumeOptionValue(constant));\n }\n return this.#acknowledgeOption(key, \"true\");\n }\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Unexpected unknown option`),\n ),\n );\n }\n\n #tryConsumeOptionShort(short: string, rest: string): boolean | null {\n const key = this.#keyByShort.get(short);\n if (key !== undefined) {\n if (rest.startsWith(\"=\")) {\n this.#acknowledgeOption(key, rest.slice(1));\n return true;\n }\n const valued = this.#valuedByKey.get(key);\n if (valued) {\n if (rest === \"\") {\n this.#acknowledgeOption(key, this.#consumeOptionValue(`-${short}`));\n } else {\n this.#acknowledgeOption(key, rest);\n }\n return true;\n }\n this.#acknowledgeOption(key, \"true\");\n return rest === \"\";\n }\n return null;\n }\n\n #consumeOptionValue(constant: string) {\n const arg = this.#consumeArg();\n if (arg === null) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value, but got end of input`),\n ),\n );\n }\n if (this.#parsedDouble) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value before \"--\"`),\n ),\n );\n }\n // TODO - is that weird, could a valid value start with dash ?\n if (arg.startsWith(\"-\")) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value, but got: \"${arg}\"`),\n ),\n );\n }\n return arg;\n }\n\n #acknowledgeOption(key: ReaderOptionKey, value: string) {\n this.getOptionValues(key).push(value);\n }\n}\n","import { CommandUsage } from \"./Command\";\nimport {\n TypoGrid,\n TypoString,\n typoStyleConstants,\n typoStyleUserInput,\n TypoSupport,\n TypoText,\n} from \"./Typo\";\n\nexport function usageToStyledLines(params: {\n cliName: Lowercase<string>;\n commandUsage: CommandUsage;\n typoSupport: TypoSupport;\n}) {\n const { cliName, commandUsage, typoSupport } = params;\n\n const lines = new Array<string>();\n\n const breadcrumbs = [\n textUsageTitle(\"Usage:\").computeStyledString(typoSupport),\n textConstants(cliName).computeStyledString(typoSupport),\n ].concat(\n commandUsage.breadcrumbs.map((breadcrumb) => {\n if (\"positional\" in breadcrumb) {\n return textUserInput(breadcrumb.positional).computeStyledString(\n typoSupport,\n );\n }\n if (\"command\" in breadcrumb) {\n return textConstants(breadcrumb.command).computeStyledString(\n typoSupport,\n );\n }\n throw new Error(`Unknown breadcrumb: ${JSON.stringify(breadcrumb)}`);\n }),\n );\n lines.push(breadcrumbs.join(\" \"));\n\n lines.push(\"\");\n const infoText = new TypoText();\n infoText.pushString(textUsageIntro(commandUsage.information.description));\n if (commandUsage.information.hint) {\n infoText.pushString(textDelimiter(\" \"));\n infoText.pushString(textSubtleInfo(`(${commandUsage.information.hint})`));\n }\n lines.push(infoText.computeStyledString(typoSupport));\n if (commandUsage.information.details) {\n const detailsString = textSubtleInfo(commandUsage.information.details);\n lines.push(detailsString.computeStyledString(typoSupport));\n }\n\n if (commandUsage.positionals.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Positionals:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const positionalUsage of commandUsage.positionals) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n typoGridRow.push(new TypoText(textUserInput(positionalUsage.label)));\n typoGridRow.push(...createInformationals(positionalUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.subcommands.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Subcommands:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const subcommandUsage of commandUsage.subcommands) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n typoGridRow.push(new TypoText(textConstants(subcommandUsage.name)));\n typoGridRow.push(...createInformationals(subcommandUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.options.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Options:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const optionUsage of commandUsage.options) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n if (optionUsage.short) {\n typoGridRow.push(\n new TypoText(\n textConstants(`-${optionUsage.short}`),\n textDelimiter(\", \"),\n ),\n );\n } else {\n typoGridRow.push(new TypoText());\n }\n if (optionUsage.label) {\n typoGridRow.push(\n new TypoText(\n textConstants(`--${optionUsage.long}`),\n textDelimiter(\" \"),\n textUserInput(optionUsage.label),\n ),\n );\n } else {\n typoGridRow.push(\n new TypoText(\n textConstants(`--${optionUsage.long}`),\n textSubtleInfo(\"[=no]\"),\n ),\n );\n }\n typoGridRow.push(...createInformationals(optionUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n lines.push(\"\");\n return lines;\n}\n\nfunction createInformationals(usage: {\n description: string | undefined;\n hint: string | undefined;\n}): Array<TypoText> {\n const informationals = [];\n if (usage.description) {\n informationals.push(textDelimiter(\" \"));\n informationals.push(textUsefulInfo(usage.description));\n }\n if (usage.hint) {\n informationals.push(textDelimiter(\" \"));\n informationals.push(textSubtleInfo(`(${usage.hint})`));\n }\n if (informationals.length > 0) {\n return [new TypoText(textDelimiter(\" \"), ...informationals)];\n }\n return [];\n}\n\nfunction textUsageIntro(value: string): TypoString {\n return new TypoString(value, { bold: true });\n}\n\nfunction textUsageTitle(value: string): TypoString {\n return new TypoString(value, { fgColor: \"darkMagenta\", bold: true });\n}\n\nfunction textUsefulInfo(value: string): TypoString {\n return new TypoString(value);\n}\n\nfunction textSubtleInfo(value: string): TypoString {\n return new TypoString(value, { italic: true, dim: true });\n}\n\nfunction textBlockTitle(value: string): TypoString {\n return new TypoString(value, { fgColor: \"darkGreen\", bold: true });\n}\n\nfunction textConstants(value: string): TypoString {\n return new TypoString(value, typoStyleConstants);\n}\n\nfunction textUserInput(value: string): TypoString {\n return new TypoString(value, typoStyleUserInput);\n}\n\nfunction textDelimiter(value: string): TypoString {\n return new TypoString(value);\n}\n","import { CommandDescriptor, CommandFactory } from \"./Command\";\nimport { ReaderArgs } from \"./Reader\";\nimport { TypoSupport } from \"./Typo\";\nimport { usageToStyledLines } from \"./Usage\";\n\nexport async function runAsCliAndExit<Context>(\n cliName: Lowercase<string>,\n cliArgs: ReadonlyArray<string>,\n context: Context,\n command: CommandDescriptor<Context, void>,\n application?: {\n usageOnHelp?: boolean | undefined;\n buildVersion?: string | undefined;\n useColors?: boolean | undefined;\n onLogStdOut?: ((message: string) => void) | undefined; // TODO - this is a problem, deep commands use console\n onLogStdErr?: ((message: string) => void) | undefined;\n onExit?: ((code: number) => never) | undefined;\n onExecutionError?: ((error: unknown) => void) | undefined;\n },\n): Promise<never> {\n const readerArgs = new ReaderArgs(cliArgs);\n const usageOnHelp = application?.usageOnHelp ?? true;\n if (usageOnHelp) {\n readerArgs.registerOption({\n shorts: [],\n longs: [\"help\"],\n valued: false,\n });\n }\n const buildVersion = application?.buildVersion;\n if (buildVersion) {\n readerArgs.registerOption({\n shorts: [],\n longs: [\"version\"],\n valued: false,\n });\n }\n /*\n // TODO - handle completions ?\n readerArgs.registerFlag({\n key: \"completion\",\n shorts: [],\n longs: [\"completion\"],\n });\n */\n const typoSupport = chooseTypoSupport(application?.useColors);\n const onLogStdOut = application?.onLogStdOut ?? console.log;\n const onLogStdErr = application?.onLogStdErr ?? console.error;\n const onExit = application?.onExit ?? process.exit;\n const commandFactory = command.createFactory(readerArgs);\n while (true) {\n try {\n const positional = readerArgs.consumePositional();\n if (positional === undefined) {\n break;\n }\n } catch (_) {}\n }\n if (usageOnHelp) {\n if (readerArgs.getOptionValues(\"--help\" as any).length > 0) {\n onLogStdOut(computeUsageString(cliName, commandFactory, typoSupport));\n return onExit(0);\n }\n }\n if (buildVersion) {\n if (readerArgs.getOptionValues(\"--version\" as any).length > 0) {\n onLogStdOut([cliName, buildVersion].join(\" \"));\n return onExit(0);\n }\n }\n try {\n const commandInstance = commandFactory.createInstance();\n try {\n await commandInstance.executeWithContext(context);\n return onExit(0);\n } catch (executionError) {\n if (application?.onExecutionError) {\n application.onExecutionError(executionError);\n } else {\n onLogStdErr(typoSupport.computeStyledErrorMessage(executionError));\n }\n return onExit(1);\n }\n } catch (parsingError) {\n onLogStdErr(computeUsageString(cliName, commandFactory, typoSupport));\n onLogStdErr(typoSupport.computeStyledErrorMessage(parsingError));\n return onExit(1);\n }\n}\n\nfunction computeUsageString<Context, Result>(\n cliName: Lowercase<string>,\n commandFactory: CommandFactory<Context, Result>,\n typoSupport: TypoSupport,\n) {\n return usageToStyledLines({\n cliName,\n commandUsage: commandFactory.generateUsage(),\n typoSupport,\n }).join(\"\\n\");\n}\n\nfunction chooseTypoSupport(useColors?: boolean): TypoSupport {\n if (useColors === undefined) {\n return TypoSupport.inferFromProcess();\n }\n return useColors ? TypoSupport.tty() : TypoSupport.none();\n}\n"],"mappings":"m3BAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,gBAAAE,EAAA,cAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,gBAAAC,EAAA,aAAAC,EAAA,YAAAC,GAAA,mBAAAC,GAAA,2BAAAC,GAAA,cAAAC,GAAA,eAAAC,GAAA,qBAAAC,GAAA,sBAAAC,GAAA,uBAAAC,GAAA,uBAAAC,GAAA,wBAAAC,GAAA,oBAAAC,GAAA,eAAAC,GAAA,gBAAAC,EAAA,aAAAC,GAAA,eAAAC,EAAA,aAAAC,GAAA,eAAAC,GAAA,eAAAC,GAAA,cAAAC,GAAA,eAAAC,GAAA,cAAAC,GAAA,YAAAC,GAAA,uBAAAC,EAAA,qBAAAC,GAAA,uBAAAC,EAAA,uBAAAC,KAAA,eAAAC,GAAAlC,IC4BO,IAAMmC,EAAgC,CAC3C,QAAS,WACT,KAAM,EACR,EACaC,EAAgC,CAC3C,QAAS,WACT,KAAM,EACR,EACaC,GAA8B,CACzC,QAAS,UACT,KAAM,EACR,EAvCAC,EAAAC,EAyCaC,EAAN,KAAiB,CAGtB,YAAYC,EAAeC,EAAuB,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,EAE5DJ,EAAO,CAAC,CACjB,CACF,OAASK,EAAc,CACrB,OAAAN,EAAYG,GAAmBf,EAASc,EAAgBL,CAAW,CAAC,EACpEG,EAAYH,EAAY,0BAA0BS,CAAY,CAAC,EACxDL,EAAO,CAAC,CACjB,CACF,CAEA,SAASE,GACPf,EACAc,EACAL,EACA,CACA,OAAOU,GAAmB,CACxB,QAAAnB,EACA,aAAcc,EAAe,cAAc,EAC3C,YAAAL,CACF,CAAC,EAAE,KAAK;AAAA,CAAI,CACd,CAEA,SAASC,GAAkBU,EAAkC,CAC3D,OAAIA,IAAc,OACTC,EAAY,iBAAiB,EAE/BD,EAAYC,EAAY,IAAI,EAAIA,EAAY,KAAK,CAC1D","names":["index_exports","__export","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","__toCommonJS","typoStyleConstants","typoStyleUserInput","typoStyleFailure","_value","_typoStyle","TypoString","value","typoStyle","__privateAdd","__privateSet","__privateGet","typoSupport","_typoStrings","_TypoText","typoParts","typoPart","typoString","typoText","t","length","TypoText","_typoRows","TypoGrid","cells","widths","printableGrid","typoGridRow","typoGridColumnIndex","width","printableGridRow","typoGridCell","printableGridCell","padding","_typoText","_TypoError","currentTypoText","source","TypoError","_kind","_TypoSupport","kind","fgColorCode","ttyCodeFgColors","bgColorCode","ttyCodeBgColors","boldCode","ttyCodeBold","dimCode","ttyCodeDim","italicCode","ttyCodeItalic","underlineCode","ttyCodeUnderline","strikethroughCode","ttyCodeStrikethrough","ttyCodeReset","fgColorPart","bgColorPart","boldPart","dimPart","italicPart","underlinePart","error","TypoSupport","command","information","operation","readerArgs","generateUsage","operationUsage","positional","breadcrumbPositional","operationFactory","endPositional","operationInstance","context","error","commandWithSubcommands","subcommands","subcommandName","TypoError","TypoText","TypoString","typoStyleUserInput","subcommandInput","subcommandFactory","subcommandUsage","breadcrumbCommand","subcommandInstance","subcommand","metadata","commandChained","nextCommand","nextCommandFactory","nextCommandUsage","nextCommandInstance","value","operation","inputs","handler","optionsUsage","optionKey","optionInput","positionalsUsage","positionalInput","readerArgs","optionsGetters","positionalsValues","optionsValues","context","typeBoolean","value","lowerValue","typeDate","timestamp","typeUrl","typeString","typeNumber","typeBigInt","typeMapped","before","after","typeDecode","TypoText","TypoString","typoStyleUserInput","typeOneOf","type","values","valuesSet","decoded","valuesDesc","v","typeTuple","elementTypes","separator","elementType","parts","part","index","typeList","context","error","TypoError","optionFlag","definition","label","typeBoolean","readerOptions","key","registerOption","optionValues","TypoError","TypoText","TypoString","typoStyleConstants","optionValue","error","typeDecode","typoStyleUserInput","optionSingleValue","optionRepeatable","value","long","short","aliases","valued","longs","shorts","positionalRequired","definition","label","readerPositionals","positional","TypoError","TypoText","TypoString","typoStyleUserInput","typeDecode","positionalOptional","error","positionalVariadics","positionals","_args","_parsedIndex","_parsedDouble","_keyByLong","_keyByShort","_valuedByKey","_resultByKey","_ReaderArgs_instances","consumeArg_fn","processedAsPositional_fn","consumeOptionLong_fn","tryConsumeOptionShort_fn","consumeOptionValue_fn","acknowledgeOption_fn","ReaderArgs","args","__privateAdd","__privateSet","definition","key","long","short","__privateGet","i","shortSlice","shortOther","optionResult","arg","__privateMethod","__privateWrapper","valueIndexStart","shortIndexStart","shortIndexEnd","result","TypoError","TypoText","TypoString","typoStyleConstants","direct","constant","rest","value","usageToStyledLines","params","cliName","commandUsage","typoSupport","lines","breadcrumbs","textUsageTitle","textConstants","breadcrumb","textUserInput","infoText","TypoText","textUsageIntro","textDelimiter","textSubtleInfo","detailsString","textBlockTitle","typoGrid","TypoGrid","positionalUsage","typoGridRow","createInformationals","row","subcommandUsage","optionUsage","usage","informationals","textUsefulInfo","value","TypoString","typoStyleConstants","typoStyleUserInput","runAsCliAndExit","cliName","cliArgs","context","command","application","readerArgs","ReaderArgs","usageOnHelp","buildVersion","typoSupport","chooseTypoSupport","onLogStdOut","onLogStdErr","onExit","commandFactory","computeUsageString","commandInstance","executionError","parsingError","usageToStyledLines","useColors","TypoSupport"]}
|
package/package.json
CHANGED
package/src/lib/Command.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OperationDescriptor } from "./Operation";
|
|
2
2
|
import { OptionUsage } from "./Option";
|
|
3
3
|
import { PositionalUsage } from "./Positional";
|
|
4
4
|
import { ReaderArgs } from "./Reader";
|
|
5
|
-
import { TypoError, TypoString,
|
|
5
|
+
import { TypoError, TypoString, typoStyleUserInput, TypoText } from "./Typo";
|
|
6
6
|
|
|
7
|
-
export type
|
|
7
|
+
export type CommandDescriptor<Context, Result> = {
|
|
8
8
|
getInformation(): CommandInformation;
|
|
9
9
|
createFactory(readerArgs: ReaderArgs): CommandFactory<Context, Result>;
|
|
10
10
|
};
|
|
@@ -45,8 +45,8 @@ export type CommandUsageSubcommand = {
|
|
|
45
45
|
|
|
46
46
|
export function command<Context, Result>(
|
|
47
47
|
information: CommandInformation,
|
|
48
|
-
operation:
|
|
49
|
-
):
|
|
48
|
+
operation: OperationDescriptor<Context, Result>,
|
|
49
|
+
): CommandDescriptor<Context, Result> {
|
|
50
50
|
return {
|
|
51
51
|
getInformation() {
|
|
52
52
|
return information;
|
|
@@ -95,9 +95,11 @@ export function command<Context, Result>(
|
|
|
95
95
|
|
|
96
96
|
export function commandWithSubcommands<Context, Payload, Result>(
|
|
97
97
|
information: CommandInformation,
|
|
98
|
-
operation:
|
|
99
|
-
subcommands: {
|
|
100
|
-
|
|
98
|
+
operation: OperationDescriptor<Context, Payload>,
|
|
99
|
+
subcommands: {
|
|
100
|
+
[subcommand: Lowercase<string>]: CommandDescriptor<Payload, Result>;
|
|
101
|
+
},
|
|
102
|
+
): CommandDescriptor<Context, Result> {
|
|
101
103
|
return {
|
|
102
104
|
getInformation() {
|
|
103
105
|
return information;
|
|
@@ -109,7 +111,7 @@ export function commandWithSubcommands<Context, Payload, Result>(
|
|
|
109
111
|
if (subcommandName === undefined) {
|
|
110
112
|
throw new TypoError(
|
|
111
113
|
new TypoText(
|
|
112
|
-
new TypoString(`<SUBCOMMAND>`,
|
|
114
|
+
new TypoString(`<SUBCOMMAND>`, typoStyleUserInput),
|
|
113
115
|
new TypoString(`: Is required, but was not provided`),
|
|
114
116
|
),
|
|
115
117
|
);
|
|
@@ -119,7 +121,7 @@ export function commandWithSubcommands<Context, Payload, Result>(
|
|
|
119
121
|
if (subcommandInput === undefined) {
|
|
120
122
|
throw new TypoError(
|
|
121
123
|
new TypoText(
|
|
122
|
-
new TypoString(`<SUBCOMMAND>`,
|
|
124
|
+
new TypoString(`<SUBCOMMAND>`, typoStyleUserInput),
|
|
123
125
|
new TypoString(`: Invalid value: "${subcommandName}"`),
|
|
124
126
|
),
|
|
125
127
|
);
|
|
@@ -161,7 +163,7 @@ export function commandWithSubcommands<Context, Payload, Result>(
|
|
|
161
163
|
return {
|
|
162
164
|
breadcrumbs: operationUsage.positionals
|
|
163
165
|
.map((positional) => breadcrumbPositional(positional.label))
|
|
164
|
-
.concat([
|
|
166
|
+
.concat([breadcrumbPositional("<SUBCOMMAND>")]),
|
|
165
167
|
information: information,
|
|
166
168
|
positionals: operationUsage.positionals,
|
|
167
169
|
subcommands: Object.entries(subcommands).map((subcommand) => {
|
|
@@ -186,9 +188,9 @@ export function commandWithSubcommands<Context, Payload, Result>(
|
|
|
186
188
|
|
|
187
189
|
export function commandChained<Context, Payload, Result>(
|
|
188
190
|
information: CommandInformation,
|
|
189
|
-
operation:
|
|
190
|
-
nextCommand:
|
|
191
|
-
):
|
|
191
|
+
operation: OperationDescriptor<Context, Payload>,
|
|
192
|
+
nextCommand: CommandDescriptor<Payload, Result>,
|
|
193
|
+
): CommandDescriptor<Context, Result> {
|
|
192
194
|
return {
|
|
193
195
|
getInformation() {
|
|
194
196
|
return information;
|
package/src/lib/Operation.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Option, OptionUsage } from "./Option";
|
|
|
2
2
|
import { Positional, PositionalUsage } from "./Positional";
|
|
3
3
|
import { ReaderArgs } from "./Reader";
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type OperationDescriptor<Input, Output> = {
|
|
6
6
|
generateUsage(): OperationUsage;
|
|
7
7
|
createFactory(readerArgs: ReaderArgs): OperationFactory<Input, Output>;
|
|
8
8
|
};
|
|
@@ -34,7 +34,7 @@ export function operation<
|
|
|
34
34
|
context: Context,
|
|
35
35
|
inputs: { options: Options; positionals: Positionals },
|
|
36
36
|
) => Promise<Result>,
|
|
37
|
-
):
|
|
37
|
+
): OperationDescriptor<Context, Result> {
|
|
38
38
|
return {
|
|
39
39
|
generateUsage() {
|
|
40
40
|
const optionsUsage = new Array<OptionUsage>();
|
package/src/lib/Option.ts
CHANGED
package/src/lib/Run.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommandDescriptor, CommandFactory } from "./Command";
|
|
2
2
|
import { ReaderArgs } from "./Reader";
|
|
3
3
|
import { TypoSupport } from "./Typo";
|
|
4
4
|
import { usageToStyledLines } from "./Usage";
|
|
@@ -7,15 +7,15 @@ export async function runAsCliAndExit<Context>(
|
|
|
7
7
|
cliName: Lowercase<string>,
|
|
8
8
|
cliArgs: ReadonlyArray<string>,
|
|
9
9
|
context: Context,
|
|
10
|
-
command:
|
|
10
|
+
command: CommandDescriptor<Context, void>,
|
|
11
11
|
application?: {
|
|
12
12
|
usageOnHelp?: boolean | undefined;
|
|
13
13
|
buildVersion?: string | undefined;
|
|
14
14
|
useColors?: boolean | undefined;
|
|
15
|
-
onExecutionError?: ((error: unknown) => void) | undefined;
|
|
16
15
|
onLogStdOut?: ((message: string) => void) | undefined; // TODO - this is a problem, deep commands use console
|
|
17
16
|
onLogStdErr?: ((message: string) => void) | undefined;
|
|
18
17
|
onExit?: ((code: number) => never) | undefined;
|
|
18
|
+
onExecutionError?: ((error: unknown) => void) | undefined;
|
|
19
19
|
},
|
|
20
20
|
): Promise<never> {
|
|
21
21
|
const readerArgs = new ReaderArgs(cliArgs);
|
|
@@ -48,16 +48,13 @@ export async function runAsCliAndExit<Context>(
|
|
|
48
48
|
const onLogStdErr = application?.onLogStdErr ?? console.error;
|
|
49
49
|
const onExit = application?.onExit ?? process.exit;
|
|
50
50
|
const commandFactory = command.createFactory(readerArgs);
|
|
51
|
-
const errors = [];
|
|
52
51
|
while (true) {
|
|
53
52
|
try {
|
|
54
53
|
const positional = readerArgs.consumePositional();
|
|
55
54
|
if (positional === undefined) {
|
|
56
55
|
break;
|
|
57
56
|
}
|
|
58
|
-
} catch (
|
|
59
|
-
errors.push(error);
|
|
60
|
-
}
|
|
57
|
+
} catch (_) {}
|
|
61
58
|
}
|
|
62
59
|
if (usageOnHelp) {
|
|
63
60
|
if (readerArgs.getOptionValues("--help" as any).length > 0) {
|
|
@@ -76,20 +73,17 @@ export async function runAsCliAndExit<Context>(
|
|
|
76
73
|
try {
|
|
77
74
|
await commandInstance.executeWithContext(context);
|
|
78
75
|
return onExit(0);
|
|
79
|
-
} catch (
|
|
76
|
+
} catch (executionError) {
|
|
80
77
|
if (application?.onExecutionError) {
|
|
81
|
-
application.onExecutionError(
|
|
78
|
+
application.onExecutionError(executionError);
|
|
82
79
|
} else {
|
|
83
|
-
onLogStdErr(typoSupport.computeStyledErrorMessage(
|
|
80
|
+
onLogStdErr(typoSupport.computeStyledErrorMessage(executionError));
|
|
84
81
|
}
|
|
85
82
|
return onExit(1);
|
|
86
83
|
}
|
|
87
|
-
} catch (
|
|
88
|
-
errors.unshift(error);
|
|
84
|
+
} catch (parsingError) {
|
|
89
85
|
onLogStdErr(computeUsageString(cliName, commandFactory, typoSupport));
|
|
90
|
-
|
|
91
|
-
onLogStdErr(typoSupport.computeStyledErrorMessage(error));
|
|
92
|
-
}
|
|
86
|
+
onLogStdErr(typoSupport.computeStyledErrorMessage(parsingError));
|
|
93
87
|
return onExit(1);
|
|
94
88
|
}
|
|
95
89
|
}
|
package/src/lib/Type.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TypoError, TypoString, typoStyleUserInput, TypoText } from "./Typo";
|
|
2
2
|
|
|
3
3
|
export type Type<Value> = {
|
|
4
|
-
// TODO - maybe include an optional hint ??
|
|
5
4
|
label: Uppercase<string>; // TODO - is there a better way to enforce uppercase labels?
|
|
6
5
|
decoder(value: string): Value;
|
|
7
6
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect, it } from "@jest/globals";
|
|
2
2
|
import {
|
|
3
|
-
Command,
|
|
4
3
|
command,
|
|
4
|
+
CommandDescriptor,
|
|
5
5
|
commandWithSubcommands,
|
|
6
6
|
operation,
|
|
7
7
|
optionFlag,
|
|
@@ -144,7 +144,7 @@ it("run", async () => {
|
|
|
144
144
|
async function executeInterpreted<Context, Result>(
|
|
145
145
|
positionals: Array<string>,
|
|
146
146
|
context: Context,
|
|
147
|
-
command:
|
|
147
|
+
command: CommandDescriptor<Context, Result>,
|
|
148
148
|
) {
|
|
149
149
|
const readerArgs = new ReaderArgs(positionals);
|
|
150
150
|
const commandFactory = command.createFactory(readerArgs);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { it } from "@jest/globals";
|
|
2
2
|
import {
|
|
3
|
-
Command,
|
|
4
3
|
command,
|
|
4
|
+
CommandDescriptor,
|
|
5
5
|
commandWithSubcommands,
|
|
6
6
|
operation,
|
|
7
7
|
optionFlag,
|
|
@@ -151,7 +151,7 @@ it("run", async () => {
|
|
|
151
151
|
*/
|
|
152
152
|
|
|
153
153
|
expect(usage1).toStrictEqual([
|
|
154
|
-
"{{Usage:}@darkMagenta}+ {{my-cli}@darkCyan}+ {{<POS-1>}@darkBlue}+ {{<POS-2>}@darkBlue}+ {{<SUBCOMMAND>}@
|
|
154
|
+
"{{Usage:}@darkMagenta}+ {{my-cli}@darkCyan}+ {{<POS-1>}@darkBlue}+ {{<POS-2>}@darkBlue}+ {{<SUBCOMMAND>}@darkBlue}+",
|
|
155
155
|
"",
|
|
156
156
|
"{Root command description}+",
|
|
157
157
|
"{{Root command details. Second line of root command details.}-}*",
|
|
@@ -211,7 +211,7 @@ it("run", async () => {
|
|
|
211
211
|
|
|
212
212
|
async function getUsage<Context, Result>(
|
|
213
213
|
args: Array<string>,
|
|
214
|
-
command:
|
|
214
|
+
command: CommandDescriptor<Context, Result>,
|
|
215
215
|
) {
|
|
216
216
|
const readerArgs = new ReaderArgs(args);
|
|
217
217
|
const commandFactory = command.createFactory(readerArgs);
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "../src";
|
|
18
18
|
|
|
19
19
|
// TODO - unit test for chained commands
|
|
20
|
-
// TODO - unit test for
|
|
20
|
+
// TODO - unit test for errors styling
|
|
21
21
|
|
|
22
22
|
it("run", async () => {
|
|
23
23
|
const rootUsage = [
|
|
@@ -100,16 +100,17 @@ it("run", async () => {
|
|
|
100
100
|
await testCase(["--version", "--help"], [rootUsage], [], 0);
|
|
101
101
|
await testCase(["--help", "--version"], [rootUsage], [], 0);
|
|
102
102
|
|
|
103
|
-
// Test multiple errors at once
|
|
103
|
+
// Test multiple errors at once (first one should show only)
|
|
104
104
|
await testCase(
|
|
105
|
-
["--invalid1", "--invalid2", "--invalid3"],
|
|
105
|
+
["--invalid1", "--invalid2", "required1", "--invalid3"],
|
|
106
106
|
[],
|
|
107
|
-
[
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
],
|
|
107
|
+
[rootUsage, "Error: --invalid1: Unexpected unknown option"],
|
|
108
|
+
1,
|
|
109
|
+
);
|
|
110
|
+
await testCase(
|
|
111
|
+
["required1", "unknown", "-wut", "--flag", "--single-value"],
|
|
112
|
+
[],
|
|
113
|
+
[rootUsage, 'Error: <SUBCOMMAND>: Invalid value: "unknown"'],
|
|
113
114
|
1,
|
|
114
115
|
);
|
|
115
116
|
|
|
@@ -285,8 +286,6 @@ async function testCase(
|
|
|
285
286
|
const onLogStdErr = makeMocked<string, void>([
|
|
286
287
|
null as unknown as void,
|
|
287
288
|
null as unknown as void,
|
|
288
|
-
null as unknown as void,
|
|
289
|
-
null as unknown as void,
|
|
290
289
|
]);
|
|
291
290
|
const onExit = makeMocked<number, never>([null as never]);
|
|
292
291
|
const cmd = commandWithSubcommands<null, void, void>(
|