zod-args-parser 2.0.0-beta.2 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +46 -13
- package/lib/esm/coerce/coerce-methods.js +17 -4
- package/lib/esm/coerce/coerce-methods.js.map +2 -2
- package/lib/esm/definitions/define-cli.js +29 -21
- package/lib/esm/definitions/define-cli.js.map +2 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/parse/context/cli-context-builder.js +2 -1
- package/lib/esm/parse/context/cli-context-builder.js.map +2 -2
- package/lib/iife/index.js +41 -1
- package/lib/iife/index.js.map +1 -1
- package/lib/mjs/coerce/coerce-methods.mjs +17 -4
- package/lib/mjs/coerce/coerce-methods.mjs.map +2 -2
- package/lib/mjs/definitions/define-cli.mjs +29 -21
- package/lib/mjs/definitions/define-cli.mjs.map +2 -2
- package/lib/mjs/index.mjs.map +1 -1
- package/lib/mjs/parse/context/cli-context-builder.mjs +2 -1
- package/lib/mjs/parse/context/cli-context-builder.mjs.map +2 -2
- package/lib/types/cli-error/cli-error.d.ts +1 -1
- package/lib/types/coerce/coerce-methods.d.ts +2 -2
- package/lib/types/coerce/coerce-methods.d.ts.map +1 -1
- package/lib/types/definitions/define-cli.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/parse/context/cli-context-builder.d.ts.map +1 -1
- package/package.json +23 -22
- package/src/autocomplete-scripts/bash-autocomplete-script.ts +0 -0
- package/src/autocomplete-scripts/powershell-autocomplete-script.ts +0 -0
- package/src/autocomplete-scripts/zsh-autocomplete-script.ts +0 -0
- package/src/cli-error/cli-error.ts +0 -0
- package/src/cli-error/error-cause.ts +0 -0
- package/src/cli-error/error-code/definition-error-code.ts +0 -0
- package/src/cli-error/error-code/internal-error-code.ts +0 -0
- package/src/cli-error/error-code/parse-error-code.ts +0 -0
- package/src/cli-error/error-code/validation-error-code.ts +0 -0
- package/src/cli-error/error-message/definition-error-message.ts +0 -0
- package/src/cli-error/error-message/internal-error-message.ts +0 -0
- package/src/cli-error/error-message/parse-error-message.ts +0 -0
- package/src/cli-error/error-message/validation-error-message.ts +0 -0
- package/src/coerce/coerce-methods.ts +18 -4
- package/src/coerce/string-to-array.ts +0 -0
- package/src/coerce/string-to-primitive.ts +0 -0
- package/src/coerce/string-to-set.ts +0 -0
- package/src/definitions/define-arguments.ts +0 -0
- package/src/definitions/define-cli.ts +33 -24
- package/src/definitions/define-options.ts +0 -0
- package/src/definitions/define-subcommand.ts +0 -0
- package/src/definitions/validate-cli-definition.ts +0 -0
- package/src/help-message/format-arguments.ts +0 -0
- package/src/help-message/format-options.ts +0 -0
- package/src/help-message/format-subcommands.ts +0 -0
- package/src/help-message/generate-for-cli.ts +0 -0
- package/src/help-message/generate-for-subcommand.ts +0 -0
- package/src/help-message/print-help.ts +0 -0
- package/src/help-message/set-defaults.ts +0 -0
- package/src/help-message/styles.ts +0 -0
- package/src/help-message/terminal-markdown.ts +0 -0
- package/src/index.ts +1 -0
- package/src/markdown/generate-markdown.ts +0 -0
- package/src/metadata/arguments-metadata.ts +0 -0
- package/src/metadata/cli-metadata.ts +0 -0
- package/src/metadata/options-metadata.ts +0 -0
- package/src/metadata/subcommands-metadata.ts +0 -0
- package/src/parse/context/cli-context-builder.ts +2 -1
- package/src/parse/context/object-context-builder.ts +0 -0
- package/src/parse/parser-utilities.ts +0 -0
- package/src/parse/safe-parse.ts +0 -0
- package/src/parse/validation/validate-context.ts +0 -0
- package/src/parse/validation/validators/arguments.ts +0 -0
- package/src/parse/validation/validators/conflict.ts +0 -0
- package/src/parse/validation/validators/exclusive.ts +0 -0
- package/src/parse/validation/validators/explicitly-passed.ts +0 -0
- package/src/parse/validation/validators/options.ts +0 -0
- package/src/parse/validation/validators/requires.ts +0 -0
- package/src/types/context-types.ts +0 -0
- package/src/types/definitions-types.ts +0 -0
- package/src/types/error-types.ts +0 -0
- package/src/types/help-message-types.ts +0 -0
- package/src/types/io-types.ts +0 -0
- package/src/types/metadata-types.ts +0 -0
- package/src/types/schema-types.ts +0 -0
- package/src/types/types.ts +0 -0
- package/src/types/utilities-types.ts +0 -0
- package/src/utilities/parse-argv.ts +0 -0
- package/src/utilities/schema-utilities.ts +0 -0
- package/src/utilities/utilities.ts +0 -0
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ A strictly typed command-line arguments parser powered by schema validation.
|
|
|
27
27
|
- [Creating a Custom Help Message Style](#creating-a-custom-help-message-style)
|
|
28
28
|
- [Help Message as HTML](#help-message-as-html)
|
|
29
29
|
- [Handling and Inspecting Errors](#handling-and-inspecting-errors)
|
|
30
|
+
- [Loading from a CDN](#loading-from-a-cdn)
|
|
30
31
|
- [API Reference](#api-reference)
|
|
31
32
|
- [Type Utilities](docs/api-reference.md#type-utilities)
|
|
32
33
|
- [Coerce Helpers](docs/api-reference.md#coerce-helpers)
|
|
@@ -68,16 +69,12 @@ The following example uses `zod` as the validation library, but you can use any
|
|
|
68
69
|
|
|
69
70
|
```ts
|
|
70
71
|
import * as z from "zod";
|
|
71
|
-
import { defineCLI
|
|
72
|
+
import { defineCLI } from "zod-args-parser";
|
|
72
73
|
|
|
73
74
|
const cli = defineCLI({
|
|
74
75
|
cliName: "hello",
|
|
75
76
|
options: {
|
|
76
|
-
/**
|
|
77
|
-
* 💡 **Tip:** Adding a **JSDoc** comment here will be displayed in IDE hovers alongside the TypeScript type.
|
|
78
|
-
*
|
|
79
|
-
* `--name` or `-n`
|
|
80
|
-
*/
|
|
77
|
+
/** `--name` or `-n` */
|
|
81
78
|
name: {
|
|
82
79
|
aliases: ["n"],
|
|
83
80
|
schema: z.string().default("world"),
|
|
@@ -92,7 +89,6 @@ cli.onExecute(({ options }) => {
|
|
|
92
89
|
const result = cli.run(process.argv.slice(2));
|
|
93
90
|
if (result.error) {
|
|
94
91
|
console.error(result.error.message);
|
|
95
|
-
process.exit(1);
|
|
96
92
|
}
|
|
97
93
|
```
|
|
98
94
|
|
|
@@ -104,7 +100,9 @@ if (result.error) {
|
|
|
104
100
|
|
|
105
101
|
### Creating a subcommand
|
|
106
102
|
|
|
107
|
-
Subcommands are defined using the `defineSubcommand` function, which accepts a
|
|
103
|
+
Subcommands are defined using the `defineSubcommand` function, which accepts a `Subcommand` definition object.
|
|
104
|
+
|
|
105
|
+
See [Subcommand Definition](./docs/api-reference.md#subcommand).
|
|
108
106
|
|
|
109
107
|
```ts
|
|
110
108
|
import { defineSubcommand, helpMessageStyles } from "zod-args-parser";
|
|
@@ -202,10 +200,16 @@ Options can be defined directly inside the CLI or subcommand definition. Or usin
|
|
|
202
200
|
Option names can use any common case style:
|
|
203
201
|
`camelCase`, `PascalCase`, `snake_case`, or `SCREAMING_SNAKE_CASE`.
|
|
204
202
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
203
|
+
| name | as argument |
|
|
204
|
+
| ----------- | ------------- |
|
|
205
|
+
| `listName` | `--list-name` |
|
|
206
|
+
| `ListName` | `--list-name` |
|
|
207
|
+
| `list_name` | `--list-name` |
|
|
208
|
+
| `LIST_NAME` | `--list-name` |
|
|
209
|
+
| `H` | `-h` |
|
|
210
|
+
| `h` | `-h` |
|
|
211
|
+
|
|
212
|
+
See [Option Definition](./docs/api-reference.md#option).
|
|
209
213
|
|
|
210
214
|
```ts
|
|
211
215
|
import * as z from "zod";
|
|
@@ -294,6 +298,8 @@ The order of argument definitions matters.
|
|
|
294
298
|
2. If `allowPositionals: false` → only the last typed argument may be optional.
|
|
295
299
|
3. Argument names cannot be numeric, because it affects argument ordering.
|
|
296
300
|
|
|
301
|
+
See [Argument Definition](./docs/api-reference.md#argument).
|
|
302
|
+
|
|
297
303
|
```ts
|
|
298
304
|
import { defineSubcommand, coerce } from "zod-args-parser";
|
|
299
305
|
|
|
@@ -322,6 +328,8 @@ const createListCommand = defineSubcommand({
|
|
|
322
328
|
|
|
323
329
|
Options and typed arguments can be shared between subcommands/main CLI.
|
|
324
330
|
|
|
331
|
+
See [Option Definition](./docs/api-reference.md#option) and [Argument Definition](./docs/api-reference.md#argument).
|
|
332
|
+
|
|
325
333
|
```ts
|
|
326
334
|
// shared.ts
|
|
327
335
|
import * as z from "zod";
|
|
@@ -641,9 +649,34 @@ if (results.error) {
|
|
|
641
649
|
}
|
|
642
650
|
```
|
|
643
651
|
|
|
652
|
+
### Loading from a CDN
|
|
653
|
+
|
|
654
|
+
**Global IIFE**
|
|
655
|
+
|
|
656
|
+
```html
|
|
657
|
+
<!-- using jsdelivr -->
|
|
658
|
+
<script src="https://cdn.jsdelivr.net/npm/zod-args-parser"></script>
|
|
659
|
+
|
|
660
|
+
<!-- using unpkg -->
|
|
661
|
+
<script src="https://unpkg.com/zod-args-parser"></script>
|
|
662
|
+
|
|
663
|
+
<script>
|
|
664
|
+
// Access the library as a global
|
|
665
|
+
const { defineCLI, coerce } = ZodArgsParser;
|
|
666
|
+
</script>
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
**ESM Module**
|
|
670
|
+
|
|
671
|
+
```html
|
|
672
|
+
<script type="module">
|
|
673
|
+
import { defineCLI, coerce } from "https://cdn.jsdelivr.net/npm/zod-args-parser/+esm";
|
|
674
|
+
</script>
|
|
675
|
+
```
|
|
676
|
+
|
|
644
677
|
## API Reference
|
|
645
678
|
|
|
646
|
-
See the [API Reference](docs/api-reference.md) for more information.
|
|
679
|
+
See the [API Reference](./docs/api-reference.md) for more information.
|
|
647
680
|
|
|
648
681
|
## License
|
|
649
682
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// src/coerce/coerce-methods.ts
|
|
2
|
+
import { CliError } from "../cli-error/cli-error.js";
|
|
3
|
+
import { ErrorCause } from "../cli-error/error-cause.js";
|
|
4
|
+
import { ValidationErrorCode } from "../cli-error/error-code/validation-error-code.js";
|
|
2
5
|
import { walkObject } from "../utilities/utilities.js";
|
|
3
6
|
import { stringToBooleanArray, stringToNumberArray, stringToStringArray } from "./string-to-array.js";
|
|
4
7
|
import { stringToBigint, stringToBoolean, stringToNumber } from "./string-to-primitive.js";
|
|
@@ -6,9 +9,19 @@ import { stringToBooleanSet, stringToNumberSet, stringToStringSet } from "./stri
|
|
|
6
9
|
var string = (terminalInput) => terminalInput;
|
|
7
10
|
var number = (terminalInput) => stringToNumber(terminalInput);
|
|
8
11
|
var bigint = (terminalInput) => stringToBigint(terminalInput);
|
|
9
|
-
var json = (terminalInput) => JSON.parse(terminalInput);
|
|
10
12
|
var boolean = (terminalInput) => stringToBoolean(terminalInput);
|
|
11
13
|
boolean.type = "boolean";
|
|
14
|
+
var json = (terminalInput) => {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(terminalInput);
|
|
17
|
+
} catch {
|
|
18
|
+
throw new CliError({
|
|
19
|
+
cause: ErrorCause.Validation,
|
|
20
|
+
code: ValidationErrorCode.CoercionFailed,
|
|
21
|
+
context: { coerceToType: "json", providedValue: terminalInput }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
12
25
|
var stringArray = (separator) => {
|
|
13
26
|
return (terminalInput) => stringToStringArray(terminalInput, separator);
|
|
14
27
|
};
|
|
@@ -29,7 +42,7 @@ var booleanSet = (separator) => {
|
|
|
29
42
|
};
|
|
30
43
|
var object = (options = {}) => {
|
|
31
44
|
const coerceMethod = (terminalInput) => {
|
|
32
|
-
const object2 =
|
|
45
|
+
const object2 = json(terminalInput);
|
|
33
46
|
if (!options.coerceBoolean && !options.coerceNumber && !options.coerceBigint && !options.coerceDate) {
|
|
34
47
|
return object2;
|
|
35
48
|
}
|
|
@@ -114,7 +127,7 @@ var coerce = {
|
|
|
114
127
|
* converted.
|
|
115
128
|
*
|
|
116
129
|
* @since 2.0.0
|
|
117
|
-
* @throws {
|
|
130
|
+
* @throws {CliError} If input is not a valid JSON string.
|
|
118
131
|
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/README.md##structured-object-options}
|
|
119
132
|
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
120
133
|
*/
|
|
@@ -186,7 +199,7 @@ var coerce = {
|
|
|
186
199
|
* Parses a JSON string into a JavaScript object.
|
|
187
200
|
*
|
|
188
201
|
* @since 2.0.0
|
|
189
|
-
* @throws {
|
|
202
|
+
* @throws {CliError} If input is not a valid JSON string.
|
|
190
203
|
* @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
|
|
191
204
|
*/
|
|
192
205
|
json
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/coerce/coerce-methods.ts"],
|
|
4
|
-
"sourcesContent": ["import { walkObject } from \"../utilities/utilities.ts\";\nimport { stringToBooleanArray, stringToNumberArray, stringToStringArray } from \"./string-to-array.ts\";\nimport { stringToBigint, stringToBoolean, stringToNumber } from \"./string-to-primitive.ts\";\nimport { stringToBooleanSet, stringToNumberSet, stringToStringSet } from \"./string-to-set.ts\";\n\nimport type { ObjectCoerceMethodOptions } from \"../types/types.ts\";\n\nconst string = <T extends string | undefined>(terminalInput: string): T => terminalInput as T;\nconst number = <T extends number | undefined>(terminalInput: string): T => stringToNumber(terminalInput) as T;\nconst bigint = <T extends bigint | undefined>(terminalInput: string): T => stringToBigint(terminalInput) as T;\nconst
|
|
5
|
-
"mappings": ";AAAA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB,qBAAqB,2BAA2B;AAC/E,SAAS,gBAAgB,iBAAiB,sBAAsB;AAChE,SAAS,oBAAoB,mBAAmB,yBAAyB;AAIzE,IAAM,SAAS,CAA+B,kBAA6B;AAC3E,IAAM,SAAS,CAA+B,kBAA6B,eAAe,aAAa;AACvG,IAAM,SAAS,CAA+B,kBAA6B,eAAe,aAAa;AACvG,IAAM,OAAO,CAAI,kBAA6B,KAAK,MAAM,aAAa;
|
|
4
|
+
"sourcesContent": ["import { CliError } from \"../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../cli-error/error-cause.ts\";\nimport { ValidationErrorCode } from \"../cli-error/error-code/validation-error-code.ts\";\nimport { walkObject } from \"../utilities/utilities.ts\";\nimport { stringToBooleanArray, stringToNumberArray, stringToStringArray } from \"./string-to-array.ts\";\nimport { stringToBigint, stringToBoolean, stringToNumber } from \"./string-to-primitive.ts\";\nimport { stringToBooleanSet, stringToNumberSet, stringToStringSet } from \"./string-to-set.ts\";\n\nimport type { ObjectCoerceMethodOptions } from \"../types/types.ts\";\n\nconst string = <T extends string | undefined>(terminalInput: string): T => terminalInput as T;\nconst number = <T extends number | undefined>(terminalInput: string): T => stringToNumber(terminalInput) as T;\nconst bigint = <T extends bigint | undefined>(terminalInput: string): T => stringToBigint(terminalInput) as T;\nconst boolean = <T extends boolean | undefined>(terminalInput: string): T => stringToBoolean(terminalInput) as T;\nboolean.type = \"boolean\";\n\nconst json = <T>(terminalInput: string): T => {\n try {\n return JSON.parse(terminalInput) as T;\n } catch {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.CoercionFailed,\n context: { coerceToType: \"json\", providedValue: terminalInput },\n });\n }\n};\n\nconst stringArray = (separator: string) => {\n return <T extends string[] | undefined>(terminalInput: string): T =>\n stringToStringArray(terminalInput, separator) as T;\n};\n\nconst numberArray = (separator: string) => {\n return <T extends number[] | undefined>(terminalInput: string): T =>\n stringToNumberArray(terminalInput, separator) as T;\n};\n\nconst booleanArray = (separator: string) => {\n return <T extends boolean[] | undefined>(terminalInput: string): T =>\n stringToBooleanArray(terminalInput, separator) as T;\n};\n\nconst stringSet = (separator: string) => {\n return <T extends Set<string> | undefined>(terminalInput: string): T =>\n stringToStringSet(terminalInput, separator) as T;\n};\n\nconst numberSet = (separator: string) => {\n return <T extends Set<number> | undefined>(terminalInput: string): T =>\n stringToNumberSet(terminalInput, separator) as T;\n};\n\nconst booleanSet = (separator: string) => {\n return <T extends Set<boolean> | undefined>(terminalInput: string): T =>\n stringToBooleanSet(terminalInput, separator) as T;\n};\n\nconst object = (options: ObjectCoerceMethodOptions = {}) => {\n const coerceMethod = <T extends Record<string, unknown> | undefined>(terminalInput: string): T => {\n const object = json<T>(terminalInput);\n\n if (!options.coerceBoolean && !options.coerceNumber && !options.coerceBigint && !options.coerceDate) {\n return object;\n }\n\n walkObject(object!, (_, value, path) => {\n if (typeof value !== \"string\") return value;\n\n const shouldCoerce = (boolOrArray: boolean | string[] | undefined) => {\n if (!boolOrArray) return false;\n if (typeof boolOrArray === \"boolean\") return boolOrArray;\n return boolOrArray.includes(path);\n };\n\n if (shouldCoerce(options.coerceBoolean)) {\n try {\n return stringToBoolean(value);\n } catch {\n return value;\n }\n }\n\n if (shouldCoerce(options.coerceNumber)) {\n try {\n return stringToNumber(value);\n } catch {\n return value;\n }\n }\n\n if (shouldCoerce(options.coerceBigint)) {\n try {\n return BigInt(value);\n } catch {\n return value;\n }\n }\n\n if (shouldCoerce(options.coerceDate)) {\n try {\n return new Date(value);\n } catch {\n return value;\n }\n }\n\n return value;\n });\n\n return object;\n };\n\n return coerceMethod;\n};\n\nexport const coerce = {\n /**\n * Since the terminal input is a string, this method does nothing.\n *\n * @since 2.0.0\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n string,\n\n /**\n * Coerces a string matching `\"true\"` or `\"false\"` (case-insensitive) to a boolean value.\n *\n * @since 2.0.0\n * @throws {CliError} If input is not a valid boolean string.\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n boolean,\n\n /**\n * Coerces a string matching a number to a number value.\n *\n * @since 2.0.0\n * @throws {CliError} If input is empty or not a valid number.\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n number,\n\n /**\n * Coerces a string matching a number to a bigint value.\n *\n * @since 2.0.0\n * @throws {CliError} If input is empty or not a valid bigint.\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n bigint,\n\n /**\n * Coerces a JSON string into a JavaScript object, optionally converting certain string values into native types such\n * as booleans, numbers, bigints, or dates.\n *\n * Each coercion option attempts conversion and silently falls back to the original string if the value cannot be\n * converted.\n *\n * @since 2.0.0\n * @throws {CliError} If input is not a valid JSON string.\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/README.md##structured-object-options}\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n object,\n\n /**\n * Converts a string to an array of strings by splitting it on the specified separator.\n *\n * @since 2.0.0\n * @param separator - The separator to use to split the string.`\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n stringArray,\n\n /**\n * Converts a string to an array of numbers by splitting it on the specified separator.\n *\n * Items that match the number regex will be converted to numbers.\n *\n * @since 2.0.0\n * @param separator - The separator to use to split the string.`\n * @throws {CliError} - When an item cannot be converted to a number\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n numberArray,\n\n /**\n * Converts a string to an array of booleans by splitting it on the specified separator.\n *\n * Items that match `\"true\"` or `\"false\"` (case-insensitive) will be converted to booleans.\n *\n * @since 2.0.0\n * @param separator - The separator to use to split the string.`\n * @throws {CliError} - When an item cannot be converted to a boolean\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n booleanArray,\n\n /**\n * Converts a string to a set of strings by splitting it on the specified separator.\n *\n * Items that match the number regex will be converted to numbers.\n *\n * @since 2.0.0\n * @param separator - The separator to use to split the string.`\n * @throws {CliError} - When an item cannot be converted to a number\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n stringSet,\n\n /**\n * Converts a string to a set of numbers by splitting it on the specified separator.\n *\n * Items that match the number regex will be converted to numbers.\n *\n * @since 2.0.0\n * @param separator - The separator to use to split the string.\n * @throws {CliError} - When an item cannot be converted to a number\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n numberSet,\n\n /**\n * Converts a string to a set of booleans by splitting it on the specified separator.\n *\n * Items that match `\"true\"` or `\"false\"` (case-insensitive) will be converted to booleans.\n *\n * @since 2.0.0\n * @param separator - The separator to use to split the string.\n * @throws {CliError} - When an item cannot be converted to a boolean\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n booleanSet,\n\n /**\n * Parses a JSON string into a JavaScript object.\n *\n * @since 2.0.0\n * @throws {CliError} If input is not a valid JSON string.\n * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}\n */\n json,\n};\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB,qBAAqB,2BAA2B;AAC/E,SAAS,gBAAgB,iBAAiB,sBAAsB;AAChE,SAAS,oBAAoB,mBAAmB,yBAAyB;AAIzE,IAAM,SAAS,CAA+B,kBAA6B;AAC3E,IAAM,SAAS,CAA+B,kBAA6B,eAAe,aAAa;AACvG,IAAM,SAAS,CAA+B,kBAA6B,eAAe,aAAa;AACvG,IAAM,UAAU,CAAgC,kBAA6B,gBAAgB,aAAa;AAC1G,QAAQ,OAAO;AAEf,IAAM,OAAO,CAAI,kBAA6B;AAC5C,MAAI;AACF,WAAO,KAAK,MAAM,aAAa;AAAA,EACjC,QAAQ;AACN,UAAM,IAAI,SAAS;AAAA,MACjB,OAAO,WAAW;AAAA,MAClB,MAAM,oBAAoB;AAAA,MAC1B,SAAS,EAAE,cAAc,QAAQ,eAAe,cAAc;AAAA,IAChE,CAAC;AAAA,EACH;AACF;AAEA,IAAM,cAAc,CAAC,cAAsB;AACzC,SAAO,CAAiC,kBACtC,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AO,KAAK;AAAA,QACrB,QAAQ;AACN,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,UAAI,aAAa,QAAQ,UAAU,GAAG;AACpC,YAAI;AACF,iBAAO,IAAI,KAAK,KAAK;AAAA,QACvB,QAAQ;AACN,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,aAAO;AAAA,IACT,CAAC;AAED,WAAOA;AAAA,EACT;AAEA,SAAO;AACT;AAEO,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA;AACF;",
|
|
6
6
|
"names": ["object"]
|
|
7
7
|
}
|
|
@@ -57,30 +57,38 @@ function defineCLI(input) {
|
|
|
57
57
|
const validateResult = validate(context, cliDefinition);
|
|
58
58
|
await Promise.all(handlers.map(async (handler) => await handler(validateResult)));
|
|
59
59
|
};
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
const attachHelpMethods = () => {
|
|
61
|
+
const generateHelpMethods = {
|
|
62
|
+
generateCliHelpMessage(options) {
|
|
63
|
+
return generateCliHelpMessage(cliDefinition, options);
|
|
64
|
+
},
|
|
65
|
+
generateSubcommandHelpMessage(subcommandName, options) {
|
|
66
|
+
const foundSubcommand = cliDefinition.subcommands?.find((s) => s.name === subcommandName);
|
|
67
|
+
if (!foundSubcommand) {
|
|
68
|
+
throw new CliError({
|
|
69
|
+
cause: ErrorCause.Definition,
|
|
70
|
+
code: DefinitionErrorCode.SubcommandHelpNotFound,
|
|
71
|
+
context: { cliName: cliDefinition.cliName, subcommandName }
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return generateSubcommandHelpMessage(foundSubcommand, options, cliDefinition.cliName);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
Object.assign(cliDefinition, generateHelpMethods);
|
|
78
|
+
if (cliDefinition.subcommands) {
|
|
79
|
+
for (const subcommandSchema of cliDefinition.subcommands) {
|
|
80
|
+
Object.assign(subcommandSchema, generateHelpMethods);
|
|
72
81
|
}
|
|
73
|
-
return generateSubcommandHelpMessage(foundSubcommand, options, cliDefinition.cliName);
|
|
74
82
|
}
|
|
75
83
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
const run = (stringOrArgv) => {
|
|
85
|
+
attachHelpMethods();
|
|
86
|
+
return safeParse(stringOrArgv, cliDefinition);
|
|
87
|
+
};
|
|
88
|
+
const runAsync = (stringOrArgv) => {
|
|
89
|
+
attachHelpMethods();
|
|
90
|
+
return safeParseAsync(stringOrArgv, cliDefinition);
|
|
91
|
+
};
|
|
84
92
|
return Object.assign(cliDefinition, { onExecute, execute, executeAsync, run, runAsync });
|
|
85
93
|
}
|
|
86
94
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/definitions/define-cli.ts"],
|
|
4
|
-
"sourcesContent": ["import { CliError } from \"../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../cli-error/error-cause.ts\";\nimport { DefinitionErrorCode } from \"../cli-error/error-code/definition-error-code.ts\";\nimport { generateCliHelpMessage } from \"../help-message/generate-for-cli.ts\";\nimport { generateSubcommandHelpMessage } from \"../help-message/generate-for-subcommand.ts\";\nimport { buildObjectContext } from \"../parse/context/object-context-builder.ts\";\nimport { safeParse, safeParseAsync } from \"../parse/safe-parse.ts\";\nimport { validate } from \"../parse/validation/validate-context.ts\";\nimport { prepareDefinitionTypes } from \"../utilities/schema-utilities.ts\";\n\nimport type { Argument, Cli, Option, Subcommand } from \"../types/definitions-types.ts\";\nimport type { PrintHelpOptions } from \"../types/help-message-types.ts\";\nimport type { AttachedMethods, AttachedMethodsWide, ValidateMethods } from \"../types/types.ts\";\nimport type { Prettify } from \"../types/utilities-types.ts\";\n\ntype OptionsInput<T> =\n T extends Record<string, Option> ? { [OptionName in keyof T]: Option<T[OptionName][\"schema\"]> } : T;\n\ntype ArgumentsInput<T> =\n T extends Record<string, Argument> ? { [ArgumentName in keyof T]: Argument<T[ArgumentName][\"schema\"]> } : T;\n\ntype SubcommandsInput<T extends readonly [Subcommand, ...Subcommand[]]> = {\n [SubcommandIndex in keyof T]: {\n [K in keyof T[SubcommandIndex]]: T[SubcommandIndex][K] extends Record<string, Option>\n ? OptionsInput<T[SubcommandIndex][K]>\n : T[SubcommandIndex][K] extends Record<string, Argument>\n ? ArgumentsInput<T[SubcommandIndex][K]>\n : T[SubcommandIndex][K];\n } & Subcommand;\n};\n\n// This will prevent extra keys and enable jsdoc on hover\ntype CliInput<T extends Cli> = {\n [K in keyof T]: K extends keyof Cli\n ? T[K] extends readonly [Subcommand, ...Subcommand[]]\n ? SubcommandsInput<T[K]>\n : K extends \"options\"\n ? OptionsInput<T[K]>\n : K extends \"arguments\"\n ? ArgumentsInput<T[K]>\n : T[K]\n : never;\n};\n\nexport function defineCLI<T extends Cli>(input: CliInput<T> & Cli) {\n const cliDefinition = input as T;\n\n prepareDefinitionTypes(cliDefinition.options);\n prepareDefinitionTypes(cliDefinition.arguments);\n\n if (cliDefinition.subcommands) {\n for (const subcommand of Object.values(cliDefinition.subcommands)) {\n prepareDefinitionTypes(subcommand.options);\n prepareDefinitionTypes(subcommand.arguments);\n }\n }\n\n const onExecute = (handler: (Cli[\"_onExecute\"] & {})[number]) => {\n cliDefinition._onExecute ??= [];\n cliDefinition._onExecute.push(handler);\n\n return () => {\n const handlerIndex = cliDefinition._onExecute?.indexOf(handler);\n if (!handlerIndex || handlerIndex < 0) return;\n cliDefinition._onExecute?.splice(handlerIndex, 1);\n };\n };\n\n const execute: AttachedMethodsWide[\"execute\"] = inputValues => {\n inputValues ??= {};\n\n const handlers = cliDefinition._onExecute;\n if (!handlers) {\n throw new CliError({\n cause: ErrorCause.Definition,\n code: DefinitionErrorCode.MissingOnExecute,\n context: { commandKind: \"command\", commandName: cliDefinition.cliName },\n });\n }\n\n const context = buildObjectContext(inputValues, cliDefinition);\n const validateResult = validate(context, cliDefinition);\n\n for (const handler of handlers) {\n void handler(validateResult);\n }\n };\n\n const executeAsync: AttachedMethodsWide[\"executeAsync\"] = async inputValues => {\n inputValues ??= {};\n\n const handlers = cliDefinition._onExecute;\n\n if (!handlers) {\n throw new CliError({\n cause: ErrorCause.Definition,\n code: DefinitionErrorCode.MissingOnExecute,\n context: { commandKind: \"command\", commandName: cliDefinition.cliName },\n });\n }\n\n const context = buildObjectContext(inputValues, cliDefinition);\n const validateResult = validate(context, cliDefinition);\n\n await Promise.all(handlers.map(async handler => await handler(validateResult)));\n };\n\n // Add print methods for CLI schema and its subcommands\n
|
|
5
|
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AAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS,EAAE,aAAa,WAAW,aAAa,cAAc,QAAQ;AAAA,MACxE,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,mBAAmB,aAAa,aAAa;AAC7D,UAAM,iBAAiB,SAAS,SAAS,aAAa;AAEtD,UAAM,QAAQ,IAAI,SAAS,IAAI,OAAM,YAAW,MAAM,QAAQ,cAAc,CAAC,CAAC;AAAA,EAChF;
|
|
4
|
+
"sourcesContent": ["import { CliError } from \"../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../cli-error/error-cause.ts\";\nimport { DefinitionErrorCode } from \"../cli-error/error-code/definition-error-code.ts\";\nimport { generateCliHelpMessage } from \"../help-message/generate-for-cli.ts\";\nimport { generateSubcommandHelpMessage } from \"../help-message/generate-for-subcommand.ts\";\nimport { buildObjectContext } from \"../parse/context/object-context-builder.ts\";\nimport { safeParse, safeParseAsync } from \"../parse/safe-parse.ts\";\nimport { validate } from \"../parse/validation/validate-context.ts\";\nimport { prepareDefinitionTypes } from \"../utilities/schema-utilities.ts\";\n\nimport type { Argument, Cli, Option, Subcommand } from \"../types/definitions-types.ts\";\nimport type { PrintHelpOptions } from \"../types/help-message-types.ts\";\nimport type { AttachedMethods, AttachedMethodsWide, ValidateMethods } from \"../types/types.ts\";\nimport type { Prettify } from \"../types/utilities-types.ts\";\n\ntype OptionsInput<T> =\n T extends Record<string, Option> ? { [OptionName in keyof T]: Option<T[OptionName][\"schema\"]> } : T;\n\ntype ArgumentsInput<T> =\n T extends Record<string, Argument> ? { [ArgumentName in keyof T]: Argument<T[ArgumentName][\"schema\"]> } : T;\n\ntype SubcommandsInput<T extends readonly [Subcommand, ...Subcommand[]]> = {\n [SubcommandIndex in keyof T]: {\n [K in keyof T[SubcommandIndex]]: T[SubcommandIndex][K] extends Record<string, Option>\n ? OptionsInput<T[SubcommandIndex][K]>\n : T[SubcommandIndex][K] extends Record<string, Argument>\n ? ArgumentsInput<T[SubcommandIndex][K]>\n : T[SubcommandIndex][K];\n } & Subcommand;\n};\n\n// This will prevent extra keys and enable jsdoc on hover\ntype CliInput<T extends Cli> = {\n [K in keyof T]: K extends keyof Cli\n ? T[K] extends readonly [Subcommand, ...Subcommand[]]\n ? SubcommandsInput<T[K]>\n : K extends \"options\"\n ? OptionsInput<T[K]>\n : K extends \"arguments\"\n ? ArgumentsInput<T[K]>\n : T[K]\n : never;\n};\n\nexport function defineCLI<T extends Cli>(input: CliInput<T> & Cli) {\n const cliDefinition = input as T;\n\n prepareDefinitionTypes(cliDefinition.options);\n prepareDefinitionTypes(cliDefinition.arguments);\n\n if (cliDefinition.subcommands) {\n for (const subcommand of Object.values(cliDefinition.subcommands)) {\n prepareDefinitionTypes(subcommand.options);\n prepareDefinitionTypes(subcommand.arguments);\n }\n }\n\n const onExecute = (handler: (Cli[\"_onExecute\"] & {})[number]) => {\n cliDefinition._onExecute ??= [];\n cliDefinition._onExecute.push(handler);\n\n return () => {\n const handlerIndex = cliDefinition._onExecute?.indexOf(handler);\n if (!handlerIndex || handlerIndex < 0) return;\n cliDefinition._onExecute?.splice(handlerIndex, 1);\n };\n };\n\n const execute: AttachedMethodsWide[\"execute\"] = inputValues => {\n inputValues ??= {};\n\n const handlers = cliDefinition._onExecute;\n if (!handlers) {\n throw new CliError({\n cause: ErrorCause.Definition,\n code: DefinitionErrorCode.MissingOnExecute,\n context: { commandKind: \"command\", commandName: cliDefinition.cliName },\n });\n }\n\n const context = buildObjectContext(inputValues, cliDefinition);\n const validateResult = validate(context, cliDefinition);\n\n for (const handler of handlers) {\n void handler(validateResult);\n }\n };\n\n const executeAsync: AttachedMethodsWide[\"executeAsync\"] = async inputValues => {\n inputValues ??= {};\n\n const handlers = cliDefinition._onExecute;\n\n if (!handlers) {\n throw new CliError({\n cause: ErrorCause.Definition,\n code: DefinitionErrorCode.MissingOnExecute,\n context: { commandKind: \"command\", commandName: cliDefinition.cliName },\n });\n }\n\n const context = buildObjectContext(inputValues, cliDefinition);\n const validateResult = validate(context, cliDefinition);\n\n await Promise.all(handlers.map(async handler => await handler(validateResult)));\n };\n\n const attachHelpMethods = () => {\n // Add print methods for CLI schema and its subcommands\n const generateHelpMethods: Pick<AttachedMethodsWide, \"generateCliHelpMessage\" | \"generateSubcommandHelpMessage\"> = {\n generateCliHelpMessage(options?: PrintHelpOptions) {\n return generateCliHelpMessage(cliDefinition, options);\n },\n generateSubcommandHelpMessage(subcommandName: string, options?: PrintHelpOptions) {\n const foundSubcommand = cliDefinition.subcommands?.find(s => s.name === subcommandName);\n if (!foundSubcommand) {\n throw new CliError({\n cause: ErrorCause.Definition,\n code: DefinitionErrorCode.SubcommandHelpNotFound,\n context: { cliName: cliDefinition.cliName, subcommandName },\n });\n }\n return generateSubcommandHelpMessage(foundSubcommand, options, cliDefinition.cliName);\n },\n };\n\n Object.assign(cliDefinition, generateHelpMethods);\n\n if (cliDefinition.subcommands) {\n for (const subcommandSchema of cliDefinition.subcommands) {\n Object.assign(subcommandSchema, generateHelpMethods);\n }\n }\n };\n\n const run = (stringOrArgv: string | string[]) => {\n attachHelpMethods();\n return safeParse(stringOrArgv, cliDefinition);\n };\n\n const runAsync = (stringOrArgv: string | string[]) => {\n attachHelpMethods();\n return safeParseAsync(stringOrArgv, cliDefinition);\n };\n\n return Object.assign(cliDefinition, { onExecute, execute, executeAsync, run, runAsync }) as Prettify<\n T & AttachedMethods<T> & ValidateMethods<T>\n >;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,qCAAqC;AAC9C,SAAS,0BAA0B;AACnC,SAAS,WAAW,sBAAsB;AAC1C,SAAS,gBAAgB;AACzB,SAAS,8BAA8B;AAoChC,SAAS,UAAyB,OAA0B;AACjE,QAAM,gBAAgB;AAEtB,yBAAuB,cAAc,OAAO;AAC5C,yBAA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,cAAc,CAAC,CAAC;AAAA,EAChF;AAEA,QAAM,oBAAoB,MAAM;AAE9B,UAAM,sBAA6G;AAAA,MACjH,uBAAuB,SAA4B;AACjD,eAAO,uBAAuB,eAAe,OAAO;AAAA,MACtD;AAAA,MACA,8BAA8B,gBAAwB,SAA4B;AAChF,cAAM,kBAAkB,cAAc,aAAa,KAAK,OAAK,EAAE,SAAS,cAAc;AACtF,YAAI,CAAC,iBAAiB;AACpB,gBAAM,IAAI,SAAS;AAAA,YACjB,OAAO,WAAW;AAAA,YAClB,MAAM,oBAAoB;AAAA,YAC1B,SAAS,EAAE,SAAS,cAAc,SAAS,eAAe;AAAA,UAC5D,CAAC;AAAA,QACH;AACA,eAAO,8BAA8B,iBAAiB,SAAS,cAAc,OAAO;AAAA,MACtF;AAAA,IACF;AAEA,WAAO,OAAO,eAAe,mBAAmB;AAEhD,QAAI,cAAc,aAAa;AAC7B,iBAAW,oBAAoB,cAAc,aAAa;AACxD,eAAO,OAAO,kBAAkB,mBAAmB;AAAA,MACrD;AAAA,IACF;AAAA,EACF;AAEA,QAAM,MAAM,CAAC,iBAAoC;AAC/C,sBAAkB;AAClB,WAAO,UAAU,cAAc,aAAa;AAAA,EAC9C;AAEA,QAAM,WAAW,CAAC,iBAAoC;AACpD,sBAAkB;AAClB,WAAO,eAAe,cAAc,aAAa;AAAA,EACnD;AAEA,SAAO,OAAO,OAAO,eAAe,EAAE,WAAW,SAAS,cAAc,KAAK,SAAS,CAAC;AAGzF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { generateCliHelpMessage } from \"./help-message/generate-for-cli.ts\";\nexport { generateSubcommandHelpMessage } from \"./help-message/generate-for-subcommand.ts\";\nexport { printCliHelp, printSubcommandHelp } from \"./help-message/print-help.ts\";\nexport { HelpMessageStyle, helpMessageStyles } from \"./help-message/styles.ts\";\n\nexport { generateBashAutocompleteScript } from \"./autocomplete-scripts/bash-autocomplete-script.ts\";\nexport { generatePowerShellAutocompleteScript } from \"./autocomplete-scripts/powershell-autocomplete-script.ts\";\nexport { generateZshAutocompleteScript } from \"./autocomplete-scripts/zsh-autocomplete-script.ts\";\nexport { generateMarkdown } from \"./markdown/generate-markdown.ts\";\n\nexport { getArgumentsMetadata } from \"./metadata/arguments-metadata.ts\";\nexport { getCliMetadata } from \"./metadata/cli-metadata.ts\";\nexport { getOptionsMetadata } from \"./metadata/options-metadata.ts\";\nexport { getSubcommandsMetadata } from \"./metadata/subcommands-metadata.ts\";\n\nexport { defineArguments } from \"./definitions/define-arguments.ts\";\nexport { defineCLI } from \"./definitions/define-cli.ts\";\nexport { defineOptions } from \"./definitions/define-options.ts\";\nexport { defineSubcommand } from \"./definitions/define-subcommand.ts\";\n\nexport { coerce } from \"./coerce/coerce-methods.ts\";\n\nexport { CliError } from \"./cli-error/cli-error.ts\";\nexport { ErrorCause } from \"./cli-error/error-cause.ts\";\nexport { DefinitionErrorCode } from \"./cli-error/error-code/definition-error-code.ts\";\nexport { InternalErrorCode } from \"./cli-error/error-code/internal-error-code.ts\";\nexport { ParseErrorCode } from \"./cli-error/error-code/parse-error-code.ts\";\nexport { ValidationErrorCode } from \"./cli-error/error-code/validation-error-code.ts\";\n\nexport type * from \"./types/context-types.ts\";\nexport type * from \"./types/definitions-types.ts\";\nexport type {\n CliErrorI,\n CliErrorOptionUnion,\n DefinitionErrorI,\n ErrorCauseI,\n InternalErrorI,\n ParseErrorI,\n ValidationErrorI,\n} from \"./types/error-types.ts\";\nexport type * from \"./types/help-message-types.ts\";\nexport type * from \"./types/io-types.ts\";\nexport type * from \"./types/metadata-types.ts\";\nexport type * from \"./types/types.ts\";\n"],
|
|
4
|
+
"sourcesContent": ["export { generateCliHelpMessage } from \"./help-message/generate-for-cli.ts\";\nexport { generateSubcommandHelpMessage } from \"./help-message/generate-for-subcommand.ts\";\nexport { printCliHelp, printSubcommandHelp } from \"./help-message/print-help.ts\";\nexport { HelpMessageStyle, helpMessageStyles } from \"./help-message/styles.ts\";\n\nexport { generateBashAutocompleteScript } from \"./autocomplete-scripts/bash-autocomplete-script.ts\";\nexport { generatePowerShellAutocompleteScript } from \"./autocomplete-scripts/powershell-autocomplete-script.ts\";\nexport { generateZshAutocompleteScript } from \"./autocomplete-scripts/zsh-autocomplete-script.ts\";\nexport { generateMarkdown } from \"./markdown/generate-markdown.ts\";\n\nexport { getArgumentsMetadata } from \"./metadata/arguments-metadata.ts\";\nexport { getCliMetadata } from \"./metadata/cli-metadata.ts\";\nexport { getOptionsMetadata } from \"./metadata/options-metadata.ts\";\nexport { getSubcommandsMetadata } from \"./metadata/subcommands-metadata.ts\";\n\nexport { defineArguments } from \"./definitions/define-arguments.ts\";\nexport { defineCLI } from \"./definitions/define-cli.ts\";\nexport { defineOptions } from \"./definitions/define-options.ts\";\nexport { defineSubcommand } from \"./definitions/define-subcommand.ts\";\n\nexport { coerce } from \"./coerce/coerce-methods.ts\";\n\nexport { CliError } from \"./cli-error/cli-error.ts\";\nexport { ErrorCause } from \"./cli-error/error-cause.ts\";\nexport { DefinitionErrorCode } from \"./cli-error/error-code/definition-error-code.ts\";\nexport { InternalErrorCode } from \"./cli-error/error-code/internal-error-code.ts\";\nexport { ParseErrorCode } from \"./cli-error/error-code/parse-error-code.ts\";\nexport { ValidationErrorCode } from \"./cli-error/error-code/validation-error-code.ts\";\n\nexport type * from \"./types/context-types.ts\";\nexport type * from \"./types/definitions-types.ts\";\nexport type {\n CliErrorI,\n CliErrorOptionUnion,\n DefinitionErrorI,\n ErrorCauseI,\n InternalErrorI,\n ParseErrorI,\n ValidationErrorI,\n} from \"./types/error-types.ts\";\nexport type * from \"./types/help-message-types.ts\";\nexport type * from \"./types/io-types.ts\";\nexport type * from \"./types/metadata-types.ts\";\nexport type * from \"./types/schema-types.ts\";\nexport type * from \"./types/types.ts\";\n"],
|
|
5
5
|
"mappings": ";AAAA,SAAS,8BAA8B;AACvC,SAAS,qCAAqC;AAC9C,SAAS,cAAc,2BAA2B;AAClD,SAAS,kBAAkB,yBAAyB;AAEpD,SAAS,sCAAsC;AAC/C,SAAS,4CAA4C;AACrD,SAAS,qCAAqC;AAC9C,SAAS,wBAAwB;AAEjC,SAAS,4BAA4B;AACrC,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,8BAA8B;AAEvC,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AAEjC,SAAS,cAAc;AAEvB,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,6 +3,7 @@ import { CliError } from "../../cli-error/cli-error.js";
|
|
|
3
3
|
import { ErrorCause } from "../../cli-error/error-cause.js";
|
|
4
4
|
import { InternalErrorCode } from "../../cli-error/error-code/internal-error-code.js";
|
|
5
5
|
import { ParseErrorCode } from "../../cli-error/error-code/parse-error-code.js";
|
|
6
|
+
import { coerce } from "../../coerce/coerce-methods.js";
|
|
6
7
|
import {
|
|
7
8
|
decoupleFlags,
|
|
8
9
|
findOption,
|
|
@@ -115,7 +116,7 @@ function buildCliContext(argv, cliDefinition) {
|
|
|
115
116
|
}
|
|
116
117
|
context.options ??= {};
|
|
117
118
|
if (optionWithKeys) {
|
|
118
|
-
const previousObject =
|
|
119
|
+
const previousObject = coerce.json(context.options[optionName]?.stringValue || "{}");
|
|
119
120
|
let current = previousObject;
|
|
120
121
|
for (let index2 = 0; index2 < keys.length; index2++) {
|
|
121
122
|
const key = keys[index2];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/parse/context/cli-context-builder.ts"],
|
|
4
|
-
"sourcesContent": ["import { CliError } from \"../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../cli-error/error-cause.ts\";\nimport { InternalErrorCode } from \"../../cli-error/error-code/internal-error-code.ts\";\nimport { ParseErrorCode } from \"../../cli-error/error-code/parse-error-code.ts\";\nimport {\n decoupleFlags,\n findOption,\n findSubcommandDefinition,\n isFlagArgument,\n isOptionArgument,\n splitAndGetKeys,\n} from \"../parser-utilities.ts\";\n\nimport type { ContextWide } from \"../../types/context-types.ts\";\nimport type { Cli } from \"../../types/definitions-types.ts\";\n\n/**\n * Parse argv and create a cli context\n *\n * @throws {CliError}\n */\nexport function buildCliContext(argv: string[], cliDefinition: Cli) {\n const cliName = cliDefinition.cliName;\n const subcommandArray = cliDefinition.subcommands ?? [];\n const allSubcommands = new Set<string>(subcommandArray.flatMap(c => [c.name, ...(c.aliases || [])]));\n\n // decouple flags E.g. `-rf` -> `-r, -f`\n argv = decoupleFlags(argv);\n\n const context: ContextWide = {\n subcommand: undefined,\n };\n\n /** Get the current subcommand definition or cli definition if subcommand name is `undefined` object */\n const getCommandDefinition = () => findSubcommandDefinition(context.subcommand, cliDefinition);\n\n for (let index = 0; index < argv.length; index++) {\n const argvItem = argv[index];\n\n // * Subcommand check\n if (index === 0) {\n context.subcommand = allSubcommands.has(argvItem) ? argvItem : undefined;\n\n // First argument is a subcommand. Skip to the next argument\n if (context.subcommand) continue;\n }\n\n // * Option check\n\n const argumentAndValue = argvItem.split(\"=\").filter(Boolean); // E.g --option=value -> [\"--option\", \"value\"]\n const argumentWithEquals = argvItem.includes(\"=\"); // E.g --option=value\n const [argument, keys] = splitAndGetKeys(argumentAndValue[0]); // E.g --option.foo.bar -> [\"--option\", [\"foo\", \"bar\"]]\n const optionWithKeys = keys.length > 0; // E.g --option.foo.bar\n const argumentValue: string | undefined = argumentAndValue[1];\n const isNegated = argument.startsWith(\"--no-\");\n\n if (isOptionArgument(argument)) {\n const commandDefinition = getCommandDefinition();\n const commandKind = context.subcommand === undefined ? \"command\" : \"subcommand\";\n const commandName = context.subcommand ?? cliName;\n\n if (isFlagArgument(argument) && argumentWithEquals) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.FlagAssignedValue,\n context: { commandKind, commandName, flag: argument, value: argumentValue },\n });\n }\n\n if (!commandDefinition) {\n if (context.subcommand === undefined) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.CannotFindCliDefinition,\n context: { cliName },\n });\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.UnknownSubcommand,\n context: { commandName },\n });\n }\n\n if (!commandDefinition.options) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.CommandWithoutOptions,\n context: { commandKind, commandName, optionName: argument },\n });\n }\n\n const nameOptionTuple = findOption(argument, commandDefinition.options);\n if (!nameOptionTuple) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.UnknownOption,\n context: { commandKind, commandName, optionName: argument },\n });\n }\n\n const [optionName, optionDefinition] = nameOptionTuple;\n\n if (!optionWithKeys && context.options && optionName in context.options) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.DuplicateOptionProvided,\n context: { commandKind, commandName, optionName },\n });\n }\n\n if (!optionDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: { commandKind, commandName, kind: \"option\", name: optionName },\n });\n }\n\n const { schema, optional, defaultValue, coerceTo } = optionDefinition._preparedType;\n\n const nextArgument = argv[index + 1];\n\n let optionValue: string | boolean | undefined = argumentWithEquals ? argumentValue : nextArgument;\n\n const isBoolean = coerceTo === \"boolean\";\n\n if (isNegated && !isBoolean) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.InvalidNegationForNonBooleanOption,\n context: { commandKind, commandName, optionName },\n });\n }\n\n // infer value for boolean options\n if (isBoolean) {\n if (!argumentWithEquals) {\n optionValue = \"true\";\n }\n\n if (isNegated && [\"true\", \"false\"].includes(optionValue.toLowerCase())) {\n optionValue = optionValue === \"true\" ? \"false\" : \"true\";\n }\n }\n\n if (optionValue === undefined || (!argumentWithEquals && isOptionArgument(optionValue))) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.OptionMissingValue,\n context: { commandKind, commandName, optionName },\n });\n }\n\n context.options ??= {};\n\n // Handle options with keys for type `object`\n // E.g. `--option.key.nested=value`\n if (optionWithKeys) {\n const previousObject = JSON.parse(context.options[optionName]?.stringValue || \"{}\") as Record<string, any>;\n\n let current = previousObject;\n for (let index = 0; index < keys.length; index++) {\n const key = keys[index];\n\n if (current[key] === undefined) {\n current[key] = {};\n }\n\n if (index === keys.length - 1) {\n current[key] = optionValue;\n continue;\n }\n\n current = current[key] as Record<string, any>;\n }\n\n optionValue = JSON.stringify(previousObject);\n }\n\n context.options[optionName] = {\n schema,\n optional,\n defaultValue,\n flag: argument,\n stringValue: optionValue,\n source: \"terminal\",\n };\n\n // Skip to the next argument if it is the current option's value.\n if (!argumentWithEquals && !isBoolean) {\n index++;\n }\n\n continue;\n }\n\n const commandDefinition = getCommandDefinition();\n\n // * Arguments check\n if (commandDefinition?.arguments) {\n context.arguments ??= {};\n\n const currentArgumentCount = Object.keys(context.arguments).length;\n const argumentDefinitionEntries = Object.entries(commandDefinition.arguments);\n\n // The current argument is a typed argument and not a positional\n if (currentArgumentCount < argumentDefinitionEntries.length) {\n const [name, argumentDefinition] = argumentDefinitionEntries[currentArgumentCount];\n\n if (!argumentDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n kind: \"argument\",\n name,\n },\n });\n }\n\n const { schema, optional, defaultValue } = argumentDefinition._preparedType;\n\n context.arguments[name] = { schema, optional, defaultValue, stringValue: argvItem, source: \"terminal\" };\n continue;\n }\n }\n\n // The current argument is a positional and not a typed argument (when `allowPositionals` is enabled)\n if (commandDefinition?.allowPositionals) {\n context.positionals ??= [];\n context.positionals.push(argvItem);\n continue;\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.PositionalArgumentNotAllowed,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n argumentName: argvItem,\n },\n });\n }\n\n const commandDefinition = getCommandDefinition();\n if (!commandDefinition) {\n if (context.subcommand === undefined) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.CannotFindCliDefinition,\n context: { cliName },\n });\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.UnknownSubcommand,\n context: { commandName: context.subcommand ?? cliName },\n });\n }\n\n // Options\n if (commandDefinition.options) {\n context.options ??= {};\n\n for (const [name, optionDefinition] of Object.entries(commandDefinition.options)) {\n // option already added to the context (found during argument parsing)\n if (name in context.options) continue;\n\n if (!optionDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n kind: \"option\",\n name,\n },\n });\n }\n\n const { schema, optional, defaultValue } = optionDefinition._preparedType;\n\n if (optional) {\n // optional without default value\n if (defaultValue === undefined) {\n continue;\n }\n\n // optional with default value\n context.options[name] = { schema, optional, defaultValue, source: \"default\" };\n continue;\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.MissingRequiredOption,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n optionName: name,\n },\n });\n }\n }\n\n // Arguments\n if (commandDefinition.arguments) {\n context.arguments ??= {};\n\n const currentArgumentCount = Object.keys(context.arguments).length;\n\n const argumentDefinitionEntries = Object.entries(commandDefinition.arguments);\n const argumentsDefinitionLength = argumentDefinitionEntries.length;\n\n // missing arguments\n if (currentArgumentCount < argumentsDefinitionLength) {\n for (let index = currentArgumentCount; index < argumentsDefinitionLength; index++) {\n const [name, argumentDefinition] = argumentDefinitionEntries[index];\n\n if (!argumentDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n kind: \"argument\",\n name,\n },\n });\n }\n\n const { schema, optional, defaultValue } = argumentDefinition._preparedType;\n\n if (optional) {\n // optional argument without default value\n if (defaultValue === undefined) {\n continue;\n }\n\n // optional argument with default value\n context.arguments[name] = { schema, optional, defaultValue, source: \"default\" };\n continue;\n }\n\n // required argument\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.MissingRequiredArgument,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n argumentName: name,\n },\n });\n }\n }\n }\n\n // make sure `positionals` is defined when `allowPositionals` is enabled\n if (commandDefinition.allowPositionals) {\n context.positionals ??= [];\n }\n\n return context;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUA,SAAS,gBAAgB,MAAgB,eAAoB;AAClE,QAAM,UAAU,cAAc;AAC9B,QAAM,kBAAkB,cAAc,eAAe,CAAC;AACtD,QAAM,iBAAiB,IAAI,IAAY,gBAAgB,QAAQ,OAAK,CAAC,EAAE,MAAM,GAAI,EAAE,WAAW,CAAC,CAAE,CAAC,CAAC;AAGnG,SAAO,cAAc,IAAI;AAEzB,QAAM,UAAuB;AAAA,IAC3B,YAAY;AAAA,EACd;AAGA,QAAM,uBAAuB,MAAM,yB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YAAY,CAAC,GAAG;AACtE,wBAAc,gBAAgB,SAAS,UAAU;AAAA,QACnD;AAAA,MACF;AAEA,UAAI,gBAAgB,UAAc,CAAC,sBAAsB,iBAAiB,WAAW,GAAI;AACvF,cAAM,IAAI,SAAS;AAAA,UACjB,OAAO,WAAW;AAAA,UAClB,MAAM,eAAe;AAAA,UACrB,SAAS,EAAE,aAAa,aAAa,WAAW;AAAA,QAClD,CAAC;AAAA,MACH;AAEA,cAAQ,YAAY,CAAC;AAIrB,UAAI,gBAAgB;AAClB,cAAM,iBAAiB,
|
|
4
|
+
"sourcesContent": ["import { CliError } from \"../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../cli-error/error-cause.ts\";\nimport { InternalErrorCode } from \"../../cli-error/error-code/internal-error-code.ts\";\nimport { ParseErrorCode } from \"../../cli-error/error-code/parse-error-code.ts\";\nimport { coerce } from \"../../coerce/coerce-methods.ts\";\nimport {\n decoupleFlags,\n findOption,\n findSubcommandDefinition,\n isFlagArgument,\n isOptionArgument,\n splitAndGetKeys,\n} from \"../parser-utilities.ts\";\n\nimport type { ContextWide } from \"../../types/context-types.ts\";\nimport type { Cli } from \"../../types/definitions-types.ts\";\n\n/**\n * Parse argv and create a cli context\n *\n * @throws {CliError}\n */\nexport function buildCliContext(argv: string[], cliDefinition: Cli) {\n const cliName = cliDefinition.cliName;\n const subcommandArray = cliDefinition.subcommands ?? [];\n const allSubcommands = new Set<string>(subcommandArray.flatMap(c => [c.name, ...(c.aliases || [])]));\n\n // decouple flags E.g. `-rf` -> `-r, -f`\n argv = decoupleFlags(argv);\n\n const context: ContextWide = {\n subcommand: undefined,\n };\n\n /** Get the current subcommand definition or cli definition if subcommand name is `undefined` object */\n const getCommandDefinition = () => findSubcommandDefinition(context.subcommand, cliDefinition);\n\n for (let index = 0; index < argv.length; index++) {\n const argvItem = argv[index];\n\n // * Subcommand check\n if (index === 0) {\n context.subcommand = allSubcommands.has(argvItem) ? argvItem : undefined;\n\n // First argument is a subcommand. Skip to the next argument\n if (context.subcommand) continue;\n }\n\n // * Option check\n\n const argumentAndValue = argvItem.split(\"=\").filter(Boolean); // E.g --option=value -> [\"--option\", \"value\"]\n const argumentWithEquals = argvItem.includes(\"=\"); // E.g --option=value\n const [argument, keys] = splitAndGetKeys(argumentAndValue[0]); // E.g --option.foo.bar -> [\"--option\", [\"foo\", \"bar\"]]\n const optionWithKeys = keys.length > 0; // E.g --option.foo.bar\n const argumentValue: string | undefined = argumentAndValue[1];\n const isNegated = argument.startsWith(\"--no-\");\n\n if (isOptionArgument(argument)) {\n const commandDefinition = getCommandDefinition();\n const commandKind = context.subcommand === undefined ? \"command\" : \"subcommand\";\n const commandName = context.subcommand ?? cliName;\n\n if (isFlagArgument(argument) && argumentWithEquals) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.FlagAssignedValue,\n context: { commandKind, commandName, flag: argument, value: argumentValue },\n });\n }\n\n if (!commandDefinition) {\n if (context.subcommand === undefined) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.CannotFindCliDefinition,\n context: { cliName },\n });\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.UnknownSubcommand,\n context: { commandName },\n });\n }\n\n if (!commandDefinition.options) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.CommandWithoutOptions,\n context: { commandKind, commandName, optionName: argument },\n });\n }\n\n const nameOptionTuple = findOption(argument, commandDefinition.options);\n if (!nameOptionTuple) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.UnknownOption,\n context: { commandKind, commandName, optionName: argument },\n });\n }\n\n const [optionName, optionDefinition] = nameOptionTuple;\n\n if (!optionWithKeys && context.options && optionName in context.options) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.DuplicateOptionProvided,\n context: { commandKind, commandName, optionName },\n });\n }\n\n if (!optionDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: { commandKind, commandName, kind: \"option\", name: optionName },\n });\n }\n\n const { schema, optional, defaultValue, coerceTo } = optionDefinition._preparedType;\n\n const nextArgument = argv[index + 1];\n\n let optionValue: string | boolean | undefined = argumentWithEquals ? argumentValue : nextArgument;\n\n const isBoolean = coerceTo === \"boolean\";\n\n if (isNegated && !isBoolean) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.InvalidNegationForNonBooleanOption,\n context: { commandKind, commandName, optionName },\n });\n }\n\n // infer value for boolean options\n if (isBoolean) {\n if (!argumentWithEquals) {\n optionValue = \"true\";\n }\n\n if (isNegated && [\"true\", \"false\"].includes(optionValue.toLowerCase())) {\n optionValue = optionValue === \"true\" ? \"false\" : \"true\";\n }\n }\n\n if (optionValue === undefined || (!argumentWithEquals && isOptionArgument(optionValue))) {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.OptionMissingValue,\n context: { commandKind, commandName, optionName },\n });\n }\n\n context.options ??= {};\n\n // Handle options with keys for type `object`\n // E.g. `--option.key.nested=value`\n if (optionWithKeys) {\n const previousObject = coerce.json<Record<string, any>>(context.options[optionName]?.stringValue || \"{}\");\n\n let current = previousObject;\n for (let index = 0; index < keys.length; index++) {\n const key = keys[index];\n\n if (current[key] === undefined) {\n current[key] = {};\n }\n\n if (index === keys.length - 1) {\n current[key] = optionValue;\n continue;\n }\n\n current = current[key] as Record<string, any>;\n }\n\n optionValue = JSON.stringify(previousObject);\n }\n\n context.options[optionName] = {\n schema,\n optional,\n defaultValue,\n flag: argument,\n stringValue: optionValue,\n source: \"terminal\",\n };\n\n // Skip to the next argument if it is the current option's value.\n if (!argumentWithEquals && !isBoolean) {\n index++;\n }\n\n continue;\n }\n\n const commandDefinition = getCommandDefinition();\n\n // * Arguments check\n if (commandDefinition?.arguments) {\n context.arguments ??= {};\n\n const currentArgumentCount = Object.keys(context.arguments).length;\n const argumentDefinitionEntries = Object.entries(commandDefinition.arguments);\n\n // The current argument is a typed argument and not a positional\n if (currentArgumentCount < argumentDefinitionEntries.length) {\n const [name, argumentDefinition] = argumentDefinitionEntries[currentArgumentCount];\n\n if (!argumentDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n kind: \"argument\",\n name,\n },\n });\n }\n\n const { schema, optional, defaultValue } = argumentDefinition._preparedType;\n\n context.arguments[name] = { schema, optional, defaultValue, stringValue: argvItem, source: \"terminal\" };\n continue;\n }\n }\n\n // The current argument is a positional and not a typed argument (when `allowPositionals` is enabled)\n if (commandDefinition?.allowPositionals) {\n context.positionals ??= [];\n context.positionals.push(argvItem);\n continue;\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.PositionalArgumentNotAllowed,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n argumentName: argvItem,\n },\n });\n }\n\n const commandDefinition = getCommandDefinition();\n if (!commandDefinition) {\n if (context.subcommand === undefined) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.CannotFindCliDefinition,\n context: { cliName },\n });\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.UnknownSubcommand,\n context: { commandName: context.subcommand ?? cliName },\n });\n }\n\n // Options\n if (commandDefinition.options) {\n context.options ??= {};\n\n for (const [name, optionDefinition] of Object.entries(commandDefinition.options)) {\n // option already added to the context (found during argument parsing)\n if (name in context.options) continue;\n\n if (!optionDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n kind: \"option\",\n name,\n },\n });\n }\n\n const { schema, optional, defaultValue } = optionDefinition._preparedType;\n\n if (optional) {\n // optional without default value\n if (defaultValue === undefined) {\n continue;\n }\n\n // optional with default value\n context.options[name] = { schema, optional, defaultValue, source: \"default\" };\n continue;\n }\n\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.MissingRequiredOption,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n optionName: name,\n },\n });\n }\n }\n\n // Arguments\n if (commandDefinition.arguments) {\n context.arguments ??= {};\n\n const currentArgumentCount = Object.keys(context.arguments).length;\n\n const argumentDefinitionEntries = Object.entries(commandDefinition.arguments);\n const argumentsDefinitionLength = argumentDefinitionEntries.length;\n\n // missing arguments\n if (currentArgumentCount < argumentsDefinitionLength) {\n for (let index = currentArgumentCount; index < argumentsDefinitionLength; index++) {\n const [name, argumentDefinition] = argumentDefinitionEntries[index];\n\n if (!argumentDefinition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n kind: \"argument\",\n name,\n },\n });\n }\n\n const { schema, optional, defaultValue } = argumentDefinition._preparedType;\n\n if (optional) {\n // optional argument without default value\n if (defaultValue === undefined) {\n continue;\n }\n\n // optional argument with default value\n context.arguments[name] = { schema, optional, defaultValue, source: \"default\" };\n continue;\n }\n\n // required argument\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.MissingRequiredArgument,\n context: {\n commandKind: context.subcommand ? \"subcommand\" : \"command\",\n commandName: context.subcommand ?? cliName,\n argumentName: name,\n },\n });\n }\n }\n }\n\n // make sure `positionals` is defined when `allowPositionals` is enabled\n if (commandDefinition.allowPositionals) {\n context.positionals ??= [];\n }\n\n return context;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB;AAAA,EACE;AAA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