@reliverse/rempts 1.7.8 → 1.7.9
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.
|
@@ -3,6 +3,7 @@ type EmptyArgs = Record<string, never>;
|
|
|
3
3
|
type BaseArgProps = {
|
|
4
4
|
description?: string;
|
|
5
5
|
required?: boolean;
|
|
6
|
+
allowed?: string[];
|
|
6
7
|
};
|
|
7
8
|
type PositionalArgDefinition = {
|
|
8
9
|
type: "positional";
|
|
@@ -11,6 +12,7 @@ type PositionalArgDefinition = {
|
|
|
11
12
|
type BooleanArgDefinition = {
|
|
12
13
|
type: "boolean";
|
|
13
14
|
default?: boolean;
|
|
15
|
+
allowed?: boolean[];
|
|
14
16
|
} & BaseArgProps;
|
|
15
17
|
type StringArgDefinition = {
|
|
16
18
|
type: "string";
|
|
@@ -19,6 +21,7 @@ type StringArgDefinition = {
|
|
|
19
21
|
type NumberArgDefinition = {
|
|
20
22
|
type: "number";
|
|
21
23
|
default?: number;
|
|
24
|
+
allowed?: number[];
|
|
22
25
|
} & BaseArgProps;
|
|
23
26
|
type ArrayArgDefinition = {
|
|
24
27
|
type: "array";
|
|
@@ -654,25 +654,51 @@ function castArgValue(def, rawVal, argName) {
|
|
|
654
654
|
}
|
|
655
655
|
return def.default ?? void 0;
|
|
656
656
|
}
|
|
657
|
+
let castedValue;
|
|
657
658
|
switch (def.type) {
|
|
658
659
|
case "boolean":
|
|
659
660
|
if (typeof rawVal === "string") {
|
|
660
661
|
const lower = rawVal.toLowerCase();
|
|
661
|
-
if (lower === "true")
|
|
662
|
-
if (lower === "false")
|
|
662
|
+
if (lower === "true") castedValue = true;
|
|
663
|
+
else if (lower === "false") castedValue = false;
|
|
664
|
+
else castedValue = Boolean(rawVal);
|
|
665
|
+
} else {
|
|
666
|
+
castedValue = Boolean(rawVal);
|
|
667
|
+
}
|
|
668
|
+
if (def.allowed && !def.allowed.includes(castedValue)) {
|
|
669
|
+
throw new Error(
|
|
670
|
+
`Invalid value for --${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
|
|
671
|
+
);
|
|
663
672
|
}
|
|
664
|
-
return
|
|
673
|
+
return castedValue;
|
|
665
674
|
case "string":
|
|
666
|
-
|
|
675
|
+
castedValue = typeof rawVal === "string" ? rawVal : String(rawVal);
|
|
676
|
+
if (def.allowed && !def.allowed.includes(castedValue)) {
|
|
677
|
+
throw new Error(
|
|
678
|
+
`Invalid value for --${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
return castedValue;
|
|
667
682
|
case "number": {
|
|
668
683
|
const n = Number(rawVal);
|
|
669
684
|
if (Number.isNaN(n)) {
|
|
670
685
|
throw new Error(`Invalid number provided for --${argName}: ${rawVal}`);
|
|
671
686
|
}
|
|
687
|
+
if (def.allowed && !def.allowed.includes(n)) {
|
|
688
|
+
throw new Error(
|
|
689
|
+
`Invalid value for --${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
|
|
690
|
+
);
|
|
691
|
+
}
|
|
672
692
|
return n;
|
|
673
693
|
}
|
|
674
694
|
case "positional":
|
|
675
|
-
|
|
695
|
+
castedValue = String(rawVal);
|
|
696
|
+
if (def.allowed && !def.allowed.includes(castedValue)) {
|
|
697
|
+
throw new Error(
|
|
698
|
+
`Invalid value for <${argName}>: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
return castedValue;
|
|
676
702
|
case "array": {
|
|
677
703
|
const arrVal = Array.isArray(rawVal) ? rawVal : [String(rawVal)];
|
|
678
704
|
const result = [];
|
|
@@ -705,6 +731,11 @@ function castArgValue(def, rawVal, argName) {
|
|
|
705
731
|
`Array argument --${argName}: Quoted values are not supported due to shell parsing limitations. Please avoid using single or double quotes around array elements.`
|
|
706
732
|
);
|
|
707
733
|
}
|
|
734
|
+
if (def.allowed && !def.allowed.includes(p)) {
|
|
735
|
+
throw new Error(
|
|
736
|
+
`Invalid value in array --${argName}: ${p}. Allowed values are: ${def.allowed.join(", ")}`
|
|
737
|
+
);
|
|
738
|
+
}
|
|
708
739
|
});
|
|
709
740
|
result.push(...parts);
|
|
710
741
|
}
|
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"name": "@reliverse/rempts",
|
|
30
30
|
"type": "module",
|
|
31
|
-
"version": "1.7.
|
|
31
|
+
"version": "1.7.9",
|
|
32
32
|
"author": "reliverse",
|
|
33
33
|
"bugs": {
|
|
34
34
|
"email": "blefnk@gmail.com",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@biomejs/biome": "1.9.4",
|
|
46
46
|
"@eslint/js": "^9.26.0",
|
|
47
|
-
"@reliverse/dler": "^1.2.
|
|
47
|
+
"@reliverse/dler": "^1.2.4",
|
|
48
48
|
"@reliverse/relidler-cfg": "^1.1.3",
|
|
49
49
|
"@stylistic/eslint-plugin": "^4.2.0",
|
|
50
50
|
"@total-typescript/ts-reset": "^0.6.1",
|