@shell-shock/core 0.17.5 → 0.17.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/command-validation-logic.cjs +214 -152
- package/dist/components/command-validation-logic.mjs +213 -152
- package/dist/components/command-validation-logic.mjs.map +1 -1
- package/dist/components/docs.cjs +113 -9
- package/dist/components/docs.mjs +109 -9
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/exec-builtin.cjs +36 -1
- package/dist/components/exec-builtin.d.cts.map +1 -1
- package/dist/components/exec-builtin.d.mts.map +1 -1
- package/dist/components/exec-builtin.mjs +35 -1
- package/dist/components/exec-builtin.mjs.map +1 -1
- package/dist/components/helpers.cjs +51 -2
- package/dist/components/helpers.mjs +50 -2
- package/dist/components/helpers.mjs.map +1 -1
- package/dist/components/index.cjs +17 -1
- package/dist/components/index.mjs +9 -9
- package/dist/components/options-parser-logic.cjs +411 -174
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +405 -174
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/state-builtin.cjs +61 -5
- package/dist/components/state-builtin.mjs +60 -5
- package/dist/components/state-builtin.mjs.map +1 -1
- package/dist/components/usage.cjs +46 -3
- package/dist/components/usage.mjs +45 -3
- package/dist/components/usage.mjs.map +1 -1
- package/dist/components/utils-builtin.cjs +68 -3
- package/dist/components/utils-builtin.mjs +67 -3
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/helpers/automd.cjs +28 -13
- package/dist/helpers/automd.mjs +28 -13
- package/dist/helpers/automd.mjs.map +1 -1
- package/dist/index.cjs +11 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/plugin-utils/compute-bin.cjs +50 -0
- package/dist/plugin-utils/compute-bin.d.cts +13 -0
- package/dist/plugin-utils/compute-bin.d.cts.map +1 -0
- package/dist/plugin-utils/compute-bin.d.mts +13 -0
- package/dist/plugin-utils/compute-bin.d.mts.map +1 -0
- package/dist/plugin-utils/compute-bin.mjs +50 -0
- package/dist/plugin-utils/compute-bin.mjs.map +1 -0
- package/dist/plugin-utils/get-command-tree.cjs +50 -0
- package/dist/plugin-utils/get-command-tree.d.cts +15 -1
- package/dist/plugin-utils/get-command-tree.d.cts.map +1 -1
- package/dist/plugin-utils/get-command-tree.d.mts +15 -1
- package/dist/plugin-utils/get-command-tree.d.mts.map +1 -1
- package/dist/plugin-utils/get-command-tree.mjs +49 -1
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +4 -0
- package/dist/plugin-utils/index.d.cts +3 -2
- package/dist/plugin-utils/index.d.mts +3 -2
- package/dist/plugin-utils/index.mjs +3 -2
- package/dist/plugin.cjs +170 -52
- package/dist/plugin.mjs +170 -52
- package/dist/plugin.mjs.map +1 -1
- package/dist/resolver/deepkit.cjs +1 -1
- package/dist/resolver/deepkit.mjs +1 -1
- package/dist/resolver/deepkit.mjs.map +1 -1
- package/dist/types/command.cjs +120 -10
- package/dist/types/command.d.cts +95 -8
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +95 -8
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/command.mjs +109 -10
- package/dist/types/command.mjs.map +1 -1
- package/dist/types/index.cjs +12 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +2 -2
- package/package.json +10 -10
|
@@ -12,39 +12,76 @@ import { ElseClause, ElseIfClause, IfStatement, InterfaceDeclaration, InterfaceM
|
|
|
12
12
|
import { pascalCase } from "@stryke/string-format/pascal-case";
|
|
13
13
|
|
|
14
14
|
//#region src/components/options-parser-logic.tsx
|
|
15
|
+
function __assignType(fn, args) {
|
|
16
|
+
fn.__type = args;
|
|
17
|
+
return fn;
|
|
18
|
+
}
|
|
19
|
+
const __ΩDynamicSegmentsParserLogicProps = [
|
|
20
|
+
"CommandTree",
|
|
21
|
+
"command",
|
|
22
|
+
"The command to generate the dynamic path segments parser logic for. This is used to access the command options and parameters when generating the parser logic for dynamic path segments.",
|
|
23
|
+
"isCaseSensitive",
|
|
24
|
+
"Whether the command options should be parsed in a case-sensitive manner. This will affect how the generated code compares command-line arguments to option names and aliases.",
|
|
25
|
+
"DynamicSegmentsParserLogicProps",
|
|
26
|
+
"P\"w!4\"?#)4$?%Mw&y"
|
|
27
|
+
];
|
|
15
28
|
function DynamicSegmentsParserLogic(props) {
|
|
16
29
|
const { command } = props;
|
|
17
30
|
return createComponent(For, {
|
|
18
31
|
get each() {
|
|
19
32
|
return command.segments ?? [];
|
|
20
33
|
},
|
|
21
|
-
children
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
get children() {
|
|
35
|
+
return __assignType((segment, index) => createComponent(Show, {
|
|
36
|
+
get when() {
|
|
37
|
+
return isDynamicPathSegment(segment);
|
|
38
|
+
},
|
|
39
|
+
get children() {
|
|
40
|
+
return [
|
|
41
|
+
createComponent(VarDeclaration, {
|
|
42
|
+
"let": true,
|
|
43
|
+
get name() {
|
|
44
|
+
return camelCase(getDynamicPathSegmentName(segment));
|
|
45
|
+
},
|
|
46
|
+
type: "string | undefined"
|
|
47
|
+
}),
|
|
48
|
+
createIntrinsic("hbr", {}),
|
|
49
|
+
createComponent(IfStatement, {
|
|
50
|
+
condition: code`args.length > ${2 + index} && args[${2 + index}]`,
|
|
51
|
+
get children() {
|
|
52
|
+
return code`${camelCase(getDynamicPathSegmentName(segment))} = args[${2 + index}];`;
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
createIntrinsic("hbr", {}),
|
|
56
|
+
createIntrinsic("hbr", {})
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
}), [
|
|
60
|
+
"segment",
|
|
61
|
+
"index",
|
|
62
|
+
"",
|
|
63
|
+
"P\"2!\"2\"\"/#"
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
46
66
|
});
|
|
47
67
|
}
|
|
68
|
+
DynamicSegmentsParserLogic.__type = [
|
|
69
|
+
() => __ΩDynamicSegmentsParserLogicProps,
|
|
70
|
+
"props",
|
|
71
|
+
"DynamicSegmentsParserLogic",
|
|
72
|
+
"Pn!2\"\"/#"
|
|
73
|
+
];
|
|
74
|
+
const __ΩArgumentsParserLogicProps = [
|
|
75
|
+
"CommandTree",
|
|
76
|
+
"command",
|
|
77
|
+
"The command to generate the positional parameters parser logic for.",
|
|
78
|
+
"appSpecificEnvPrefix",
|
|
79
|
+
"The environment variable prefix to use for options that have an associated environment variable. This prefix will be used in the generated code to access the environment variables (e.g., `env.${appSpecificEnvPrefix}_OPTION_NAME`).",
|
|
80
|
+
"isCaseSensitive",
|
|
81
|
+
"Whether the command options should be parsed in a case-sensitive manner. This will affect how the generated code compares command-line arguments to option names and aliases.",
|
|
82
|
+
"ArgumentsParserLogicProps",
|
|
83
|
+
"P\"w!4\"?#&4$?%)4&?'Mw(y"
|
|
84
|
+
];
|
|
48
85
|
function ArgumentsParserLogic(props) {
|
|
49
86
|
const { command, appSpecificEnvPrefix, isCaseSensitive } = props;
|
|
50
87
|
return createComponent(Show, {
|
|
@@ -58,7 +95,15 @@ function ArgumentsParserLogic(props) {
|
|
|
58
95
|
name: "optionsIndex",
|
|
59
96
|
type: "number",
|
|
60
97
|
get initializer() {
|
|
61
|
-
return code`Math.max(0, args.slice(${command.segments.length + 1}).findIndex(arg => arg.startsWith("-") && /^(${Object.values(command.options ?? {}).map((option) => `${isCaseSensitive || option.name.length === 1 ? option.name : option.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}${option.alias && option.alias.length > 0 ? "|" : ""}${option.alias?.map((a) => (isCaseSensitive || option.name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", "")) === "?" ? "\\?" : isCaseSensitive || option.name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", "")
|
|
98
|
+
return code`Math.max(0, args.slice(${command.segments.length + 1}).findIndex(arg => arg.startsWith("-") && /^(${Object.values(command.options ?? {}).map(__assignType((option) => `${isCaseSensitive || option.name.length === 1 ? option.name : option.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}${option.alias && option.alias.length > 0 ? "|" : ""}${option.alias?.map(__assignType((a) => (isCaseSensitive || option.name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", "")) === "?" ? "\\?" : isCaseSensitive || option.name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", ""), [
|
|
99
|
+
"a",
|
|
100
|
+
"",
|
|
101
|
+
"P\"2!\"/\""
|
|
102
|
+
])).join("|")}`, [
|
|
103
|
+
"option",
|
|
104
|
+
"",
|
|
105
|
+
"P\"2!\"/\""
|
|
106
|
+
])).join("|")})=?.*$/.test(arg${isCaseSensitive ? "" : ".toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"}))) + ${command.segments.length + 1};`;
|
|
62
107
|
}
|
|
63
108
|
}),
|
|
64
109
|
createComponent(Spacing, {}),
|
|
@@ -67,7 +112,15 @@ function ArgumentsParserLogic(props) {
|
|
|
67
112
|
name: "argsIndex",
|
|
68
113
|
type: "number",
|
|
69
114
|
get initializer() {
|
|
70
|
-
return code`optionsIndex > ${command.segments.length + 1} ? ${command.segments.length + 1} : (Math.max(0, args.slice(optionsIndex).findLastIndex(arg => arg.startsWith("-") && /^(${Object.values(command.options ?? {}).map((option) => `${isCaseSensitive || option.name.length === 1 ? option.name : option.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}${option.alias && option.alias.length > 0 ? "|" : ""}${option.alias?.map((a) => (isCaseSensitive || option.name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", "")) === "?" ? "\\?" : isCaseSensitive || option.name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", "")
|
|
115
|
+
return code`optionsIndex > ${command.segments.length + 1} ? ${command.segments.length + 1} : (Math.max(0, args.slice(optionsIndex).findLastIndex(arg => arg.startsWith("-") && /^(${Object.values(command.options ?? {}).map(__assignType((option) => `${isCaseSensitive || option.name.length === 1 ? option.name : option.name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}${option.alias && option.alias.length > 0 ? "|" : ""}${option.alias?.map(__assignType((a) => (isCaseSensitive || option.name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", "")) === "?" ? "\\?" : isCaseSensitive || option.name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", ""), [
|
|
116
|
+
"a",
|
|
117
|
+
"",
|
|
118
|
+
"P\"2!\"/\""
|
|
119
|
+
])).join("|")}`, [
|
|
120
|
+
"option",
|
|
121
|
+
"",
|
|
122
|
+
"P\"2!\"/\""
|
|
123
|
+
])).join("|")})=?.*$/.test(arg${isCaseSensitive ? "" : ".toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"}))) + ${command.segments.length + 1});`;
|
|
71
124
|
}
|
|
72
125
|
}),
|
|
73
126
|
createComponent(Spacing, {}),
|
|
@@ -76,103 +129,136 @@ function ArgumentsParserLogic(props) {
|
|
|
76
129
|
return command.args ?? [];
|
|
77
130
|
},
|
|
78
131
|
hardline: true,
|
|
79
|
-
children
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
get type() {
|
|
98
|
-
return createComponent(CommandParameterType, { parameter: arg });
|
|
99
|
-
},
|
|
100
|
-
get initializer() {
|
|
101
|
-
return [
|
|
102
|
-
code` ( `,
|
|
103
|
-
createComponent(Show, {
|
|
104
|
-
get when() {
|
|
105
|
-
return isSetString(arg.env);
|
|
106
|
-
},
|
|
107
|
-
get children() {
|
|
108
|
-
return code`env.${appSpecificEnvPrefix}_${constantCase(String(arg.env))} ?? `;
|
|
109
|
-
}
|
|
110
|
-
}),
|
|
111
|
-
createComponent(Show, {
|
|
112
|
-
get when() {
|
|
113
|
-
return arg.default !== void 0;
|
|
114
|
-
},
|
|
115
|
-
get fallback() {
|
|
116
|
-
return arg.variadic ? code`[]` : code`undefined`;
|
|
117
|
-
},
|
|
118
|
-
get children() {
|
|
119
|
-
return arg.kind === CommandParameterKinds.string ? code`"${arg.default}"` : code`${arg.default}`;
|
|
120
|
-
}
|
|
121
|
-
}),
|
|
122
|
-
code`) as `,
|
|
123
|
-
createComponent(CommandParameterType, { parameter: arg }),
|
|
124
|
-
code`; `
|
|
125
|
-
];
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}),
|
|
130
|
-
createComponent(Spacing, {}),
|
|
131
|
-
createComponent(IfStatement, {
|
|
132
|
-
condition: code`argsIndex + ${index} < args.length && argsIndex + ${index} !== optionsIndex`,
|
|
133
|
-
get children() {
|
|
134
|
-
return [
|
|
135
|
-
memo(() => code`${camelCase(arg.name)} = `),
|
|
136
|
-
createComponent(Show, {
|
|
137
|
-
get when() {
|
|
138
|
-
return arg.kind === CommandParameterKinds.string || arg.kind === CommandParameterKinds.number;
|
|
132
|
+
get children() {
|
|
133
|
+
return __assignType((arg, index) => [
|
|
134
|
+
createComponent(Show, {
|
|
135
|
+
get when() {
|
|
136
|
+
return isSetString(arg.env) || arg.default !== void 0 || arg.variadic;
|
|
137
|
+
},
|
|
138
|
+
get fallback() {
|
|
139
|
+
return [
|
|
140
|
+
memo(() => code`let ${camelCase(arg.name)}!: `),
|
|
141
|
+
createComponent(CommandParameterType, { parameter: arg }),
|
|
142
|
+
code`; `
|
|
143
|
+
];
|
|
144
|
+
},
|
|
145
|
+
get children() {
|
|
146
|
+
return createComponent(VarDeclaration, {
|
|
147
|
+
"let": true,
|
|
148
|
+
get name() {
|
|
149
|
+
return camelCase(arg.name);
|
|
139
150
|
},
|
|
140
|
-
get
|
|
141
|
-
return createComponent(
|
|
151
|
+
get type() {
|
|
152
|
+
return createComponent(CommandParameterType, { parameter: arg });
|
|
142
153
|
},
|
|
143
|
-
get
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
154
|
+
get initializer() {
|
|
155
|
+
return [
|
|
156
|
+
code` ( `,
|
|
157
|
+
createComponent(Show, {
|
|
158
|
+
get when() {
|
|
159
|
+
return isSetString(arg.env);
|
|
160
|
+
},
|
|
161
|
+
get children() {
|
|
162
|
+
return code`env.${appSpecificEnvPrefix}_${constantCase(String(arg.env))} ?? `;
|
|
163
|
+
}
|
|
164
|
+
}),
|
|
165
|
+
createComponent(Show, {
|
|
166
|
+
get when() {
|
|
167
|
+
return arg.default !== void 0 && (!arg.variadic || arg.default.length > 0);
|
|
168
|
+
},
|
|
169
|
+
get fallback() {
|
|
170
|
+
return createComponent(Show, {
|
|
171
|
+
get when() {
|
|
172
|
+
return arg.variadic;
|
|
173
|
+
},
|
|
174
|
+
fallback: code`undefined`,
|
|
175
|
+
children: code`[]`
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
get children() {
|
|
179
|
+
return createComponent(Show, {
|
|
180
|
+
get when() {
|
|
181
|
+
return arg.variadic;
|
|
182
|
+
},
|
|
183
|
+
get fallback() {
|
|
184
|
+
return arg.kind === CommandParameterKinds.string ? code`"${arg.default}"` : code`${arg.default}`;
|
|
185
|
+
},
|
|
186
|
+
get children() {
|
|
187
|
+
return code`[${arg.default?.map(__assignType((value) => arg.kind === CommandParameterKinds.string ? `"${value}"` : value, [
|
|
188
|
+
"value",
|
|
189
|
+
"",
|
|
190
|
+
"P\"2!\"/\""
|
|
191
|
+
])).join(", ")}]`;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}),
|
|
196
|
+
code`) as `,
|
|
197
|
+
createComponent(CommandParameterType, { parameter: arg }),
|
|
198
|
+
code`; `
|
|
199
|
+
];
|
|
161
200
|
}
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}),
|
|
204
|
+
createComponent(Spacing, {}),
|
|
205
|
+
createComponent(IfStatement, {
|
|
206
|
+
condition: code`argsIndex + ${index} < args.length && argsIndex + ${index} !== optionsIndex`,
|
|
207
|
+
get children() {
|
|
208
|
+
return [
|
|
209
|
+
memo(() => code`${camelCase(arg.name)} = `),
|
|
210
|
+
createComponent(Show, {
|
|
211
|
+
get when() {
|
|
212
|
+
return arg.kind === CommandParameterKinds.string || arg.kind === CommandParameterKinds.number;
|
|
213
|
+
},
|
|
214
|
+
get fallback() {
|
|
215
|
+
return createComponent(BooleanInputParserLogic, { name: `args[argsIndex + ${index}] ` });
|
|
216
|
+
},
|
|
217
|
+
get children() {
|
|
218
|
+
return createComponent(Show, {
|
|
219
|
+
get when() {
|
|
220
|
+
return arg.variadic;
|
|
221
|
+
},
|
|
222
|
+
get fallback() {
|
|
223
|
+
return createComponent(Show, {
|
|
224
|
+
get when() {
|
|
225
|
+
return arg.kind === CommandParameterKinds.number;
|
|
226
|
+
},
|
|
227
|
+
fallback: code`args[argsIndex + ${index}] `,
|
|
228
|
+
children: code`Number(args[argsIndex + ${index}]) `
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
get children() {
|
|
232
|
+
return code`args.slice(argsIndex + ${index}, (optionsIndex > argsIndex ? optionsIndex : args.length) - ${command.args.length - index}).join(" ").split(",").map(item => item.trim().replace(/^("|')/, "").replace(/("|')$/, "")).filter(Boolean)`;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}),
|
|
237
|
+
code` as `,
|
|
238
|
+
createComponent(CommandParameterType, { parameter: arg }),
|
|
239
|
+
code`; `
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
}),
|
|
243
|
+
createComponent(Spacing, {})
|
|
244
|
+
], [
|
|
245
|
+
"arg",
|
|
246
|
+
"index",
|
|
247
|
+
"",
|
|
248
|
+
"P\"2!\"2\"\"/#"
|
|
249
|
+
]);
|
|
250
|
+
}
|
|
171
251
|
})
|
|
172
252
|
];
|
|
173
253
|
}
|
|
174
254
|
});
|
|
175
255
|
}
|
|
256
|
+
ArgumentsParserLogic.__type = [
|
|
257
|
+
() => __ΩArgumentsParserLogicProps,
|
|
258
|
+
"props",
|
|
259
|
+
"ArgumentsParserLogic",
|
|
260
|
+
"Pn!2\"\"/#"
|
|
261
|
+
];
|
|
176
262
|
/**
|
|
177
263
|
* The command option interface property.
|
|
178
264
|
*/
|
|
@@ -245,12 +331,36 @@ function OptionsMember({ option }) {
|
|
|
245
331
|
}
|
|
246
332
|
})];
|
|
247
333
|
}
|
|
334
|
+
OptionsMember.__type = [
|
|
335
|
+
"CommandOption",
|
|
336
|
+
"option",
|
|
337
|
+
"param0",
|
|
338
|
+
"OptionsMember",
|
|
339
|
+
"The command option interface property.",
|
|
340
|
+
"PP\"w!4\"M2#\"/$?%"
|
|
341
|
+
];
|
|
342
|
+
const __ΩOptionsMemberParserLogicProps = [
|
|
343
|
+
"name",
|
|
344
|
+
"The option name to generate the parser logic for.",
|
|
345
|
+
"CommandOption",
|
|
346
|
+
"option",
|
|
347
|
+
"The command option to generate the parser logic for.",
|
|
348
|
+
"isCaseSensitive",
|
|
349
|
+
true,
|
|
350
|
+
"Whether the command options should be parsed in a case-sensitive manner. This will affect how the generated code compares command-line arguments to option names and aliases.",
|
|
351
|
+
"OptionsMemberParserLogicProps",
|
|
352
|
+
"P&4!?\"\"w#4$?%)4&>'?(Mw)y"
|
|
353
|
+
];
|
|
248
354
|
/**
|
|
249
355
|
* The command option property parser logic.
|
|
250
356
|
*/
|
|
251
357
|
function OptionsMemberParserLogic(props) {
|
|
252
358
|
const { name, option, isCaseSensitive } = props;
|
|
253
|
-
const equalsRegex = `/^--?(${isCaseSensitive || name.length === 1 ? name : name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}${option.alias && option.alias.length > 0 ? "|" : ""}${option.alias?.map((a) => (isCaseSensitive || name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", "")) === "?" ? "\\?" : isCaseSensitive || name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", "")
|
|
359
|
+
const equalsRegex = `/^--?(${isCaseSensitive || name.length === 1 ? name : name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}${option.alias && option.alias.length > 0 ? "|" : ""}${option.alias?.map(__assignType((a) => (isCaseSensitive || name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", "")) === "?" ? "\\?" : isCaseSensitive || name.length === 1 ? a : a.toLowerCase().replaceAll("-", "").replaceAll("_", ""), [
|
|
360
|
+
"a",
|
|
361
|
+
"",
|
|
362
|
+
"P\"2!\"/\""
|
|
363
|
+
])).join("|")})=/`;
|
|
254
364
|
return [createComponent(Show, {
|
|
255
365
|
get when() {
|
|
256
366
|
return option.kind === CommandParameterKinds.string || option.kind === CommandParameterKinds.number;
|
|
@@ -298,7 +408,11 @@ function OptionsMemberParserLogic(props) {
|
|
|
298
408
|
return (option.kind === CommandParameterKinds.string || option.kind === CommandParameterKinds.number) && option.choices && option.choices.length > 0;
|
|
299
409
|
},
|
|
300
410
|
get children() {
|
|
301
|
-
return code` as ${option.choices?.map((choice) => isSetString(choice) ? `"${choice}"` : choice
|
|
411
|
+
return code` as ${option.choices?.map(__assignType((choice) => isSetString(choice) ? `"${choice}"` : choice, [
|
|
412
|
+
"choice",
|
|
413
|
+
"",
|
|
414
|
+
"P\"2!\"/\""
|
|
415
|
+
])).join(" | ")} `;
|
|
302
416
|
}
|
|
303
417
|
}),
|
|
304
418
|
code`); `
|
|
@@ -333,7 +447,11 @@ function OptionsMemberParserLogic(props) {
|
|
|
333
447
|
return (option.kind === CommandParameterKinds.string || option.kind === CommandParameterKinds.number) && option.choices && option.choices.length > 0;
|
|
334
448
|
},
|
|
335
449
|
get children() {
|
|
336
|
-
return code` as ${option.choices?.map((choice) => isSetString(choice) ? `"${choice}"` : choice
|
|
450
|
+
return code` as ${option.choices?.map(__assignType((choice) => isSetString(choice) ? `"${choice}"` : choice, [
|
|
451
|
+
"choice",
|
|
452
|
+
"",
|
|
453
|
+
"P\"2!\"/\""
|
|
454
|
+
])).join(" | ")} `;
|
|
337
455
|
}
|
|
338
456
|
}),
|
|
339
457
|
code`); `
|
|
@@ -370,7 +488,11 @@ function OptionsMemberParserLogic(props) {
|
|
|
370
488
|
return option.choices && option.choices.length > 0;
|
|
371
489
|
},
|
|
372
490
|
get children() {
|
|
373
|
-
return code` as ${option.choices?.map((choice) => `"${choice}"
|
|
491
|
+
return code` as ${option.choices?.map(__assignType((choice) => `"${choice}"`, [
|
|
492
|
+
"choice",
|
|
493
|
+
"",
|
|
494
|
+
"P\"2!\"/\""
|
|
495
|
+
])).join(" | ")}`;
|
|
374
496
|
}
|
|
375
497
|
}),
|
|
376
498
|
code`; `
|
|
@@ -439,7 +561,11 @@ function OptionsMemberParserLogic(props) {
|
|
|
439
561
|
return option.choices && option.choices.length > 0;
|
|
440
562
|
},
|
|
441
563
|
get children() {
|
|
442
|
-
return code` as ${option.choices?.map((choice) => `"${choice}"
|
|
564
|
+
return code` as ${option.choices?.map(__assignType((choice) => `"${choice}"`, [
|
|
565
|
+
"choice",
|
|
566
|
+
"",
|
|
567
|
+
"P\"2!\"/\""
|
|
568
|
+
])).join(" | ")}`;
|
|
443
569
|
}
|
|
444
570
|
}),
|
|
445
571
|
code`; `
|
|
@@ -549,6 +675,24 @@ function OptionsMemberParserLogic(props) {
|
|
|
549
675
|
}
|
|
550
676
|
})];
|
|
551
677
|
}
|
|
678
|
+
OptionsMemberParserLogic.__type = [
|
|
679
|
+
() => __ΩOptionsMemberParserLogicProps,
|
|
680
|
+
"props",
|
|
681
|
+
"OptionsMemberParserLogic",
|
|
682
|
+
"The command option property parser logic.",
|
|
683
|
+
"Pn!2\"\"/#?$"
|
|
684
|
+
];
|
|
685
|
+
const __ΩOptionsMemberParserConditionProps = [
|
|
686
|
+
"name",
|
|
687
|
+
"The option name to generate the parser logic for.",
|
|
688
|
+
"alias",
|
|
689
|
+
"Aliases for the option, which will also be parsed in the generated code. This will affect how the generated code compares command-line arguments to option names and aliases.",
|
|
690
|
+
"isCaseSensitive",
|
|
691
|
+
true,
|
|
692
|
+
"Whether the command options should be parsed in a case-sensitive manner. This will affect how the generated code compares command-line arguments to option names and aliases.",
|
|
693
|
+
"OptionsMemberParserConditionProps",
|
|
694
|
+
"P&4!?\"&F4#8?$)4%>&?'Mw(y"
|
|
695
|
+
];
|
|
552
696
|
function OptionsMemberParserCondition(props) {
|
|
553
697
|
const { name, alias: aliasProp, isCaseSensitive } = props;
|
|
554
698
|
return [memo(() => code`${isCaseSensitive ? "arg.startsWith(\"--" : "arg.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\").startsWith(\""}${isCaseSensitive ? name : name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}=") || ${isCaseSensitive ? "arg" : "arg.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${isCaseSensitive ? name : name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}" || ${isCaseSensitive ? "arg.startsWith(\"-" : "arg.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\").startsWith(\""}${isCaseSensitive ? name : name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}=") || ${isCaseSensitive ? "arg" : "arg.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${isCaseSensitive ? name : name.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"`), createComponent(Show, {
|
|
@@ -558,17 +702,33 @@ function OptionsMemberParserCondition(props) {
|
|
|
558
702
|
get children() {
|
|
559
703
|
return createComponent(For, {
|
|
560
704
|
each: aliasProp ?? [],
|
|
561
|
-
children
|
|
705
|
+
get children() {
|
|
706
|
+
return __assignType((alias) => code` || ${isCaseSensitive || alias.length === 1 ? "arg.startsWith(\"--" : "arg.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\").startsWith(\""}${isCaseSensitive || alias.length === 1 ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}=") || ${isCaseSensitive || alias.length === 1 ? "arg" : "arg.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${isCaseSensitive || alias.length === 1 ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}" || ${isCaseSensitive || alias.length === 1 ? "arg.startsWith(\"-" : "arg.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\").startsWith(\""}${isCaseSensitive || alias.length === 1 ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}=") || ${isCaseSensitive || alias.length === 1 ? "arg" : "arg.toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${isCaseSensitive || alias.length === 1 ? alias : alias.toLowerCase().replaceAll("-", "").replaceAll("_", "")}"`, [
|
|
707
|
+
"alias",
|
|
708
|
+
"",
|
|
709
|
+
"P\"2!\"/\""
|
|
710
|
+
]);
|
|
711
|
+
}
|
|
562
712
|
});
|
|
563
713
|
}
|
|
564
714
|
})];
|
|
565
715
|
}
|
|
716
|
+
OptionsMemberParserCondition.__type = [
|
|
717
|
+
() => __ΩOptionsMemberParserConditionProps,
|
|
718
|
+
"props",
|
|
719
|
+
"OptionsMemberParserCondition",
|
|
720
|
+
"Pn!2\"\"/#"
|
|
721
|
+
];
|
|
566
722
|
function OptionsInterfaceDeclaration(props) {
|
|
567
723
|
const { command } = props;
|
|
568
|
-
const options = computed(() => computedOptions(Object.entries(command.options).map(([name, option]) => ({
|
|
724
|
+
const options = computed(() => computedOptions(Object.entries(command.options).map(__assignType(([name, option]) => ({
|
|
569
725
|
...option,
|
|
570
726
|
name
|
|
571
|
-
})
|
|
727
|
+
}), [
|
|
728
|
+
"param0",
|
|
729
|
+
"",
|
|
730
|
+
"P\"2!\"/\""
|
|
731
|
+
]))));
|
|
572
732
|
return createComponent(InterfaceDeclaration, {
|
|
573
733
|
"export": true,
|
|
574
734
|
get name() {
|
|
@@ -581,37 +741,75 @@ function OptionsInterfaceDeclaration(props) {
|
|
|
581
741
|
return Object.values(options.value);
|
|
582
742
|
},
|
|
583
743
|
hardline: true,
|
|
584
|
-
children
|
|
744
|
+
get children() {
|
|
745
|
+
return __assignType((option) => createComponent(OptionsMember, { option }), [
|
|
746
|
+
"option",
|
|
747
|
+
"",
|
|
748
|
+
"P\"2!\"/\""
|
|
749
|
+
]);
|
|
750
|
+
}
|
|
585
751
|
});
|
|
586
752
|
}
|
|
587
753
|
});
|
|
588
754
|
}
|
|
755
|
+
OptionsInterfaceDeclaration.__type = [
|
|
756
|
+
"CommandTree",
|
|
757
|
+
"command",
|
|
758
|
+
"props",
|
|
759
|
+
"OptionsInterfaceDeclaration",
|
|
760
|
+
"PP\"w!4\"M2#\"/$"
|
|
761
|
+
];
|
|
762
|
+
const __ΩOptionsParserLogicProps = [
|
|
763
|
+
"appSpecificEnvPrefix",
|
|
764
|
+
"The environment variable prefix to use for options that have an associated environment variable. This prefix will be used in the generated code to access the environment variables (e.g., `env.${appSpecificEnvPrefix}_OPTION_NAME`).",
|
|
765
|
+
"isCaseSensitive",
|
|
766
|
+
true,
|
|
767
|
+
"Whether the command options should be parsed in a case-sensitive manner. This will affect how the generated code compares command-line arguments to option names and aliases.",
|
|
768
|
+
"OptionsParserLogicProps",
|
|
769
|
+
"P!&4!?\")4#8>$?%Mw&y"
|
|
770
|
+
];
|
|
589
771
|
/**
|
|
590
772
|
* The command options parser logic.
|
|
591
773
|
*/
|
|
592
774
|
function OptionsParserLogic(props) {
|
|
593
775
|
const { segments = [], options: _options, name: _name, appSpecificEnvPrefix, isCaseSensitive = false } = props;
|
|
594
|
-
const options = computed(() => computedOptions(Object.entries(_options).map(([name, option]) => ({
|
|
776
|
+
const options = computed(() => computedOptions(Object.entries(_options).map(__assignType(([name, option]) => ({
|
|
595
777
|
...option,
|
|
596
778
|
name
|
|
597
|
-
})
|
|
779
|
+
}), [
|
|
780
|
+
"param0",
|
|
781
|
+
"",
|
|
782
|
+
"P\"2!\"/\""
|
|
783
|
+
]))));
|
|
598
784
|
return [
|
|
599
785
|
createComponent(VarDeclaration, {
|
|
600
786
|
"const": true,
|
|
601
787
|
name: "options",
|
|
602
788
|
get initializer() {
|
|
603
789
|
return code` {
|
|
604
|
-
${segments.length > 0 ? "...useGlobalOptions(), " : ""}${Object.entries(options.value).filter(([, option]) => option.env || option.default !== void 0 || (option.kind === CommandParameterKinds.string || option.kind === CommandParameterKinds.number) && option.variadic
|
|
790
|
+
${segments.length > 0 ? "...useGlobalOptions(), " : ""}${Object.entries(options.value).filter(__assignType(([, option]) => option.env || option.default !== void 0 || (option.kind === CommandParameterKinds.string || option.kind === CommandParameterKinds.number) && option.variadic, [
|
|
791
|
+
"param0",
|
|
792
|
+
"",
|
|
793
|
+
"P\"2!\"/\""
|
|
794
|
+
])).map(__assignType(([name, option]) => {
|
|
605
795
|
if (option.kind === CommandParameterKinds.string) return ` ${name.includes("?") || name.includes("-") ? `"${name}"` : `${name}`}: ${option.env ? `env.${appSpecificEnvPrefix}_${option.env}` : ""}${option.variadic ? option.default !== void 0 ? `${option.env ? " ?? " : ""}${JSON.stringify(option.default)}` : option.env ? " ?? []" : "[]" : option.default !== void 0 ? `${option.env ? " ?? " : ""}"${option.default}"` : ""}, `;
|
|
606
796
|
else if (option.kind === CommandParameterKinds.number) return ` ${name.includes("?") || name.includes("-") ? `"${name}"` : `${name}`}: ${option.env ? `env.${appSpecificEnvPrefix}_${option.env}` : ""}${option.variadic ? option.default && Array.isArray(option.default) ? `${option.env ? " ?? " : ""}${JSON.stringify(option.default)}` : option.env ? " ?? []" : "[]" : option.default !== void 0 ? `${option.env ? " ?? " : ""}${option.default}` : ""}, `;
|
|
607
797
|
else if (option.kind === CommandParameterKinds.boolean) return ` ${name.includes("?") || name.includes("-") ? `"${name}"` : `${name}`}: ${option.env ? `env.${appSpecificEnvPrefix}_${option.env} ?? ` : ""}${option.default ? "true" : "false"},`;
|
|
608
798
|
return "";
|
|
609
|
-
}
|
|
799
|
+
}, [
|
|
800
|
+
"param0",
|
|
801
|
+
"",
|
|
802
|
+
"P\"2!\"/\""
|
|
803
|
+
])).join("")}
|
|
610
804
|
} as unknown as ${segments.length > 0 ? pascalCase(_name) : "Global"}Options;`;
|
|
611
805
|
}
|
|
612
806
|
}),
|
|
613
807
|
createComponent(Spacing, {}),
|
|
614
|
-
memo(() => code`for (let i = 0; i < args.slice(${segments.filter((segment) => isDynamicPathSegment(segment)
|
|
808
|
+
memo(() => code`for (let i = 0; i < args.slice(${segments.filter(__assignType((segment) => isDynamicPathSegment(segment), [
|
|
809
|
+
"segment",
|
|
810
|
+
"",
|
|
811
|
+
"P\"2!\"/\""
|
|
812
|
+
])).length}).length; i++) { `),
|
|
615
813
|
createIntrinsic("hbr", {}),
|
|
616
814
|
createComponent(VarDeclaration, {
|
|
617
815
|
"const": true,
|
|
@@ -629,55 +827,81 @@ function OptionsParserLogic(props) {
|
|
|
629
827
|
return Object.entries(options.value);
|
|
630
828
|
},
|
|
631
829
|
hardline: true,
|
|
632
|
-
children
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
830
|
+
get children() {
|
|
831
|
+
return __assignType(([name, option], i) => createComponent(Show, {
|
|
832
|
+
when: i === 0,
|
|
833
|
+
get fallback() {
|
|
834
|
+
return createComponent(ElseIfClause, {
|
|
835
|
+
get condition() {
|
|
836
|
+
return [createComponent(OptionsMemberParserCondition, {
|
|
837
|
+
name,
|
|
838
|
+
get alias() {
|
|
839
|
+
return option.alias;
|
|
840
|
+
},
|
|
841
|
+
isCaseSensitive
|
|
842
|
+
})];
|
|
843
|
+
},
|
|
844
|
+
get children() {
|
|
845
|
+
return createComponent(OptionsMemberParserLogic, {
|
|
846
|
+
name,
|
|
847
|
+
option,
|
|
848
|
+
isCaseSensitive
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
},
|
|
853
|
+
get children() {
|
|
854
|
+
return createComponent(IfStatement, {
|
|
855
|
+
get condition() {
|
|
856
|
+
return createComponent(OptionsMemberParserCondition, {
|
|
857
|
+
name,
|
|
858
|
+
get alias() {
|
|
859
|
+
return option.alias;
|
|
860
|
+
},
|
|
861
|
+
isCaseSensitive
|
|
862
|
+
});
|
|
863
|
+
},
|
|
864
|
+
get children() {
|
|
865
|
+
return createComponent(OptionsMemberParserLogic, {
|
|
866
|
+
name,
|
|
867
|
+
option,
|
|
868
|
+
isCaseSensitive
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
}), [
|
|
874
|
+
"param0",
|
|
875
|
+
"i",
|
|
876
|
+
"",
|
|
877
|
+
"P\"2!\"2\"\"/#"
|
|
878
|
+
]);
|
|
879
|
+
}
|
|
675
880
|
}),
|
|
676
881
|
createIntrinsic("hbr", {}),
|
|
677
882
|
code` } `,
|
|
678
883
|
createIntrinsic("hbr", {})
|
|
679
884
|
];
|
|
680
885
|
}
|
|
886
|
+
OptionsParserLogic.__type = [
|
|
887
|
+
() => __ΩOptionsParserLogicProps,
|
|
888
|
+
"props",
|
|
889
|
+
"OptionsParserLogic",
|
|
890
|
+
"The command options parser logic.",
|
|
891
|
+
"Pn!2\"\"/#?$"
|
|
892
|
+
];
|
|
893
|
+
const __ΩCommandParserLogicProps = [
|
|
894
|
+
"CommandTree",
|
|
895
|
+
"command",
|
|
896
|
+
"The command to generate the parser logic for.",
|
|
897
|
+
"appSpecificEnvPrefix",
|
|
898
|
+
"The environment variable prefix to use for options that have an associated environment variable. This prefix will be used in the generated code to access the environment variables (e.g., `env.${appSpecificEnvPrefix}_OPTION_NAME`).",
|
|
899
|
+
"isCaseSensitive",
|
|
900
|
+
true,
|
|
901
|
+
"Whether the command options should be parsed in a case-sensitive manner. This will affect how the generated code compares command-line arguments to option names and aliases.",
|
|
902
|
+
"CommandParserLogicProps",
|
|
903
|
+
"P\"w!4\"?#&4$?%)4&8>'?(Mw)y"
|
|
904
|
+
];
|
|
681
905
|
/**
|
|
682
906
|
* The command parser logic, which includes parsing dynamic path segments, positional parameters, and options.
|
|
683
907
|
*/
|
|
@@ -711,7 +935,14 @@ function CommandParserLogic(props) {
|
|
|
711
935
|
createComponent(Spacing, {})
|
|
712
936
|
];
|
|
713
937
|
}
|
|
938
|
+
CommandParserLogic.__type = [
|
|
939
|
+
() => __ΩCommandParserLogicProps,
|
|
940
|
+
"props",
|
|
941
|
+
"CommandParserLogic",
|
|
942
|
+
"The command parser logic, which includes parsing dynamic path segments, positional parameters, and options.",
|
|
943
|
+
"Pn!2\"\"/#?$"
|
|
944
|
+
];
|
|
714
945
|
|
|
715
946
|
//#endregion
|
|
716
|
-
export { ArgumentsParserLogic, CommandParserLogic, DynamicSegmentsParserLogic, OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserCondition, OptionsMemberParserLogic, OptionsParserLogic };
|
|
947
|
+
export { ArgumentsParserLogic, CommandParserLogic, DynamicSegmentsParserLogic, OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserCondition, OptionsMemberParserLogic, OptionsParserLogic, __ΩArgumentsParserLogicProps, __ΩCommandParserLogicProps, __ΩDynamicSegmentsParserLogicProps, __ΩOptionsMemberParserConditionProps, __ΩOptionsMemberParserLogicProps, __ΩOptionsParserLogicProps };
|
|
717
948
|
//# sourceMappingURL=options-parser-logic.mjs.map
|