@shell-shock/preset-script 0.3.1 → 0.3.3

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.
Files changed (84) hide show
  1. package/README.md +1 -1
  2. package/dist/components/banner-function-declaration.cjs +68 -0
  3. package/dist/components/banner-function-declaration.cjs.map +1 -0
  4. package/dist/components/banner-function-declaration.d.cts +19 -0
  5. package/dist/components/banner-function-declaration.d.cts.map +1 -0
  6. package/dist/components/banner-function-declaration.d.mts +19 -0
  7. package/dist/components/banner-function-declaration.d.mts.map +1 -0
  8. package/dist/components/banner-function-declaration.mjs +67 -0
  9. package/dist/components/banner-function-declaration.mjs.map +1 -0
  10. package/dist/components/bin-entry.cjs +1 -1
  11. package/dist/components/bin-entry.mjs +1 -1
  12. package/dist/components/command-entry.cjs +28 -18
  13. package/dist/components/command-entry.cjs.map +1 -1
  14. package/dist/components/command-entry.d.cts +5 -5
  15. package/dist/components/command-entry.d.cts.map +1 -1
  16. package/dist/components/command-entry.d.mts +4 -4
  17. package/dist/components/command-entry.d.mts.map +1 -1
  18. package/dist/components/command-entry.mjs +27 -17
  19. package/dist/components/command-entry.mjs.map +1 -1
  20. package/dist/components/command-router.cjs +8 -29
  21. package/dist/components/command-router.cjs.map +1 -1
  22. package/dist/components/command-router.mjs +8 -29
  23. package/dist/components/command-router.mjs.map +1 -1
  24. package/dist/components/console-builtin.cjs +10 -66
  25. package/dist/components/console-builtin.cjs.map +1 -1
  26. package/dist/components/console-builtin.d.cts +2 -11
  27. package/dist/components/console-builtin.d.cts.map +1 -1
  28. package/dist/components/console-builtin.d.mts +2 -11
  29. package/dist/components/console-builtin.d.mts.map +1 -1
  30. package/dist/components/console-builtin.mjs +12 -67
  31. package/dist/components/console-builtin.mjs.map +1 -1
  32. package/dist/components/help.cjs +75 -9
  33. package/dist/components/help.cjs.map +1 -1
  34. package/dist/components/help.d.cts +15 -1
  35. package/dist/components/help.d.cts.map +1 -1
  36. package/dist/components/help.d.mts +20 -6
  37. package/dist/components/help.d.mts.map +1 -1
  38. package/dist/components/help.mjs +75 -10
  39. package/dist/components/help.mjs.map +1 -1
  40. package/dist/components/index.cjs +3 -8
  41. package/dist/components/index.d.cts +4 -4
  42. package/dist/components/index.d.mts +4 -4
  43. package/dist/components/index.mjs +4 -4
  44. package/dist/components/utils-builtin.cjs +2 -2
  45. package/dist/components/utils-builtin.cjs.map +1 -1
  46. package/dist/components/utils-builtin.d.cts +7 -7
  47. package/dist/components/utils-builtin.d.mts +7 -7
  48. package/dist/components/utils-builtin.mjs +2 -2
  49. package/dist/components/utils-builtin.mjs.map +1 -1
  50. package/dist/components/virtual-command-entry.cjs +3 -3
  51. package/dist/components/virtual-command-entry.cjs.map +1 -1
  52. package/dist/components/virtual-command-entry.d.cts +4 -4
  53. package/dist/components/virtual-command-entry.d.mts +3 -3
  54. package/dist/components/virtual-command-entry.d.mts.map +1 -1
  55. package/dist/components/virtual-command-entry.mjs +3 -3
  56. package/dist/components/virtual-command-entry.mjs.map +1 -1
  57. package/dist/contexts/theme.cjs +2 -2
  58. package/dist/contexts/theme.cjs.map +1 -1
  59. package/dist/helpers/ansi-utils.cjs +3 -0
  60. package/dist/helpers/ansi-utils.d.cts +8 -1
  61. package/dist/helpers/ansi-utils.d.cts.map +1 -1
  62. package/dist/helpers/ansi-utils.d.mts +8 -1
  63. package/dist/helpers/ansi-utils.d.mts.map +1 -1
  64. package/dist/helpers/ansi-utils.mjs +1 -1
  65. package/dist/helpers/get-default-options.d.cts +13 -0
  66. package/dist/helpers/get-default-options.d.cts.map +1 -0
  67. package/dist/helpers/get-default-options.d.mts +13 -0
  68. package/dist/helpers/get-default-options.d.mts.map +1 -0
  69. package/dist/index.cjs +20 -53
  70. package/dist/index.cjs.map +1 -1
  71. package/dist/index.d.cts.map +1 -1
  72. package/dist/index.d.mts.map +1 -1
  73. package/dist/index.mjs +19 -52
  74. package/dist/index.mjs.map +1 -1
  75. package/dist/types/plugin.d.mts.map +1 -1
  76. package/package.json +47 -20
  77. package/dist/components/args-parser-logic.cjs +0 -678
  78. package/dist/components/args-parser-logic.cjs.map +0 -1
  79. package/dist/components/args-parser-logic.d.cts +0 -45
  80. package/dist/components/args-parser-logic.d.cts.map +0 -1
  81. package/dist/components/args-parser-logic.d.mts +0 -45
  82. package/dist/components/args-parser-logic.d.mts.map +0 -1
  83. package/dist/components/args-parser-logic.mjs +0 -672
  84. package/dist/components/args-parser-logic.mjs.map +0 -1
