@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.
- package/README.md +1 -1
- package/dist/components/docs.cjs +1 -1
- package/dist/components/docs.cjs.map +1 -1
- package/dist/components/docs.d.mts +5 -5
- package/dist/components/docs.mjs +1 -1
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/helpers.cjs +15 -0
- package/dist/components/helpers.cjs.map +1 -0
- package/dist/components/helpers.d.cts +13 -0
- package/dist/components/helpers.d.cts.map +1 -0
- package/dist/components/helpers.d.mts +13 -0
- package/dist/components/helpers.d.mts.map +1 -0
- package/dist/components/helpers.mjs +14 -0
- package/dist/components/helpers.mjs.map +1 -0
- package/dist/components/index.cjs +4 -2
- package/dist/components/index.d.cts +3 -2
- package/dist/components/index.d.mts +3 -2
- package/dist/components/index.mjs +3 -2
- package/dist/components/options-parser-logic.cjs +121 -97
- package/dist/components/options-parser-logic.cjs.map +1 -1
- package/dist/components/options-parser-logic.d.cts +25 -17
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts +18 -10
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +120 -96
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/usage.cjs +33 -1
- package/dist/components/usage.cjs.map +1 -1
- package/dist/components/usage.d.cts +2 -2
- package/dist/components/usage.d.mts +2 -2
- package/dist/components/usage.d.mts.map +1 -1
- package/dist/components/usage.mjs +35 -3
- package/dist/components/usage.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +4 -21
- package/dist/helpers/persistence.cjs.map +1 -1
- package/dist/helpers/persistence.mjs +4 -21
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/resolve-command.cjs +15 -55
- package/dist/helpers/resolve-command.cjs.map +1 -1
- package/dist/helpers/resolve-command.mjs +16 -56
- package/dist/helpers/resolve-command.mjs.map +1 -1
- package/dist/helpers/validations.cjs +13 -36
- package/dist/helpers/validations.cjs.map +1 -1
- package/dist/helpers/validations.mjs +12 -36
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/plugin-utils/context-helpers.cjs +3 -45
- package/dist/plugin-utils/context-helpers.cjs.map +1 -1
- package/dist/plugin-utils/context-helpers.d.cts +1 -37
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/context-helpers.d.mts +1 -37
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +4 -44
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +0 -2
- package/dist/plugin-utils/index.d.cts +2 -2
- package/dist/plugin-utils/index.d.mts +2 -2
- package/dist/plugin-utils/index.mjs +2 -2
- package/dist/plugin.cjs +9 -15
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +9 -15
- package/dist/plugin.mjs.map +1 -1
- package/dist/types/command.d.cts +26 -118
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +26 -118
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/index.d.cts +3 -2
- package/dist/types/index.d.mts +3 -2
- package/dist/types/runtime.d.cts +5 -15
- package/dist/types/runtime.d.cts.map +1 -1
- package/dist/types/runtime.d.mts +5 -15
- package/dist/types/runtime.d.mts.map +1 -1
- package/package.json +24 -10
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { CommandOption, CommandTree
|
|
2
|
-
import * as
|
|
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
|
|
5
|
+
interface DynamicSegmentsParserLogicProps {
|
|
6
6
|
/**
|
|
7
|
-
* The command
|
|
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
|
-
|
|
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
|
|
12
|
-
interface
|
|
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
|
|
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
|
-
}):
|
|
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):
|
|
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
|
|
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
|
|
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):
|
|
75
|
+
declare function OptionsMemberParserCondition(props: OptionsMemberParserConditionProps): _alloy_js_core5.Children;
|
|
68
76
|
declare function OptionsInterfaceDeclaration(props: {
|
|
69
77
|
command: CommandTree;
|
|
70
|
-
}):
|
|
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):
|
|
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):
|
|
118
|
+
declare function CommandParserLogic(props: CommandParserLogicProps): _alloy_js_core5.Children;
|
|
111
119
|
//#endregion
|
|
112
|
-
export { CommandParserLogic, CommandParserLogicProps,
|
|
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":";;;;
|
|
1
|
+
{"version":3,"file":"options-parser-logic.d.cts","names":[],"sources":["../../src/components/options-parser-logic.tsx"],"sourcesContent":[],"mappings":";;;;UA8CiB,+BAAA;;;AAAjB;EAYgB,OAAA,EARL,WAQK;EA6BC;AAiBjB;AA6KA;EAAgC,eAAA,EAAA,OAAA;;AAAiC,iBA3NjD,0BAAA,CA2NmD,KAAA,EA1N1D,+BA0N0D,CAAA,EA1N3B,eAAA,CAAA,QA0N2B;AAAA,UA9LlD,yBAAA,CA8LkD;EAuClD;AAsBjB;AAuKA;EAmBgB,OAAA,EAjbL,WAibK;EAmEA;AAchB;AAsBA;EA6HiB,SAAA,EAAA,MAAA;EAsBD;;;;;iBA9pBA,oBAAA,QAA4B,4BAAyB,eAAA,CAAA;;;;iBA6KrD,aAAA;;;UAAoC;IAAa,eAAA,CAAE;UAuClD,6BAAA;;;;;;;;UASP;;;;;;;;;;;iBAaM,wBAAA,QAAgC,gCAA6B,eAAA,CAAA;UAuK5D,iCAAA;;;;;;;;;;;;;;;;iBAmBD,4BAAA,QACP,oCAAiC,eAAA,CAAA;iBAkE1B,2BAAA;WAA8C;IAAW,eAAA,CAAE;UAc1D,uBAAA;;;;WAIN;;;;;;;;;;;;;;;iBAkBK,kBAAA,QAA0B,0BAAuB,eAAA,CAAA;UA6HhD,uBAAA;;;;WAIN;;;;;;;;;;;;;;;iBAkBK,kBAAA,QAA0B,0BAAuB,eAAA,CAAA"}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { CommandOption, CommandTree
|
|
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
|
|
5
|
+
interface DynamicSegmentsParserLogicProps {
|
|
6
6
|
/**
|
|
7
|
-
* The command
|
|
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
|
-
|
|
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
|
|
12
|
-
interface
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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":";;;;
|
|
1
|
+
{"version":3,"file":"options-parser-logic.d.mts","names":[],"sources":["../../src/components/options-parser-logic.tsx"],"sourcesContent":[],"mappings":";;;;UA8CiB,+BAAA;;;AAAjB;EAYgB,OAAA,EARL,WAQK;EA6BC;AAiBjB;AA6KA;EAAgC,eAAA,EAAA,OAAA;;AAAiC,iBA3NjD,0BAAA,CA2NmD,KAAA,EA1N1D,+BA0N0D,CAAA,EA1N3B,eAAA,CAAA,QA0N2B;AAAA,UA9LlD,yBAAA,CA8LkD;EAuClD;AAsBjB;AAuKA;EAmBgB,OAAA,EAjbL,WAibK;EAmEA;AAchB;AAsBA;EA6HiB,SAAA,EAAA,MAAA;EAsBD;;;;;iBA9pBA,oBAAA,QAA4B,4BAAyB,eAAA,CAAA;;;;iBA6KrD,aAAA;;;UAAoC;IAAa,eAAA,CAAE;UAuClD,6BAAA;;;;;;;;UASP;;;;;;;;;;;iBAaM,wBAAA,QAAgC,gCAA6B,eAAA,CAAA;UAuK5D,iCAAA;;;;;;;;;;;;;;;;iBAmBD,4BAAA,QACP,oCAAiC,eAAA,CAAA;iBAkE1B,2BAAA;WAA8C;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
|
|
13
|
-
const {
|
|
14
|
+
function DynamicSegmentsParserLogic(props) {
|
|
15
|
+
const { command } = props;
|
|
14
16
|
return createComponent(For, {
|
|
15
17
|
get each() {
|
|
16
|
-
return
|
|
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
|
-
|
|
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
|
|
58
|
-
const { command, envPrefix } = props;
|
|
59
|
-
return
|
|
60
|
-
get
|
|
61
|
-
return command.
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
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.
|
|
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(
|
|
552
|
-
|
|
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(
|
|
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,
|
|
615
|
+
export { ArgumentsParserLogic, CommandParserLogic, DynamicSegmentsParserLogic, OptionsInterfaceDeclaration, OptionsMember, OptionsMemberParserCondition, OptionsMemberParserLogic, OptionsParserLogic };
|
|
592
616
|
//# sourceMappingURL=options-parser-logic.mjs.map
|