cli-kiss 0.2.1 → 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.
- package/README.md +1 -2
- package/dist/index.d.ts +71 -63
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/docs/guide/01_getting_started.md +5 -5
- package/docs/guide/02_commands.md +1 -1
- package/docs/guide/06_run.md +3 -3
- package/docs/index.md +1 -1
- package/package.json +1 -1
- package/src/lib/Command.ts +27 -27
- package/src/lib/Operation.ts +27 -21
- package/src/lib/Option.ts +19 -25
- package/src/lib/Positional.ts +57 -29
- package/src/lib/Run.ts +3 -3
- package/tests/unit.command.execute.ts +2 -2
- package/tests/unit.command.usage.ts +2 -2
- package/tests/unit.runner.cycle.ts +20 -1
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -397,12 +397,22 @@ type Option<Value> = {
|
|
|
397
397
|
generateUsage(): OptionUsage;
|
|
398
398
|
/**
|
|
399
399
|
* Registers the option on `readerOptions` so the argument reader recognises it, and
|
|
400
|
-
* returns an {@link
|
|
400
|
+
* returns an {@link OptionParser} that can later retrieve the parsed value(s).
|
|
401
401
|
*
|
|
402
402
|
* @param readerOptions - The shared {@link ReaderArgs} that will parse the raw
|
|
403
403
|
* command-line tokens.
|
|
404
404
|
*/
|
|
405
|
-
|
|
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;
|
|
406
416
|
};
|
|
407
417
|
/**
|
|
408
418
|
* Human-readable metadata for a single CLI option, used to render the `Options:` section
|
|
@@ -432,22 +442,6 @@ type OptionUsage = {
|
|
|
432
442
|
*/
|
|
433
443
|
label: Uppercase<string> | undefined;
|
|
434
444
|
};
|
|
435
|
-
/**
|
|
436
|
-
* Retrieves the parsed value for a registered option after argument parsing is complete.
|
|
437
|
-
*
|
|
438
|
-
* Returned by {@link Option.createGetter} and called by {@link OperationFactory.createInstance}.
|
|
439
|
-
*
|
|
440
|
-
* @typeParam Value - The TypeScript type of the parsed value.
|
|
441
|
-
*/
|
|
442
|
-
type OptionGetter<Value> = {
|
|
443
|
-
/**
|
|
444
|
-
* Returns the fully decoded and validated value for the option.
|
|
445
|
-
*
|
|
446
|
-
* @throws {@link TypoError} if the option appeared more times than allowed, the value
|
|
447
|
-
* failed type decoding, or a required default could not be computed.
|
|
448
|
-
*/
|
|
449
|
-
getValue(): Value;
|
|
450
|
-
};
|
|
451
445
|
/**
|
|
452
446
|
* Creates a boolean flag option — an option that the user passes without a value (e.g.
|
|
453
447
|
* `--verbose`) to signal `true`, or can explicitly set with `--flag=true` / `--flag=no`.
|
|
@@ -609,15 +603,28 @@ type Positional<Value> = {
|
|
|
609
603
|
/** Returns human-readable metadata used to render the `Positionals:` section of help. */
|
|
610
604
|
generateUsage(): PositionalUsage;
|
|
611
605
|
/**
|
|
612
|
-
* Consumes the
|
|
613
|
-
*
|
|
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
|
|
614
624
|
*
|
|
615
|
-
* @
|
|
616
|
-
* remaining positional tokens.
|
|
617
|
-
* @throws {@link TypoError} if the positional is required but absent, or if the raw
|
|
618
|
-
* value fails type decoding.
|
|
625
|
+
* @throws {@link TypoError} if the positional was missing (when required) or if decoding failed.
|
|
619
626
|
*/
|
|
620
|
-
|
|
627
|
+
parseValue(): Value;
|
|
621
628
|
};
|
|
622
629
|
/**
|
|
623
630
|
* Human-readable metadata for a single positional argument, used to render the
|
|
@@ -644,7 +651,7 @@ type PositionalUsage = {
|
|
|
644
651
|
*
|
|
645
652
|
* The parser consumes the next available positional token and decodes it with
|
|
646
653
|
* `definition.type`. If no token is available, a {@link TypoError} is thrown immediately
|
|
647
|
-
* during parsing (i.e. inside {@link
|
|
654
|
+
* during parsing (i.e. inside {@link Operation.createFactory}).
|
|
648
655
|
*
|
|
649
656
|
* The label displayed in the usage line defaults to the uppercased `type.content`
|
|
650
657
|
* wrapped in angle brackets (e.g. `<STRING>`). Supply `label` to override.
|
|
@@ -768,9 +775,9 @@ declare function positionalVariadics<Value>(definition: {
|
|
|
768
775
|
* Describes an operation — the combination of options, positional arguments, and an
|
|
769
776
|
* async execution handler that together form the core logic of a CLI command.
|
|
770
777
|
*
|
|
771
|
-
* An `
|
|
778
|
+
* An `Operation` is created with {@link operation} and passed to
|
|
772
779
|
* {@link command}, {@link commandWithSubcommands}, or {@link commandChained} to build
|
|
773
|
-
* a full {@link
|
|
780
|
+
* a full {@link Command}.
|
|
774
781
|
*
|
|
775
782
|
* @typeParam Input - The context value the handler receives at execution time (forwarded
|
|
776
783
|
* from the parent command's context or from a preceding chained operation).
|
|
@@ -778,7 +785,7 @@ declare function positionalVariadics<Value>(definition: {
|
|
|
778
785
|
* typically `void`; for intermediate stages it is the payload forwarded to the next
|
|
779
786
|
* command in a chain.
|
|
780
787
|
*/
|
|
781
|
-
type
|
|
788
|
+
type Operation<Input, Output> = {
|
|
782
789
|
/**
|
|
783
790
|
* Returns usage metadata (options and positionals) without consuming any arguments.
|
|
784
791
|
* Called by the parent command factory when building the help/usage output.
|
|
@@ -798,11 +805,11 @@ type OperationDescriptor<Input, Output> = {
|
|
|
798
805
|
createFactory(readerArgs: ReaderArgs): OperationFactory<Input, Output>;
|
|
799
806
|
};
|
|
800
807
|
/**
|
|
801
|
-
* Produced by {@link
|
|
808
|
+
* Produced by {@link Operation.createFactory} after argument parsing.
|
|
802
809
|
* Instantiating it finalises value extraction and produces an {@link OperationInstance}.
|
|
803
810
|
*
|
|
804
|
-
* @typeParam Input -
|
|
805
|
-
* @typeParam Output -
|
|
811
|
+
* @typeParam Input - operation instance input type {@link Operation}.
|
|
812
|
+
* @typeParam Output - operation instance output type {@link Operation}.
|
|
806
813
|
*/
|
|
807
814
|
type OperationFactory<Input, Output> = {
|
|
808
815
|
/**
|
|
@@ -810,7 +817,7 @@ type OperationFactory<Input, Output> = {
|
|
|
810
817
|
* {@link OperationInstance} ready for execution.
|
|
811
818
|
*
|
|
812
819
|
* @throws {@link TypoError} if any option or positional validation failed during
|
|
813
|
-
* {@link
|
|
820
|
+
* {@link Operation.createFactory}.
|
|
814
821
|
*/
|
|
815
822
|
createInstance(): OperationInstance<Input, Output>;
|
|
816
823
|
};
|
|
@@ -832,7 +839,7 @@ type OperationInstance<Input, Output> = {
|
|
|
832
839
|
executeWithContext(input: Input): Promise<Output>;
|
|
833
840
|
};
|
|
834
841
|
/**
|
|
835
|
-
* Collected usage metadata produced by {@link
|
|
842
|
+
* Collected usage metadata produced by {@link Operation.generateUsage}.
|
|
836
843
|
* Consumed by the parent command factory when building {@link CommandUsage}.
|
|
837
844
|
*/
|
|
838
845
|
type OperationUsage = {
|
|
@@ -842,12 +849,11 @@ type OperationUsage = {
|
|
|
842
849
|
positionals: Array<PositionalUsage>;
|
|
843
850
|
};
|
|
844
851
|
/**
|
|
845
|
-
* Creates an {@link
|
|
852
|
+
* Creates an {@link Operation} from a set of options, positionals, and an
|
|
846
853
|
* async handler function.
|
|
847
854
|
*
|
|
848
855
|
* The `handler` receives:
|
|
849
|
-
* - `context` — the value passed down from the parent command
|
|
850
|
-
* {@link runAndExit}).
|
|
856
|
+
* - `context` — the value passed down from the parent command.
|
|
851
857
|
* - `inputs.options` — an object whose keys match those declared in `inputs.options` and whose values are
|
|
852
858
|
* the parsed option values.
|
|
853
859
|
* - `inputs.positionals` — a tuple whose elements match `inputs.positionals` and whose
|
|
@@ -866,7 +872,7 @@ type OperationUsage = {
|
|
|
866
872
|
* same order.
|
|
867
873
|
* @param handler - The async function that implements the command logic. Receives the
|
|
868
874
|
* execution context and all parsed inputs.
|
|
869
|
-
* @returns An {@link
|
|
875
|
+
* @returns An {@link Operation} ready to be composed into a command.
|
|
870
876
|
*
|
|
871
877
|
* @example
|
|
872
878
|
* ```ts
|
|
@@ -898,23 +904,25 @@ declare function operation<Context, Result, Options extends {
|
|
|
898
904
|
}, handler: (context: Context, inputs: {
|
|
899
905
|
options: Options;
|
|
900
906
|
positionals: Positionals;
|
|
901
|
-
}) => Promise<Result>):
|
|
907
|
+
}) => Promise<Result>): Operation<Context, Result>;
|
|
902
908
|
|
|
903
909
|
/**
|
|
904
910
|
* Describes a CLI command: how to parse its arguments from raw CLI input and how to
|
|
905
911
|
* execute it within a given context.
|
|
906
912
|
*
|
|
907
|
-
* A `
|
|
908
|
-
* one with {@link command}, {@link commandWithSubcommands},
|
|
909
|
-
* 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.
|
|
910
916
|
*
|
|
911
917
|
* @typeParam Context - The value passed into the command when it is executed. It flows
|
|
912
918
|
* from {@link runAndExit}'s `context` argument down through the command chain.
|
|
913
919
|
* @typeParam Result - The value produced by executing the command. For root commands
|
|
914
920
|
* passed to {@link runAndExit} this is always `void`.
|
|
915
921
|
*/
|
|
916
|
-
type
|
|
917
|
-
/**
|
|
922
|
+
type Command<Context, Result> = {
|
|
923
|
+
/**
|
|
924
|
+
* Returns the static metadata information about this command.
|
|
925
|
+
*/
|
|
918
926
|
getInformation(): CommandInformation;
|
|
919
927
|
/**
|
|
920
928
|
* Parses `readerArgs` and returns a {@link CommandFactory} that can generate usage
|
|
@@ -927,14 +935,14 @@ type CommandDescriptor<Context, Result> = {
|
|
|
927
935
|
createFactory(readerArgs: ReaderArgs): CommandFactory<Context, Result>;
|
|
928
936
|
};
|
|
929
937
|
/**
|
|
930
|
-
* Produced by {@link
|
|
938
|
+
* Produced by {@link Command.createFactory} after the raw CLI arguments have
|
|
931
939
|
* been parsed. Provides two capabilities:
|
|
932
940
|
*
|
|
933
941
|
* 1. **Usage generation** — always available, even when parsing failed.
|
|
934
942
|
* 2. **Instance creation** — throws a {@link TypoError} if parsing failed.
|
|
935
943
|
*
|
|
936
|
-
* @typeParam Context -
|
|
937
|
-
* @typeParam Result -
|
|
944
|
+
* @typeParam Context - Input passed to the command {@link Command}.
|
|
945
|
+
* @typeParam Result - Result of the command's logic {@link Command}.
|
|
938
946
|
*/
|
|
939
947
|
type CommandFactory<Context, Result> = {
|
|
940
948
|
/**
|
|
@@ -947,7 +955,7 @@ type CommandFactory<Context, Result> = {
|
|
|
947
955
|
* Creates a {@link CommandInstance} that is ready to execute.
|
|
948
956
|
*
|
|
949
957
|
* @throws {@link TypoError} if the argument parsing that occurred during
|
|
950
|
-
* {@link
|
|
958
|
+
* {@link Command.createFactory} encountered an error (e.g. unknown
|
|
951
959
|
* option, missing required positional, invalid type).
|
|
952
960
|
*/
|
|
953
961
|
createInstance(): CommandInstance<Context, Result>;
|
|
@@ -1046,7 +1054,7 @@ type CommandUsageSubcommand = {
|
|
|
1046
1054
|
};
|
|
1047
1055
|
/**
|
|
1048
1056
|
* Creates a leaf command — a command that has no subcommands and directly executes
|
|
1049
|
-
* an {@link
|
|
1057
|
+
* an {@link Operation}.
|
|
1050
1058
|
*
|
|
1051
1059
|
* During parsing, `command` reads all positionals and options consumed by `operation`,
|
|
1052
1060
|
* then asserts that no extra positionals remain. Any unexpected trailing positional
|
|
@@ -1059,7 +1067,7 @@ type CommandUsageSubcommand = {
|
|
|
1059
1067
|
* @param information - Static metadata (description, hint, details) for the command.
|
|
1060
1068
|
* @param operation - The operation that defines options, positionals, and the execution
|
|
1061
1069
|
* handler for this command.
|
|
1062
|
-
* @returns A {@link
|
|
1070
|
+
* @returns A {@link Command} suitable for passing to {@link runAndExit}
|
|
1063
1071
|
* or composing with {@link commandWithSubcommands} / {@link commandChained}.
|
|
1064
1072
|
*
|
|
1065
1073
|
* @example
|
|
@@ -1073,9 +1081,9 @@ type CommandUsageSubcommand = {
|
|
|
1073
1081
|
* );
|
|
1074
1082
|
* ```
|
|
1075
1083
|
*/
|
|
1076
|
-
declare function command<Context, Result>(information: CommandInformation, operation:
|
|
1084
|
+
declare function command<Context, Result>(information: CommandInformation, operation: Operation<Context, Result>): Command<Context, Result>;
|
|
1077
1085
|
/**
|
|
1078
|
-
* Creates a command that first runs an {@link
|
|
1086
|
+
* Creates a command that first runs an {@link Operation} to produce an
|
|
1079
1087
|
* intermediate `Payload`, then dispatches execution to one of several named subcommands
|
|
1080
1088
|
* based on the next positional argument.
|
|
1081
1089
|
*
|
|
@@ -1100,8 +1108,8 @@ declare function command<Context, Result>(information: CommandInformation, opera
|
|
|
1100
1108
|
* @param operation - The operation that is always executed first, before the
|
|
1101
1109
|
* subcommand. Its output becomes the subcommand's context.
|
|
1102
1110
|
* @param subcommands - A map of lowercase subcommand names to their
|
|
1103
|
-
* {@link
|
|
1104
|
-
* @returns A {@link
|
|
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
|
|
1105
1113
|
* subcommands.
|
|
1106
1114
|
*
|
|
1107
1115
|
* @example
|
|
@@ -1116,12 +1124,12 @@ declare function command<Context, Result>(information: CommandInformation, opera
|
|
|
1116
1124
|
* );
|
|
1117
1125
|
* ```
|
|
1118
1126
|
*/
|
|
1119
|
-
declare function commandWithSubcommands<Context, Payload, Result>(information: CommandInformation, operation:
|
|
1120
|
-
[subcommand: Lowercase<string>]:
|
|
1121
|
-
}):
|
|
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>;
|
|
1122
1130
|
/**
|
|
1123
1131
|
* Creates a command that chains two command stages by piping the output of an
|
|
1124
|
-
* {@link
|
|
1132
|
+
* {@link Operation} directly into a {@link Command} as its context.
|
|
1125
1133
|
*
|
|
1126
1134
|
* Unlike {@link commandWithSubcommands}, there is no runtime token consumed for routing;
|
|
1127
1135
|
* the `nextCommand` is always the continuation. This is useful for splitting a complex
|
|
@@ -1149,7 +1157,7 @@ declare function commandWithSubcommands<Context, Payload, Result>(information: C
|
|
|
1149
1157
|
* @param operation - The first stage operation. Its output becomes `nextCommand`'s
|
|
1150
1158
|
* context.
|
|
1151
1159
|
* @param nextCommand - The second stage command, executed after `operation` succeeds.
|
|
1152
|
-
* @returns A {@link
|
|
1160
|
+
* @returns A {@link Command} that transparently composes the two stages.
|
|
1153
1161
|
*
|
|
1154
1162
|
* @example
|
|
1155
1163
|
* ```ts
|
|
@@ -1163,7 +1171,7 @@ declare function commandWithSubcommands<Context, Payload, Result>(information: C
|
|
|
1163
1171
|
* );
|
|
1164
1172
|
* ```
|
|
1165
1173
|
*/
|
|
1166
|
-
declare function commandChained<Context, Payload, Result>(information: CommandInformation, operation:
|
|
1174
|
+
declare function commandChained<Context, Payload, Result>(information: CommandInformation, operation: Operation<Context, Payload>, nextCommand: Command<Payload, Result>): Command<Context, Result>;
|
|
1167
1175
|
|
|
1168
1176
|
/**
|
|
1169
1177
|
* Parses the provided CLI arguments against the given command descriptor, executes
|
|
@@ -1191,7 +1199,7 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
|
|
|
1191
1199
|
* summary header and in the `--version` output.
|
|
1192
1200
|
* @param cliArgs - The raw command-line arguments to parse, typically `process.argv.slice(2)`.
|
|
1193
1201
|
* @param context - The context value forwarded to the command's execution handler.
|
|
1194
|
-
* @param command - The root {@link
|
|
1202
|
+
* @param command - The root {@link Command} that describes how to parse and execute
|
|
1195
1203
|
* the CLI.
|
|
1196
1204
|
* @param options - Optional configuration for the runner.
|
|
1197
1205
|
* @param options.useTtyColors - Controls terminal color output in styled messages.
|
|
@@ -1233,7 +1241,7 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
|
|
|
1233
1241
|
* });
|
|
1234
1242
|
* ```
|
|
1235
1243
|
*/
|
|
1236
|
-
declare function runAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command:
|
|
1244
|
+
declare function runAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command: Command<Context, void>, options?: {
|
|
1237
1245
|
useTtyColors?: boolean | undefined | "mock";
|
|
1238
1246
|
usageOnHelp?: boolean | undefined;
|
|
1239
1247
|
usageOnError?: boolean | undefined;
|
|
@@ -1571,4 +1579,4 @@ declare function usageToStyledLines(params: {
|
|
|
1571
1579
|
typoSupport: TypoSupport;
|
|
1572
1580
|
}): string[];
|
|
1573
1581
|
|
|
1574
|
-
export { type
|
|
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
|