cli-kiss 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,13 @@
1
1
  # CLI - Keep It Simple, Stupid
2
2
 
3
- No bloat, no dependency, full-featured CLI command runner
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
+ Documentation and examples: **https://crypto-vincent.github.io/cli-kiss/** 💋
package/dist/index.d.ts CHANGED
@@ -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
  */
@@ -396,12 +397,22 @@ type Option<Value> = {
396
397
  generateUsage(): OptionUsage;
397
398
  /**
398
399
  * Registers the option on `readerOptions` so the argument reader recognises it, and
399
- * returns an {@link OptionGetter} that can later retrieve the parsed value(s).
400
+ * returns an {@link OptionParser} that can later retrieve the parsed value(s).
400
401
  *
401
402
  * @param readerOptions - The shared {@link ReaderArgs} that will parse the raw
402
403
  * command-line tokens.
403
404
  */
404
- createGetter(readerOptions: ReaderArgs): OptionGetter<Value>;
405
+ createParser(readerOptions: ReaderArgs): OptionParser<Value>;
406
+ };
407
+ /**
408
+ * Retrieves the parsed value for a registered option after argument parsing is complete.
409
+ *
410
+ * Returned by {@link Option.createParser} and called by {@link OperationFactory.createInstance}.
411
+ *
412
+ * @typeParam Value - The TypeScript type of the parsed value.
413
+ */
414
+ type OptionParser<Value> = {
415
+ parseValue(): Value;
405
416
  };
406
417
  /**
407
418
  * Human-readable metadata for a single CLI option, used to render the `Options:` section
@@ -431,22 +442,6 @@ type OptionUsage = {
431
442
  */
432
443
  label: Uppercase<string> | undefined;
433
444
  };
434
- /**
435
- * Retrieves the parsed value for a registered option after argument parsing is complete.
436
- *
437
- * Returned by {@link Option.createGetter} and called by {@link OperationFactory.createInstance}.
438
- *
439
- * @typeParam Value - The TypeScript type of the parsed value.
440
- */
441
- type OptionGetter<Value> = {
442
- /**
443
- * Returns the fully decoded and validated value for the option.
444
- *
445
- * @throws {@link TypoError} if the option appeared more times than allowed, the value
446
- * failed type decoding, or a required default could not be computed.
447
- */
448
- getValue(): Value;
449
- };
450
445
  /**
451
446
  * Creates a boolean flag option — an option that the user passes without a value (e.g.
452
447
  * `--verbose`) to signal `true`, or can explicitly set with `--flag=true` / `--flag=no`.
@@ -608,15 +603,28 @@ type Positional<Value> = {
608
603
  /** Returns human-readable metadata used to render the `Positionals:` section of help. */
609
604
  generateUsage(): PositionalUsage;
610
605
  /**
611
- * Consumes the next positional token(s) from `readerPositionals` and returns the
612
- * decoded value.
606
+ * Consumes the positional from `readerPositionals` and then returns a parser that produces the final decoded value.
607
+ *
608
+ * The parser is created during {@link Operation.createFactory} and may throw a
609
+ * {@link TypoError} if the positional is missing (when required) or if decoding fails.
610
+ * @param readerPositionals - The source of positional arguments to be consumed.
611
+ */
612
+ createParser(readerPositionals: ReaderPositionals): PositionalParser<Value>;
613
+ };
614
+ /**
615
+ * Retrieves the parsed value for a positional argument after parsing is complete.
616
+ *
617
+ * Returned by {@link Positional.createParser} and called by {@link OperationFactory.createInstance}.
618
+ *
619
+ * @typeParam Value - The TypeScript type of the parsed value.
620
+ */
621
+ type PositionalParser<Value> = {
622
+ /**
623
+ * Returns the fully decoded and validated value for the positional
613
624
  *
614
- * @param readerPositionals - The shared {@link ReaderArgs} that manages the queue of
615
- * remaining positional tokens.
616
- * @throws {@link TypoError} if the positional is required but absent, or if the raw
617
- * value fails type decoding.
625
+ * @throws {@link TypoError} if the positional was missing (when required) or if decoding failed.
618
626
  */
619
- consumePositionals(readerPositionals: ReaderPositionals): Value;
627
+ parseValue(): Value;
620
628
  };
