@reliverse/rempts 1.7.22 → 1.7.24

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.
@@ -628,11 +628,7 @@ async function runCommandWithArgs(command, argv, parserOptions, returnCtx) {
628
628
  if (def.type === "boolean") {
629
629
  defaultMap[argKey] = def.default !== void 0 ? def.default : false;
630
630
  } else if (def.default !== void 0) {
631
- if (def.type === "array" && typeof def.default === "string") {
632
- defaultMap[argKey] = [def.default];
633
- } else {
634
- defaultMap[argKey] = def.default;
635
- }
631
+ defaultMap[argKey] = def.type === "array" && typeof def.default === "string" ? [def.default] : def.default;
636
632
  }
637
633
  }
638
634
  const mergedParserOptions = {
@@ -668,38 +664,27 @@ async function runCommandWithArgs(command, argv, parserOptions, returnCtx) {
668
664
  if (def.type === "array" && rawVal !== void 0 && !Array.isArray(rawVal)) {
669
665
  rawVal = [rawVal];
670
666
  }
671
- const valueOrDefault = rawVal ?? defaultMap[key];
672
- if (valueOrDefault == null && def.required) {
667
+ const casted = rawVal !== void 0 ? castArgValue(def, rawVal, key) : def.default;
668
+ const argUsed = rawVal !== void 0 && (def.type === "boolean" ? casted === true : true);
669
+ if (casted == null && def.required) {
673
670
  await showUsage(command, parserOptions);
674
671
  relinka("error", `Missing required argument: --${key}`);
675
672
  if (autoExit) process.exit(1);
676
673
  else throw new Error(`Missing required argument: --${key}`);
677
674
  }
678
- if (def.dependencies && Array.isArray(def.dependencies)) {
679
- const isArgUsed = rawVal !== void 0 || def.default !== void 0;
680
- if (isArgUsed) {
681
- const missingDeps = def.dependencies.filter(
682
- (dependency) => !(parsed[dependency] ?? defaultMap[dependency])
675
+ if (argUsed && def.dependencies?.length) {
676
+ const missingDeps = def.dependencies.filter((d) => {
677
+ const depVal = parsed[d] ?? defaultMap[d];
678
+ return !depVal;
679
+ });
680
+ if (missingDeps.length > 0) {
681
+ const depsList = missingDeps.map((d) => `--${d}`).join(", ");
682
+ throw new Error(
683
+ `Argument --${key} can only be used when ${depsList} ${missingDeps.length === 1 ? "is" : "are"} set`
683
684
  );
684
- if (missingDeps.length > 0) {
685
- const depsList = missingDeps.map((d) => `--${d}`).join(", ");
686
- throw new Error(
687
- `Argument --${key} can only be used when ${depsList} ${missingDeps.length === 1 ? "is" : "are"} set`
688
- );
689
- }
690
685
  }
691
686
  }
692
- try {
693
- if (def.type === "boolean") {
694
- finalArgs[key] = rawVal !== void 0 ? castArgValue(def, rawVal, key) : false;
695
- } else {
696
- finalArgs[key] = castArgValue(def, rawVal, key);
697
- }
698
- } catch (err) {
699
- relinka("error", String(err));
700
- if (autoExit) process.exit(1);
701
- else throw err;
702
- }
687
+ finalArgs[key] = def.type === "boolean" ? Boolean(casted) : casted;
703
688
  }
704
689
  const ctx = {
705
690
  args: finalArgs,
@@ -852,11 +837,7 @@ export async function runCmd(command, argv = [], parserOptions = {}) {
852
837
  if (def.type === "boolean") {
853
838
  defaultMap[argKey] = def.default !== void 0 ? def.default : false;
854
839
  } else if (def.default !== void 0) {
855
- if (def.type === "array" && typeof def.default === "string") {
856
- defaultMap[argKey] = [def.default];
857
- } else {
858
- defaultMap[argKey] = def.default;
859
- }
840
+ defaultMap[argKey] = def.type === "array" && typeof def.default === "string" ? [def.default] : def.default;
860
841
  }
861
842
  }
862
843
  const mergedParserOptions = {
@@ -889,34 +870,24 @@ export async function runCmd(command, argv = [], parserOptions = {}) {
889
870
  if (def.type === "array" && rawVal !== void 0 && !Array.isArray(rawVal)) {
890
871
  rawVal = [rawVal];
891
872
  }
892
- const valueOrDefault = rawVal ?? defaultMap[key];
893
- if (valueOrDefault == null && def.required) {
873
+ const casted = rawVal !== void 0 ? castArgValue(def, rawVal, key) : def.default;
874
+ const argUsed = rawVal !== void 0 && (def.type === "boolean" ? casted === true : true);
875
+ if (casted == null && def.required) {
894
876
  throw new Error(`Missing required argument: --${key}`);
895
877
  }
896
- if (def.dependencies && Array.isArray(def.dependencies)) {
897
- const isArgUsed = rawVal !== void 0 || def.default !== void 0;
898
- if (isArgUsed) {
899
- const missingDeps = def.dependencies.filter(
900
- (dependency) => !(parsed[dependency] ?? defaultMap[dependency])
878
+ if (argUsed && def.dependencies?.length) {
879
+ const missingDeps = def.dependencies.filter((d) => {
880
+ const depVal = parsed[d] ?? defaultMap[d];
881
+ return !depVal;
882
+ });
883
+ if (missingDeps.length) {
884
+ const depsList = missingDeps.map((d) => `--${d}`).join(", ");
885
+ throw new Error(
886
+ `Argument --${key} can only be used when ${depsList} ${missingDeps.length === 1 ? "is" : "are"} set`
901
887
  );
902
- if (missingDeps.length > 0) {
903
- const depsList = missingDeps.map((d) => `--${d}`).join(", ");
904
- throw new Error(
905
- `Argument --${key} can only be used when ${depsList} ${missingDeps.length === 1 ? "is" : "are"} set`
906
- );
907
- }
908
888
  }
909
889
  }
910
- try {
911
- if (def.type === "boolean") {
912
- finalArgs[key] = rawVal !== void 0 ? castArgValue(def, rawVal, key) : false;
913
- } else {
914
- finalArgs[key] = castArgValue(def, rawVal, key);
915
- }
916
- } catch (err) {
917
- relinka("error", String(err));
918
- throw err;
919
- }
890
+ finalArgs[key] = def.type === "boolean" ? Boolean(casted) : casted;
920
891
  }
921
892
  const ctx = {
922
893
  args: finalArgs,
@@ -937,11 +908,7 @@ function getParsedContext(command, argv, parserOptions) {
937
908
  if (def.type === "boolean") {
938
909
  defaultMap[argKey] = def.default !== void 0 ? def.default : false;
939
910
  } else if (def.default !== void 0) {
940
- if (def.type === "array" && typeof def.default === "string") {
941
- defaultMap[argKey] = [def.default];
942
- } else {
943
- defaultMap[argKey] = def.default;
944
- }
911
+ defaultMap[argKey] = def.type === "array" && typeof def.default === "string" ? [def.default] : def.default;
945
912
  }
946
913
  }
947
914
  const mergedParserOptions = {
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "license": "MIT",
30
30
  "name": "@reliverse/rempts",
31
31
  "type": "module",
32
- "version": "1.7.22",
32
+ "version": "1.7.24",
33
33
  "author": "reliverse",
34
34
  "bugs": {
35
35
  "email": "blefnk@gmail.com",