@@ -1,672 +0,0 @@
1
- import { createComponent, createIntrinsic, memo } from "@alloy-js/core/jsx-runtime";
2
- import { For, Show, code } from "@alloy-js/core";
3
- import { ElseClause, ElseIfClause, IfStatement, InterfaceDeclaration, InterfaceMember, VarDeclaration } from "@alloy-js/typescript";
4
- import { getVariableCommandPathName, isVariableCommandPath } from "@shell-shock/core/plugin-utils/context-helpers";
5
- import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
6
- import { pascalCase } from "@stryke/string-format/pascal-case";
7
- import { camelCase } from "@stryke/string-format/camel-case";
8
- import { constantCase } from "@stryke/string-format/constant-case";
9
- import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
10
- import { isSetString } from "@stryke/type-checks/is-set-string";
11
-
12
- //#region src/components/args-parser-logic.tsx
13
- function VariablePathsParserLogic(props) {
14
- const { path } = props;
15
- return createComponent(For, {
16
- get each() {
17
- return path.segments ?? [];
18
- },
19
- children: (segment, index) => createComponent(Show, {
20
- get when() {
21
- return isVariableCommandPath(segment);
22
- },
23
- get children() {
24
- return [
25
- createComponent(VarDeclaration, {
26
- "let": true,
27
- get name() {
28
- return camelCase(getVariableCommandPathName(segment));
29
- },
30
- type: "string | undefined",
31
- get initializer() {
32
- return createComponent(Show, {
33
- get when() {
34
- return isSetString(path.variables[getVariableCommandPathName(segment)]?.default);
35
- },
36
- fallback: code`undefined;`,
37
- get children() {
38
- return code` ?? "${path.variables[getVariableCommandPathName(segment)]?.default}";`;
39
- }
40
- });
41
- }
42
- }),
43
- createIntrinsic("hbr", {}),
44
- createComponent(IfStatement, {
45
- condition: code`args.length > ${2 + index} && args[${2 + index}]`,
46
- get children() {
47
- return code`${camelCase(getVariableCommandPathName(segment))} = args[${2 + index}];`;
48
- }
49
- }),
50
- createIntrinsic("hbr", {}),
51
- createIntrinsic("hbr", {}),
52
- createComponent(Show, {
53
- get when() {
54
- return !path.variables[getVariableCommandPathName(segment)]?.optional;
55
- },
56
- get children() {
57
- return createComponent(IfStatement, {
58
- get condition() {
59
- return code`!${camelCase(getVariableCommandPathName(segment))}`;
60
- },
61
- get children() {
62
- return [memo(() => code`error(\`Missing required command path variable: "${getVariableCommandPathName(segment)}".\`);`), code`return;`];
63
- }
64
- });
65
- }
66
- }),
67
- createIntrinsic("hbr", {})
68
- ];
69
- }
70
- })
71
- });
72
- }
73
- /**
74
- * The command parameter parser logic.
75
- */
76
- function ParamsParserLogic(props) {
77
- const { params } = props;
78
- const context = usePowerlines();
79
- return createComponent(Show, {
80
- get when() {
81
- return params && params.length > 0;
82
- },
83
- get children() {
84
- return [
85
- createComponent(For, {
86
- each: params ?? [],
87
- hardline: true,
88
- children: (param) => createComponent(VarDeclaration, {
89
- "let": true,
90
- get name() {
91
- return camelCase(param.name);
92
- },
93
- get type() {
94
- return param.variadic ? "string[]" : "string | undefined";
95
- },
96
- get initializer() {
97
- return memo(() => !!param.variadic)() ? code`[]` : [
98
- memo(() => code`env.${context.config.envPrefix}_${constantCase(param.name)} ?? `),
99
- createComponent(Show, {
100
- get when() {
101
- return isSetString(param.default);
102
- },
103
- get children() {
104
- return code`"${param.default}"`;
105
- }
106
- }),
107
- code`undefined;`
108
- ];
109
- }
110
- })
111
- }),
112
- createIntrinsic("hbr", {}),
113
- createComponent(VarDeclaration, {
114
- "const": true,
115
- name: "argsDiv",
116
- type: "number",
117
- initializer: code` args.findIndex(arg => arg === "--");`
118
- }),
119
- createIntrinsic("hbr", {}),
120
- createComponent(IfStatement, {
121
- condition: code`argsDiv !== -1`,
122
- get children() {
123
- return createComponent(For, {
124
- each: params ?? [],
125
- hardline: true,
126
- children: (param, index) => [
127
- createComponent(IfStatement, {
128
- condition: code`args.length > argsDiv + ${index + 1} && args[argsDiv + ${index + 1}]`,
129
- get children() {
130
- return createComponent(Show, {
131
- get when() {
132
- return param.variadic;
133
- },
134
- get fallback() {
135
- return code`${camelCase(param.name)} = args[argsDiv + ${index + 1}];`;
136
- },
137
- get children() {
138
- return code`${camelCase(param.name)}.push(args[argsDiv + ${index + 1}]);`;
139
- }
140
- });
141
- }
142
- }),
143
- createIntrinsic("hbr", {}),
144
- createComponent(Show, {
145
- get when() {
146
- return !param.optional;
147
- },
148
- get children() {
149
- return createComponent(Show, {
150
- get when() {
151
- return !param.default;
152
- },
153
- get fallback() {
154
- return createComponent(ElseClause, { get children() {
155
- return code`${camelCase(param.name)} = "${param.default}";`;
156
- } });
157
- },
158
- get children() {
159
- return createComponent(ElseClause, { get children() {
160
- return [memo(() => code`error(\`Missing required command parameter: "${param.name}".\`);`), code`return;`];
161
- } });
162
- }
163
- });
164
- }
165
- }),
166
- createIntrinsic("hbr", {})
167
- ]
168
- });
169
- }
170
- })
171
- ];
172
- }
173
- });
174
- }
175
- /**
176
- * The command option interface property.
177
- */
178
- function OptionsMember({ name, option }) {
179
- const doc = option.description || `The ${option.title} command option.`;
180
- return [
181
- createComponent(Show, {
182
- get when() {
183
- return option.kind === ReflectionKind.string;
184
- },
185
- get children() {
186
- return createComponent(InterfaceMember, {
187
- name,
188
- doc,
189
- get type() {
190
- return option.variadic ? "string[]" : "string";
191
- },
192
- get optional() {
193
- return option.optional;
194
- }
195
- });
196
- }
197
- }),
198
- createComponent(Show, {
199
- get when() {
200
- return option.kind === ReflectionKind.number;
201
- },
202
- get children() {
203
- return createComponent(InterfaceMember, {
204
- name,
205
- doc,
206
- get type() {
207
- return option.variadic ? "number[]" : "number";
208
- },
209
- get optional() {
210
- return option.optional;
211
- }
212
- });
213
- }
214
- }),
215
- createComponent(Show, {
216
- get when() {
217
- return option.kind === ReflectionKind.boolean;
218
- },
219
- get children() {
220
- return [createComponent(InterfaceMember, {
221
- name,
222
- doc,
223
- type: "boolean",
224
- get optional() {
225
- return option.optional;
226
- }
227
- }), createComponent(Show, {
228
- get when() {
229
- return Boolean(option.isNegativeOf);
230
- },
231
- get children() {
232
- return [createIntrinsic("hbr", {}), createComponent(InterfaceMember, {
233
- get name() {
234
- return option.isNegativeOf;
235
- },
236
- doc,
237
- type: "boolean",
238
- get optional() {
239
- return option.optional;
240
- }
241
- })];
242
- }
243
- })];
244
- }
245
- }),
246
- createComponent(Show, {
247
- get when() {
248
- return option.alias && option.alias.length > 0;
249
- },
250
- get children() {
251
- return [createIntrinsic("hbr", {}), createComponent(For, {
252
- get each() {
253
- return option.alias ?? [];
254
- },
255
- hardline: true,
256
- children: (alias) => createComponent(OptionsMember, {
257
- name: alias,
258
- get option() {
259
- return {
260
- ...option,
261
- alias: [],
262
- description: `${doc.replace(/\.+$/, "")}. This property is an alias for ${name}.`
263
- };
264
- }
265
- })
266
- })];
267
- }
268
- })
269
- ];
270
- }
271
- /**
272
- * The command option property parser logic.
273
- */
274
- function OptionsMemberParserLogic({ name, option }) {
275
- const context = usePowerlines();
276
- const equalsRegex = `/^--?(${context?.config.isCaseSensitive && name.length > 1 ? name : name.toLowerCase()}${option.alias && option.alias.length > 0 ? "|" : ""}${option.alias?.map((a) => (context?.config.isCaseSensitive && name.length > 1 ? a : a.toLowerCase()) === "?" ? "\\?" : context?.config.isCaseSensitive && name.length > 1 ? a : a.toLowerCase()).join("|")})=/`;
277
- return [
278
- createComponent(Show, {
279
- get when() {
280
- return option.kind === ReflectionKind.string || option.kind === ReflectionKind.number;
281
- },
282
- get children() {
283
- return [createComponent(Show, {
284
- get when() {
285
- return option.variadic;
286
- },
287
- get children() {
288
- return [
289
- createComponent(Show, {
290
- get when() {
291
- return name.includes("?") || name.includes("-");
292
- },
293
- fallback: code`options.${name} ??= []; `,
294
- children: code`options["${name}"] ??= []; `
295
- }),
296
- createIntrinsic("hbr", {}),
297
- createComponent(IfStatement, {
298
- condition: `${equalsRegex}.test(arg)`,
299
- get children() {
300
- return [
301
- createComponent(Show, {
302
- get when() {
303
- return name.includes("?") || name.includes("-");
304
- },
305
- fallback: code`options.${name}.push(`,
306
- children: code`options["${name}"].push(`
307
- }),
308
- createComponent(Show, {
309
- get when() {
310
- return option.kind === ReflectionKind.string;
311
- },
312
- children: code`...arg.replace(${equalsRegex}, "").split(",").map(item => item.trim().replace(/^("|')/, "").replace(/("|')$/, "")).filter(Boolean) `
313
- }),
314
- createComponent(Show, {
315
- get when() {
316
- return option.kind === ReflectionKind.number;
317
- },
318
- children: code`...arg.replace(${equalsRegex}, "").split(",").map(item => item.trim().replace(/^("|')/, "").replace(/("|')$/, "")).filter(Boolean).map(Number).filter(value => !Number.isNaN(value)) `
319
- }),
320
- code`); `
321
- ];
322
- }
323
- }),
324
- createComponent(ElseIfClause, {
325
- condition: `args.length > i + 1`,
326
- get children() {
327
- return [
328
- createComponent(Show, {
329
- get when() {
330
- return name.includes("?") || name.includes("-");
331
- },
332
- fallback: code`options.${name}.push(`,
333
- children: code`options["${name}"].push(`
334
- }),
335
- createComponent(Show, {
336
- get when() {
337
- return option.kind === ReflectionKind.string;
338
- },
339
- children: code`...args[++i].split(",").map(item => item.trim().replace(/^("|')/, "").replace(/("|')$/, "")).filter(Boolean) `
340
- }),
341
- createComponent(Show, {
342
- get when() {
343
- return option.kind === ReflectionKind.number;
344
- },
345
- children: code`...args[++i].split(",").map(item => item.trim().replace(/^("|')/, "").replace(/("|')$/, "")).filter(Boolean).map(Number).filter(value => !Number.isNaN(value)) `
346
- }),
347
- code`); `
348
- ];
349
- }
350
- })
351
- ];
352
- }
353
- }), createComponent(Show, {
354
- get when() {
355
- return !option.variadic;
356
- },
357
- get children() {
358
- return [
359
- createComponent(IfStatement, {
360
- condition: `${equalsRegex}.test(arg)`,
361
- get children() {
362
- return [createComponent(Show, {
363
- get when() {
364
- return option.kind === ReflectionKind.string;
365
- },
366
- get children() {
367
- return [createComponent(Show, {
368
- get when() {
369
- return name.includes("?") || name.includes("-");
370
- },
371
- fallback: code`options.${name}`,
372
- children: code`options["${name}"]`
373
- }), code` = arg.replace(${equalsRegex}, "").trim().replace(/^("|')/, "").replace(/("|')$/, ""); `];
374
- }
375
- }), createComponent(Show, {
376
- get when() {
377
- return option.kind === ReflectionKind.number;
378
- },
379
- get children() {
380
- return [
381
- createComponent(VarDeclaration, {
382
- "const": true,
383
- name: "value",
384
- initializer: code` Number(arg.replace(${equalsRegex}, "").trim().replace(/^("|')/, "").replace(/("|')$/, "")); `
385
- }),
386
- createIntrinsic("hbr", {}),
387
- createComponent(IfStatement, {
388
- condition: `!Number.isNaN(value)`,
389
- get children() {
390
- return [createComponent(Show, {
391
- get when() {
392
- return name.includes("?") || name.includes("-");
393
- },
394
- fallback: code`options.${name}`,
395
- children: code`options["${name}"]`
396
- }), code` = value; `];
397
- }
398
- }),
399
- createComponent(ElseClause, { get children() {
400
- return code`warn(\`Invalid value provided for the ${option.title} option: "\${value}" is not a valid number.\`); `;
401
- } })
402
- ];
403
- }
404
- })];
405
- }
406
- }),
407
- createComponent(ElseIfClause, {
408
- condition: `args.length > i + 1`,
409
- get children() {
410
- return [createComponent(Show, {
411
- get when() {
412
- return option.kind === ReflectionKind.string;
413
- },
414
- get children() {
415
- return [createComponent(Show, {
416
- get when() {
417
- return name.includes("?") || name.includes("-");
418
- },
419
- fallback: code`options.${name}`,
420
- children: code`options["${name}"]`
421
- }), code` = args[++i].trim().replace(/^("|')/, "").replace(/("|')$/, ""); `];
422
- }
423
- }), createComponent(Show, {
424
- get when() {
425
- return option.kind === ReflectionKind.number;
426
- },
427
- get children() {
428
- return [
429
- createComponent(VarDeclaration, {
430
- "const": true,
431
- name: "value",
432
- initializer: code` Number(args[++i].trim().replace(/^("|')/, "").replace(/("|')$/, "")); `
433
- }),
434
- createIntrinsic("hbr", {}),
435
- createComponent(IfStatement, {
436
- condition: `!Number.isNaN(value)`,
437
- get children() {
438
- return [createComponent(Show, {
439
- get when() {
440
- return name.includes("?") || name.includes("-");
441
- },
442
- fallback: code`options.${name}`,
443
- children: code`options["${name}"]`
444
- }), code` = value; `];
445
- }
446
- }),
447
- createComponent(ElseClause, { get children() {
448
- return code`warn(\`Invalid value provided for the ${option.title} option: "\${value}" is not a valid number.\`); `;
449
- } })
450
- ];
451
- }
452
- })];
453
- }
454
- }),
455
- createIntrinsic("hbr", {})
456
- ];
457
- }
458
- })];
459
- }
460
- }),
461
- createComponent(Show, {
462
- get when() {
463
- return option.kind === ReflectionKind.boolean;
464
- },
465
- get children() {
466
- return [
467
- createComponent(IfStatement, {
468
- condition: `${equalsRegex}.test(arg)`,
469
- get children() {
470
- return [
471
- createComponent(VarDeclaration, {
472
- "const": true,
473
- name: "value",
474
- initializer: code` arg.replace(${equalsRegex}, "").trim().replace(/^("|')/, "").replace(/("|')$/, "").toLowerCase(); `
475
- }),
476
- createIntrinsic("hbr", {}),
477
- createComponent(Show, {
478
- get when() {
479
- return name.includes("?") || name.includes("-");
480
- },
481
- fallback: code`options.${name}`,
482
- children: code`options["${name}"]`
483
- }),
484
- code` = value !== "false" && value !== "f" && value !== "no" && value !== "n" && value !== "0"; `
485
- ];
486
- }
487
- }),
488
- createComponent(ElseClause, { get children() {
489
- return createComponent(Show, {
490
- get when() {
491
- return name.includes("?") || name.includes("-");
492
- },
493
- fallback: code`options.${name} = true; `,
494
- children: code`options["${name}"] = true; `
495
- });
496
- } }),
497
- createComponent(Show, {
498
- get when() {
499
- return Boolean(option.isNegativeOf);
500
- },
501
- get children() {
502
- return [createIntrinsic("hbr", {}), createComponent(Show, {
503
- get when() {
504
- return option.isNegativeOf.includes("?") || option.isNegativeOf.includes("-");
505
- },
506
- get fallback() {
507
- return code`options.${option.isNegativeOf} = false; `;
508
- },
509
- get children() {
510
- return code`options["${option.isNegativeOf}"] = false; `;
511
- }
512
- })];
513
- }
514
- })
515
- ];
516
- }
517
- }),
518
- createComponent(Show, {
519
- get when() {
520
- return option.alias && option.alias.length > 0;
521
- },
522
- get children() {
523
- return [createIntrinsic("hbr", {}), createComponent(For, {
524
- get each() {
525
- return option.alias ?? [];
526
- },
527
- hardline: true,
528
- children: (alias) => [createComponent(Show, {
529
- get when() {
530
- return alias.includes("?") || alias.includes("-");
531
- },
532
- fallback: code`options.${alias} `,
533
- children: code`options["${alias}"] `
534
- }), createComponent(Show, {
535
- get when() {
536
- return name.includes("?") || name.includes("-");
537
- },
538
- fallback: code` = options.${name}; `,
539
- children: code` = options["${name}"]; `
540
- })]
541
- })];
542
- }
543
- })
544
- ];
545
- }
546
- function OptionsMemberParserCondition(props) {
547
- const { name, alias } = props;
548
- const context = usePowerlines();
549
- return [memo(() => code`arg.startsWith("--${context?.config.isCaseSensitive ? name : name.toLowerCase()}=") || arg === "--${context?.config.isCaseSensitive ? name : name.toLowerCase()}" || arg.startsWith("-${name}=") || arg === "-${name}"`), createComponent(Show, {
550
- get when() {
551
- return alias && alias.length > 0;
552
- },
553
- get children() {
554
- return createComponent(For, {
555
- each: alias ?? [],
556
- children: (a) => code` || arg.startsWith("--${context?.config.isCaseSensitive ? a : a.toLowerCase()}=") || arg === "--${context?.config.isCaseSensitive ? a : a.toLowerCase()}" || arg.startsWith("-${a}=") || arg === "-${a}"`
557
- });
558
- }
559
- })];
560
- }
561
- function OptionsInterfaceDeclaration(props) {
562
- const { command } = props;
563
- return createComponent(InterfaceDeclaration, {
564
- "export": true,
565
- get name() {
566
- return `${pascalCase(command.name)}Options`;
567
- },
568
- get children() {
569
- return createComponent(For, {
570
- get each() {
571
- return Object.entries(command.options);
572
- },
573
- children: ([name, option]) => createComponent(OptionsMember, {
574
- name,
575
- option
576
- })
577
- });
578
- }
579
- });
580
- }
581
- /**
582
- * The command options parser logic.
583
- */
584
- function OptionsParserLogic(props) {
585
- const { command } = props;
586
- const context = usePowerlines();
587
- return [
588
- createComponent(VarDeclaration, {
589
- "const": true,
590
- name: "options",
591
- get initializer() {
592
- return code` {
593
- ${Object.entries(command.options).map(([name, option]) => {
594
- if (option.kind === ReflectionKind.string) return ` ${name.includes("?") || name.includes("-") ? `"${name}"` : `${name}`}: ${option.env ? `env.${context.config.envPrefix}_${option.env}` : ""}${option.variadic ? option.default !== void 0 ? `${option.env ? " ?? " : ""}${JSON.stringify(option.default)}` : option.env ? " ?? []" : "" : option.default !== void 0 ? `${option.env ? " ?? " : ""}"${option.default}"` : ""}, `;
595
- else if (option.kind === ReflectionKind.number) return ` ${name.includes("?") || name.includes("-") ? `"${name}"` : `${name}`}: ${option.env ? `env.${context.config.envPrefix}_${option.env}` : ""}${option.variadic ? option.default !== void 0 ? `${option.env ? " ?? " : ""}${JSON.stringify(option.default)}` : option.env ? " ?? []" : "" : option.default !== void 0 ? `${option.env ? " ?? " : ""}${option.default}` : ""}, `;
596
- else if (option.kind === ReflectionKind.boolean) return ` ${name.includes("?") || name.includes("-") ? `"${name}"` : `${name}`}: ${option.env ? `env.${context.config.envPrefix}_${option.env} ?? ` : ""}${option.default ? "true" : "false"},`;
597
- return "";
598
- }).join("")}
599
- } as ${pascalCase(command.name)}Options;`;
600
- }
601
- }),
602
- createIntrinsic("hbr", {}),
603
- createIntrinsic("hbr", {}),
604
- memo(() => code`for (let i = 0; i < args.slice(${command.path.segments.filter((segment) => isVariableCommandPath(segment)).length}).length; i++) { `),
605
- createIntrinsic("hbr", {}),
606
- createComponent(VarDeclaration, {
607
- "const": true,
608
- name: "arg",
609
- type: "string",
610
- get initializer() {
611
- return code` args[i].length > 3 && args[i].startsWith("--")
612
- ? \`--\${args[i].slice(2).replaceAll("-", "")${context?.config.isCaseSensitive ? "" : ".toLowerCase()"}}\`
613
- : args[i].length > 2 && args[i].startsWith("-")
614
- ? \`-\${args[i].slice(1).replaceAll("-", "")}\`
615
- : args[i]; `;
616
- }
617
- }),
618
- createIntrinsic("hbr", {}),
619
- createComponent(For, {
620
- get each() {
621
- return Object.entries(command.options);
622
- },
623
- hardline: true,
624
- children: ([name, option], i) => createComponent(Show, {
625
- when: i === 0,
626
- get fallback() {
627
- return createComponent(ElseIfClause, {
628
- get condition() {
629
- return createComponent(OptionsMemberParserCondition, {
630
- name,
631
- get alias() {
632
- return option.alias;
633
- }
634
- });
635
- },
636
- get children() {
637
- return createComponent(OptionsMemberParserLogic, {
638
- name,
639
- option
640
- });
641
- }
642
- });
643
- },
644
- get children() {
645
- return createComponent(IfStatement, {
646
- get condition() {
647
- return createComponent(OptionsMemberParserCondition, {
648
- name,
649
- get alias() {
650
- return option.alias;
651
- }
652
- });
653
- },
654
- get children() {
655
- return createComponent(OptionsMemberParserLogic, {
656
- name,
657
- option
658
- });
659
- }
660
- });
661
- }
662
- })
663
- }),
664
- createIntrinsic("hbr", {}),
665
- code` } `,
666
- createIntrinsic("hbr", {})
667
- ];
668
- }
669
-
670
- //#endregion
671
- export { OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserLogic, OptionsParserLogic, ParamsParserLogic, VariablePathsParserLogic };
672
- //# sourceMappingURL=args-parser-logic.mjs.map