621
629
  /**
622
630
  * Human-readable metadata for a single positional argument, used to render the
@@ -643,7 +651,7 @@ type PositionalUsage = {
643
651
  *
644
652
  * The parser consumes the next available positional token and decodes it with
645
653
  * `definition.type`. If no token is available, a {@link TypoError} is thrown immediately
646
- * during parsing (i.e. inside {@link OperationDescriptor.createFactory}).
654
+ * during parsing (i.e. inside {@link Operation.createFactory}).
647
655
  *
648
656
  * The label displayed in the usage line defaults to the uppercased `type.content`
649
657
  * wrapped in angle brackets (e.g. `<STRING>`). Supply `label` to override.
@@ -767,9 +775,9 @@ declare function positionalVariadics<Value>(definition: {
767
775
  * Describes an operation — the combination of options, positional arguments, and an
768
776
  * async execution handler that together form the core logic of a CLI command.
769
777
  *
770
- * An `OperationDescriptor` is created with {@link operation} and passed to
778
+ * An `Operation` is created with {@link operation} and passed to
771
779
  * {@link command}, {@link commandWithSubcommands}, or {@link commandChained} to build
772
- * a full {@link CommandDescriptor}.
780
+ * a full {@link Command}.
773
781
  *
774
782
  * @typeParam Input - The context value the handler receives at execution time (forwarded
775
783
  * from the parent command's context or from a preceding chained operation).
@@ -777,7 +785,7 @@ declare function positionalVariadics<Value>(definition: {
777
785
  * typically `void`; for intermediate stages it is the payload forwarded to the next
778
786
  * command in a chain.
779
787
  */
