@bemoje/cli 3.1.2 → 3.1.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.
package/lib/index.js CHANGED
@@ -11,13 +11,58 @@ import { isPromise } from 'util/types';
11
11
  var __defProp = Object.defineProperty;
12
12
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
13
 
14
- // ../decorators/src/assertDescriptorValueIsFunction.ts
15
- function assertDescriptorValueIsFunction(key, descriptor) {
16
- if (!(typeof descriptor.value === "function" && descriptor.value !== Function.prototype)) {
17
- throw new TypeError(`"value" not a function for ${key} with descriptor: ${JSON.stringify(descriptor)}.`);
14
+ // src/lib/helpers/parseOptionFlags.ts
15
+ function parseOptionFlags(flags) {
16
+ const match = flags.match(/^-(.+?), --([A-Za-z][\w-]*)(?:\s*(<(.+?)>|\[(.+?)]))?$/);
17
+ if (!match) {
18
+ throw new Error(`Invalid option format: ${flags}`);
18
19
  }
20
+ const short = match[1];
21
+ if (short.length !== 1) {
22
+ throw new Error(`Expected short name to be a single character. Got: -${short}`);
23
+ }
24
+ const long = match[2];
25
+ const argName = (match[4] || match[5])?.replace(/\.{3}$/, "") || void 0;
26
+ const name = long.split("-").reduce((str, word) => {
27
+ return str + word[0].toUpperCase() + word.slice(1);
28
+ });
29
+ return {
30
+ short,
31
+ long,
32
+ name,
33
+ argName
34
+ };
19
35
  }
20
- __name(assertDescriptorValueIsFunction, "assertDescriptorValueIsFunction");
36
+ __name(parseOptionFlags, "parseOptionFlags");
37
+
38
+ // src/lib/helpers/getCommandAndAncestors.ts
39
+ function getCommandAndAncestors(cmd) {
40
+ const result = [];
41
+ let command = cmd;
42
+ for (; command; command = command.parent) {
43
+ result.push(command);
44
+ }
45
+ return result;
46
+ }
47
+ __name(getCommandAndAncestors, "getCommandAndAncestors");
48
+
49
+ // src/lib/helpers/getCommandAncestors.ts
50
+ function getCommandAncestors(cmd) {
51
+ return getCommandAndAncestors(cmd).slice(1);
52
+ }
53
+ __name(getCommandAncestors, "getCommandAncestors");
54
+
55
+ // src/lib/helpers/findOption.ts
56
+ function findOption(cmd, nameOrShortOrLong) {
57
+ return nameOrShortOrLong.startsWith("--") ? cmd.options.find((o) => {
58
+ return o.long === nameOrShortOrLong.slice(2);
59
+ }) : nameOrShortOrLong.startsWith("-") ? cmd.options.find((o) => {
60
+ return o.short === nameOrShortOrLong.slice(1);
61
+ }) : cmd.options.find((o) => {
62
+ return o.name === nameOrShortOrLong;
63
+ });
64
+ }
65
+ __name(findOption, "findOption");
21
66
 
22
67
  // ../object/src/entriesOf.ts
23
68
  function entriesOf(obj) {
@@ -63,6 +108,22 @@ function valuesOf(obj) {
63
108
  }
64
109
  __name(valuesOf, "valuesOf");
65
110
 
111
+ // src/lib/helpers/findCommand.ts
112
+ function findCommand(cmd, nameOrAlias) {
113
+ return cmd.commands[nameOrAlias] ?? valuesOf(cmd.commands).find((c) => {
114
+ return c.aliases.includes(nameOrAlias);
115
+ });
116
+ }
117
+ __name(findCommand, "findCommand");
118
+
119
+ // ../decorators/src/assertDescriptorValueIsFunction.ts
120
+ function assertDescriptorValueIsFunction(key, descriptor) {
121
+ if (!(typeof descriptor.value === "function" && descriptor.value !== Function.prototype)) {
122
+ throw new TypeError(`"value" not a function for ${key} with descriptor: ${JSON.stringify(descriptor)}.`);
123
+ }
124
+ }
125
+ __name(assertDescriptorValueIsFunction, "assertDescriptorValueIsFunction");
126
+
66
127
  // ../map/src/mapGetOrDefault.ts
67
128
  function mapGetOrDefault(map, key, factory) {
68
129
  let value = map.get(key);
@@ -823,43 +884,6 @@ function collectVariadicOptionValues(parsed, options) {
823
884
  }
824
885
  __name(collectVariadicOptionValues, "collectVariadicOptionValues");
825
886
 
826
- // src/lib/helpers/findCommand.ts
827
- function findCommand(cmd, nameOrAlias) {
828
- return cmd.commands[nameOrAlias] ?? valuesOf(cmd.commands).find((c) => {
829
- return c.aliases.includes(nameOrAlias);
830
- });
831
- }
832
- __name(findCommand, "findCommand");
833
-
834
- // src/lib/helpers/findOption.ts
835
- function findOption(cmd, nameOrShortOrLong) {
836
- return nameOrShortOrLong.startsWith("--") ? cmd.options.find((o) => {
837
- return o.long === nameOrShortOrLong.slice(2);
838
- }) : nameOrShortOrLong.startsWith("-") ? cmd.options.find((o) => {
839
- return o.short === nameOrShortOrLong.slice(1);
840
- }) : cmd.options.find((o) => {
841
- return o.name === nameOrShortOrLong;
842
- });
843
- }
844
- __name(findOption, "findOption");
845
-
846
- // src/lib/helpers/getCommandAndAncestors.ts
847
- function getCommandAndAncestors(cmd) {
848
- const result = [];
849
- let command = cmd;
850
- for (; command; command = command.parent) {
851
- result.push(command);
852
- }
853
- return result;
854
- }
855
- __name(getCommandAndAncestors, "getCommandAndAncestors");
856
-
857
- // src/lib/helpers/getCommandAncestors.ts
858
- function getCommandAncestors(cmd) {
859
- return getCommandAndAncestors(cmd).slice(1);
860
- }
861
- __name(getCommandAncestors, "getCommandAncestors");
862
-
863
887
  // src/lib/internal/mergeOptionDefaults.ts
864
888
  function mergeOptionDefaults(values, options) {
865
889
  for (const option of options) {
@@ -889,30 +913,6 @@ function normalizeArgv(argv, options) {
889
913
  return argv;
890
914
  }
891
915
  __name(normalizeArgv, "normalizeArgv");
892
-
893
- // src/lib/helpers/parseOptionFlags.ts
894
- function parseOptionFlags(flags) {
895
- const match = flags.match(/^-(.+?), --([A-Za-z][\w-]*)(?:\s*(<(.+?)>|\[(.+?)]))?$/);
896
- if (!match) {
897
- throw new Error(`Invalid option format: ${flags}`);
898
- }
899
- const short = match[1];
900
- if (short.length !== 1) {
901
- throw new Error(`Expected short name to be a single character. Got: -${short}`);
902
- }
903
- const long = match[2];
904
- const argName = (match[4] || match[5])?.replace(/\.{3}$/, "") || void 0;
905
- const name = long.split("-").reduce((str, word) => {
906
- return str + word[0].toUpperCase() + word.slice(1);
907
- });
908
- return {
909
- short,
910
- long,
911
- name,
912
- argName
913
- };
914
- }
915
- __name(parseOptionFlags, "parseOptionFlags");
916
916
  function resolveArguments(positionals, args) {
917
917
  const result = args.map((arg, index) => {
918
918
  if (arg.variadic) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemoje/cli",
3
- "version": "3.1.2",
3
+ "version": "3.1.3",
4
4
  "description": "A type-safe CLI framework for building command-line interfaces with typed arguments, options, subcommands, and auto-generated help - without execution coupling.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -40,7 +40,7 @@
40
40
  "default": "./lib/index.cjs"
41
41
  }
42
42
  },
43
- "./lib/Command": {
43
+ "./helpers": {
44
44
  "import": {
45
45
  "types": "./lib/index.d.ts",
46
46
  "default": "./lib/index.js"
@@ -50,7 +50,7 @@
50
50
  "default": "./lib/index.cjs"
51
51
  }
52
52
  },
53
- "./lib/Help": {
53
+ "./Command": {
54
54
  "import": {
55
55
  "types": "./lib/index.d.ts",
56
56
  "default": "./lib/index.js"
@@ -60,7 +60,7 @@
60
60
  "default": "./lib/index.cjs"
61
61
  }
62
62
  },
63
- "./lib/helpers/findCommand": {
63
+ "./Help": {
64
64
  "import": {
65
65
  "types": "./lib/index.d.ts",
66
66
  "default": "./lib/index.js"
@@ -70,47 +70,7 @@
70
70
  "default": "./lib/index.cjs"
71
71
  }
72
72
  },
73
- "./lib/helpers/findOption": {
74
- "import": {
75
- "types": "./lib/index.d.ts",
76
- "default": "./lib/index.js"
77
- },
78
- "require": {
79
- "types": "./lib/index.d.cts",
80
- "default": "./lib/index.cjs"
81
- }
82
- },
83
- "./lib/helpers/getCommandAncestors": {
84
- "import": {
85
- "types": "./lib/index.d.ts",
86
- "default": "./lib/index.js"
87
- },
88
- "require": {
89
- "types": "./lib/index.d.cts",
90
- "default": "./lib/index.cjs"
91
- }
92
- },
93
- "./lib/helpers/getCommandAndAncestors": {
94
- "import": {
95
- "types": "./lib/index.d.ts",
96
- "default": "./lib/index.js"
97
- },
98
- "require": {
99
- "types": "./lib/index.d.cts",
100
- "default": "./lib/index.cjs"
101
- }
102
- },
103
- "./lib/helpers/parseOptionFlags": {
104
- "import": {
105
- "types": "./lib/index.d.ts",
106
- "default": "./lib/index.js"
107
- },
108
- "require": {
109
- "types": "./lib/index.d.cts",
110
- "default": "./lib/index.cjs"
111
- }
112
- },
113
- "./lib/types": {
73
+ "./types": {
114
74
  "import": {
115
75
  "types": "./lib/index.d.ts",
116
76
  "default": "./lib/index.js"