cli-kiss 0.1.9 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/docs.yml +35 -0
- package/README.md +12 -1
- package/dist/index.d.ts +22 -28
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/.vitepress/config.mts +41 -0
- package/docs/guide/01_getting_started.md +116 -0
- package/docs/guide/02_commands.md +157 -0
- package/docs/guide/03_options.md +111 -0
- package/docs/guide/04_positionals.md +118 -0
- package/docs/guide/05_types.md +134 -0
- package/docs/guide/06_run.md +161 -0
- package/docs/index.md +30 -0
- package/package.json +6 -3
- package/src/index.ts +0 -1
- package/src/lib/Command.ts +6 -7
- package/src/lib/Operation.ts +2 -2
- package/src/lib/Reader.ts +1 -1
- package/src/lib/Run.ts +23 -29
- package/src/lib/Type.ts +1 -0
- package/src/lib/Typo.ts +2 -3
- package/src/lib/Usage.ts +2 -3
- package/tests/unit.runner.cycle.ts +6 -6
- package/tests/unit.runner.errors.ts +33 -33
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Deploy docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
pages: write
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: pages
|
|
14
|
+
cancel-in-progress: false
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
deploy:
|
|
18
|
+
environment:
|
|
19
|
+
name: github-pages
|
|
20
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
- uses: actions/setup-node@v4
|
|
25
|
+
with:
|
|
26
|
+
node-version: lts/*
|
|
27
|
+
cache: npm
|
|
28
|
+
- run: npm i
|
|
29
|
+
- run: npm run docs:build
|
|
30
|
+
- uses: actions/configure-pages@v5
|
|
31
|
+
- uses: actions/upload-pages-artifact@v3
|
|
32
|
+
with:
|
|
33
|
+
path: docs/.vitepress/dist
|
|
34
|
+
- uses: actions/deploy-pages@v4
|
|
35
|
+
id: deployment
|
package/README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
# CLI - Keep It Simple, Stupid
|
|
2
2
|
|
|
3
|
-
No bloat, no dependency
|
|
3
|
+
Full-featured CLI builder for TypeScript. No bloat, no dependency.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install cli-kiss
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Cookbook
|
|
12
|
+
|
|
13
|
+
Full documentation and examples: **https://crypto-vincent.github.io/cli-kiss/**
|
|
14
|
+
💋
|
package/dist/index.d.ts
CHANGED
|
@@ -76,7 +76,7 @@ type ReaderPositionals = {
|
|
|
76
76
|
* - End-of-options separator: `--` — all subsequent tokens are treated as positionals.
|
|
77
77
|
*
|
|
78
78
|
* In most cases you do not need to use `ReaderArgs` directly; it is created internally
|
|
79
|
-
* by {@link
|
|
79
|
+
* by {@link runAndExit}. It is exposed for advanced use cases such as building
|
|
80
80
|
* custom runners.
|
|
81
81
|
*/
|
|
82
82
|
declare class ReaderArgs {
|
|
@@ -195,6 +195,7 @@ declare const typeBoolean: Type<boolean>;
|
|
|
195
195
|
* @example
|
|
196
196
|
* ```ts
|
|
197
197
|
* typeDate.decoder("2024-01-15") // → Date object for 2024-01-15
|
|
198
|
+
* typeDate.decoder("2024-01-15T13:45:30Z") // → Date object for 2024-01-15 13:45:30 UTC
|
|
198
199
|
* typeDate.decoder("not a date") // throws TypoError
|
|
199
200
|
* ```
|
|
200
201
|
*/
|
|
@@ -825,7 +826,7 @@ type OperationInstance<Input, Output> = {
|
|
|
825
826
|
* option/positional values.
|
|
826
827
|
*
|
|
827
828
|
* @param input - Context from the parent command (or the root context supplied to
|
|
828
|
-
* {@link
|
|
829
|
+
* {@link runAndExit}).
|
|
829
830
|
* @returns A promise resolving to the handler's return value.
|
|
830
831
|
*/
|
|
831
832
|
executeWithContext(input: Input): Promise<Output>;
|
|
@@ -846,7 +847,7 @@ type OperationUsage = {
|
|
|
846
847
|
*
|
|
847
848
|
* The `handler` receives:
|
|
848
849
|
* - `context` — the value passed down from the parent command (or from
|
|
849
|
-
* {@link
|
|
850
|
+
* {@link runAndExit}).
|
|
850
851
|
* - `inputs.options` — an object whose keys match those declared in `inputs.options` and whose values are
|
|
851
852
|
* the parsed option values.
|
|
852
853
|
* - `inputs.positionals` — a tuple whose elements match `inputs.positionals` and whose
|
|
@@ -905,12 +906,12 @@ declare function operation<Context, Result, Options extends {
|
|
|
905
906
|
*
|
|
906
907
|
* A `CommandDescriptor` is the central building block of a `cli-kiss` CLI. You create
|
|
907
908
|
* one with {@link command}, {@link commandWithSubcommands}, or {@link commandChained},
|
|
908
|
-
* and pass it to {@link
|
|
909
|
+
* and pass it to {@link runAndExit} to run your CLI.
|
|
909
910
|
*
|
|
910
911
|
* @typeParam Context - The value passed into the command when it is executed. It flows
|
|
911
|
-
* from {@link
|
|
912
|
+
* from {@link runAndExit}'s `context` argument down through the command chain.
|
|
912
913
|
* @typeParam Result - The value produced by executing the command. For root commands
|
|
913
|
-
* passed to {@link
|
|
914
|
+
* passed to {@link runAndExit} this is always `void`.
|
|
914
915
|
*/
|
|
915
916
|
type CommandDescriptor<Context, Result> = {
|
|
916
917
|
/** Returns the static metadata (description, hint, details) for this command. */
|
|
@@ -961,7 +962,7 @@ type CommandInstance<Context, Result> = {
|
|
|
961
962
|
/**
|
|
962
963
|
* Executes the command with the provided context.
|
|
963
964
|
*
|
|
964
|
-
* @param context - Arbitrary value injected by the caller (see {@link
|
|
965
|
+
* @param context - Arbitrary value injected by the caller (see {@link runAndExit}).
|
|
965
966
|
* @returns A promise that resolves to the command's result, or rejects if the
|
|
966
967
|
* command handler throws.
|
|
967
968
|
*/
|
|
@@ -970,8 +971,7 @@ type CommandInstance<Context, Result> = {
|
|
|
970
971
|
/**
|
|
971
972
|
* Static, human-readable metadata attached to a command.
|
|
972
973
|
*
|
|
973
|
-
* This information is displayed in the usage/help output produced by
|
|
974
|
-
* {@link usageToStyledLines}.
|
|
974
|
+
* This information is displayed in the usage/help output produced by {@link usageToStyledLines}.
|
|
975
975
|
*/
|
|
976
976
|
type CommandInformation = {
|
|
977
977
|
/** Short description of what the command does. Shown prominently in the usage header. */
|
|
@@ -1059,7 +1059,7 @@ type CommandUsageSubcommand = {
|
|
|
1059
1059
|
* @param information - Static metadata (description, hint, details) for the command.
|
|
1060
1060
|
* @param operation - The operation that defines options, positionals, and the execution
|
|
1061
1061
|
* handler for this command.
|
|
1062
|
-
* @returns A {@link CommandDescriptor} suitable for passing to {@link
|
|
1062
|
+
* @returns A {@link CommandDescriptor} suitable for passing to {@link runAndExit}
|
|
1063
1063
|
* or composing with {@link commandWithSubcommands} / {@link commandChained}.
|
|
1064
1064
|
*
|
|
1065
1065
|
* @example
|
|
@@ -1178,7 +1178,7 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
|
|
|
1178
1178
|
* - `1` — Argument parsing failed (a usage summary is also printed to stderr), or the
|
|
1179
1179
|
* command threw an unhandled execution error.
|
|
1180
1180
|
*
|
|
1181
|
-
* **Built-in flags
|
|
1181
|
+
* **Built-in flags:**
|
|
1182
1182
|
* - `--help` — Enabled by default (`usageOnHelp: true`). Prints the usage summary to
|
|
1183
1183
|
* stdout and exits with code `0`. This flag takes precedence over `--version`.
|
|
1184
1184
|
* - `--version` — Enabled when `buildVersion` is provided. Prints `<cliName> <version>`
|
|
@@ -1206,10 +1206,8 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
|
|
|
1206
1206
|
* stderr before the error message whenever argument parsing fails.
|
|
1207
1207
|
* @param options.buildVersion - When provided, registers a `--version` flag that prints
|
|
1208
1208
|
* `<cliName> <buildVersion>` to stdout and exits with code `0`.
|
|
1209
|
-
* @param options.
|
|
1210
|
-
*
|
|
1211
|
-
* @param options.onLogStdOut - Overrides the standard output sink (default: `console.log`).
|
|
1212
|
-
* @param options.onLogStdErr - Overrides the standard error sink (default: `console.error`).
|
|
1209
|
+
* @param options.onError - Custom handler for errors thrown during command execution.
|
|
1210
|
+
* If omitted, the error is printed to stderr via {@link TypoSupport}.
|
|
1213
1211
|
* @param options.onExit - Overrides the process exit function (default: `process.exit`).
|
|
1214
1212
|
* Useful for testing — supply a function that throws or captures the exit code instead
|
|
1215
1213
|
* of actually terminating the process.
|
|
@@ -1218,7 +1216,7 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
|
|
|
1218
1216
|
*
|
|
1219
1217
|
* @example
|
|
1220
1218
|
* ```ts
|
|
1221
|
-
* import {
|
|
1219
|
+
* import { runAndExit, command, operation, positionalRequired, typeString } from "cli-kiss";
|
|
1222
1220
|
*
|
|
1223
1221
|
* const greetCommand = command(
|
|
1224
1222
|
* { description: "Greet someone" },
|
|
@@ -1230,19 +1228,17 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
|
|
|
1230
1228
|
* ),
|
|
1231
1229
|
* );
|
|
1232
1230
|
*
|
|
1233
|
-
* await
|
|
1231
|
+
* await runAndExit("greet", process.argv.slice(2), undefined, greetCommand, {
|
|
1234
1232
|
* buildVersion: "1.0.0",
|
|
1235
1233
|
* });
|
|
1236
1234
|
* ```
|
|
1237
1235
|
*/
|
|
1238
|
-
declare function
|
|
1236
|
+
declare function runAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command: CommandDescriptor<Context, void>, options?: {
|
|
1239
1237
|
useTtyColors?: boolean | undefined | "mock";
|
|
1240
1238
|
usageOnHelp?: boolean | undefined;
|
|
1241
1239
|
usageOnError?: boolean | undefined;
|
|
1242
1240
|
buildVersion?: string | undefined;
|
|
1243
|
-
|
|
1244
|
-
onLogStdOut?: ((message: string) => void) | undefined;
|
|
1245
|
-
onLogStdErr?: ((message: string) => void) | undefined;
|
|
1241
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
1246
1242
|
onExit?: ((code: number) => never) | undefined;
|
|
1247
1243
|
}): Promise<never>;
|
|
1248
1244
|
|
|
@@ -1464,9 +1460,8 @@ declare class TypoError extends Error {
|
|
|
1464
1460
|
* - {@link TypoSupport.inferFromProcess} — auto-detects based on `process.stdout.isTTY`
|
|
1465
1461
|
* and the `FORCE_COLOR` / `NO_COLOR` environment variables.
|
|
1466
1462
|
*
|
|
1467
|
-
* `TypoSupport` is consumed by {@link
|
|
1468
|
-
* and can also be used directly when building custom usage renderers with
|
|
1469
|
-
* {@link usageToStyledLines}.
|
|
1463
|
+
* `TypoSupport` is consumed by {@link runAndExit} (via the `useTtyColors` option)
|
|
1464
|
+
* and can also be used directly when building custom usage renderers with {@link usageToStyledLines}.
|
|
1470
1465
|
*/
|
|
1471
1466
|
declare class TypoSupport {
|
|
1472
1467
|
#private;
|
|
@@ -1555,8 +1550,7 @@ declare class TypoSupport {
|
|
|
1555
1550
|
* in each column sets the width for the entire section.
|
|
1556
1551
|
*
|
|
1557
1552
|
* @param params.cliName - The CLI program name shown at the start of the usage line.
|
|
1558
|
-
* @param params.commandUsage - The usage model produced by
|
|
1559
|
-
* {@link CommandFactory.generateUsage}.
|
|
1553
|
+
* @param params.commandUsage - The usage model produced by {@link CommandFactory.generateUsage}.
|
|
1560
1554
|
* @param params.typoSupport - Controls color/styling of the output.
|
|
1561
1555
|
* @returns An ordered array of strings, one per output line (including a trailing
|
|
1562
1556
|
* empty string for the blank line at the end).
|
|
@@ -1566,7 +1560,7 @@ declare class TypoSupport {
|
|
|
1566
1560
|
* const lines = usageToStyledLines({
|
|
1567
1561
|
* cliName: "my-cli",
|
|
1568
1562
|
* commandUsage: commandFactory.generateUsage(),
|
|
1569
|
-
* typoSupport: TypoSupport.
|
|
1563
|
+
* typoSupport: TypoSupport.tty(),
|
|
1570
1564
|
* });
|
|
1571
1565
|
* process.stdout.write(lines.join("\n"));
|
|
1572
1566
|
* ```
|
|
@@ -1577,4 +1571,4 @@ declare function usageToStyledLines(params: {
|
|
|
1577
1571
|
typoSupport: TypoSupport;
|
|
1578
1572
|
}): string[];
|
|
1579
1573
|
|
|
1580
|
-
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,
|
|
1574
|
+
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, runAndExit, typeBoolean, typeConverted, typeDate, typeInteger, typeList, typeNumber, typeOneOf, typeString, typeTuple, typeUrl, typoStyleConstants, typoStyleFailure, typoStyleLogic, typoStyleQuote, typoStyleRegularStrong, typoStyleRegularWeaker, typoStyleTitle, typoStyleUserInput, usageToStyledLines };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var X=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var bt=Object.getOwnPropertyNames;var Ct=Object.prototype.hasOwnProperty;var dt=e=>{throw TypeError(e)};var St=(e,t)=>{for(var n in t)X(e,n,{get:t[n],enumerable:!0})},Tt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of bt(t))!Ct.call(e,o)&&o!==n&&X(e,o,{get:()=>t[o],enumerable:!(r=xt(t,o))||r.enumerable});return e};var Ut=e=>Tt(X({},"__esModule",{value:!0}),e);var Z=(e,t,n)=>t.has(e)||dt("Cannot "+n);var c=(e,t,n)=>(Z(e,t,"read from private field"),n?n.call(e):t.get(e)),w=(e,t,n)=>t.has(e)?dt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),m=(e,t,n,r)=>(Z(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),h=(e,t,n)=>(Z(e,t,"access private method"),n);var yt=(e,t,n,r)=>({set _(o){m(e,t,o,n)},get _(){return c(e,t,r)}});var oe={};St(oe,{ReaderArgs:()=>j,TypoError:()=>g,TypoGrid:()=>P,TypoString:()=>s,TypoSupport:()=>I,TypoText:()=>u,command:()=>Et,commandChained:()=>Lt,commandWithSubcommands:()=>vt,operation:()=>Gt,optionFlag:()=>Ht,optionRepeatable:()=>Jt,optionSingleValue:()=>Qt,positionalOptional:()=>Xt,positionalRequired:()=>zt,positionalVariadics:()=>Zt,runAsCliAndExit:()=>ne,typeBoolean:()=>H,typeConverted:()=>Nt,typeDate:()=>Bt,typeInteger:()=>Dt,typeList:()=>qt,typeNumber:()=>Wt,typeOneOf:()=>jt,typeString:()=>Kt,typeTuple:()=>Yt,typeUrl:()=>Mt,typoStyleConstants:()=>x,typoStyleFailure:()=>mt,typoStyleLogic:()=>S,typoStyleQuote:()=>f,typoStyleRegularStrong:()=>tt,typoStyleRegularWeaker:()=>et,typoStyleTitle:()=>_,typoStyleUserInput:()=>b,usageToStyledLines:()=>ct});module.exports=Ut(oe);var _={fgColor:"darkGreen",bold:!0},S={fgColor:"darkMagenta",bold:!0},f={fgColor:"darkYellow",bold:!0},mt={fgColor:"darkRed",bold:!0},x={fgColor:"darkCyan",bold:!0},b={fgColor:"darkBlue",bold:!0},tt={bold:!0},et={italic:!0,dim:!0},F,N,s=class{constructor(t,n={}){w(this,F);w(this,N);m(this,F,t),m(this,N,n)}getRawString(){return c(this,F)}computeStyledString(t){return t.computeStyledString(c(this,F),c(this,N))}};F=new WeakMap,N=new WeakMap;var T,nt=class nt{constructor(...t){w(this,T);m(this,T,[]);for(let n of t)n instanceof nt?this.pushText(n):n instanceof s?this.pushString(n):typeof n=="string"&&this.pushString(new s(n))}pushString(t){c(this,T).push(t)}pushText(t){for(let n of c(t,T))c(this,T).push(n)}computeStyledString(t){return c(this,T).map(n=>n.computeStyledString(t)).join("")}computeRawString(){return c(this,T).map(t=>t.getRawString()).join("")}computeRawLength(){let t=0;for(let n of c(this,T))t+=n.getRawString().length;return t}};T=new WeakMap;var u=nt,V,P=class{constructor(){w(this,V);m(this,V,[])}pushRow(t){c(this,V).push(t)}computeStyledGrid(t){let n=new Array,r=new Array;for(let o of c(this,V))for(let i=0;i<o.length;i++){let p=o[i].computeRawLength();(n[i]===void 0||p>n[i])&&(n[i]=p)}for(let o of c(this,V)){let i=new Array;for(let a=0;a<o.length;a++){let p=o[a],l=p.computeStyledString(t);if(i.push(l),a<o.length-1){let d=p.computeRawLength(),U=" ".repeat(n[a]-d);i.push(U)}}r.push(i)}return r}};V=new WeakMap;var G,q=class q extends Error{constructor(n,r){let o=new u;o.pushText(n),r instanceof q?(o.pushString(new s(": ")),o.pushText(c(r,G))):r instanceof Error?o.pushString(new s(`: ${r.message}`)):r!==void 0&&o.pushString(new s(`: ${String(r)}`));super(o.computeRawString());w(this,G);m(this,G,o)}computeStyledString(n){return c(this,G).computeStyledString(n)}static tryWithContext(n,r){try{return n()}catch(o){throw new q(r(),o)}}};G=new WeakMap;var g=q,k,C=class C{constructor(t){w(this,k);m(this,k,t)}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.tty():C.none()}computeStyledString(t,n){if(c(this,k)==="none")return t;if(c(this,k)==="tty"){let r=n.fgColor?Vt[n.fgColor]:"",o=n.bgColor?Pt[n.bgColor]:"",i=n.bold?Rt:"",a=n.dim?kt:"",p=n.italic?It:"",l=n.underline?$t:"",d=n.strikethrough?At:"";return`${r}${o}${i}${a}${p}${l}${d}${t}${Ot}`}if(c(this,k)==="mock"){let r=n.fgColor?`{${t}}@${n.fgColor}`:t,o=n.bgColor?`{${r}}#${n.bgColor}`:r,i=n.bold?`{${o}}+`:o,a=n.dim?`{${i}}-`:i,p=n.italic?`{${a}}*`:a,l=n.underline?`{${p}}_`:p;return n.strikethrough?`{${l}}~`:l}throw new Error(`Unknown TypoSupport kind: ${c(this,k)}`)}computeStyledErrorMessage(t){return[this.computeStyledString("Error:",mt),t instanceof g?t.computeStyledString(this):t instanceof Error?t.message:String(t)].join(" ")}};k=new WeakMap;var I=C,Ot="\x1B[0m",Rt="\x1B[1m",kt="\x1B[2m",It="\x1B[3m",$t="\x1B[4m",At="\x1B[9m",Vt={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"},Pt={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 Et(e,t){return{getInformation(){return e},createFactory(n){function r(){let o=t.generateUsage();return{breadcrumbs:o.positionals.map(i=>E(i.label)),information:e,positionals:o.positionals,subcommands:[],options:o.options}}try{let o=t.createFactory(n),i=n.consumePositional();if(i!==void 0)throw new g(new u(new s("Unexpected argument: "),new s(`"${i}"`,f)));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 vt(e,t,n){return{getInformation(){return e},createFactory(r){try{let o=t.createFactory(r),i=r.consumePositional();if(i===void 0)throw new g(new u(new s("<SUBCOMMAND>",b),new s(": Is required, but was not provided")));let a=n[i];if(a===void 0)throw new g(new u(new s("<SUBCOMMAND>",b),new s(": Invalid value: "),new s(`"${i}"`,f)));let p=a.createFactory(r);return{generateUsage(){let l=t.generateUsage(),d=p.generateUsage();return{breadcrumbs:l.positionals.map(U=>E(U.label)).concat([Ft(i)]).concat(d.breadcrumbs),information:d.information,positionals:l.positionals.concat(d.positionals),subcommands:d.subcommands,options:l.options.concat(d.options)}},createInstance(){let l=o.createInstance(),d=p.createInstance();return{async executeWithContext(U){return await d.executeWithContext(await l.executeWithContext(U))}}}}}catch(o){return{generateUsage(){let i=t.generateUsage();return{breadcrumbs:i.positionals.map(a=>E(a.label)).concat([E("<SUBCOMMAND>")]),information:e,positionals:i.positionals,subcommands:Object.entries(n).map(a=>{let p=a[1].getInformation();return{name:a[0],description:p.description,hint:p.hint}}),options:i.options}},createInstance(){throw o}}}}}}function Lt(e,t,n){return{getInformation(){return e},createFactory(r){try{let o=t.createFactory(r),i=n.createFactory(r);return{generateUsage(){let a=t.generateUsage(),p=i.generateUsage();return{breadcrumbs:a.positionals.map(l=>E(l.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=i.createInstance();return{async executeWithContext(l){return await p.executeWithContext(await a.executeWithContext(l))}}}}}catch(o){return{generateUsage(){let i=t.generateUsage();return{breadcrumbs:i.positionals.map(a=>E(a.label)).concat([E("[REST]...")]),information:e,positionals:i.positionals,subcommands:[],options:i.options}},createInstance(){throw o}}}}}}function E(e){return{positional:e}}function Ft(e){return{command:e}}function Gt(e,t){return{generateUsage(){let n=new Array;for(let o in e.options){let i=e.options[o];i&&n.push(i.generateUsage())}let r=new Array;for(let o of e.positionals)r.push(o.generateUsage());return{options:n,positionals:r}},createFactory(n){let r={};for(let i in e.options){let a=e.options[i];r[i]=a.createGetter(n)}let o=[];for(let i of e.positionals)o.push(i.consumePositionals(n));return{createInstance(){let i={};for(let a in r)i[a]=r[a].getValue();return{executeWithContext(a){return t(a,{options:i,positionals:o})}}}}}}}var H={content:"Boolean",decoder(e){let t=e.toLowerCase();if(t==="true"||t==="yes")return!0;if(t==="false"||t==="no")return!1;throw new g(new u(new s("Invalid value: "),new s(`"${e}"`,f)))}},Bt={content:"Date",decoder(e){try{let t=Date.parse(e);if(isNaN(t))throw new Error;return new Date(t)}catch{throw new g(new u(new s("Not a valid ISO_8601: "),new s(`"${e}"`,f)))}}},Wt={content:"Number",decoder(e){try{let t=Number(e);if(isNaN(t))throw new Error;return t}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Dt={content:"Integer",decoder(e){try{return BigInt(e)}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Mt={content:"Url",decoder(e){try{return new URL(e)}catch{throw new g(new u(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Kt={content:"String",decoder(e){return e}};function Nt(e,t){return{content:t.content,decoder:n=>t.decoder(g.tryWithContext(()=>e.decoder(n),()=>new u(new s("from: "),new s(e.content,S))))}}function jt(e,t){let n=new Set(t);return{content:e,decoder(r){if(n.has(r))return r;let o=[];for(let i of t){if(o.length>=5){o.push(new s("..."));break}o.length>0&&o.push(new s(" | ")),o.push(new s(`"${i}"`,f))}throw new g(new u(new s("Invalid value: "),new s(`"${r}"`,f),new s(" (expected one of: "),...o,new s(")")))}}}function Yt(e,t=","){return{content:e.map(n=>n.content).join(t),decoder(n){let r=n.split(t,e.length);if(r.length!==e.length)throw new g(new u(new s(`Found ${r.length} splits: `),new s(`Expected ${e.length} splits from: `),new s(`"${n}"`,f)));return r.map((o,i)=>{let a=e[i];return g.tryWithContext(()=>a.decoder(o),()=>new u(new s(`at ${i}: `),new s(a.content,S)))})}}}function qt(e,t=","){return{content:`${e.content}[${t}${e.content}]...`,decoder(n){return n.split(t).map((o,i)=>g.tryWithContext(()=>e.decoder(o),()=>new u(new s(`at ${i}: `),new s(e.content,S))))}}}function Ht(e){let t=`<${H.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,long:e.long,short:e.short,label:void 0}},createGetter(n){let r=rt(n,{...e,valued:!1});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new g(new u(new s(`--${e.long}`,x),new s(": Must not be set multiple times")));let i=o[0];if(i===void 0)try{return e.default?e.default():!1}catch(a){throw new g(new u(new s(`--${e.long}`,x),new s(": Failed to get default value")),a)}return ot(e.long,t,H,i)}}}}}function Qt(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,long:e.long,short:e.short,label:t}},createGetter(n){let r=rt(n,{...e,valued:!0});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new g(new u(new s(`--${e.long}`,x),new s(": Requires a single value, but got multiple")));let i=o[0];if(i===void 0)try{return e.default()}catch(a){throw new g(new u(new s(`--${e.long}`,x),new s(": Failed to get default value")),a)}return ot(e.long,t,e.type,i)}}}}}function Jt(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,long:e.long,short:e.short,label:t}},createGetter(n){let r=rt(n,{...e,valued:!0});return{getValue(){return n.getOptionValues(r).map(i=>ot(e.long,t,e.type,i))}}}}}function ot(e,t,n,r){return g.tryWithContext(()=>n.decoder(r),()=>new u(new s(`--${e}`,x),new s(": "),new s(t,b),new s(": "),new s(n.content,S)))}function rt(e,t){let{long:n,short:r,aliases:o,valued:i}=t,a=n?[n]:[];o?.longs&&a.push(...o?.longs);let p=r?[r]:[];return o?.shorts&&p.push(...o?.shorts),e.registerOption({longs:a,shorts:p,valued:i})}function zt(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)throw new g(new u(new s(t,b),new s(": Is required, but was not provided")));return st(t,e.type,r)}}}function Xt(e){let t=`[${e.label??e.type.content.toUpperCase()}]`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)try{return e.default()}catch(o){throw new g(new u(new s(t,b),new s(": Failed to get default value")),o)}return st(t,e.type,r)}}}function Zt(e){let t=`[${e.label??e.type.content.toUpperCase()}]`;return{generateUsage(){return{description:e.description,hint:e.hint,label:`${t}...`+(e.endDelimiter?`["${e.endDelimiter}"]`:"")}},consumePositionals(n){let r=[];for(;;){let o=n.consumePositional();if(o===void 0||o===e.endDelimiter)break;r.push(st(t,e.type,o))}return r}}}function st(e,t,n){return g.tryWithContext(()=>t.decoder(n),()=>new u(new s(e,b),new s(": "),new s(t.content,S)))}var Y,B,A,v,O,L,W,y,Q,ht,it,wt,at,$,j=class{constructor(t){w(this,y);w(this,Y);w(this,B);w(this,A);w(this,v);w(this,O);w(this,L);w(this,W);m(this,Y,t),m(this,B,0),m(this,A,!1),m(this,v,new Map),m(this,O,new Map),m(this,L,new Map),m(this,W,new Map)}registerOption(t){let n=[...t.longs.map(r=>`--${r}`),...t.shorts.map(r=>`-${r}`)].join(", ");for(let r of t.longs){if(c(this,v).has(r))throw new Error(`Option already registered: --${r}`);c(this,v).set(r,n)}for(let r of t.shorts){if(c(this,O).has(r))throw new Error(`Option already registered: -${r}`);for(let o=0;o<r.length;o++){let i=r.slice(0,o);if(c(this,O).has(i))throw new Error(`Option -${r} overlap with shorter option: -${i}`)}for(let o of c(this,O).keys())if(o.startsWith(r))throw new Error(`Option -${r} overlap with longer option: -${o}`);c(this,O).set(r,n)}return c(this,L).set(n,t.valued),c(this,W).set(n,new Array),n}getOptionValues(t){let n=c(this,W).get(t);if(n===void 0)throw new Error(`Unregistered option: ${t}`);return n}consumePositional(){for(;;){let t=h(this,y,Q).call(this);if(t===null)return;if(h(this,y,ht).call(this,t))return t}}};Y=new WeakMap,B=new WeakMap,A=new WeakMap,v=new WeakMap,O=new WeakMap,L=new WeakMap,W=new WeakMap,y=new WeakSet,Q=function(){let t=c(this,Y)[c(this,B)];return t===void 0?null:(yt(this,B)._++,!c(this,A)&&t==="--"?(m(this,A,!0),h(this,y,Q).call(this)):t)},ht=function(t){if(c(this,A))return!0;if(t.startsWith("--")){let n=t.indexOf("=");return n===-1?h(this,y,it).call(this,t.slice(2),null):h(this,y,it).call(this,t.slice(2,n),t.slice(n+1)),!1}if(t.startsWith("-")){let n=1,r=2;for(;r<=t.length;){let o=h(this,y,wt).call(this,t.slice(n,r),t.slice(r));if(o===!0)return!1;o===!1&&(n=r),r++}throw new g(new u(new s(`-${t.slice(n)}`,x),new s(": Unexpected unknown option")))}return!0},it=function(t,n){let r=`--${t}`,o=c(this,v).get(t);if(o!==void 0)return n!==null?h(this,y,$).call(this,o,n):c(this,L).get(o)?h(this,y,$).call(this,o,h(this,y,at).call(this,r)):h(this,y,$).call(this,o,"true");throw new g(new u(new s(r,x),new s(": Unexpected unknown option")))},wt=function(t,n){let r=c(this,O).get(t);return r!==void 0?n.startsWith("=")?(h(this,y,$).call(this,r,n.slice(1)),!0):c(this,L).get(r)?(n===""?h(this,y,$).call(this,r,h(this,y,at).call(this,`-${t}`)):h(this,y,$).call(this,r,n),!0):(h(this,y,$).call(this,r,"true"),n===""):null},at=function(t){let n=h(this,y,Q).call(this);if(n===null)throw new g(new u(new s(t,x),new s(": Requires a value, but got end of input")));if(c(this,A))throw new g(new u(new s(t,x),new s(": Requires a value before "),new s('"--"',f)));if(n.startsWith("-"))throw new g(new u(new s(t,x),new s(": Requires a value, but got: "),new s(`"${n}"`,f)));return n},$=function(t,n){this.getOptionValues(t).push(n)};function ct(e){let{cliName:t,commandUsage:n,typoSupport:r}=e,o=new Array,i=[_t("Usage:").computeStyledString(r),D(t).computeStyledString(r)].concat(n.breadcrumbs.map(p=>{if("positional"in p)return lt(p.positional).computeStyledString(r);if("command"in p)return D(p.command).computeStyledString(r);throw new Error(`Unknown breadcrumb: ${JSON.stringify(p)}`)}));o.push(i.join(" ")),o.push("");let a=new u;a.pushString(te(n.information.description)),n.information.hint&&(a.pushString(R(" ")),a.pushString(J(`(${n.information.hint})`))),o.push(a.computeStyledString(r));for(let p of n.information.details??[]){let l=new u;l.pushString(J(p)),o.push(l.computeStyledString(r))}if(n.positionals.length>0){o.push(""),o.push(ut("Positionals:").computeStyledString(r));let p=new P;for(let l of n.positionals){let d=new Array;d.push(new u(R(" "))),d.push(new u(lt(l.label))),d.push(...pt(l)),p.pushRow(d)}o.push(...p.computeStyledGrid(r).map(l=>l.join("")))}if(n.subcommands.length>0){o.push(""),o.push(ut("Subcommands:").computeStyledString(r));let p=new P;for(let l of n.subcommands){let d=new Array;d.push(new u(R(" "))),d.push(new u(D(l.name))),d.push(...pt(l)),p.pushRow(d)}o.push(...p.computeStyledGrid(r).map(l=>l.join("")))}if(n.options.length>0){o.push(""),o.push(ut("Options:").computeStyledString(r));let p=new P;for(let l of n.options){let d=new Array;d.push(new u(R(" "))),l.short?d.push(new u(D(`-${l.short}`),R(", "))):d.push(new u),l.label?d.push(new u(D(`--${l.long}`),R(" "),lt(l.label))):d.push(new u(D(`--${l.long}`),J("[=no]"))),d.push(...pt(l)),p.pushRow(d)}o.push(...p.computeStyledGrid(r).map(l=>l.join("")))}return o.push(""),o}function pt(e){let t=[];return e.description&&(t.push(R(" ")),t.push(ee(e.description))),e.hint&&(t.push(R(" ")),t.push(J(`(${e.hint})`))),t.length>0?[new u(R(" "),...t)]:[]}function _t(e){return new s(e,S)}function te(e){return new s(e,tt)}function ee(e){return new s(e)}function ut(e){return new s(e,_)}function J(e){return new s(e,et)}function D(e){return new s(e,x)}function lt(e){return new s(e,b)}function R(e){return new s(e)}async function ne(e,t,n,r,o){let i=new j(t),a=o?.usageOnHelp??!0;a&&i.registerOption({shorts:[],longs:["help"],valued:!1});let p=o?.buildVersion;p&&i.registerOption({shorts:[],longs:["version"],valued:!1});let l=o?.useTtyColors===void 0?I.inferFromProcess():o.useTtyColors==="mock"?I.mock():o.useTtyColors?I.tty():I.none(),d=o?.onLogStdOut??console.log,U=o?.onLogStdErr??console.error,M=o?.onExit??process.exit,z=r.createFactory(i);for(;;)try{if(i.consumePositional()===void 0)break}catch{}if(a&&i.getOptionValues("--help").length>0)return d(ft(e,z,l)),M(0);if(p&&i.getOptionValues("--version").length>0)return d([e,p].join(" ")),M(0);try{let K=z.createInstance();try{return await K.executeWithContext(n),M(0)}catch(gt){return o?.onExecutionError?o.onExecutionError(gt):U(l.computeStyledErrorMessage(gt)),M(1)}}catch(K){return(o?.usageOnError??!0)&&U(ft(e,z,l)),U(l.computeStyledErrorMessage(K)),M(1)}}function ft(e,t,n){return ct({cliName:e,commandUsage:t.generateUsage(),typoSupport:n}).join(`
|
|
2
|
-
`)}0&&(module.exports={ReaderArgs,TypoError,TypoGrid,TypoString,TypoSupport,TypoText,command,commandChained,commandWithSubcommands,operation,optionFlag,optionRepeatable,optionSingleValue,positionalOptional,positionalRequired,positionalVariadics,
|
|
1
|
+
"use strict";var J=Object.defineProperty;var wt=Object.getOwnPropertyDescriptor;var ft=Object.getOwnPropertyNames;var xt=Object.prototype.hasOwnProperty;var ct=e=>{throw TypeError(e)};var bt=(e,t)=>{for(var n in t)J(e,n,{get:t[n],enumerable:!0})},Ct=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ft(t))!xt.call(e,o)&&o!==n&&J(e,o,{get:()=>t[o],enumerable:!(r=wt(t,o))||r.enumerable});return e};var St=e=>Ct(J({},"__esModule",{value:!0}),e);var z=(e,t,n)=>t.has(e)||ct("Cannot "+n);var c=(e,t,n)=>(z(e,t,"read from private field"),n?n.call(e):t.get(e)),w=(e,t,n)=>t.has(e)?ct("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),m=(e,t,n,r)=>(z(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),h=(e,t,n)=>(z(e,t,"access private method"),n);var gt=(e,t,n,r)=>({set _(o){m(e,t,o,n)},get _(){return c(e,t,r)}});var ee={};bt(ee,{ReaderArgs:()=>N,TypoError:()=>d,TypoGrid:()=>P,TypoString:()=>s,TypoSupport:()=>I,TypoText:()=>l,command:()=>At,commandChained:()=>vt,commandWithSubcommands:()=>Pt,operation:()=>Ft,optionFlag:()=>Yt,optionRepeatable:()=>Ht,optionSingleValue:()=>qt,positionalOptional:()=>Jt,positionalRequired:()=>Qt,positionalVariadics:()=>zt,runAndExit:()=>te,typeBoolean:()=>q,typeConverted:()=>Mt,typeDate:()=>Gt,typeInteger:()=>Lt,typeList:()=>jt,typeNumber:()=>Bt,typeOneOf:()=>Kt,typeString:()=>Dt,typeTuple:()=>Nt,typeUrl:()=>Wt,typoStyleConstants:()=>x,typoStyleFailure:()=>dt,typoStyleLogic:()=>S,typoStyleQuote:()=>f,typoStyleRegularStrong:()=>Z,typoStyleRegularWeaker:()=>_,typoStyleTitle:()=>X,typoStyleUserInput:()=>b,usageToStyledLines:()=>lt});module.exports=St(ee);var X={fgColor:"darkGreen",bold:!0},S={fgColor:"darkMagenta",bold:!0},f={fgColor:"darkYellow",bold:!0},dt={fgColor:"darkRed",bold:!0},x={fgColor:"darkCyan",bold:!0},b={fgColor:"darkBlue",bold:!0},Z={bold:!0},_={italic:!0,dim:!0},G,K,s=class{constructor(t,n={}){w(this,G);w(this,K);m(this,G,t),m(this,K,n)}getRawString(){return c(this,G)}computeStyledString(t){return t.computeStyledString(c(this,G),c(this,K))}};G=new WeakMap,K=new WeakMap;var U,tt=class tt{constructor(...t){w(this,U);m(this,U,[]);for(let n of t)n instanceof tt?this.pushText(n):n instanceof s?this.pushString(n):typeof n=="string"&&this.pushString(new s(n))}pushString(t){c(this,U).push(t)}pushText(t){for(let n of c(t,U))c(this,U).push(n)}computeStyledString(t){return c(this,U).map(n=>n.computeStyledString(t)).join("")}computeRawString(){return c(this,U).map(t=>t.getRawString()).join("")}computeRawLength(){let t=0;for(let n of c(this,U))t+=n.getRawString().length;return t}};U=new WeakMap;var l=tt,A,P=class{constructor(){w(this,A);m(this,A,[])}pushRow(t){c(this,A).push(t)}computeStyledGrid(t){let n=new Array,r=new Array;for(let o of c(this,A))for(let i=0;i<o.length;i++){let p=o[i].computeRawLength();(n[i]===void 0||p>n[i])&&(n[i]=p)}for(let o of c(this,A)){let i=new Array;for(let a=0;a<o.length;a++){let p=o[a],u=p.computeStyledString(t);if(i.push(u),a<o.length-1){let g=p.computeRawLength(),T=" ".repeat(n[a]-g);i.push(T)}}r.push(i)}return r}};A=new WeakMap;var B,Y=class Y extends Error{constructor(n,r){let o=new l;o.pushText(n),r instanceof Y?(o.pushString(new s(": ")),o.pushText(c(r,B))):r instanceof Error?o.pushString(new s(`: ${r.message}`)):r!==void 0&&o.pushString(new s(`: ${String(r)}`));super(o.computeRawString());w(this,B);m(this,B,o)}computeStyledString(n){return c(this,B).computeStyledString(n)}static tryWithContext(n,r){try{return n()}catch(o){throw new Y(r(),o)}}};B=new WeakMap;var d=Y,k,C=class C{constructor(t){w(this,k);m(this,k,t)}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.tty():C.none()}computeStyledString(t,n){if(c(this,k)==="none")return t;if(c(this,k)==="tty"){let r=n.fgColor?$t[n.fgColor]:"",o=n.bgColor?Vt[n.bgColor]:"",i=n.bold?Ut:"",a=n.dim?Rt:"",p=n.italic?Ot:"",u=n.underline?kt:"",g=n.strikethrough?It:"";return`${r}${o}${i}${a}${p}${u}${g}${t}${Tt}`}if(c(this,k)==="mock"){let r=n.fgColor?`{${t}}@${n.fgColor}`:t,o=n.bgColor?`{${r}}#${n.bgColor}`:r,i=n.bold?`{${o}}+`:o,a=n.dim?`{${i}}-`:i,p=n.italic?`{${a}}*`:a,u=n.underline?`{${p}}_`:p;return n.strikethrough?`{${u}}~`:u}throw new Error(`Unknown TypoSupport kind: ${c(this,k)}`)}computeStyledErrorMessage(t){return[this.computeStyledString("Error:",dt),t instanceof d?t.computeStyledString(this):t instanceof Error?t.message:String(t)].join(" ")}};k=new WeakMap;var I=C,Tt="\x1B[0m",Ut="\x1B[1m",Rt="\x1B[2m",Ot="\x1B[3m",kt="\x1B[4m",It="\x1B[9m",$t={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"},Vt={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(e,t){return{getInformation(){return e},createFactory(n){function r(){let o=t.generateUsage();return{breadcrumbs:o.positionals.map(i=>v(i.label)),information:e,positionals:o.positionals,subcommands:[],options:o.options}}try{let o=t.createFactory(n),i=n.consumePositional();if(i!==void 0)throw new d(new l(new s("Unexpected argument: "),new s(`"${i}"`,f)));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 Pt(e,t,n){return{getInformation(){return e},createFactory(r){try{let o=t.createFactory(r),i=r.consumePositional();if(i===void 0)throw new d(new l(new s("<SUBCOMMAND>",b),new s(": Is required, but was not provided")));let a=n[i];if(a===void 0)throw new d(new l(new s("<SUBCOMMAND>",b),new s(": Invalid value: "),new s(`"${i}"`,f)));let p=a.createFactory(r);return{generateUsage(){let u=t.generateUsage(),g=p.generateUsage();return{breadcrumbs:u.positionals.map(T=>v(T.label)).concat([Et(i)]).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 i=t.generateUsage();return{breadcrumbs:i.positionals.map(a=>v(a.label)).concat([v("<SUBCOMMAND>")]),information:e,positionals:i.positionals,subcommands:Object.entries(n).map(a=>{let p=a[1].getInformation();return{name:a[0],description:p.description,hint:p.hint}}),options:i.options}},createInstance(){throw o}}}}}}function vt(e,t,n){return{getInformation(){return e},createFactory(r){try{let o=t.createFactory(r),i=n.createFactory(r);return{generateUsage(){let a=t.generateUsage(),p=i.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=i.createInstance();return{async executeWithContext(u){return await p.executeWithContext(await a.executeWithContext(u))}}}}}catch(o){return{generateUsage(){let i=t.generateUsage();return{breadcrumbs:i.positionals.map(a=>v(a.label)).concat([v("[REST]...")]),information:e,positionals:i.positionals,subcommands:[],options:i.options}},createInstance(){throw o}}}}}}function v(e){return{positional:e}}function Et(e){return{command:e}}function Ft(e,t){return{generateUsage(){let n=new Array;for(let o in e.options){let i=e.options[o];i&&n.push(i.generateUsage())}let r=new Array;for(let o of e.positionals)r.push(o.generateUsage());return{options:n,positionals:r}},createFactory(n){let r={};for(let i in e.options){let a=e.options[i];r[i]=a.createGetter(n)}let o=[];for(let i of e.positionals)o.push(i.consumePositionals(n));return{createInstance(){let i={};for(let a in r)i[a]=r[a].getValue();return{executeWithContext(a){return t(a,{options:i,positionals:o})}}}}}}}var q={content:"Boolean",decoder(e){let t=e.toLowerCase();if(t==="true"||t==="yes")return!0;if(t==="false"||t==="no")return!1;throw new d(new l(new s("Invalid value: "),new s(`"${e}"`,f)))}},Gt={content:"Date",decoder(e){try{let t=Date.parse(e);if(isNaN(t))throw new Error;return new Date(t)}catch{throw new d(new l(new s("Not a valid ISO_8601: "),new s(`"${e}"`,f)))}}},Bt={content:"Number",decoder(e){try{let t=Number(e);if(isNaN(t))throw new Error;return t}catch{throw new d(new l(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Lt={content:"Integer",decoder(e){try{return BigInt(e)}catch{throw new d(new l(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Wt={content:"Url",decoder(e){try{return new URL(e)}catch{throw new d(new l(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Dt={content:"String",decoder(e){return e}};function Mt(e,t){return{content:t.content,decoder:n=>t.decoder(d.tryWithContext(()=>e.decoder(n),()=>new l(new s("from: "),new s(e.content,S))))}}function Kt(e,t){let n=new Set(t);return{content:e,decoder(r){if(n.has(r))return r;let o=[];for(let i of t){if(o.length>=5){o.push(new s("..."));break}o.length>0&&o.push(new s(" | ")),o.push(new s(`"${i}"`,f))}throw new d(new l(new s("Invalid value: "),new s(`"${r}"`,f),new s(" (expected one of: "),...o,new s(")")))}}}function Nt(e,t=","){return{content:e.map(n=>n.content).join(t),decoder(n){let r=n.split(t,e.length);if(r.length!==e.length)throw new d(new l(new s(`Found ${r.length} splits: `),new s(`Expected ${e.length} splits from: `),new s(`"${n}"`,f)));return r.map((o,i)=>{let a=e[i];return d.tryWithContext(()=>a.decoder(o),()=>new l(new s(`at ${i}: `),new s(a.content,S)))})}}}function jt(e,t=","){return{content:`${e.content}[${t}${e.content}]...`,decoder(n){return n.split(t).map((o,i)=>d.tryWithContext(()=>e.decoder(o),()=>new l(new s(`at ${i}: `),new s(e.content,S))))}}}function Yt(e){let t=`<${q.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,long:e.long,short:e.short,label:void 0}},createGetter(n){let r=nt(n,{...e,valued:!1});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new d(new l(new s(`--${e.long}`,x),new s(": Must not be set multiple times")));let i=o[0];if(i===void 0)try{return e.default?e.default():!1}catch(a){throw new d(new l(new s(`--${e.long}`,x),new s(": Failed to get default value")),a)}return et(e.long,t,q,i)}}}}}function qt(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,long:e.long,short:e.short,label:t}},createGetter(n){let r=nt(n,{...e,valued:!0});return{getValue(){let o=n.getOptionValues(r);if(o.length>1)throw new d(new l(new s(`--${e.long}`,x),new s(": Requires a single value, but got multiple")));let i=o[0];if(i===void 0)try{return e.default()}catch(a){throw new d(new l(new s(`--${e.long}`,x),new s(": Failed to get default value")),a)}return et(e.long,t,e.type,i)}}}}}function Ht(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,long:e.long,short:e.short,label:t}},createGetter(n){let r=nt(n,{...e,valued:!0});return{getValue(){return n.getOptionValues(r).map(i=>et(e.long,t,e.type,i))}}}}}function et(e,t,n,r){return d.tryWithContext(()=>n.decoder(r),()=>new l(new s(`--${e}`,x),new s(": "),new s(t,b),new s(": "),new s(n.content,S)))}function nt(e,t){let{long:n,short:r,aliases:o,valued:i}=t,a=n?[n]:[];o?.longs&&a.push(...o?.longs);let p=r?[r]:[];return o?.shorts&&p.push(...o?.shorts),e.registerOption({longs:a,shorts:p,valued:i})}function Qt(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)throw new d(new l(new s(t,b),new s(": Is required, but was not provided")));return ot(t,e.type,r)}}}function Jt(e){let t=`[${e.label??e.type.content.toUpperCase()}]`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},consumePositionals(n){let r=n.consumePositional();if(r===void 0)try{return e.default()}catch(o){throw new d(new l(new s(t,b),new s(": Failed to get default value")),o)}return ot(t,e.type,r)}}}function zt(e){let t=`[${e.label??e.type.content.toUpperCase()}]`;return{generateUsage(){return{description:e.description,hint:e.hint,label:`${t}...`+(e.endDelimiter?`["${e.endDelimiter}"]`:"")}},consumePositionals(n){let r=[];for(;;){let o=n.consumePositional();if(o===void 0||o===e.endDelimiter)break;r.push(ot(t,e.type,o))}return r}}}function ot(e,t,n){return d.tryWithContext(()=>t.decoder(n),()=>new l(new s(e,b),new s(": "),new s(t.content,S)))}var j,L,V,E,R,F,W,y,H,yt,rt,mt,st,$,N=class{constructor(t){w(this,y);w(this,j);w(this,L);w(this,V);w(this,E);w(this,R);w(this,F);w(this,W);m(this,j,t),m(this,L,0),m(this,V,!1),m(this,E,new Map),m(this,R,new Map),m(this,F,new Map),m(this,W,new Map)}registerOption(t){let n=[...t.longs.map(r=>`--${r}`),...t.shorts.map(r=>`-${r}`)].join(", ");for(let r of t.longs){if(c(this,E).has(r))throw new Error(`Option already registered: --${r}`);c(this,E).set(r,n)}for(let r of t.shorts){if(c(this,R).has(r))throw new Error(`Option already registered: -${r}`);for(let o=0;o<r.length;o++){let i=r.slice(0,o);if(c(this,R).has(i))throw new Error(`Option -${r} overlap with shorter option: -${i}`)}for(let o of c(this,R).keys())if(o.startsWith(r))throw new Error(`Option -${r} overlap with longer option: -${o}`);c(this,R).set(r,n)}return c(this,F).set(n,t.valued),c(this,W).set(n,new Array),n}getOptionValues(t){let n=c(this,W).get(t);if(n===void 0)throw new Error(`Unregistered option: ${t}`);return n}consumePositional(){for(;;){let t=h(this,y,H).call(this);if(t===null)return;if(h(this,y,yt).call(this,t))return t}}};j=new WeakMap,L=new WeakMap,V=new WeakMap,E=new WeakMap,R=new WeakMap,F=new WeakMap,W=new WeakMap,y=new WeakSet,H=function(){let t=c(this,j)[c(this,L)];return t===void 0?null:(gt(this,L)._++,!c(this,V)&&t==="--"?(m(this,V,!0),h(this,y,H).call(this)):t)},yt=function(t){if(c(this,V))return!0;if(t.startsWith("--")){let n=t.indexOf("=");return n===-1?h(this,y,rt).call(this,t.slice(2),null):h(this,y,rt).call(this,t.slice(2,n),t.slice(n+1)),!1}if(t.startsWith("-")){let n=1,r=2;for(;r<=t.length;){let o=h(this,y,mt).call(this,t.slice(n,r),t.slice(r));if(o===!0)return!1;o===!1&&(n=r),r++}throw new d(new l(new s(`-${t.slice(n)}`,x),new s(": Unexpected unknown option")))}return!0},rt=function(t,n){let r=`--${t}`,o=c(this,E).get(t);if(o!==void 0)return n!==null?h(this,y,$).call(this,o,n):c(this,F).get(o)?h(this,y,$).call(this,o,h(this,y,st).call(this,r)):h(this,y,$).call(this,o,"true");throw new d(new l(new s(r,x),new s(": Unexpected unknown option")))},mt=function(t,n){let r=c(this,R).get(t);return r!==void 0?n.startsWith("=")?(h(this,y,$).call(this,r,n.slice(1)),!0):c(this,F).get(r)?(n===""?h(this,y,$).call(this,r,h(this,y,st).call(this,`-${t}`)):h(this,y,$).call(this,r,n),!0):(h(this,y,$).call(this,r,"true"),n===""):null},st=function(t){let n=h(this,y,H).call(this);if(n===null)throw new d(new l(new s(t,x),new s(": Requires a value, but got end of input")));if(c(this,V))throw new d(new l(new s(t,x),new s(": Requires a value before "),new s('"--"',f)));if(n.startsWith("-"))throw new d(new l(new s(t,x),new s(": Requires a value, but got: "),new s(`"${n}"`,f)));return n},$=function(t,n){this.getOptionValues(t).push(n)};function lt(e){let{cliName:t,commandUsage:n,typoSupport:r}=e,o=new Array,i=[Xt("Usage:").computeStyledString(r),D(t).computeStyledString(r)].concat(n.breadcrumbs.map(p=>{if("positional"in p)return pt(p.positional).computeStyledString(r);if("command"in p)return D(p.command).computeStyledString(r);throw new Error(`Unknown breadcrumb: ${JSON.stringify(p)}`)}));o.push(i.join(" ")),o.push("");let a=new l;a.pushString(Zt(n.information.description)),n.information.hint&&(a.pushString(O(" ")),a.pushString(Q(`(${n.information.hint})`))),o.push(a.computeStyledString(r));for(let p of n.information.details??[]){let u=new l;u.pushString(Q(p)),o.push(u.computeStyledString(r))}if(n.positionals.length>0){o.push(""),o.push(at("Positionals:").computeStyledString(r));let p=new P;for(let u of n.positionals){let g=new Array;g.push(new l(O(" "))),g.push(new l(pt(u.label))),g.push(...it(u)),p.pushRow(g)}o.push(...p.computeStyledGrid(r).map(u=>u.join("")))}if(n.subcommands.length>0){o.push(""),o.push(at("Subcommands:").computeStyledString(r));let p=new P;for(let u of n.subcommands){let g=new Array;g.push(new l(O(" "))),g.push(new l(D(u.name))),g.push(...it(u)),p.pushRow(g)}o.push(...p.computeStyledGrid(r).map(u=>u.join("")))}if(n.options.length>0){o.push(""),o.push(at("Options:").computeStyledString(r));let p=new P;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(" "),pt(u.label))):g.push(new l(D(`--${u.long}`),Q("[=no]"))),g.push(...it(u)),p.pushRow(g)}o.push(...p.computeStyledGrid(r).map(u=>u.join("")))}return o.push(""),o}function it(e){let t=[];return e.description&&(t.push(O(" ")),t.push(_t(e.description))),e.hint&&(t.push(O(" ")),t.push(Q(`(${e.hint})`))),t.length>0?[new l(O(" "),...t)]:[]}function Xt(e){return new s(e,S)}function Zt(e){return new s(e,Z)}function _t(e){return new s(e)}function at(e){return new s(e,X)}function Q(e){return new s(e,_)}function D(e){return new s(e,x)}function pt(e){return new s(e,b)}function O(e){return new s(e)}async function te(e,t,n,r,o){let i=new N(t),a=o?.usageOnHelp??!0;a&&i.registerOption({shorts:[],longs:["help"],valued:!1});let p=o?.buildVersion;p&&i.registerOption({shorts:[],longs:["version"],valued:!1});let u=r.createFactory(i);for(;;)try{if(i.consumePositional()===void 0)break}catch{}let g=o?.onExit??process.exit,T=o?.useTtyColors===void 0?I.inferFromProcess():o.useTtyColors==="mock"?I.mock():o.useTtyColors?I.tty():I.none();if(a&&i.getOptionValues("--help").length>0)return console.log(ht(e,u,T)),g(0);if(p&&i.getOptionValues("--version").length>0)return console.log([e,p].join(" ")),g(0);try{let M=u.createInstance();try{return await M.executeWithContext(n),g(0)}catch(ut){return o?.onError?o.onError(ut):console.error(T.computeStyledErrorMessage(ut)),g(1)}}catch(M){return(o?.usageOnError??!0)&&console.error(ht(e,u,T)),console.error(T.computeStyledErrorMessage(M)),g(1)}}function ht(e,t,n){return lt({cliName:e,commandUsage:t.generateUsage(),typoSupport:n}).join(`
|
|
2
|
+
`)}0&&(module.exports={ReaderArgs,TypoError,TypoGrid,TypoString,TypoSupport,TypoText,command,commandChained,commandWithSubcommands,operation,optionFlag,optionRepeatable,optionSingleValue,positionalOptional,positionalRequired,positionalVariadics,runAndExit,typeBoolean,typeConverted,typeDate,typeInteger,typeList,typeNumber,typeOneOf,typeString,typeTuple,typeUrl,typoStyleConstants,typoStyleFailure,typoStyleLogic,typoStyleQuote,typoStyleRegularStrong,typoStyleRegularWeaker,typoStyleTitle,typoStyleUserInput,usageToStyledLines});
|
|
3
3
|
//# sourceMappingURL=index.js.map
|