780
- type OperationDescriptor<Input, Output> = {
788
+ type Operation<Input, Output> = {
781
789
  /**
782
790
  * Returns usage metadata (options and positionals) without consuming any arguments.
783
791
  * Called by the parent command factory when building the help/usage output.
@@ -797,11 +805,11 @@ type OperationDescriptor<Input, Output> = {
797
805
  createFactory(readerArgs: ReaderArgs): OperationFactory<Input, Output>;
798
806
  };
799
807
  /**
800
- * Produced by {@link OperationDescriptor.createFactory} after argument parsing.
808
+ * Produced by {@link Operation.createFactory} after argument parsing.
801
809
  * Instantiating it finalises value extraction and produces an {@link OperationInstance}.
802
810
  *
803
- * @typeParam Input - Forwarded from the parent {@link OperationDescriptor}.
804
- * @typeParam Output - Forwarded from the parent {@link OperationDescriptor}.
811
+ * @typeParam Input - operation instance input type {@link Operation}.
812
+ * @typeParam Output - operation instance output type {@link Operation}.
805
813
  */
806
814
  type OperationFactory<Input, Output> = {
807
815
  /**
@@ -809,7 +817,7 @@ type OperationFactory<Input, Output> = {
809
817
  * {@link OperationInstance} ready for execution.
810
818
  *
811
819
  * @throws {@link TypoError} if any option or positional validation failed during
812
- * {@link OperationDescriptor.createFactory}.
820
+ * {@link Operation.createFactory}.
813
821
  */
814
822
  createInstance(): OperationInstance<Input, Output>;
815
823
  };
@@ -831,7 +839,7 @@ type OperationInstance<Input, Output> = {
831
839
  executeWithContext(input: Input): Promise<Output>;
832
840
  };
833
841
  /**
834
- * Collected usage metadata produced by {@link OperationDescriptor.generateUsage}.
842
+ * Collected usage metadata produced by {@link Operation.generateUsage}.
835
843
  * Consumed by the parent command factory when building {@link CommandUsage}.
836
844
  */
837
845
  type OperationUsage = {
@@ -841,12 +849,11 @@ type OperationUsage = {
841
849
  positionals: Array<PositionalUsage>;
842
850
  };
843
851
  /**
844
- * Creates an {@link OperationDescriptor} from a set of options, positionals, and an
852
+ * Creates an {@link Operation} from a set of options, positionals, and an
845
853
  * async handler function.
846
854
  *
847
855
  * The `handler` receives:
848
- * - `context` — the value passed down from the parent command (or from
849
- * {@link runAndExit}).
856
+ * - `context` — the value passed down from the parent command.
850
857
  * - `inputs.options` — an object whose keys match those declared in `inputs.options` and whose values are
851
858
  * the parsed option values.
852
859
  * - `inputs.positionals` — a tuple whose elements match `inputs.positionals` and whose
@@ -865,7 +872,7 @@ type OperationUsage = {
865
872
  * same order.
866
873
  * @param handler - The async function that implements the command logic. Receives the
867
874
  * execution context and all parsed inputs.
868
- * @returns An {@link OperationDescriptor} ready to be composed into a command.
875
+ * @returns An {@link Operation} ready to be composed into a command.
869
876
  *
870
877
  * @example
871
878
  * ```ts
@@ -897,23 +904,25 @@ declare function operation<Context, Result, Options extends {
897
904
  }, handler: (context: Context, inputs: {
898
905
  options: Options;
899
906
  positionals: Positionals;
900
- }) => Promise<Result>): OperationDescriptor<Context, Result>;
907
+ }) => Promise<Result>): Operation<Context, Result>;
901
908
 
902
909
  /**
903
910
  * Describes a CLI command: how to parse its arguments from raw CLI input and how to
904
911
  * execute it within a given context.
905
912
  *
906
- * A `CommandDescriptor` is the central building block of a `cli-kiss` CLI. You create
907
- * one with {@link command}, {@link commandWithSubcommands}, or {@link commandChained},
908
- * and pass it to {@link runAndExit} to run your CLI.
913
+ * A `Command` is the central building block of a `cli-kiss` CLI.
914
+ * You create one with {@link command}, {@link commandWithSubcommands},
915
+ * or {@link commandChained}, and pass it to {@link runAndExit} to run your CLI.
909
916
  *
910
917
  * @typeParam Context - The value passed into the command when it is executed. It flows
911
918
  * from {@link runAndExit}'s `context` argument down through the command chain.
912
919
  * @typeParam Result - The value produced by executing the command. For root commands
913
920
  * passed to {@link runAndExit} this is always `void`.
914
921
  */
915
- type CommandDescriptor<Context, Result> = {
916
- /** Returns the static metadata (description, hint, details) for this command. */
922
+ type Command<Context, Result> = {
923
+ /**
924
+ * Returns the static metadata information about this command.
925
+ */
917
926
  getInformation(): CommandInformation;
918
927
  /**
919
928
  * Parses `readerArgs` and returns a {@link CommandFactory} that can generate usage
@@ -926,14 +935,14 @@ type CommandDescriptor<Context, Result> = {
926
935
  createFactory(readerArgs: ReaderArgs): CommandFactory<Context, Result>;
927
936
  };
928
937
  /**
929
- * Produced by {@link CommandDescriptor.createFactory} after the raw CLI arguments have
938
+ * Produced by {@link Command.createFactory} after the raw CLI arguments have
930
939
  * been parsed. Provides two capabilities:
931
940
  *
932
941
  * 1. **Usage generation** — always available, even when parsing failed.
933
942
  * 2. **Instance creation** — throws a {@link TypoError} if parsing failed.
934
943
  *
935
- * @typeParam Context - Forwarded from the parent {@link CommandDescriptor}.
936
- * @typeParam Result - Forwarded from the parent {@link CommandDescriptor}.
944
+ * @typeParam Context - Input passed to the command {@link Command}.
945
+ * @typeParam Result - Result of the command's logic {@link Command}.
937
946
  */
938
947
  type CommandFactory<Context, Result> = {
939
948
  /**
@@ -946,7 +955,7 @@ type CommandFactory<Context, Result> = {
946
955
  * Creates a {@link CommandInstance} that is ready to execute.
947
956
  *
948
957
  * @throws {@link TypoError} if the argument parsing that occurred during
949
- * {@link CommandDescriptor.createFactory} encountered an error (e.g. unknown
958
+ * {@link Command.createFactory} encountered an error (e.g. unknown
950
959
  * option, missing required positional, invalid type).
951
960
  */
952
961
  createInstance(): CommandInstance<Context, Result>;
@@ -1045,7 +1054,7 @@ type CommandUsageSubcommand = {
1045
1054
  };
1046
1055
  /**
1047
1056
  * Creates a leaf command — a command that has no subcommands and directly executes
1048
- * an {@link OperationDescriptor}.
1057
+ * an {@link Operation}.
1049
1058
  *
1050
1059
  * During parsing, `command` reads all positionals and options consumed by `operation`,
1051
1060
  * then asserts that no extra positionals remain. Any unexpected trailing positional
@@ -1058,7 +1067,7 @@ type CommandUsageSubcommand = {
1058
1067
  * @param information - Static metadata (description, hint, details) for the command.
1059
1068
  * @param operation - The operation that defines options, positionals, and the execution
1060
1069
  * handler for this command.
1061
- * @returns A {@link CommandDescriptor} suitable for passing to {@link runAndExit}
1070
+ * @returns A {@link Command} suitable for passing to {@link runAndExit}
1062
1071
  * or composing with {@link commandWithSubcommands} / {@link commandChained}.
1063
1072
  *
1064
1073
  * @example
@@ -1072,9 +1081,9 @@ type CommandUsageSubcommand = {
1072
1081
  * );
1073
1082
  * ```
1074
1083
  */
1075
- declare function command<Context, Result>(information: CommandInformation, operation: OperationDescriptor<Context, Result>): CommandDescriptor<Context, Result>;
1084
+ declare function command<Context, Result>(information: CommandInformation, operation: Operation<Context, Result>): Command<Context, Result>;
1076
1085
  /**
1077
- * Creates a command that first runs an {@link OperationDescriptor} to produce an
1086
+ * Creates a command that first runs an {@link Operation} to produce an
1078
1087
  * intermediate `Payload`, then dispatches execution to one of several named subcommands
1079
1088
  * based on the next positional argument.
1080
1089
  *
@@ -1099,8 +1108,8 @@ declare function command<Context, Result>(information: CommandInformation, opera
1099
1108
  * @param operation - The operation that is always executed first, before the
1100
1109
  * subcommand. Its output becomes the subcommand's context.
1101
1110
  * @param subcommands - A map of lowercase subcommand names to their
1102
- * {@link CommandDescriptor}s. The keys are the literal tokens the user types.
1103
- * @returns A {@link CommandDescriptor} that dispatches to one of the provided
1111
+ * {@link Command}s. The keys are the literal tokens the user types.
1112
+ * @returns A {@link Command} that dispatches to one of the provided
1104
1113
  * subcommands.
1105
1114
  *
1106
1115
  * @example
@@ -1115,12 +1124,12 @@ declare function command<Context, Result>(information: CommandInformation, opera
1115
1124
  * );
1116
1125
  * ```
1117
1126
  */
1118
- declare function commandWithSubcommands<Context, Payload, Result>(information: CommandInformation, operation: OperationDescriptor<Context, Payload>, subcommands: {
1119
- [subcommand: Lowercase<string>]: CommandDescriptor<Payload, Result>;
1120
- }): CommandDescriptor<Context, Result>;
1127
+ declare function commandWithSubcommands<Context, Payload, Result>(information: CommandInformation, operation: Operation<Context, Payload>, subcommands: {
1128
+ [subcommand: Lowercase<string>]: Command<Payload, Result>;
1129
+ }): Command<Context, Result>;
1121
1130
  /**
1122
1131
  * Creates a command that chains two command stages by piping the output of an
1123
- * {@link OperationDescriptor} directly into a {@link CommandDescriptor} as its context.
1132
+ * {@link Operation} directly into a {@link Command} as its context.
1124
1133
  *
1125
1134
  * Unlike {@link commandWithSubcommands}, there is no runtime token consumed for routing;
1126
1135
  * the `nextCommand` is always the continuation. This is useful for splitting a complex
@@ -1148,7 +1157,7 @@ declare function commandWithSubcommands<Context, Payload, Result>(information: C
1148
1157
  * @param operation - The first stage operation. Its output becomes `nextCommand`'s
1149
1158
  * context.
1150
1159
  * @param nextCommand - The second stage command, executed after `operation` succeeds.
1151
- * @returns A {@link CommandDescriptor} that transparently composes the two stages.
1160
+ * @returns A {@link Command} that transparently composes the two stages.
1152
1161
  *
1153
1162
  * @example
1154
1163
  * ```ts
@@ -1162,7 +1171,7 @@ declare function commandWithSubcommands<Context, Payload, Result>(information: C
1162
1171
  * );
1163
1172
  * ```
1164
1173
  */
1165
- declare function commandChained<Context, Payload, Result>(information: CommandInformation, operation: OperationDescriptor<Context, Payload>, nextCommand: CommandDescriptor<Payload, Result>): CommandDescriptor<Context, Result>;
1174
+ declare function commandChained<Context, Payload, Result>(information: CommandInformation, operation: Operation<Context, Payload>, nextCommand: Command<Payload, Result>): Command<Context, Result>;
1166
1175
 
1167
1176
  /**
1168
1177
  * Parses the provided CLI arguments against the given command descriptor, executes
@@ -1177,7 +1186,7 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
1177
1186
  * - `1` — Argument parsing failed (a usage summary is also printed to stderr), or the
1178
1187
  * command threw an unhandled execution error.
1179
1188
  *
1180
- * **Built-in flags (opt-out):**
1189
+ * **Built-in flags:**
1181
1190
  * - `--help` — Enabled by default (`usageOnHelp: true`). Prints the usage summary to
1182
1191
  * stdout and exits with code `0`. This flag takes precedence over `--version`.
1183
1192
  * - `--version` — Enabled when `buildVersion` is provided. Prints `<cliName> <version>`
@@ -1190,7 +1199,7 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
1190
1199
  * summary header and in the `--version` output.
1191
1200
  * @param cliArgs - The raw command-line arguments to parse, typically `process.argv.slice(2)`.
1192
1201
  * @param context - The context value forwarded to the command's execution handler.
1193
- * @param command - The root {@link CommandDescriptor} that describes how to parse and execute
1202
+ * @param command - The root {@link Command} that describes how to parse and execute
1194
1203
  * the CLI.
1195
1204
  * @param options - Optional configuration for the runner.
1196
1205
  * @param options.useTtyColors - Controls terminal color output in styled messages.
@@ -1232,7 +1241,7 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
1232
1241
  * });
1233
1242
  * ```
1234
1243
  */
1235
- declare function runAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command: CommandDescriptor<Context, void>, options?: {
1244
+ declare function runAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command: Command<Context, void>, options?: {
1236
1245
  useTtyColors?: boolean | undefined | "mock";
1237
1246
  usageOnHelp?: boolean | undefined;
1238
1247
  usageOnError?: boolean | undefined;
@@ -1570,4 +1579,4 @@ declare function usageToStyledLines(params: {
1570
1579
  typoSupport: TypoSupport;
1571
1580
  }): string[];
1572
1581
 
1573
- 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 };
1582
+ export { type Command, type CommandFactory, type CommandInformation, type CommandInstance, type CommandUsage, type CommandUsageBreadcrumb, type CommandUsageSubcommand, type Operation, type OperationFactory, type OperationInstance, type OperationUsage, type Option, type OptionParser, type OptionUsage, type Positional, type PositionalParser, 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 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(`
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:()=>A,TypoString:()=>s,TypoSupport:()=>k,TypoText:()=>l,command:()=>$t,commandChained:()=>vt,commandWithSubcommands:()=>At,operation:()=>Ft,optionFlag:()=>Yt,optionRepeatable:()=>Ht,optionSingleValue:()=>qt,positionalOptional:()=>Jt,positionalRequired:()=>Qt,positionalVariadics:()=>zt,runAndExit:()=>te,typeBoolean:()=>q,typeConverted:()=>Kt,typeDate:()=>Bt,typeInteger:()=>Wt,typeList:()=>jt,typeNumber:()=>Lt,typeOneOf:()=>Dt,typeString:()=>Mt,typeTuple:()=>Nt,typeUrl:()=>Gt,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},B,D,s=class{constructor(t,n={}){w(this,B);w(this,D);m(this,B,t),m(this,D,n)}getRawString(){return c(this,B)}computeStyledString(t){return t.computeStyledString(c(this,B),c(this,D))}};B=new WeakMap,D=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=class{constructor(){w(this,$);m(this,$,[])}pushRow(t){c(this,$).push(t)}computeStyledGrid(t){let n=new Array,r=new Array;for(let o of c(this,$))for(let a=0;a<o.length;a++){let i=o[a].computeRawLength();(n[a]===void 0||i>n[a])&&(n[a]=i)}for(let o of c(this,$)){let a=new Array;for(let p=0;p<o.length;p++){let i=o[p],u=i.computeStyledString(t);if(a.push(u),p<o.length-1){let g=i.computeRawLength(),T=" ".repeat(n[p]-g);a.push(T)}}r.push(a)}return r}};$=new WeakMap;var L,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,L))):r instanceof Error?o.pushString(new s(`: ${r.message}`)):r!==void 0&&o.pushString(new s(`: ${String(r)}`));super(o.computeRawString());w(this,L);m(this,L,o)}computeStyledString(n){return c(this,L).computeStyledString(n)}static tryWithContext(n,r){try{return n()}catch(o){throw new Y(r(),o)}}};L=new WeakMap;var d=Y,P,C=class C{constructor(t){w(this,P);m(this,P,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,P)==="none")return t;if(c(this,P)==="tty"){let r=n.fgColor?Vt[n.fgColor]:"",o=n.bgColor?It[n.bgColor]:"",a=n.bold?Ut:"",p=n.dim?Rt:"",i=n.italic?Ot:"",u=n.underline?Pt:"",g=n.strikethrough?kt:"";return`${r}${o}${a}${p}${i}${u}${g}${t}${Tt}`}if(c(this,P)==="mock"){let r=n.fgColor?`{${t}}@${n.fgColor}`:t,o=n.bgColor?`{${r}}#${n.bgColor}`:r,a=n.bold?`{${o}}+`:o,p=n.dim?`{${a}}-`:a,i=n.italic?`{${p}}*`:p,u=n.underline?`{${i}}_`:i;return n.strikethrough?`{${u}}~`:u}throw new Error(`Unknown TypoSupport kind: ${c(this,P)}`)}computeStyledErrorMessage(t){return[this.computeStyledString("Error:",dt),t instanceof d?t.computeStyledString(this):t instanceof Error?t.message:String(t)].join(" ")}};P=new WeakMap;var k=C,Tt="\x1B[0m",Ut="\x1B[1m",Rt="\x1B[2m",Ot="\x1B[3m",Pt="\x1B[4m",kt="\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"},It={darkBlack:"\x1B[40m",darkRed:"\x1B[41m",darkGreen:"\x1B[42m",darkYellow:"\x1B[43m",darkBlue:"\x1B[44m",darkMagenta:"\x1B[45m",darkCyan:"\x1B[46m",darkWhite:"\x1B[47m",brightBlack:"\x1B[100m",brightRed:"\x1B[101m",brightGreen:"\x1B[102m",brightYellow:"\x1B[103m",brightBlue:"\x1B[104m",brightMagenta:"\x1B[105m",brightCyan:"\x1B[106m",brightWhite:"\x1B[107m"};function $t(e,t){return{getInformation(){return e},createFactory(n){function r(){let o=t.generateUsage();return{breadcrumbs:o.positionals.map(a=>v(a.label)),information:e,positionals:o.positionals,subcommands:[],options:o.options}}try{let o=t.createFactory(n),a=n.consumePositional();if(a!==void 0)throw new d(new l(new s("Unexpected argument: "),new s(`"${a}"`,f)));return{generateUsage:r,createInstance(){let p=o.createInstance();return{async executeWithContext(i){return await p.executeWithContext(i)}}}}}catch(o){return{generateUsage:r,createInstance(){throw o}}}}}}function At(e,t,n){return{getInformation(){return e},createFactory(r){try{let o=t.createFactory(r),a=r.consumePositional();if(a===void 0)throw new d(new l(new s("<SUBCOMMAND>",b),new s(": Is required, but was not provided")));let p=n[a];if(p===void 0)throw new d(new l(new s("<SUBCOMMAND>",b),new s(": Invalid value: "),new s(`"${a}"`,f)));let i=p.createFactory(r);return{generateUsage(){let u=t.generateUsage(),g=i.generateUsage();return{breadcrumbs:u.positionals.map(T=>v(T.label)).concat([Et(a)]).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=i.createInstance();return{async executeWithContext(T){return await g.executeWithContext(await u.executeWithContext(T))}}}}}catch(o){return{generateUsage(){let a=t.generateUsage();return{breadcrumbs:a.positionals.map(p=>v(p.label)).concat([v("<SUBCOMMAND>")]),information:e,positionals:a.positionals,subcommands:Object.entries(n).map(p=>{let i=p[1].getInformation();return{name:p[0],description:i.description,hint:i.hint}}),options:a.options}},createInstance(){throw o}}}}}}function vt(e,t,n){return{getInformation(){return e},createFactory(r){try{let o=t.createFactory(r),a=n.createFactory(r);return{generateUsage(){let p=t.generateUsage(),i=a.generateUsage();return{breadcrumbs:p.positionals.map(u=>v(u.label)).concat(i.breadcrumbs),information:i.information,positionals:p.positionals.concat(i.positionals),subcommands:i.subcommands,options:p.options.concat(i.options)}},createInstance(){let p=o.createInstance(),i=a.createInstance();return{async executeWithContext(u){return await i.executeWithContext(await p.executeWithContext(u))}}}}}catch(o){return{generateUsage(){let a=t.generateUsage();return{breadcrumbs:a.positionals.map(p=>v(p.label)).concat([v("[REST]...")]),information:e,positionals:a.positionals,subcommands:[],options:a.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 a=e.options[o];a&&n.push(a.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 a in e.options){let p=e.options[a];r[a]=p.createParser(n)}let o=[];for(let a of e.positionals)o.push(a.createParser(n));return{createInstance(){let a={};for(let i in r)a[i]=r[i].parseValue();let p=[];for(let i of o)p.push(i.parseValue());return{executeWithContext(i){return t(i,{options:a,positionals:p})}}}}}}}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)))}},Bt={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)))}}},Lt={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)))}}},Wt={content:"Integer",decoder(e){try{return BigInt(e)}catch{throw new d(new l(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Gt={content:"Url",decoder(e){try{return new URL(e)}catch{throw new d(new l(new s("Unable to parse: "),new s(`"${e}"`,f)))}}},Mt={content:"String",decoder(e){return e}};function Kt(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 Dt(e,t){let n=new Set(t);return{content:e,decoder(r){if(n.has(r))return r;let o=[];for(let a of t){if(o.length>=5){o.push(new s("..."));break}o.length>0&&o.push(new s(" | ")),o.push(new s(`"${a}"`,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,a)=>{let p=e[a];return d.tryWithContext(()=>p.decoder(o),()=>new l(new s(`at ${a}: `),new s(p.content,S)))})}}}function jt(e,t=","){return{content:`${e.content}[${t}${e.content}]...`,decoder(n){return n.split(t).map((o,a)=>d.tryWithContext(()=>e.decoder(o),()=>new l(new s(`at ${a}: `),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}},createParser(n){let r=nt(n,{...e,valued:!1});return{parseValue(){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 a=o[0];if(a===void 0)try{return e.default?e.default():!1}catch(p){throw new d(new l(new s(`--${e.long}`,x),new s(": Failed to get default value")),p)}return et(e.long,t,q,a)}}}}}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}},createParser(n){let r=nt(n,{...e,valued:!0});return{parseValue(){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 a=o[0];if(a===void 0)try{return e.default()}catch(p){throw new d(new l(new s(`--${e.long}`,x),new s(": Failed to get default value")),p)}return et(e.long,t,e.type,a)}}}}}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}},createParser(n){let r=nt(n,{...e,valued:!0});return{parseValue(){return n.getOptionValues(r).map(a=>et(e.long,t,e.type,a))}}}}}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:a}=t,p=n?[n]:[];o?.longs&&p.push(...o?.longs);let i=r?[r]:[];return o?.shorts&&i.push(...o?.shorts),e.registerOption({longs:p,shorts:i,valued:a})}function Qt(e){let t=`<${e.label??e.type.content.toUpperCase()}>`;return{generateUsage(){return{description:e.description,hint:e.hint,label:t}},createParser(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{parseValue(){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}},createParser(n){let r=n.consumePositional();return{parseValue(){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}"]`:"")}},createParser(n){let r=new Array;for(;;){let o=n.consumePositional();if(o===void 0||o===e.endDelimiter)break;r.push(o)}return{parseValue(){return r.map(o=>ot(t,e.type,o))}}}}}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,W,I,E,R,F,G,y,H,yt,rt,mt,st,V,N=class{constructor(t){w(this,y);w(this,j);w(this,W);w(this,I);w(this,E);w(this,R);w(this,F);w(this,G);m(this,j,t),m(this,W,0),m(this,I,!1),m(this,E,new Map),m(this,R,new Map),m(this,F,new Map),m(this,G,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 a=r.slice(0,o);if(c(this,R).has(a))throw new Error(`Option -${r} overlap with shorter option: -${a}`)}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,G).set(n,new Array),n}getOptionValues(t){let n=c(this,G).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,W=new WeakMap,I=new WeakMap,E=new WeakMap,R=new WeakMap,F=new WeakMap,G=new WeakMap,y=new WeakSet,H=function(){let t=c(this,j)[c(this,W)];return t===void 0?null:(gt(this,W)._++,!c(this,I)&&t==="--"?(m(this,I,!0),h(this,y,H).call(this)):t)},yt=function(t){if(c(this,I))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,V).call(this,o,n):c(this,F).get(o)?h(this,y,V).call(this,o,h(this,y,st).call(this,r)):h(this,y,V).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,V).call(this,r,n.slice(1)),!0):c(this,F).get(r)?(n===""?h(this,y,V).call(this,r,h(this,y,st).call(this,`-${t}`)):h(this,y,V).call(this,r,n),!0):(h(this,y,V).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,I))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},V=function(t,n){this.getOptionValues(t).push(n)};function lt(e){let{cliName:t,commandUsage:n,typoSupport:r}=e,o=new Array,a=[Xt("Usage:").computeStyledString(r),M(t).computeStyledString(r)].concat(n.breadcrumbs.map(i=>{if("positional"in i)return pt(i.positional).computeStyledString(r);if("command"in i)return M(i.command).computeStyledString(r);throw new Error(`Unknown breadcrumb: ${JSON.stringify(i)}`)}));o.push(a.join(" ")),o.push("");let p=new l;p.pushString(Zt(n.information.description)),n.information.hint&&(p.pushString(O(" ")),p.pushString(Q(`(${n.information.hint})`))),o.push(p.computeStyledString(r));for(let i of n.information.details??[]){let u=new l;u.pushString(Q(i)),o.push(u.computeStyledString(r))}if(n.positionals.length>0){o.push(""),o.push(it("Positionals:").computeStyledString(r));let i=new A;for(let u of n.positionals){let g=new Array;g.push(new l(O(" "))),g.push(new l(pt(u.label))),g.push(...at(u)),i.pushRow(g)}o.push(...i.computeStyledGrid(r).map(u=>u.join("")))}if(n.subcommands.length>0){o.push(""),o.push(it("Subcommands:").computeStyledString(r));let i=new A;for(let u of n.subcommands){let g=new Array;g.push(new l(O(" "))),g.push(new l(M(u.name))),g.push(...at(u)),i.pushRow(g)}o.push(...i.computeStyledGrid(r).map(u=>u.join("")))}if(n.options.length>0){o.push(""),o.push(it("Options:").computeStyledString(r));let i=new A;for(let u of n.options){let g=new Array;g.push(new l(O(" "))),u.short?g.push(new l(M(`-${u.short}`),O(", "))):g.push(new l),u.label?g.push(new l(M(`--${u.long}`),O(" "),pt(u.label))):g.push(new l(M(`--${u.long}`),Q("[=no]"))),g.push(...at(u)),i.pushRow(g)}o.push(...i.computeStyledGrid(r).map(u=>u.join("")))}return o.push(""),o}function at(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 it(e){return new s(e,X)}function Q(e){return new s(e,_)}function M(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 a=new N(t),p=o?.usageOnHelp??!0;p&&a.registerOption({shorts:[],longs:["help"],valued:!1});let i=o?.buildVersion;i&&a.registerOption({shorts:[],longs:["version"],valued:!1});let u=r.createFactory(a);for(;;)try{if(a.consumePositional()===void 0)break}catch{}let g=o?.onExit??process.exit,T=o?.useTtyColors===void 0?k.inferFromProcess():o.useTtyColors==="mock"?k.mock():o.useTtyColors?k.tty():k.none();if(p&&a.getOptionValues("--help").length>0)return console.log(ht(e,u,T)),g(0);if(i&&a.getOptionValues("--version").length>0)return console.log([e,i].join(" ")),g(0);try{let K=u.createInstance();try{return await K.executeWithContext(n),g(0)}catch(ut){return o?.onError?o.onError(ut):console.error(T.computeStyledErrorMessage(ut)),g(1)}}catch(K){return(o?.usageOnError??!0)&&console.error(ht(e,u,T)),console.error(T.computeStyledErrorMessage(K)),g(1)}}function ht(e,t,n){return lt({cliName:e,commandUsage:t.generateUsage(),typoSupport:n}).join(`
2
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