zod-args-parser 1.2.7 → 2.0.0-alpha.0
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 +20 -20
- package/lib/commonjs/autocomplete-scripts/{bash-autocomplete-script.js → bash-autocomplete-script.cjs} +2 -2
- package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +1 -0
- package/lib/commonjs/autocomplete-scripts/{powershell-autocomplete-script.js → powershell-autocomplete-script.cjs} +3 -3
- package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +1 -0
- package/lib/commonjs/autocomplete-scripts/{zsh-autocomplete-script.js → zsh-autocomplete-script.cjs} +4 -4
- package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +1 -0
- package/lib/commonjs/help-message/format-arguments.cjs +1 -0
- package/lib/commonjs/help-message/format-arguments.cjs.map +1 -0
- package/lib/commonjs/help-message/format-cli.cjs +1 -0
- package/lib/commonjs/help-message/format-cli.cjs.map +1 -0
- package/lib/commonjs/help-message/format-options.cjs +1 -0
- package/lib/commonjs/help-message/format-options.cjs.map +1 -0
- package/lib/commonjs/help-message/format-subcommands.cjs +1 -0
- package/lib/commonjs/help-message/format-subcommands.cjs.map +1 -0
- package/lib/commonjs/help-message/styles.cjs +1 -0
- package/lib/commonjs/help-message/styles.cjs.map +1 -0
- package/lib/commonjs/index.cjs +1 -0
- package/lib/commonjs/index.cjs.map +1 -0
- package/lib/commonjs/markdown/generate-markdown.cjs +1 -0
- package/lib/commonjs/markdown/generate-markdown.cjs.map +1 -0
- package/lib/commonjs/metadata/get-arguments-metadata.cjs +1 -0
- package/lib/commonjs/metadata/get-arguments-metadata.cjs.map +1 -0
- package/lib/commonjs/metadata/get-cli-metadata.cjs +1 -0
- package/lib/commonjs/metadata/{get-cli-metadata.js.map → get-cli-metadata.cjs.map} +1 -1
- package/lib/commonjs/metadata/get-options-metadata.cjs +1 -0
- package/lib/commonjs/metadata/get-options-metadata.cjs.map +1 -0
- package/lib/commonjs/metadata/get-subcommands-metadata.cjs +1 -0
- package/lib/commonjs/metadata/get-subcommands-metadata.cjs.map +1 -0
- package/lib/commonjs/parser/parse/parse.cjs +1 -0
- package/lib/commonjs/parser/parse/parse.cjs.map +1 -0
- package/lib/commonjs/parser/parse/parser-helpers.cjs +1 -0
- package/lib/commonjs/parser/parse/parser-helpers.cjs.map +1 -0
- package/lib/commonjs/parser/safe-parse.cjs +1 -0
- package/lib/commonjs/parser/safe-parse.cjs.map +1 -0
- package/lib/commonjs/parser/unsafe-parse.cjs +1 -0
- package/lib/commonjs/parser/unsafe-parse.cjs.map +1 -0
- package/lib/commonjs/parser/validate/validate-type.cjs.map +1 -0
- package/lib/commonjs/parser/validate/validate.cjs +1 -0
- package/lib/commonjs/parser/validate/validate.cjs.map +1 -0
- package/lib/commonjs/utilities.cjs +1 -0
- package/lib/commonjs/utilities.cjs.map +1 -0
- package/lib/commonjs/zod-utilities.cjs +1 -0
- package/lib/commonjs/zod-utilities.cjs.map +1 -0
- package/lib/module/autocomplete-scripts/{bash-autocomplete-script.js → bash-autocomplete-script.mjs} +2 -2
- package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs.map +1 -0
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs +31 -0
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs.map +1 -0
- package/lib/module/autocomplete-scripts/{zsh-autocomplete-script.js → zsh-autocomplete-script.mjs} +4 -4
- package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs.map +1 -0
- package/lib/module/help-message/format-arguments.mjs +1 -0
- package/lib/module/help-message/format-arguments.mjs.map +1 -0
- package/lib/module/help-message/format-cli.mjs +1 -0
- package/lib/module/help-message/format-cli.mjs.map +1 -0
- package/lib/module/help-message/format-options.mjs +1 -0
- package/lib/module/help-message/format-options.mjs.map +1 -0
- package/lib/module/help-message/format-subcommands.mjs +1 -0
- package/lib/module/help-message/format-subcommands.mjs.map +1 -0
- package/lib/module/help-message/styles.mjs +1 -0
- package/lib/module/help-message/styles.mjs.map +1 -0
- package/lib/module/index.mjs +1 -0
- package/lib/module/index.mjs.map +1 -0
- package/lib/module/markdown/generate-markdown.mjs +1 -0
- package/lib/module/markdown/generate-markdown.mjs.map +1 -0
- package/lib/module/metadata/get-arguments-metadata.mjs +1 -0
- package/lib/module/metadata/get-arguments-metadata.mjs.map +1 -0
- package/lib/module/metadata/get-cli-metadata.mjs +1 -0
- package/lib/module/metadata/{get-cli-metadata.js.map → get-cli-metadata.mjs.map} +1 -1
- package/lib/module/metadata/get-options-metadata.mjs +1 -0
- package/lib/module/metadata/get-options-metadata.mjs.map +1 -0
- package/lib/module/metadata/get-subcommands-metadata.mjs +1 -0
- package/lib/module/metadata/get-subcommands-metadata.mjs.map +1 -0
- package/lib/module/parser/parse/parse.mjs +1 -0
- package/lib/module/parser/parse/parse.mjs.map +1 -0
- package/lib/module/parser/parse/parser-helpers.mjs +1 -0
- package/lib/module/parser/parse/parser-helpers.mjs.map +1 -0
- package/lib/module/parser/safe-parse.mjs +1 -0
- package/lib/module/parser/safe-parse.mjs.map +1 -0
- package/lib/module/parser/unsafe-parse.mjs +1 -0
- package/lib/module/parser/unsafe-parse.mjs.map +1 -0
- package/lib/module/parser/validate/validate-type.mjs.map +1 -0
- package/lib/module/parser/validate/validate.mjs +1 -0
- package/lib/module/parser/validate/validate.mjs.map +1 -0
- package/lib/module/utilities.mjs +1 -0
- package/lib/module/utilities.mjs.map +1 -0
- package/lib/module/zod-utilities.mjs +1 -0
- package/lib/module/zod-utilities.mjs.map +1 -0
- package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts +1 -1
- package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +1 -1
- package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +1 -1
- package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
- package/lib/typescript/help-message/format-arguments.d.ts +2 -2
- package/lib/typescript/help-message/format-arguments.d.ts.map +1 -1
- package/lib/typescript/help-message/format-cli.d.ts +5 -5
- package/lib/typescript/help-message/format-cli.d.ts.map +1 -1
- package/lib/typescript/help-message/format-options.d.ts +2 -2
- package/lib/typescript/help-message/format-options.d.ts.map +1 -1
- package/lib/typescript/help-message/format-subcommands.d.ts +2 -2
- package/lib/typescript/help-message/format-subcommands.d.ts.map +1 -1
- package/lib/typescript/help-message/styles.d.ts +14 -13
- package/lib/typescript/help-message/styles.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +10 -10
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/markdown/generate-markdown.d.ts +1 -1
- package/lib/typescript/markdown/generate-markdown.d.ts.map +1 -1
- package/lib/typescript/metadata/get-arguments-metadata.d.ts +1 -1
- package/lib/typescript/metadata/get-arguments-metadata.d.ts.map +1 -1
- package/lib/typescript/metadata/get-options-metadata.d.ts.map +1 -1
- package/lib/typescript/metadata/get-subcommands-metadata.d.ts.map +1 -1
- package/lib/typescript/parser/parse/parse-types.d.ts +6 -6
- package/lib/typescript/parser/parse/parse-types.d.ts.map +1 -1
- package/lib/typescript/parser/parse/parse.d.ts +2 -2
- package/lib/typescript/parser/parse/parse.d.ts.map +1 -1
- package/lib/typescript/parser/parse/parser-helpers.d.ts +7 -7
- package/lib/typescript/parser/parse/parser-helpers.d.ts.map +1 -1
- package/lib/typescript/parser/safe-parse.d.ts +2 -2
- package/lib/typescript/parser/safe-parse.d.ts.map +1 -1
- package/lib/typescript/parser/unsafe-parse.d.ts +2 -2
- package/lib/typescript/parser/unsafe-parse.d.ts.map +1 -1
- package/lib/typescript/parser/validate/validate-type.d.ts +5 -4
- package/lib/typescript/parser/validate/validate-type.d.ts.map +1 -1
- package/lib/typescript/parser/validate/validate.d.ts +5 -4
- package/lib/typescript/parser/validate/validate.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +19 -15
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/{utils.d.ts → utilities.d.ts} +9 -9
- package/lib/typescript/utilities.d.ts.map +1 -0
- package/lib/typescript/{zod-utils.d.ts → zod-utilities.d.ts} +5 -4
- package/lib/typescript/zod-utilities.d.ts.map +1 -0
- package/package.json +17 -18
- package/src/autocomplete-scripts/bash-autocomplete-script.ts +10 -10
- package/src/autocomplete-scripts/powershell-autocomplete-script.ts +17 -15
- package/src/autocomplete-scripts/zsh-autocomplete-script.ts +8 -5
- package/src/help-message/format-arguments.ts +20 -13
- package/src/help-message/format-cli.ts +65 -45
- package/src/help-message/format-options.ts +19 -12
- package/src/help-message/format-subcommands.ts +9 -9
- package/src/help-message/styles.ts +18 -18
- package/src/index.ts +21 -21
- package/src/markdown/generate-markdown.ts +55 -55
- package/src/metadata/get-arguments-metadata.ts +10 -10
- package/src/metadata/get-options-metadata.ts +8 -6
- package/src/metadata/get-subcommands-metadata.ts +3 -1
- package/src/parser/parse/parse-types.ts +6 -6
- package/src/parser/parse/parse.ts +83 -75
- package/src/parser/parse/parser-helpers.ts +24 -25
- package/src/parser/safe-parse.ts +24 -18
- package/src/parser/unsafe-parse.ts +34 -34
- package/src/parser/validate/validate-type.ts +9 -10
- package/src/parser/validate/validate.ts +34 -29
- package/src/types.ts +21 -17
- package/src/{utils.ts → utilities.ts} +44 -28
- package/src/{zod-utils.ts → zod-utilities.ts} +56 -32
- package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.js.map +0 -1
- package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.js.map +0 -1
- package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.js.map +0 -1
- package/lib/commonjs/help-message/format-arguments.js +0 -1
- package/lib/commonjs/help-message/format-arguments.js.map +0 -1
- package/lib/commonjs/help-message/format-cli.js +0 -1
- package/lib/commonjs/help-message/format-cli.js.map +0 -1
- package/lib/commonjs/help-message/format-options.js +0 -1
- package/lib/commonjs/help-message/format-options.js.map +0 -1
- package/lib/commonjs/help-message/format-subcommands.js +0 -1
- package/lib/commonjs/help-message/format-subcommands.js.map +0 -1
- package/lib/commonjs/help-message/styles.js +0 -1
- package/lib/commonjs/help-message/styles.js.map +0 -1
- package/lib/commonjs/index.js +0 -1
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/markdown/generate-markdown.js +0 -1
- package/lib/commonjs/markdown/generate-markdown.js.map +0 -1
- package/lib/commonjs/metadata/get-arguments-metadata.js +0 -1
- package/lib/commonjs/metadata/get-arguments-metadata.js.map +0 -1
- package/lib/commonjs/metadata/get-cli-metadata.js +0 -1
- package/lib/commonjs/metadata/get-options-metadata.js +0 -1
- package/lib/commonjs/metadata/get-options-metadata.js.map +0 -1
- package/lib/commonjs/metadata/get-subcommands-metadata.js +0 -1
- package/lib/commonjs/metadata/get-subcommands-metadata.js.map +0 -1
- package/lib/commonjs/parser/parse/parse.js +0 -1
- package/lib/commonjs/parser/parse/parse.js.map +0 -1
- package/lib/commonjs/parser/parse/parser-helpers.js +0 -1
- package/lib/commonjs/parser/parse/parser-helpers.js.map +0 -1
- package/lib/commonjs/parser/safe-parse.js +0 -1
- package/lib/commonjs/parser/safe-parse.js.map +0 -1
- package/lib/commonjs/parser/unsafe-parse.js +0 -1
- package/lib/commonjs/parser/unsafe-parse.js.map +0 -1
- package/lib/commonjs/parser/validate/validate-type.js.map +0 -1
- package/lib/commonjs/parser/validate/validate.js +0 -1
- package/lib/commonjs/parser/validate/validate.js.map +0 -1
- package/lib/commonjs/utils.js +0 -1
- package/lib/commonjs/utils.js.map +0 -1
- package/lib/commonjs/zod-utils.js +0 -1
- package/lib/commonjs/zod-utils.js.map +0 -1
- package/lib/module/autocomplete-scripts/bash-autocomplete-script.js.map +0 -1
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.js +0 -31
- package/lib/module/autocomplete-scripts/powershell-autocomplete-script.js.map +0 -1
- package/lib/module/autocomplete-scripts/zsh-autocomplete-script.js.map +0 -1
- package/lib/module/help-message/format-arguments.js +0 -1
- package/lib/module/help-message/format-arguments.js.map +0 -1
- package/lib/module/help-message/format-cli.js +0 -1
- package/lib/module/help-message/format-cli.js.map +0 -1
- package/lib/module/help-message/format-options.js +0 -1
- package/lib/module/help-message/format-options.js.map +0 -1
- package/lib/module/help-message/format-subcommands.js +0 -1
- package/lib/module/help-message/format-subcommands.js.map +0 -1
- package/lib/module/help-message/styles.js +0 -1
- package/lib/module/help-message/styles.js.map +0 -1
- package/lib/module/index.js +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/markdown/generate-markdown.js +0 -1
- package/lib/module/markdown/generate-markdown.js.map +0 -1
- package/lib/module/metadata/get-arguments-metadata.js +0 -1
- package/lib/module/metadata/get-arguments-metadata.js.map +0 -1
- package/lib/module/metadata/get-cli-metadata.js +0 -1
- package/lib/module/metadata/get-options-metadata.js +0 -1
- package/lib/module/metadata/get-options-metadata.js.map +0 -1
- package/lib/module/metadata/get-subcommands-metadata.js +0 -1
- package/lib/module/metadata/get-subcommands-metadata.js.map +0 -1
- package/lib/module/parser/parse/parse.js +0 -1
- package/lib/module/parser/parse/parse.js.map +0 -1
- package/lib/module/parser/parse/parser-helpers.js +0 -1
- package/lib/module/parser/parse/parser-helpers.js.map +0 -1
- package/lib/module/parser/safe-parse.js +0 -1
- package/lib/module/parser/safe-parse.js.map +0 -1
- package/lib/module/parser/unsafe-parse.js +0 -1
- package/lib/module/parser/unsafe-parse.js.map +0 -1
- package/lib/module/parser/validate/validate-type.js.map +0 -1
- package/lib/module/parser/validate/validate.js +0 -1
- package/lib/module/parser/validate/validate.js.map +0 -1
- package/lib/module/utils.js +0 -1
- package/lib/module/utils.js.map +0 -1
- package/lib/module/zod-utils.js +0 -1
- package/lib/module/zod-utils.js.map +0 -1
- package/lib/typescript/utils.d.ts.map +0 -1
- package/lib/typescript/zod-utils.d.ts.map +0 -1
- /package/lib/commonjs/parser/validate/{validate-type.js → validate-type.cjs} +0 -0
- /package/lib/module/parser/validate/{validate-type.js → validate-type.mjs} +0 -0
|
@@ -3,8 +3,8 @@ import { getCliMetadata } from "../metadata/get-cli-metadata.js";
|
|
|
3
3
|
import type { ArgumentMetadata, OptionMetadata, SubcommandMetadata } from "../metadata/metadata-types.js";
|
|
4
4
|
import type { Cli, Subcommand } from "../types.js";
|
|
5
5
|
|
|
6
|
-
export function generateMarkdown(...
|
|
7
|
-
const metadata = getCliMetadata(
|
|
6
|
+
export function generateMarkdown(...parameters: [Cli, ...Subcommand[]]): string {
|
|
7
|
+
const metadata = getCliMetadata(parameters);
|
|
8
8
|
|
|
9
9
|
let md = "<!-- Auto-generated by zod-args-parser -->\n\n";
|
|
10
10
|
|
|
@@ -22,19 +22,19 @@ export function generateMarkdown(...params: [Cli, ...Subcommand[]]): string {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// Options
|
|
25
|
-
if (metadata.options.length) {
|
|
25
|
+
if (metadata.options.length > 0) {
|
|
26
26
|
md += "\n## Options:\n\n";
|
|
27
27
|
md += renderOptions(metadata.options, 3);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// Arguments
|
|
31
|
-
if (metadata.arguments.length) {
|
|
31
|
+
if (metadata.arguments.length > 0) {
|
|
32
32
|
md += "\n## Arguments:\n\n";
|
|
33
33
|
md += renderArguments(metadata.arguments, 3);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// Subcommands
|
|
37
|
-
if (metadata.subcommands.length) {
|
|
37
|
+
if (metadata.subcommands.length > 0) {
|
|
38
38
|
md += "\n## Subcommands:\n\n";
|
|
39
39
|
md += renderSubcommands(metadata.subcommands);
|
|
40
40
|
}
|
|
@@ -46,129 +46,129 @@ export function generateMarkdown(...params: [Cli, ...Subcommand[]]): string {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function renderExamples(examples: string, list = false) {
|
|
49
|
-
let
|
|
49
|
+
let outString = "";
|
|
50
50
|
|
|
51
51
|
const lang = "bash";
|
|
52
52
|
|
|
53
53
|
const listIndent = " ".repeat(list ? 2 : 0);
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
outString += "\n" + (list ? "- " : "");
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
outString += "```" + lang + "\n";
|
|
58
|
+
outString += listIndent + examples.replace(/\n/g, "\n" + listIndent);
|
|
59
|
+
outString += "\n" + listIndent + "```\n";
|
|
60
60
|
|
|
61
|
-
return
|
|
61
|
+
return outString;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
function renderOptions(optionsMetadata: OptionMetadata[] = [], h: number) {
|
|
65
|
-
let
|
|
65
|
+
let outString = "";
|
|
66
66
|
|
|
67
|
-
for (let
|
|
68
|
-
const metadata = optionsMetadata[
|
|
67
|
+
for (let index = 0; index < optionsMetadata.length; index++) {
|
|
68
|
+
const metadata = optionsMetadata[index];
|
|
69
69
|
|
|
70
70
|
const aliases = [metadata.nameAsArg].concat(metadata.aliasesAsArgs).join(", ");
|
|
71
71
|
|
|
72
72
|
const placeholder = metadata.placeholder && ` ${metadata.placeholder}`;
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
outString += `${"#".repeat(h)} \`${aliases + placeholder}\``;
|
|
75
75
|
|
|
76
76
|
if (metadata.optional) {
|
|
77
|
-
|
|
77
|
+
outString += " **[optional]**";
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
outString += "\n\n";
|
|
81
81
|
|
|
82
82
|
if (metadata.description) {
|
|
83
|
-
|
|
83
|
+
outString += `- ${metadata.description.replace(/(\n+)/g, " $1 ")}\n`;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
if (
|
|
87
|
-
|
|
86
|
+
if (metadata.defaultValue !== undefined) {
|
|
87
|
+
outString += `- **default:** \`${metadata.defaultValueAsString}\`\n`;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
if (metadata.example) {
|
|
91
|
-
|
|
91
|
+
outString += renderExamples(metadata.example, true);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
if (
|
|
95
|
-
|
|
94
|
+
if (index < optionsMetadata.length - 1) {
|
|
95
|
+
outString += "\n";
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
return
|
|
99
|
+
return outString;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
function renderArguments(
|
|
103
|
-
let
|
|
102
|
+
function renderArguments(argumentsMetadata: ArgumentMetadata[] = [], h: number) {
|
|
103
|
+
let outString = "";
|
|
104
104
|
|
|
105
|
-
for (let
|
|
106
|
-
const metadata =
|
|
105
|
+
for (let index = 0; index < argumentsMetadata.length; index++) {
|
|
106
|
+
const metadata = argumentsMetadata[index];
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
outString += `${"#".repeat(h)} \`${metadata.name}\``;
|
|
109
109
|
|
|
110
110
|
if (metadata.optional) {
|
|
111
|
-
|
|
111
|
+
outString += " **[optional]**";
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
outString += "\n\n";
|
|
115
115
|
|
|
116
116
|
if (metadata.description) {
|
|
117
|
-
|
|
117
|
+
outString += `- ${metadata.description.replace(/(\n+)/g, " $1 ")}\n`;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
if (
|
|
121
|
-
|
|
120
|
+
if (metadata.defaultValue !== undefined) {
|
|
121
|
+
outString += `- **default:** \`${metadata.defaultValueAsString}\`\n`;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
if (metadata.example) {
|
|
125
|
-
|
|
125
|
+
outString += renderExamples(metadata.example);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
if (
|
|
129
|
-
|
|
128
|
+
if (index < argumentsMetadata.length - 1) {
|
|
129
|
+
outString += "\n";
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
return
|
|
133
|
+
return outString;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
function renderSubcommands(subcommandsMetadata: SubcommandMetadata[]) {
|
|
137
|
-
let
|
|
137
|
+
let outString = "";
|
|
138
138
|
|
|
139
|
-
for (let
|
|
140
|
-
const metadata = subcommandsMetadata[
|
|
139
|
+
for (let index = 0; index < subcommandsMetadata.length; index++) {
|
|
140
|
+
const metadata = subcommandsMetadata[index];
|
|
141
141
|
|
|
142
142
|
const aliases = [metadata.name].concat(metadata.aliases).join(", ");
|
|
143
143
|
|
|
144
144
|
const placeholder = metadata.placeholder && ` ${metadata.placeholder}`;
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
outString += `### ${aliases + placeholder}\n\n`;
|
|
147
147
|
|
|
148
148
|
if (metadata.description) {
|
|
149
|
-
|
|
149
|
+
outString += `${metadata.description}\n`;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
if (metadata.example) {
|
|
153
|
-
|
|
153
|
+
outString += renderExamples(metadata.example);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
if (metadata.options.length) {
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
if (metadata.options.length > 0) {
|
|
157
|
+
outString += "\n#### Options:\n\n";
|
|
158
|
+
outString += renderOptions(metadata.options, 4);
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
if (metadata.arguments.length) {
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
if (metadata.arguments.length > 0) {
|
|
162
|
+
outString += "\n#### Arguments:\n\n";
|
|
163
|
+
outString += renderArguments(metadata.arguments, 4);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
if (
|
|
167
|
-
|
|
166
|
+
if (index < subcommandsMetadata.length - 1) {
|
|
167
|
+
outString += "\n---\n\n";
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
return
|
|
171
|
+
return outString;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
function escapeHtmlTags(markdown: string) {
|
|
@@ -186,13 +186,13 @@ function escapeHtmlTags(markdown: string) {
|
|
|
186
186
|
/** Credits: https://github.com/chalk/ansi-regex */
|
|
187
187
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
188
188
|
// Valid string terminator sequences are BEL, ESC\, and 0x9c
|
|
189
|
-
const ST =
|
|
189
|
+
const ST = String.raw`(?:\u0007|\u001B\u005C|\u009C)`;
|
|
190
190
|
|
|
191
191
|
// OSC sequences only: ESC ] ... ST (non-greedy until the first ST)
|
|
192
192
|
const osc = `(?:\\u001B\\][\\s\\S]*?${ST})`;
|
|
193
193
|
|
|
194
194
|
// CSI and related: ESC/C1, optional intermediates, optional params (supports ; and :) then final byte
|
|
195
|
-
const csi =
|
|
195
|
+
const csi = String.raw`[\u001B\u009B][[\]()#;?]*(?:\d{1,4}(?:[;:]\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]`;
|
|
196
196
|
|
|
197
197
|
const pattern = `${osc}|${csi}`;
|
|
198
198
|
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { stringifyValue } from "../
|
|
2
|
-
import { isOptionalSchema, schemaDefaultValue, schemaDescription } from "../zod-
|
|
1
|
+
import { stringifyValue } from "../utilities.js";
|
|
2
|
+
import { isOptionalSchema, schemaDefaultValue, schemaDescription } from "../zod-utilities.js";
|
|
3
3
|
|
|
4
4
|
import type { Argument } from "../types.js";
|
|
5
5
|
import type { ArgumentMetadata } from "./metadata-types.js";
|
|
6
6
|
|
|
7
|
-
export function getArgumentsMetadata(
|
|
7
|
+
export function getArgumentsMetadata(arguments_: Argument[]): ArgumentMetadata[] {
|
|
8
8
|
const outputMetadata: ArgumentMetadata[] = [];
|
|
9
9
|
|
|
10
|
-
for (const
|
|
11
|
-
const defaultValue = schemaDefaultValue(
|
|
10
|
+
for (const argument of arguments_) {
|
|
11
|
+
const defaultValue = schemaDefaultValue(argument.type);
|
|
12
12
|
|
|
13
13
|
outputMetadata.push({
|
|
14
|
-
name:
|
|
15
|
-
description:
|
|
14
|
+
name: argument.name,
|
|
15
|
+
description: argument.description ?? schemaDescription(argument.type) ?? "",
|
|
16
16
|
defaultValue,
|
|
17
17
|
defaultValueAsString: stringifyValue(defaultValue),
|
|
18
|
-
optional: isOptionalSchema(
|
|
19
|
-
example:
|
|
20
|
-
type:
|
|
18
|
+
optional: isOptionalSchema(argument.type),
|
|
19
|
+
example: argument.example ?? "",
|
|
20
|
+
type: argument.type,
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { stringifyValue } from "../
|
|
3
|
-
import { isOptionalSchema, schemaDefaultValue, schemaDescription } from "../zod-
|
|
1
|
+
import { transformOptionToArgument } from "../parser/parse/parser-helpers.js";
|
|
2
|
+
import { stringifyValue } from "../utilities.js";
|
|
3
|
+
import { isOptionalSchema, schemaDefaultValue, schemaDescription } from "../zod-utilities.js";
|
|
4
4
|
|
|
5
5
|
import type { Option } from "../types.js";
|
|
6
6
|
import type { OptionMetadata } from "./metadata-types.js";
|
|
@@ -8,7 +8,9 @@ import type { OptionMetadata } from "./metadata-types.js";
|
|
|
8
8
|
export function getOptionsMetadata(options: Option[]): OptionMetadata[] {
|
|
9
9
|
const outputMetadata: OptionMetadata[] = [];
|
|
10
10
|
|
|
11
|
-
if (!options ||
|
|
11
|
+
if (!options || options.length === 0) {
|
|
12
|
+
return outputMetadata;
|
|
13
|
+
}
|
|
12
14
|
|
|
13
15
|
for (const option of options) {
|
|
14
16
|
const defaultValue = schemaDefaultValue(option.type);
|
|
@@ -16,9 +18,9 @@ export function getOptionsMetadata(options: Option[]): OptionMetadata[] {
|
|
|
16
18
|
|
|
17
19
|
outputMetadata.push({
|
|
18
20
|
name: option.name,
|
|
19
|
-
nameAsArg:
|
|
21
|
+
nameAsArg: transformOptionToArgument(option.name),
|
|
20
22
|
aliases,
|
|
21
|
-
aliasesAsArgs: aliases.map(
|
|
23
|
+
aliasesAsArgs: aliases.map(alias => transformOptionToArgument(alias)),
|
|
22
24
|
placeholder: option.placeholder ?? "",
|
|
23
25
|
description: option.description ?? schemaDescription(option.type) ?? "",
|
|
24
26
|
optional: isOptionalSchema(option.type),
|
|
@@ -7,7 +7,9 @@ import type { SubcommandMetadata } from "./metadata-types.js";
|
|
|
7
7
|
export function getSubcommandsMetadata(subcommands: Subcommand[]): SubcommandMetadata[] {
|
|
8
8
|
const outputMetadata: SubcommandMetadata[] = [];
|
|
9
9
|
|
|
10
|
-
if (!subcommands ||
|
|
10
|
+
if (!subcommands || subcommands.length === 0) {
|
|
11
|
+
return outputMetadata;
|
|
12
|
+
}
|
|
11
13
|
|
|
12
14
|
for (const subcommand of subcommands) {
|
|
13
15
|
const optionsMetadata = subcommand.options ? getOptionsMetadata(subcommand.options) : [];
|
|
@@ -64,11 +64,11 @@ type ParsedArgument<S extends Schema = Schema> =
|
|
|
64
64
|
source: "default";
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
type
|
|
67
|
+
type OptionsArray2Record<T extends Option[] | undefined> = T extends Option[]
|
|
68
68
|
? { [K in T[number]["name"]]: ParsedOption<Extract<T[number], { name: K }>["type"], K> }
|
|
69
69
|
: Record<never, never>;
|
|
70
70
|
|
|
71
|
-
type
|
|
71
|
+
type ArgumentsArray2ArrayType<T extends Argument[] | undefined> = T extends Argument[]
|
|
72
72
|
? { [K in keyof T]: ParsedArgument<T[K] extends { type: Schema } ? T[K]["type"] : never> }
|
|
73
73
|
: never;
|
|
74
74
|
|
|
@@ -76,14 +76,14 @@ export type ParseResult<S extends Partial<Subcommand>[]> = {
|
|
|
76
76
|
[K in keyof S]: Prettify<{
|
|
77
77
|
subcommand: S[K]["name"] extends string ? S[K]["name"] : undefined;
|
|
78
78
|
positional: S[K]["allowPositional"] extends true ? string[] : never;
|
|
79
|
-
options:
|
|
80
|
-
arguments:
|
|
79
|
+
options: S[K]["options"] extends Option[] ? OptionsArray2Record<S[K]["options"]> : never;
|
|
80
|
+
arguments: ArgumentsArray2ArrayType<S[K]["arguments"]>;
|
|
81
81
|
}>;
|
|
82
82
|
}[number];
|
|
83
83
|
|
|
84
|
-
export type
|
|
84
|
+
export type ParsedContext = {
|
|
85
85
|
subcommand: string | undefined;
|
|
86
|
-
options
|
|
86
|
+
options?: Record<string, ParsedOption>;
|
|
87
87
|
arguments?: ParsedArgument[];
|
|
88
88
|
positional?: string[];
|
|
89
89
|
};
|
|
@@ -1,47 +1,36 @@
|
|
|
1
|
-
import { generateOrdinalSuffix } from "../../
|
|
2
|
-
import { isBooleanSchema, isOptionalSchema, schemaDefaultValue } from "../../zod-
|
|
1
|
+
import { generateOrdinalSuffix } from "../../utilities.js";
|
|
2
|
+
import { isBooleanSchema, isOptionalSchema, schemaDefaultValue } from "../../zod-utilities.js";
|
|
3
3
|
import {
|
|
4
4
|
decoupleFlags,
|
|
5
5
|
findOption,
|
|
6
6
|
findSubcommand,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
isFlagArgument,
|
|
8
|
+
isOptionArgument,
|
|
9
|
+
transformOptionToArgument,
|
|
10
10
|
} from "./parser-helpers.js";
|
|
11
11
|
|
|
12
12
|
import type { Cli, Subcommand } from "../../types.js";
|
|
13
|
-
import type {
|
|
13
|
+
import type { ParsedContext } from "./parse-types.js";
|
|
14
14
|
|
|
15
|
-
export function parse(argv: string[], ...
|
|
16
|
-
const
|
|
17
|
-
const allSubcommands = new Set<string>(
|
|
15
|
+
export function parse(argv: string[], ...parameters: [Cli, ...Subcommand[]]) {
|
|
16
|
+
const subcommandArray = parameters as Subcommand[];
|
|
17
|
+
const allSubcommands = new Set<string>(subcommandArray.flatMap(c => [c.name, ...(c.aliases || [])]));
|
|
18
18
|
|
|
19
19
|
argv = decoupleFlags(argv); // decouple flags E.g. `-rf` -> `-r, -f`
|
|
20
20
|
|
|
21
|
-
const results:
|
|
21
|
+
const results: ParsedContext = {
|
|
22
22
|
subcommand: undefined,
|
|
23
|
-
options: {},
|
|
24
23
|
};
|
|
25
24
|
|
|
26
25
|
/** - Get current subcommand object */
|
|
27
|
-
const
|
|
26
|
+
const getSubcommandObject = () => findSubcommand(results.subcommand, subcommandArray);
|
|
28
27
|
|
|
29
|
-
for (let
|
|
30
|
-
const
|
|
28
|
+
for (let index = 0; index < argv.length; index++) {
|
|
29
|
+
const argument_ = argv[index];
|
|
31
30
|
|
|
32
31
|
// * Subcommand check
|
|
33
|
-
if (
|
|
34
|
-
results.subcommand = allSubcommands.has(
|
|
35
|
-
|
|
36
|
-
// add positional and arguments arrays
|
|
37
|
-
const subcommandObj = getSubcommandObj();
|
|
38
|
-
if (subcommandObj && subcommandObj.allowPositional) {
|
|
39
|
-
results.positional = [];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (subcommandObj && subcommandObj.arguments?.length) {
|
|
43
|
-
results.arguments = [];
|
|
44
|
-
}
|
|
32
|
+
if (index === 0) {
|
|
33
|
+
results.subcommand = allSubcommands.has(argument_) ? argument_ : undefined;
|
|
45
34
|
|
|
46
35
|
// First argument is a subcommand. Skip to the next argument
|
|
47
36
|
if (results.subcommand) continue;
|
|
@@ -50,22 +39,22 @@ export function parse(argv: string[], ...params: [Cli, ...Subcommand[]]) {
|
|
|
50
39
|
// * Option check
|
|
51
40
|
|
|
52
41
|
// Check for `--option=value` or `--option value`
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const argument =
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
if (
|
|
60
|
-
throw new Error(`Flag arguments cannot be assigned using "=": "${
|
|
42
|
+
const argumentAndValue = argument_.split("=").filter(Boolean);
|
|
43
|
+
const argumentWithEquals = argument_.includes("=");
|
|
44
|
+
const argument = argumentAndValue[0];
|
|
45
|
+
const argumentValue: string | undefined = argumentAndValue[1];
|
|
46
|
+
|
|
47
|
+
if (isOptionArgument(argument)) {
|
|
48
|
+
if (isFlagArgument(argument) && argumentWithEquals) {
|
|
49
|
+
throw new Error(`Flag arguments cannot be assigned using "=": "${argument_}"`, { cause: "zod-args-parser" });
|
|
61
50
|
}
|
|
62
51
|
|
|
63
|
-
const
|
|
64
|
-
if (!
|
|
52
|
+
const subcommandObject = getSubcommandObject();
|
|
53
|
+
if (!subcommandObject) {
|
|
65
54
|
throw new Error(`Unknown subcommand: "${results.subcommand}"`, { cause: "zod-args-parser" });
|
|
66
55
|
}
|
|
67
56
|
|
|
68
|
-
if (!
|
|
57
|
+
if (!subcommandObject.options) {
|
|
69
58
|
if (!results.subcommand) {
|
|
70
59
|
throw new Error(`Error: options are not allowed here: "${argument}"`, { cause: "zod-args-parser" });
|
|
71
60
|
}
|
|
@@ -75,35 +64,39 @@ export function parse(argv: string[], ...params: [Cli, ...Subcommand[]]) {
|
|
|
75
64
|
});
|
|
76
65
|
}
|
|
77
66
|
|
|
78
|
-
const option = findOption(argument,
|
|
67
|
+
const option = findOption(argument, subcommandObject.options);
|
|
79
68
|
if (!option) {
|
|
80
69
|
throw new Error(`Unknown option: "${argument}"`, { cause: "zod-args-parser" });
|
|
81
70
|
}
|
|
82
71
|
|
|
83
|
-
if (option.name in results.options) {
|
|
72
|
+
if (results.options && option.name in results.options) {
|
|
84
73
|
throw new Error(`Duplicated option: "${argument}"`, { cause: "zod-args-parser" });
|
|
85
74
|
}
|
|
86
75
|
|
|
87
76
|
const isTypeBoolean = isBooleanSchema(option.type);
|
|
88
|
-
const
|
|
77
|
+
const nextArgument = argv[index + 1];
|
|
89
78
|
|
|
90
|
-
let optionValue: string | boolean =
|
|
79
|
+
let optionValue: string | boolean = argumentWithEquals ? argumentValue : nextArgument;
|
|
91
80
|
|
|
92
81
|
// infer value for boolean options
|
|
93
|
-
if (isTypeBoolean && !
|
|
82
|
+
if (isTypeBoolean && !argumentWithEquals) {
|
|
94
83
|
optionValue = "true";
|
|
95
84
|
}
|
|
96
85
|
|
|
97
|
-
if (
|
|
86
|
+
if (optionValue === undefined) {
|
|
98
87
|
throw new Error(`Expected a value for "${argument}" but got nothing`, { cause: "zod-args-parser" });
|
|
99
88
|
}
|
|
100
89
|
|
|
101
|
-
if (!
|
|
102
|
-
throw new Error(`Expected a value for "${argument}" but got an argument "${
|
|
90
|
+
if (!argumentWithEquals && isOptionArgument(optionValue)) {
|
|
91
|
+
throw new Error(`Expected a value for "${argument}" but got an argument "${nextArgument}"`, {
|
|
103
92
|
cause: "zod-args-parser",
|
|
104
93
|
});
|
|
105
94
|
}
|
|
106
95
|
|
|
96
|
+
if (!results.options) {
|
|
97
|
+
results.options = {};
|
|
98
|
+
}
|
|
99
|
+
|
|
107
100
|
results.options[option.name] = {
|
|
108
101
|
name: option.name,
|
|
109
102
|
schema: option.type,
|
|
@@ -113,29 +106,29 @@ export function parse(argv: string[], ...params: [Cli, ...Subcommand[]]) {
|
|
|
113
106
|
};
|
|
114
107
|
|
|
115
108
|
// Skip to the next argument if it is the current option’s value.
|
|
116
|
-
if (!
|
|
117
|
-
|
|
109
|
+
if (!argumentWithEquals && !isTypeBoolean) {
|
|
110
|
+
index++;
|
|
118
111
|
}
|
|
119
112
|
|
|
120
113
|
continue;
|
|
121
114
|
}
|
|
122
115
|
|
|
123
|
-
const
|
|
116
|
+
const subcommandObject = getSubcommandObject();
|
|
124
117
|
|
|
125
118
|
// * Arguments check
|
|
126
|
-
if (
|
|
119
|
+
if (subcommandObject?.arguments) {
|
|
127
120
|
if (!results.arguments) {
|
|
128
121
|
results.arguments = [];
|
|
129
122
|
}
|
|
130
123
|
|
|
131
|
-
const
|
|
124
|
+
const currentArgumentCount = results.arguments.length;
|
|
132
125
|
|
|
133
126
|
// Any extra arguments are possibly positional
|
|
134
|
-
if (
|
|
135
|
-
const
|
|
127
|
+
if (currentArgumentCount < subcommandObject.arguments.length) {
|
|
128
|
+
const argumentType = subcommandObject.arguments[currentArgumentCount].type;
|
|
136
129
|
results.arguments.push({
|
|
137
|
-
schema:
|
|
138
|
-
rawValue:
|
|
130
|
+
schema: argumentType,
|
|
131
|
+
rawValue: argument_,
|
|
139
132
|
source: "cli",
|
|
140
133
|
});
|
|
141
134
|
continue;
|
|
@@ -143,45 +136,49 @@ export function parse(argv: string[], ...params: [Cli, ...Subcommand[]]) {
|
|
|
143
136
|
}
|
|
144
137
|
|
|
145
138
|
// * Positional check
|
|
146
|
-
if (
|
|
139
|
+
if (subcommandObject?.allowPositional) {
|
|
147
140
|
if (!results.positional) {
|
|
148
141
|
results.positional = [];
|
|
149
142
|
}
|
|
150
143
|
|
|
151
|
-
results.positional.push(
|
|
144
|
+
results.positional.push(argument_);
|
|
152
145
|
continue;
|
|
153
146
|
}
|
|
154
147
|
|
|
155
148
|
// * Unexpected
|
|
156
149
|
if (!results.subcommand) {
|
|
157
|
-
throw new Error(`Unexpected argument "${
|
|
150
|
+
throw new Error(`Unexpected argument "${argument_}": positional arguments are not allowed here`, {
|
|
158
151
|
cause: "zod-args-parser",
|
|
159
152
|
});
|
|
160
153
|
}
|
|
161
154
|
|
|
162
155
|
throw new Error(
|
|
163
|
-
`Unexpected argument "${
|
|
156
|
+
`Unexpected argument "${argument_}": positional arguments are not allowed for subcommand "${results.subcommand}"`,
|
|
164
157
|
{ cause: "zod-args-parser" },
|
|
165
158
|
);
|
|
166
159
|
}
|
|
167
160
|
|
|
168
161
|
// * Check for missing options - set defaults - add `source`
|
|
169
|
-
const
|
|
170
|
-
if (!
|
|
162
|
+
const subcommandObject = getSubcommandObject();
|
|
163
|
+
if (!subcommandObject) {
|
|
171
164
|
throw new Error(`Unknown subcommand: "${results.subcommand}"`, { cause: "zod-args-parser" });
|
|
172
165
|
}
|
|
173
166
|
|
|
174
167
|
// Options
|
|
175
|
-
if (
|
|
176
|
-
|
|
168
|
+
if (subcommandObject.options) {
|
|
169
|
+
if (!results.options) {
|
|
170
|
+
results.options = {};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
for (const option of subcommandObject.options) {
|
|
177
174
|
// option already exists
|
|
178
|
-
if (option.name in results.options) continue;
|
|
175
|
+
if (results.options && option.name in results.options) continue;
|
|
179
176
|
|
|
180
177
|
const optional = isOptionalSchema(option.type);
|
|
181
178
|
const defaultValue = schemaDefaultValue(option.type);
|
|
182
179
|
|
|
183
180
|
if (optional) {
|
|
184
|
-
if (
|
|
181
|
+
if (defaultValue === undefined) {
|
|
185
182
|
continue;
|
|
186
183
|
}
|
|
187
184
|
|
|
@@ -189,24 +186,30 @@ export function parse(argv: string[], ...params: [Cli, ...Subcommand[]]) {
|
|
|
189
186
|
continue;
|
|
190
187
|
}
|
|
191
188
|
|
|
192
|
-
throw new Error(`Missing required option: ${
|
|
189
|
+
throw new Error(`Missing required option: ${transformOptionToArgument(option.name)}`, {
|
|
190
|
+
cause: "zod-args-parser",
|
|
191
|
+
});
|
|
193
192
|
}
|
|
194
193
|
}
|
|
195
194
|
|
|
196
195
|
// Arguments
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
if (subcommandObject.arguments) {
|
|
197
|
+
if (!results.arguments) {
|
|
198
|
+
results.arguments = [];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const currentArgumentCount = results.arguments.length ?? 0;
|
|
202
|
+
const subcommandArgumentCount = subcommandObject.arguments.length;
|
|
200
203
|
|
|
201
204
|
// missing arguments
|
|
202
|
-
if (
|
|
203
|
-
for (let
|
|
204
|
-
const argumentType =
|
|
205
|
+
if (currentArgumentCount < subcommandArgumentCount) {
|
|
206
|
+
for (let index = currentArgumentCount; index < subcommandArgumentCount; index++) {
|
|
207
|
+
const argumentType = subcommandObject.arguments[index].type;
|
|
205
208
|
const optional = isOptionalSchema(argumentType);
|
|
206
209
|
const defaultValue = schemaDefaultValue(argumentType);
|
|
207
210
|
|
|
208
211
|
if (optional) {
|
|
209
|
-
if (
|
|
212
|
+
if (defaultValue === undefined) {
|
|
210
213
|
continue;
|
|
211
214
|
}
|
|
212
215
|
|
|
@@ -216,12 +219,17 @@ export function parse(argv: string[], ...params: [Cli, ...Subcommand[]]) {
|
|
|
216
219
|
continue;
|
|
217
220
|
}
|
|
218
221
|
|
|
219
|
-
throw new Error(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
+
throw new Error(
|
|
223
|
+
`the ${generateOrdinalSuffix(index)} argument is required: "${subcommandObject.arguments[index].name}"`,
|
|
224
|
+
{ cause: "zod-args-parser" },
|
|
225
|
+
);
|
|
222
226
|
}
|
|
223
227
|
}
|
|
224
228
|
}
|
|
225
229
|
|
|
230
|
+
if (subcommandObject.allowPositional && !results.positional) {
|
|
231
|
+
results.positional = [];
|
|
232
|
+
}
|
|
233
|
+
|
|
226
234
|
return results;
|
|
227
235
|
}
|