@shell-shock/core 0.7.0 → 0.8.1

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 (76) hide show
  1. package/README.md +1 -1
  2. package/dist/components/docs.cjs +1 -1
  3. package/dist/components/docs.cjs.map +1 -1
  4. package/dist/components/docs.d.mts +5 -5
  5. package/dist/components/docs.mjs +1 -1
  6. package/dist/components/docs.mjs.map +1 -1
  7. package/dist/components/helpers.cjs +15 -0
  8. package/dist/components/helpers.cjs.map +1 -0
  9. package/dist/components/helpers.d.cts +13 -0
  10. package/dist/components/helpers.d.cts.map +1 -0
  11. package/dist/components/helpers.d.mts +13 -0
  12. package/dist/components/helpers.d.mts.map +1 -0
  13. package/dist/components/helpers.mjs +14 -0
  14. package/dist/components/helpers.mjs.map +1 -0
  15. package/dist/components/index.cjs +4 -2
  16. package/dist/components/index.d.cts +3 -2
  17. package/dist/components/index.d.mts +3 -2
  18. package/dist/components/index.mjs +3 -2
  19. package/dist/components/options-parser-logic.cjs +121 -97
  20. package/dist/components/options-parser-logic.cjs.map +1 -1
  21. package/dist/components/options-parser-logic.d.cts +25 -17
  22. package/dist/components/options-parser-logic.d.cts.map +1 -1
  23. package/dist/components/options-parser-logic.d.mts +18 -10
  24. package/dist/components/options-parser-logic.d.mts.map +1 -1
  25. package/dist/components/options-parser-logic.mjs +120 -96
  26. package/dist/components/options-parser-logic.mjs.map +1 -1
  27. package/dist/components/usage.cjs +33 -1
  28. package/dist/components/usage.cjs.map +1 -1
  29. package/dist/components/usage.d.cts +2 -2
  30. package/dist/components/usage.d.mts +2 -2
  31. package/dist/components/usage.d.mts.map +1 -1
  32. package/dist/components/usage.mjs +35 -3
  33. package/dist/components/usage.mjs.map +1 -1
  34. package/dist/helpers/persistence.cjs +4 -21
  35. package/dist/helpers/persistence.cjs.map +1 -1
  36. package/dist/helpers/persistence.mjs +4 -21
  37. package/dist/helpers/persistence.mjs.map +1 -1
  38. package/dist/helpers/resolve-command.cjs +15 -55
  39. package/dist/helpers/resolve-command.cjs.map +1 -1
  40. package/dist/helpers/resolve-command.mjs +16 -56
  41. package/dist/helpers/resolve-command.mjs.map +1 -1
  42. package/dist/helpers/validations.cjs +13 -36
  43. package/dist/helpers/validations.cjs.map +1 -1
  44. package/dist/helpers/validations.mjs +12 -36
  45. package/dist/helpers/validations.mjs.map +1 -1
  46. package/dist/index.d.cts +3 -2
  47. package/dist/index.d.mts +3 -2
  48. package/dist/plugin-utils/context-helpers.cjs +3 -45
  49. package/dist/plugin-utils/context-helpers.cjs.map +1 -1
  50. package/dist/plugin-utils/context-helpers.d.cts +1 -37
  51. package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
  52. package/dist/plugin-utils/context-helpers.d.mts +1 -37
  53. package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
  54. package/dist/plugin-utils/context-helpers.mjs +4 -44
  55. package/dist/plugin-utils/context-helpers.mjs.map +1 -1
  56. package/dist/plugin-utils/index.cjs +0 -2
  57. package/dist/plugin-utils/index.d.cts +2 -2
  58. package/dist/plugin-utils/index.d.mts +2 -2
  59. package/dist/plugin-utils/index.mjs +2 -2
  60. package/dist/plugin.cjs +9 -15
  61. package/dist/plugin.cjs.map +1 -1
  62. package/dist/plugin.d.cts.map +1 -1
  63. package/dist/plugin.d.mts.map +1 -1
  64. package/dist/plugin.mjs +9 -15
  65. package/dist/plugin.mjs.map +1 -1
  66. package/dist/types/command.d.cts +26 -118
  67. package/dist/types/command.d.cts.map +1 -1
  68. package/dist/types/command.d.mts +26 -118
  69. package/dist/types/command.d.mts.map +1 -1
  70. package/dist/types/index.d.cts +3 -2
  71. package/dist/types/index.d.mts +3 -2
  72. package/dist/types/runtime.d.cts +5 -15
  73. package/dist/types/runtime.d.cts.map +1 -1
  74. package/dist/types/runtime.d.mts +5 -15
  75. package/dist/types/runtime.d.mts.map +1 -1
  76. package/package.json +24 -10
