@bemoje/cli 3.1.2 → 3.1.4

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);
@@ -327,7 +388,8 @@ var Help = class {
327
388
  const args = sub.arguments.map((arg) => {
328
389
  return arg.usage;
329
390
  }).join(" ");
330
- return (sub.aliases[0] ? `${sub.aliases[0].padEnd(this.longestSubcommandAliasLength(), " ")} | ` : "") + sub.name + (sub.options.length ? ` ${this.usageDisplayOptionsAs}` : "") + (args ? ` ${args}` : "");
391
+ return (sub.aliases[0] ? `${sub.aliases[0].padEnd(this.longestSubcommandAliasLength(), " ")} | ` : "") + sub.name + (sub.options.length ? ` ${this.usageDisplayOptionsAs}` : "") + // simplistic check for non-help option
392
+ (args ? ` ${args}` : "");
331
393
  }
332
394
  /**
333
395
  * Get the option term to show in the list of options.
@@ -823,43 +885,6 @@ function collectVariadicOptionValues(parsed, options) {
823
885
  }
824
886
  __name(collectVariadicOptionValues, "collectVariadicOptionValues");
825
887
 
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
888
  // src/lib/internal/mergeOptionDefaults.ts
864
889
  function mergeOptionDefaults(values, options) {
865
890
  for (const option of options) {
@@ -889,30 +914,6 @@ function normalizeArgv(argv, options) {
889
914
  return argv;
890
915
  }
891
916
  __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
917
  function resolveArguments(positionals, args) {
917
918
  const result = args.map((arg, index) => {
918
919
  if (arg.variadic) {
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "@bemoje/cli",
3
- "version": "3.1.2",
3
+ "version": "3.1.4",
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,
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "dependencies": {
11
+ "ansi-colors": "^4.1.3",
12
+ "es-toolkit": "^1.45.1"
13
+ },
7
14
  "keywords": [
8
15
  "cli",
9
16
  "command-line",
@@ -40,77 +47,7 @@
40
47
  "default": "./lib/index.cjs"
41
48
  }
42
49
  },
43
- "./lib/Command": {
44
- "import": {
45
- "types": "./lib/index.d.ts",
46
- "default": "./lib/index.js"
47
- },
48
- "require": {
49
- "types": "./lib/index.d.cts",
50
- "default": "./lib/index.cjs"
51
- }
52
- },
53
- "./lib/Help": {
54
- "import": {
55
- "types": "./lib/index.d.ts",
56
- "default": "./lib/index.js"
57
- },
58
- "require": {
59
- "types": "./lib/index.d.cts",
60
- "default": "./lib/index.cjs"
61
- }
62
- },
63
- "./lib/helpers/findCommand": {
64
- "import": {
65
- "types": "./lib/index.d.ts",
66
- "default": "./lib/index.js"
67
- },
68
- "require": {
69
- "types": "./lib/index.d.cts",
70
- "default": "./lib/index.cjs"
71
- }
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": {
50
+ "./*": {
114
51
  "import": {
115
52
  "types": "./lib/index.d.ts",
116
53
  "default": "./lib/index.js"
@@ -121,22 +58,15 @@
121
58
  }
122
59
  }
123
60
  },
124
- "dependencies": {
125
- "ansi-colors": "^4.1.3",
126
- "es-toolkit": "^1.45.1"
127
- },
128
- "publishConfig": {
129
- "access": "public"
61
+ "repository": {
62
+ "type": "git",
63
+ "url": "git+https://github.com/bemoje/mono.git",
64
+ "directory": "libs/cli"
130
65
  },
131
- "license": "MIT",
132
66
  "author": {
133
67
  "name": "Benjamin Møller Jensen",
134
68
  "email": "bemoje@bemoje.net",
135
69
  "url": "https://github.com/bemoje/"
136
70
  },
137
- "repository": {
138
- "type": "git",
139
- "url": "git+https://github.com/bemoje/mono.git",
140
- "directory": "libs/cli"
141
- }
71
+ "license": "MIT"
142
72
  }