@@ -1,15 +1,19 @@
1
- import { CommandOption, CommandTree, CommandTreePath } from "../types/command.cjs";
2
- import * as _alloy_js_core4 from "@alloy-js/core";
1
+ import { CommandOption, CommandTree } from "../types/command.cjs";
2
+ import * as _alloy_js_core5 from "@alloy-js/core";
3
3
 
4
4
  //#region src/components/options-parser-logic.d.ts
5
- interface DynamicPathSegmentsParserLogicProps {
5
+ interface DynamicSegmentsParserLogicProps {
6
6
  /**
7
- * The command path to generate the dynamic path segments parser logic for.
7
+ * 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.
8
8
  */
9
- path: CommandTreePath;
9
+ command: CommandTree;
10
+ /**
11
+ * 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.
12
+ */
13
+ isCaseSensitive: boolean;
10
14
  }
11
- declare function DynamicPathSegmentsParserLogic(props: DynamicPathSegmentsParserLogicProps): _alloy_js_core4.Children;
12
- interface PositionalParametersParserLogicProps {
15
+ declare function DynamicSegmentsParserLogic(props: DynamicSegmentsParserLogicProps): _alloy_js_core5.Children;
16
+ interface ArgumentsParserLogicProps {
13
17
  /**
14
18
  * The command to generate the positional parameters parser logic for.
15
19
  */
@@ -18,8 +22,12 @@ interface PositionalParametersParserLogicProps {
18
22
  * 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.${envPrefix}_OPTION_NAME`).
19
23
  */
20
24
  envPrefix: string;
25
+ /**
26
+ * 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.
27
+ */
28
+ isCaseSensitive: boolean;
21
29
  }
22
- declare function PositionalParametersParserLogic(props: PositionalParametersParserLogicProps): _alloy_js_core4.Children;
30
+ declare function ArgumentsParserLogic(props: ArgumentsParserLogicProps): _alloy_js_core5.Children;
23
31
  /**
24
32
  * The command option interface property.
25
33
  */
@@ -27,7 +35,7 @@ declare function OptionsMember({
27
35
  option
28
36
  }: {
29
37
  option: CommandOption;
30
- }): _alloy_js_core4.Children;
38
+ }): _alloy_js_core5.Children;
31
39
  interface OptionsMemberParserLogicProps {
32
40
  /**
33
41
  * The option name to generate the parser logic for.
@@ -47,27 +55,27 @@ interface OptionsMemberParserLogicProps {
47
55
  /**
48
56
  * The command option property parser logic.
49
57
  */
50
- declare function OptionsMemberParserLogic(props: OptionsMemberParserLogicProps): _alloy_js_core4.Children;
58
+ declare function OptionsMemberParserLogic(props: OptionsMemberParserLogicProps): _alloy_js_core5.Children;
51
59
  interface OptionsMemberParserConditionProps {
52
60
  /**
53
61
  * The option name to generate the parser logic for.
54
62
  */
55
63
  name: string;
56
64
  /**
57
- * 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.
65
+ * 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.
58
66
  */
59
67
  alias?: string[];
60
68
  /**
61
- * 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.
69
+ * 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.
62
70
  *
63
71
  * @defaultValue false
64
72
  */
65
73
  isCaseSensitive: boolean;
66
74
  }
67
- declare function OptionsMemberParserCondition(props: OptionsMemberParserConditionProps): _alloy_js_core4.Children;
75
+ declare function OptionsMemberParserCondition(props: OptionsMemberParserConditionProps): _alloy_js_core5.Children;
68
76
  declare function OptionsInterfaceDeclaration(props: {
69
77
  command: CommandTree;
70
- }): _alloy_js_core4.Children;
78
+ }): _alloy_js_core5.Children;
71
79
  interface OptionsParserLogicProps {
72
80
  /**
73
81
  * The command to generate the options parser logic for.
@@ -87,7 +95,7 @@ interface OptionsParserLogicProps {
87
95
  /**
88
96
  * The command options parser logic.
89
97
  */
90
- declare function OptionsParserLogic(props: OptionsParserLogicProps): _alloy_js_core4.Children;
98
+ declare function OptionsParserLogic(props: OptionsParserLogicProps): _alloy_js_core5.Children;
91
99
  interface CommandParserLogicProps {
92
100
  /**
93
101
  * The command to generate the parser logic for.
@@ -107,7 +115,7 @@ interface CommandParserLogicProps {
107
115
  /**
108
116
  * The command parser logic, which includes parsing dynamic path segments, positional parameters, and options.
109
117
  */
110
- declare function CommandParserLogic(props: CommandParserLogicProps): _alloy_js_core4.Children;
118
+ declare function CommandParserLogic(props: CommandParserLogicProps): _alloy_js_core5.Children;
111
119
  //#endregion
112
- export { CommandParserLogic, CommandParserLogicProps, DynamicPathSegmentsParserLogic, DynamicPathSegmentsParserLogicProps, OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserCondition, OptionsMemberParserConditionProps, OptionsMemberParserLogic, OptionsMemberParserLogicProps, OptionsParserLogic, OptionsParserLogicProps, PositionalParametersParserLogic, PositionalParametersParserLogicProps };
120
+ export { ArgumentsParserLogic, ArgumentsParserLogicProps, CommandParserLogic, CommandParserLogicProps, DynamicSegmentsParserLogic, DynamicSegmentsParserLogicProps, OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserCondition, OptionsMemberParserConditionProps, OptionsMemberParserLogic, OptionsMemberParserLogicProps, OptionsParserLogic, OptionsParserLogicProps };
113
121
  //# sourceMappingURL=options-parser-logic.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options-parser-logic.d.cts","names":[],"sources":["../../src/components/options-parser-logic.tsx"],"sourcesContent":[],"mappings":";;;;UA6CiB,mCAAA;;;AAAjB;EAOgB,IAAA,EAHR,eAGQ;AAoDhB;AAYgB,iBAhEA,8BAAA,CAiEP,KAAA,EAhEA,mCAgEoC,CAAA,EAhED,eAAA,CAAA,QAgEC;AAmG7B,UAhHC,oCAAA,CAgHY;EAAG;;;EAAmC,OAAA,EA5GxD,WA4GwD;EAuClD;AAsBjB;AAuKA;EAmBgB,SAAA,EAAA,MAAA;AAmEhB;AAciB,iBA5aD,+BAAA,CAgbM,KAAA,EA/ab,oCA+aa,CAAA,EA/auB,eAAA,CAAA,QA+avB;AAkBtB;AA8HA;AAsBA;iBAlfgB,aAAA;;;UAAoC;IAAa,eAAA,CAAE;UAuClD,6BAAA;;;;;;;;UAS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,15 +1,19 @@
1
- import { CommandOption, CommandTree, CommandTreePath } from "../types/command.mjs";
1
+ import { CommandOption, CommandTree } from "../types/command.mjs";
2
2
  import * as _alloy_js_core0 from "@alloy-js/core";
3
3
 
4
4
  //#region src/components/options-parser-logic.d.ts
5
- interface DynamicPathSegmentsParserLogicProps {
5
+ interface DynamicSegmentsParserLogicProps {
6
6
  /**
7
- * The command path to generate the dynamic path segments parser logic for.
7
+ * 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.
8
8
  */
9
- path: CommandTreePath;
9
+ command: CommandTree;
10
+ /**
11
+ * 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.
12
+ */
13
+ isCaseSensitive: boolean;
10
14
  }
11
- declare function DynamicPathSegmentsParserLogic(props: DynamicPathSegmentsParserLogicProps): _alloy_js_core0.Children;
12
- interface PositionalParametersParserLogicProps {
15
+ declare function DynamicSegmentsParserLogic(props: DynamicSegmentsParserLogicProps): _alloy_js_core0.Children;
16
+ interface ArgumentsParserLogicProps {
13
17
  /**
14
18
  * The command to generate the positional parameters parser logic for.
15
19
  */
@@ -18,8 +22,12 @@ interface PositionalParametersParserLogicProps {
18
22
  * 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.${envPrefix}_OPTION_NAME`).
19
23
  */
20
24
  envPrefix: string;
25
+ /**
26
+ * 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.
27
+ */
28
+ isCaseSensitive: boolean;
21
29
  }
22
- declare function PositionalParametersParserLogic(props: PositionalParametersParserLogicProps): _alloy_js_core0.Children;
30
+ declare function ArgumentsParserLogic(props: ArgumentsParserLogicProps): _alloy_js_core0.Children;
23
31
  /**
24
32
  * The command option interface property.
25
33
  */
@@ -54,11 +62,11 @@ interface OptionsMemberParserConditionProps {
54
62
  */
55
63
  name: string;
56
64
  /**
57
- * 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.
65
+ * 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.
58
66
  */
59
67
  alias?: string[];
60
68
  /**
61
- * 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.
69
+ * 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.
62
70
  *
63
71
  * @defaultValue false
64
72
  */
@@ -109,5 +117,5 @@ interface CommandParserLogicProps {
109
117
  */
110
118
  declare function CommandParserLogic(props: CommandParserLogicProps): _alloy_js_core0.Children;
111
119
  //#endregion
112
- export { CommandParserLogic, CommandParserLogicProps, DynamicPathSegmentsParserLogic, DynamicPathSegmentsParserLogicProps, OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserCondition, OptionsMemberParserConditionProps, OptionsMemberParserLogic, OptionsMemberParserLogicProps, OptionsParserLogic, OptionsParserLogicProps, PositionalParametersParserLogic, PositionalParametersParserLogicProps };
120
+ export { ArgumentsParserLogic, ArgumentsParserLogicProps, CommandParserLogic, CommandParserLogicProps, DynamicSegmentsParserLogic, DynamicSegmentsParserLogicProps, OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserCondition, OptionsMemberParserConditionProps, OptionsMemberParserLogic, OptionsMemberParserLogicProps, OptionsParserLogic, OptionsParserLogicProps };
113
121
  //# sourceMappingURL=options-parser-logic.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options-parser-logic.d.mts","names":[],"sources":["../../src/components/options-parser-logic.tsx"],"sourcesContent":[],"mappings":";;;;UA6CiB,mCAAA;;;AAAjB;EAOgB,IAAA,EAHR,eAGQ;AAoDhB;AAYgB,iBAhEA,8BAAA,CAiEP,KAAA,EAhEA,mCAgEoC,CAAA,EAhED,eAAA,CAAA,QAgEC;AAmG7B,UAhHC,oCAAA,CAgHY;EAAG;;;EAAmC,OAAA,EA5GxD,WA4GwD;EAuClD;AAsBjB;AAuKA;EAmBgB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AA8C;IAAW,eAAA,CAAE;UAc1D,uBAAA;;;;WAIN;;;;;;;;;;;;;;;iBAkBK,kBAAA,QAA0B,0BAAuB,eAAA,CAAA;UA6HhD,uBAAA;;;;WAIN;;;;;;;;;;;;;;;iBAkBK,kBAAA,QAA0B,0BAAuB,eAAA,CAAA"}
@@ -1,7 +1,9 @@
1
1
  import { getDynamicPathSegmentName, isDynamicPathSegment } from "../plugin-utils/context-helpers.mjs";
2
2
  import { computedOptions } from "../contexts/options.mjs";
3
+ import { BooleanInputParserLogic } from "./helpers.mjs";
3
4
  import { createComponent, createIntrinsic, memo } from "@alloy-js/core/jsx-runtime";
4
5
  import { camelCase } from "@stryke/string-format/camel-case";
6
+ import { constantCase } from "@stryke/string-format/constant-case";
5
7
  import { isSetString } from "@stryke/type-checks/is-set-string";
6
8
  import { For, Show, code, computed } from "@alloy-js/core";
7
9
  import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
@@ -9,11 +11,11 @@ import { ElseClause, ElseIfClause, IfStatement, InterfaceDeclaration, InterfaceM
9
11
  import { pascalCase } from "@stryke/string-format/pascal-case";
10
12
 
11
13
  //#region src/components/options-parser-logic.tsx
12
- function DynamicPathSegmentsParserLogic(props) {
13
- const { path } = props;
14
+ function DynamicSegmentsParserLogic(props) {
15
+ const { command } = props;
14
16
  return createComponent(For, {
15
17
  get each() {
16
- return path.segments ?? [];
18
+ return command.segments ?? [];
17
19
  },
18
20
  children: (segment, index) => createComponent(Show, {
19
21
  get when() {
@@ -26,19 +28,7 @@ function DynamicPathSegmentsParserLogic(props) {
26
28
  get name() {
27
29
  return camelCase(getDynamicPathSegmentName(segment));
28
30
  },
29
- get type() {
30
- return `${path.dynamics[getDynamicPathSegmentName(segment)]?.variadic ? "string[]" : "string"}${path.dynamics[getDynamicPathSegmentName(segment)]?.optional ? " | undefined" : ""}`;
31
- },
32
- get initializer() {
33
- return memo(() => !!path.dynamics[getDynamicPathSegmentName(segment)]?.variadic)() ? code`[]` : [createComponent(Show, {
34
- get when() {
35
- return isSetString(path.dynamics[getDynamicPathSegmentName(segment)]?.default);
36
- },
37
- get children() {
38
- return code`"${path.dynamics[getDynamicPathSegmentName(segment)]?.default}"`;
39
- }
40
- }), code`undefined;`];
41
- }
31
+ type: "string"
42
32
  }),
43
33
  createIntrinsic("hbr", {}),
44
34
  createComponent(IfStatement, {
@@ -54,60 +44,110 @@ function DynamicPathSegmentsParserLogic(props) {
54
44
  })
55
45
  });
56
46
  }
57
- function PositionalParametersParserLogic(props) {
58
- const { command, envPrefix } = props;
59
- return [createComponent(For, {
60
- get each() {
61
- return command.params ?? [];
47
+ function ArgumentsParserLogic(props) {
48
+ const { command, envPrefix, isCaseSensitive } = props;
49
+ return createComponent(Show, {
50
+ get when() {
51
+ return command.arguments && command.arguments.length > 0;
62
52
  },
63
- hardline: true,
64
- children: (param) => [
65
- createComponent(VarDeclaration, {
66
- "let": true,
67
- get name() {
68
- return param.name;
69
- },
70
- get type() {
71
- return `${param.kind === ReflectionKind.boolean ? "boolean" : param.kind === ReflectionKind.number ? "number" : "string"}${(param.kind === ReflectionKind.string || param.kind === ReflectionKind.number) && param.variadic ? "[]" : ""}${param.optional ? " | undefined" : ""}`;
72
- },
73
- get initializer() {
74
- return [memo(() => code`env.${envPrefix}_${param.env} ?? `), createComponent(Show, {
75
- get when() {
76
- return param.default !== void 0;
77
- },
78
- get fallback() {
79
- return (param.kind === ReflectionKind.string || param.kind === ReflectionKind.number) && param.variadic ? code`[]` : code`undefined;`;
80
- },
81
- get children() {
82
- return param.kind === ReflectionKind.string ? code`"${param.default}"` : code`${param.default}`;
83
- }
84
- })];
85
- }
86
- }),
87
- createIntrinsic("hbr", {}),
88
- createIntrinsic("hbr", {}),
89
- createComponent(IfStatement, {
90
- get condition() {
91
- return code`args.length > ${command.path.segments.filter((segment) => isDynamicPathSegment(segment)).length + 1} && args[${command.path.segments.filter((segment) => isDynamicPathSegment(segment)).length + 1}]`;
92
- },
93
- get children() {
94
- return createComponent(Show, {
95
- get when() {
96
- return param.kind === ReflectionKind.string || param.kind === ReflectionKind.number;
97
- },
98
- get fallback() {
99
- return code`${param.name} = args[${command.path.segments.filter((segment) => isDynamicPathSegment(segment)).length + 1}];`;
100
- },
101
- get children() {
102
- return code`${param.name} = ${(param.kind === ReflectionKind.string || param.kind === ReflectionKind.number) && param.variadic ? `args.slice(${command.path.segments.filter((segment) => isDynamicPathSegment(segment)).length + 1})` : `args[${command.path.segments.filter((segment) => isDynamicPathSegment(segment)).length + 1}]`}${param.kind === ReflectionKind.number ? ".map(Number).filter(value => !Number.isNaN(value))" : ""};`;
103
- }
104
- });
105
- }
106
- }),
107
- createIntrinsic("hbr", {}),
108
- createIntrinsic("hbr", {})
109
- ]
110
- })];
53
+ get children() {
54
+ return [
55
+ createComponent(VarDeclaration, {
56
+ "let": true,
57
+ name: "optionsIndex",
58
+ type: "number",
59
+ get initializer() {
60
+ 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("_", "")).join("|")}`).join("|")})=?.*$/.test(arg${isCaseSensitive ? "" : ".toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"}))) + ${command.segments.length + 1};`;
61
+ }
62
+ }),
63
+ createIntrinsic("hbr", {}),
64
+ createIntrinsic("hbr", {}),
65
+ createComponent(VarDeclaration, {
66
+ "let": true,
67
+ name: "argsIndex",
68
+ type: "number",
69
+ 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("_", "")).join("|")}`).join("|")})=?.*$/.test(arg${isCaseSensitive ? "" : ".toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"}))) + ${command.segments.length + 1});`;
71
+ }
72
+ }),
73
+ createIntrinsic("hbr", {}),
74
+ createIntrinsic("hbr", {}),
75
+ createComponent(For, {
76
+ get each() {
77
+ return command.arguments ?? [];
78
+ },
79
+ hardline: true,
80
+ children: (arg, index) => [
81
+ createComponent(VarDeclaration, {
82
+ "let": true,
83
+ get name() {
84
+ return camelCase(arg.name);
85
+ },
86
+ get type() {
87
+ return `${arg.kind === ReflectionKind.boolean ? "boolean" : arg.kind === ReflectionKind.number ? "number" : "string"}${(arg.kind === ReflectionKind.string || arg.kind === ReflectionKind.number) && arg.variadic ? "[]" : ""}${arg.optional ? " | undefined" : ""}`;
88
+ },
89
+ get initializer() {
90
+ return [createComponent(Show, {
91
+ get when() {
92
+ return isSetString(arg.env);
93
+ },
94
+ get children() {
95
+ return code`env.${envPrefix}_${constantCase(String(arg.env))} ?? `;
96
+ }
97
+ }), createComponent(Show, {
98
+ get when() {
99
+ return arg.default !== void 0;
100
+ },
101
+ get fallback() {
102
+ return (arg.kind === ReflectionKind.string || arg.kind === ReflectionKind.number) && arg.variadic ? code`[]` : code`undefined;`;
103
+ },
104
+ get children() {
105
+ return arg.kind === ReflectionKind.string ? code`"${arg.default}"` : code`${arg.default}`;
106
+ }
107
+ })];
108
+ }
109
+ }),
110
+ createIntrinsic("hbr", {}),
111
+ createIntrinsic("hbr", {}),
112
+ createComponent(IfStatement, {
113
+ condition: code`argsIndex + ${index} < args.length && argsIndex + ${index} !== optionsIndex`,
114
+ get children() {
115
+ return [memo(() => code`${camelCase(arg.name)} = `), createComponent(Show, {
116
+ get when() {
117
+ return arg.kind === ReflectionKind.string || arg.kind === ReflectionKind.number;
118
+ },
119
+ get fallback() {
120
+ return createComponent(BooleanInputParserLogic, { name: `args[argsIndex + ${index}] ` });
121
+ },
122
+ get children() {
123
+ return createComponent(Show, {
124
+ get when() {
125
+ return (arg.kind === ReflectionKind.string || arg.kind === ReflectionKind.number) && arg.variadic;
126
+ },
127
+ get fallback() {
128
+ return createComponent(Show, {
129
+ get when() {
130
+ return arg.kind === ReflectionKind.number;
131
+ },
132
+ fallback: code`args[argsIndex + ${index}]; `,
133
+ children: code`Number(args[argsIndex + ${index}]); `
134
+ });
135
+ },
136
+ get children() {
137
+ return code`args.slice(argsIndex + ${index}, (optionsIndex > argsIndex ? optionsIndex : args.length) - ${command.arguments.length - index}).join(" ").split(",").map(item => item.trim().replace(/^("|')/, "").replace(/("|')$/, "")).filter(Boolean)`;
138
+ }
139
+ });
140
+ }
141
+ })];
142
+ }
143
+ }),
144
+ createIntrinsic("hbr", {}),
145
+ createIntrinsic("hbr", {})
146
+ ]
147
+ })
148
+ ];
149
+ }
150
+ });
111
151
  }
112
152
  /**
113
153
  * The command option interface property.
@@ -381,10 +421,10 @@ function OptionsMemberParserLogic(props) {
381
421
  get when() {
382
422
  return name.includes("?") || name.includes("-");
383
423
  },
384
- fallback: code`options.${name}`,
385
- children: code`options["${name}"]`
424
+ fallback: code`options.${name} = `,
425
+ children: code`options["${name}"] = `
386
426
  }),
387
- code` = value !== "false" && value !== "f" && value !== "no" && value !== "n" && value !== "0" && value !== "off" && value !== "disable" && value !== "disabled"; `
427
+ createComponent(BooleanInputParserLogic, { name: "value" })
388
428
  ];
389
429
  }
390
430
  }),
@@ -475,7 +515,7 @@ function OptionsParserLogic(props) {
475
515
  }),
476
516
  createIntrinsic("hbr", {}),
477
517
  createIntrinsic("hbr", {}),
478
- memo(() => code`for (let i = 0; i < args.slice(${command.path.segments.filter((segment) => isDynamicPathSegment(segment)).length}).length; i++) { `),
518
+ memo(() => code`for (let i = 0; i < args.slice(${command.segments.filter((segment) => isDynamicPathSegment(segment)).length}).length; i++) { `),
479
519
  createIntrinsic("hbr", {}),
480
520
  createComponent(VarDeclaration, {
481
521
  "const": true,
@@ -548,27 +588,10 @@ function OptionsParserLogic(props) {
548
588
  function CommandParserLogic(props) {
549
589
  const { command, envPrefix, isCaseSensitive = false } = props;
550
590
  return [
551
- createComponent(DynamicPathSegmentsParserLogic, { get path() {
552
- return command.path;
553
- } }),
554
- createIntrinsic("hbr", {}),
555
- createIntrinsic("hbr", {}),
556
- createComponent(VarDeclaration, {
557
- "const": true,
558
- name: "lastSegmentIndex",
559
- type: "number",
560
- get initializer() {
561
- return memo(() => !!isDynamicPathSegment(command.path.segments[command.path.segments.length - 1]))() ? `args.some(arg => /^--?(${Object.keys(command.options).map((key) => key.toLowerCase().replaceAll("-", "").replaceAll("_", "")).join("|")})(=.*)?$/.test(arg${isCaseSensitive ? "" : ".toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"})) ? args.findIndex(arg => /^--?(${Object.keys(command.options).map((key) => key.toLowerCase().replaceAll("-", "").replaceAll("_", "")).join("|")})(=.*)?$/.test(arg${isCaseSensitive ? "" : ".toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"})) : args.length - ${command.params.length + 1}` : `args.reduce((ret, arg, index) => {
562
- if (ret === -1 && (index < args.findIndex(a => /^--?(${Object.keys(command.options).map((key) => key.toLowerCase().replaceAll("-", "").replaceAll("_", "")).join("|")})(=.*)?$/.test(a${isCaseSensitive ? "" : ".toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"})) || !args.some(a => /^--?(${Object.keys(command.options).map((key) => key.toLowerCase().replaceAll("-", "").replaceAll("_", "")).join("|")})(=.*)?$/.test(a${isCaseSensitive ? "" : ".toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"}))) && arg${isCaseSensitive ? "" : ".toLowerCase().replaceAll(\"-\", \"\").replaceAll(\"_\", \"\")"} === "${command.path.segments[command.path.segments.length - 1]?.toLowerCase()}") {
563
- return index;
564
- }
565
-
566
- return ret;
567
- }, -1); `;
568
- }
591
+ createComponent(DynamicSegmentsParserLogic, {
592
+ command,
593
+ isCaseSensitive
569
594
  }),
570
- code`
571
- `,
572
595
  createIntrinsic("hbr", {}),
573
596
  createIntrinsic("hbr", {}),
574
597
  createComponent(OptionsParserLogic, {
@@ -578,9 +601,10 @@ function CommandParserLogic(props) {
578
601
  }),
579
602
  createIntrinsic("hbr", {}),
580
603
  createIntrinsic("hbr", {}),
581
- createComponent(PositionalParametersParserLogic, {
604
+ createComponent(ArgumentsParserLogic, {
582
605
  command,
583
- envPrefix
606
+ envPrefix,
607
+ isCaseSensitive
584
608
  }),
585
609
  createIntrinsic("hbr", {}),
586
610
  createIntrinsic("hbr", {})
@@ -588,5 +612,5 @@ function CommandParserLogic(props) {
588
612
  }
589
613
 
590
614
  //#endregion
591
- export { CommandParserLogic, DynamicPathSegmentsParserLogic, OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserCondition, OptionsMemberParserLogic, OptionsParserLogic, PositionalParametersParserLogic };
615
+ export { ArgumentsParserLogic, CommandParserLogic, DynamicSegmentsParserLogic, OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserCondition, OptionsMemberParserLogic, OptionsParserLogic };
592
616
  //# sourceMappingURL=options-parser-logic.mjs.map