@bemoje/cli 3.1.0 → 3.1.2

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.
Files changed (37) hide show
  1. package/lib/index.cjs +1516 -59
  2. package/lib/index.d.cts +2658 -6
  3. package/lib/index.d.ts +2658 -6
  4. package/lib/index.js +1504 -8
  5. package/package.json +53 -85
  6. package/lib/lib/Command.cjs +0 -450
  7. package/lib/lib/Command.d.cts +0 -1
  8. package/lib/lib/Command.d.ts +0 -1
  9. package/lib/lib/Command.js +0 -443
  10. package/lib/lib/Help.cjs +0 -552
  11. package/lib/lib/Help.d.cts +0 -1
  12. package/lib/lib/Help.d.ts +0 -1
  13. package/lib/lib/Help.js +0 -545
  14. package/lib/lib/helpers/findCommand.cjs +0 -14
  15. package/lib/lib/helpers/findCommand.d.cts +0 -8
  16. package/lib/lib/helpers/findCommand.d.ts +0 -8
  17. package/lib/lib/helpers/findCommand.js +0 -11
  18. package/lib/lib/helpers/findOption.cjs +0 -16
  19. package/lib/lib/helpers/findOption.d.cts +0 -8
  20. package/lib/lib/helpers/findOption.d.ts +0 -8
  21. package/lib/lib/helpers/findOption.js +0 -14
  22. package/lib/lib/helpers/getCommandAncestors.cjs +0 -12
  23. package/lib/lib/helpers/getCommandAncestors.d.cts +0 -8
  24. package/lib/lib/helpers/getCommandAncestors.d.ts +0 -8
  25. package/lib/lib/helpers/getCommandAncestors.js +0 -9
  26. package/lib/lib/helpers/getCommandAndAncestors.cjs +0 -15
  27. package/lib/lib/helpers/getCommandAndAncestors.d.cts +0 -8
  28. package/lib/lib/helpers/getCommandAndAncestors.d.ts +0 -8
  29. package/lib/lib/helpers/getCommandAndAncestors.js +0 -13
  30. package/lib/lib/helpers/parseOptionFlags.cjs +0 -28
  31. package/lib/lib/helpers/parseOptionFlags.d.cts +0 -13
  32. package/lib/lib/helpers/parseOptionFlags.d.ts +0 -13
  33. package/lib/lib/helpers/parseOptionFlags.js +0 -26
  34. package/lib/lib/types.cjs +0 -2
  35. package/lib/lib/types.d.cts +0 -1
  36. package/lib/lib/types.d.ts +0 -1
  37. package/lib/lib/types.js +0 -1
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@bemoje/cli",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
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
+ "type": "module",
6
+ "sideEffects": false,
5
7
  "keywords": [
6
8
  "cli",
7
9
  "command-line",
@@ -18,18 +20,15 @@
18
20
  "args",
19
21
  "argv"
20
22
  ],
21
- "dependencies": {
22
- "ansi-colors": "^4.1.3",
23
- "es-toolkit": "^1.45.1"
24
- },
25
- "type": "module",
26
- "sideEffects": false,
27
- "publishConfig": {
28
- "access": "public"
29
- },
30
23
  "main": "./lib/index.cjs",
31
24
  "module": "./lib/index.js",
32
25
  "types": "./lib/index.d.ts",
26
+ "files": [
27
+ "./lib/index.js",
28
+ "./lib/index.d.ts",
29
+ "./lib/index.cjs",
30
+ "./lib/index.d.cts"
31
+ ],
33
32
  "exports": {
34
33
  ".": {
35
34
  "import": {
@@ -43,132 +42,101 @@
43
42
  },
44
43
  "./lib/Command": {
45
44
  "import": {
46
- "types": "./lib/lib/Command.d.ts",
47
- "default": "./lib/lib/Command.js"
45
+ "types": "./lib/index.d.ts",
46
+ "default": "./lib/index.js"
48
47
  },
49
48
  "require": {
50
- "types": "./lib/lib/Command.d.cts",
51
- "default": "./lib/lib/Command.cjs"
49
+ "types": "./lib/index.d.cts",
50
+ "default": "./lib/index.cjs"
52
51
  }
53
52
  },
54
53
  "./lib/Help": {
55
54
  "import": {
56
- "types": "./lib/lib/Help.d.ts",
57
- "default": "./lib/lib/Help.js"
55
+ "types": "./lib/index.d.ts",
56
+ "default": "./lib/index.js"
58
57
  },
59
58
  "require": {
60
- "types": "./lib/lib/Help.d.cts",
61
- "default": "./lib/lib/Help.cjs"
59
+ "types": "./lib/index.d.cts",
60
+ "default": "./lib/index.cjs"
62
61
  }
63
62
  },
64
63
  "./lib/helpers/findCommand": {
65
64
  "import": {
66
- "types": "./lib/lib/helpers/findCommand.d.ts",
67
- "default": "./lib/lib/helpers/findCommand.js"
65
+ "types": "./lib/index.d.ts",
66
+ "default": "./lib/index.js"
68
67
  },
69
68
  "require": {
70
- "types": "./lib/lib/helpers/findCommand.d.cts",
71
- "default": "./lib/lib/helpers/findCommand.cjs"
69
+ "types": "./lib/index.d.cts",
70
+ "default": "./lib/index.cjs"
72
71
  }
73
72
  },
74
73
  "./lib/helpers/findOption": {
75
74
  "import": {
76
- "types": "./lib/lib/helpers/findOption.d.ts",
77
- "default": "./lib/lib/helpers/findOption.js"
75
+ "types": "./lib/index.d.ts",
76
+ "default": "./lib/index.js"
78
77
  },
79
78
  "require": {
80
- "types": "./lib/lib/helpers/findOption.d.cts",
81
- "default": "./lib/lib/helpers/findOption.cjs"
79
+ "types": "./lib/index.d.cts",
80
+ "default": "./lib/index.cjs"
82
81
  }
83
82
  },
84
83
  "./lib/helpers/getCommandAncestors": {
85
84
  "import": {
86
- "types": "./lib/lib/helpers/getCommandAncestors.d.ts",
87
- "default": "./lib/lib/helpers/getCommandAncestors.js"
85
+ "types": "./lib/index.d.ts",
86
+ "default": "./lib/index.js"
88
87
  },
89
88
  "require": {
90
- "types": "./lib/lib/helpers/getCommandAncestors.d.cts",
91
- "default": "./lib/lib/helpers/getCommandAncestors.cjs"
89
+ "types": "./lib/index.d.cts",
90
+ "default": "./lib/index.cjs"
92
91
  }
93
92
  },
94
93
  "./lib/helpers/getCommandAndAncestors": {
95
94
  "import": {
96
- "types": "./lib/lib/helpers/getCommandAndAncestors.d.ts",
97
- "default": "./lib/lib/helpers/getCommandAndAncestors.js"
95
+ "types": "./lib/index.d.ts",
96
+ "default": "./lib/index.js"
98
97
  },
99
98
  "require": {
100
- "types": "./lib/lib/helpers/getCommandAndAncestors.d.cts",
101
- "default": "./lib/lib/helpers/getCommandAndAncestors.cjs"
99
+ "types": "./lib/index.d.cts",
100
+ "default": "./lib/index.cjs"
102
101
  }
103
102
  },
104
103
  "./lib/helpers/parseOptionFlags": {
105
104
  "import": {
106
- "types": "./lib/lib/helpers/parseOptionFlags.d.ts",
107
- "default": "./lib/lib/helpers/parseOptionFlags.js"
105
+ "types": "./lib/index.d.ts",
106
+ "default": "./lib/index.js"
108
107
  },
109
108
  "require": {
110
- "types": "./lib/lib/helpers/parseOptionFlags.d.cts",
111
- "default": "./lib/lib/helpers/parseOptionFlags.cjs"
109
+ "types": "./lib/index.d.cts",
110
+ "default": "./lib/index.cjs"
112
111
  }
113
112
  },
114
113
  "./lib/types": {
115
114
  "import": {
116
- "types": "./lib/lib/types.d.ts",
117
- "default": "./lib/lib/types.js"
115
+ "types": "./lib/index.d.ts",
116
+ "default": "./lib/index.js"
118
117
  },
119
118
  "require": {
120
- "types": "./lib/lib/types.d.cts",
121
- "default": "./lib/lib/types.cjs"
119
+ "types": "./lib/index.d.cts",
120
+ "default": "./lib/index.cjs"
122
121
  }
123
122
  }
124
123
  },
125
- "files": [
126
- "./lib/index.js",
127
- "./lib/index.d.ts",
128
- "./lib/index.cjs",
129
- "./lib/index.d.cts",
130
- "./lib/lib/Command.js",
131
- "./lib/lib/Command.d.ts",
132
- "./lib/lib/Command.cjs",
133
- "./lib/lib/Command.d.cts",
134
- "./lib/lib/Help.js",
135
- "./lib/lib/Help.d.ts",
136
- "./lib/lib/Help.cjs",
137
- "./lib/lib/Help.d.cts",
138
- "./lib/lib/helpers/findCommand.js",
139
- "./lib/lib/helpers/findCommand.d.ts",
140
- "./lib/lib/helpers/findCommand.cjs",
141
- "./lib/lib/helpers/findCommand.d.cts",
142
- "./lib/lib/helpers/findOption.js",
143
- "./lib/lib/helpers/findOption.d.ts",
144
- "./lib/lib/helpers/findOption.cjs",
145
- "./lib/lib/helpers/findOption.d.cts",
146
- "./lib/lib/helpers/getCommandAncestors.js",
147
- "./lib/lib/helpers/getCommandAncestors.d.ts",
148
- "./lib/lib/helpers/getCommandAncestors.cjs",
149
- "./lib/lib/helpers/getCommandAncestors.d.cts",
150
- "./lib/lib/helpers/getCommandAndAncestors.js",
151
- "./lib/lib/helpers/getCommandAndAncestors.d.ts",
152
- "./lib/lib/helpers/getCommandAndAncestors.cjs",
153
- "./lib/lib/helpers/getCommandAndAncestors.d.cts",
154
- "./lib/lib/helpers/parseOptionFlags.js",
155
- "./lib/lib/helpers/parseOptionFlags.d.ts",
156
- "./lib/lib/helpers/parseOptionFlags.cjs",
157
- "./lib/lib/helpers/parseOptionFlags.d.cts",
158
- "./lib/lib/types.js",
159
- "./lib/lib/types.d.ts",
160
- "./lib/lib/types.cjs",
161
- "./lib/lib/types.d.cts"
162
- ],
163
- "repository": {
164
- "type": "git",
165
- "url": "git+https://github.com/bemoje/mono.git",
166
- "directory": "libs/cli"
124
+ "dependencies": {
125
+ "ansi-colors": "^4.1.3",
126
+ "es-toolkit": "^1.45.1"
127
+ },
128
+ "publishConfig": {
129
+ "access": "public"
167
130
  },
131
+ "license": "MIT",
168
132
  "author": {
169
133
  "name": "Benjamin Møller Jensen",
170
134
  "email": "bemoje@bemoje.net",
171
135
  "url": "https://github.com/bemoje/"
172
136
  },
173
- "license": "MIT"
137
+ "repository": {
138
+ "type": "git",
139
+ "url": "git+https://github.com/bemoje/mono.git",
140
+ "directory": "libs/cli"
141
+ }
174
142
  }
@@ -1,450 +0,0 @@
1
- 'use strict';
2
-
3
- var Help = require('./Help');
4
- var collectVariadicOptionValues = require('./internal/collectVariadicOptionValues');
5
- var colors = require('ansi-colors');
6
- var object = require('@mono/object');
7
- var findCommand = require('./helpers/findCommand');
8
- var findOption = require('./helpers/findOption');
9
- var getCommandAncestors = require('./helpers/getCommandAncestors');
10
- var getCommandAndAncestors = require('./helpers/getCommandAndAncestors');
11
- var util = require('util');
12
- var string = require('es-toolkit/string');
13
- var decorators = require('@mono/decorators');
14
- var mergeOptionDefaults = require('./internal/mergeOptionDefaults');
15
- var normalizeArgv = require('./internal/normalizeArgv');
16
- var parseOptionFlags = require('./helpers/parseOptionFlags');
17
- var resolveArguments = require('./internal/resolveArguments');
18
- var fn = require('@mono/fn');
19
- var node = require('@mono/node');
20
- var array = require('es-toolkit/array');
21
- var validateParsed = require('./internal/validateParsed');
22
-
23
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
24
-
25
- var colors__default = /*#__PURE__*/_interopDefault(colors);
26
-
27
- var __defProp = Object.defineProperty;
28
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
29
- function _ts_decorate(decorators, target, key, desc) {
30
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
32
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
33
- return c > 3 && r && Object.defineProperty(target, key, r), r;
34
- }
35
- __name(_ts_decorate, "_ts_decorate");
36
- function _ts_metadata(k, v) {
37
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
38
- }
39
- __name(_ts_metadata, "_ts_metadata");
40
- class Command {
41
- static {
42
- __name(this, "Command");
43
- }
44
- /** parent command in the hierarchy, undefined for root command */
45
- parent;
46
- /** the command name used to invoke it */
47
- name;
48
- /** semantic version string displayed by --version flag */
49
- version;
50
- /** alternative names for invoking this command */
51
- aliases;
52
- /** brief one-line description shown in command lists */
53
- summary;
54
- /** full description displayed in help text */
55
- description;
56
- /** whether to exclude from help listings */
57
- hidden;
58
- /** category for organizing related commands in help output */
59
- group;
60
- /** positional arguments this command accepts */
61
- arguments;
62
- /** cLI options (flags) this command recognizes */
63
- options;
64
- /** subcommands registered with this command */
65
- commands;
66
- /** main action handler executed when command is invoked */
67
- action;
68
- /** option-driven actions (e.g., --help, --version) executed when their conditions match */
69
- hooks;
70
- constructor(name, parent) {
71
- this.name = name;
72
- this.aliases = [];
73
- this.description = "";
74
- this.arguments = [];
75
- this.options = [];
76
- this.commands = {};
77
- this.hooks = [];
78
- Object.defineProperty(this, "parent", {
79
- value: parent,
80
- enumerable: false
81
- });
82
- if (!parent) {
83
- this.addOption("-D, --debug", {
84
- description: "Display debug information"
85
- }).addOptionHook("debug", ({ cmd, ...data }) => {
86
- console.debug(util.inspect(cmd, {
87
- depth: 1,
88
- colors: true
89
- }));
90
- console.debug(util.inspect(data, {
91
- depth: 3,
92
- colors: true
93
- }));
94
- });
95
- this.addOption("-h, --help", {
96
- description: "Display help information"
97
- }).addOptionHook("help", ({ cmd }) => {
98
- console.log(cmd.renderHelp());
99
- process.exitCode = 0;
100
- });
101
- }
102
- }
103
- get help() {
104
- return new Help.Help(this);
105
- }
106
- /** configure how the help is rendered */
107
- helpConfiguration(cb) {
108
- const help = this.help;
109
- cb?.(help);
110
- return this;
111
- }
112
- /** renders formatted help text using provided help definition */
113
- renderHelp(config = {}) {
114
- const result = this.help.render();
115
- return config.noColor ? colors__default.default.stripColor(result) : result;
116
- }
117
- /** sets the command name */
118
- setName(name) {
119
- this.name = name;
120
- }
121
- /** sets command aliases, flattening nested arrays */
122
- setAliases(...aliases) {
123
- this.aliases = [];
124
- this.addAliases(...aliases);
125
- return this;
126
- }
127
- /** adds aliases to existing ones */
128
- addAliases(...aliases) {
129
- const taken = this.parent ? object.valuesOf(this.parent.commands).flatMap((c) => {
130
- return [
131
- c.name,
132
- ...c.aliases
133
- ];
134
- }) : [];
135
- array.uniq(aliases.flat()).filter((a) => {
136
- return !this.aliases.includes(a) && a !== this.name;
137
- }).forEach((a) => {
138
- if (taken.includes(a)) {
139
- throw new Error(`Alias "${a}" is already used by a sibling command: ${findCommand.findCommand(this.parent, a)?.name}`);
140
- }
141
- this.aliases.push(a);
142
- });
143
- this.aliases.sort((a, b) => {
144
- return a.length - b.length;
145
- });
146
- return this;
147
- }
148
- /** sets the command version */
149
- setVersion(version) {
150
- this.version = version;
151
- if (findOption.findOption(this, "version")) {
152
- return this;
153
- }
154
- return this.addOption("-V, --version", {
155
- description: "Display semver version"
156
- }).addOptionHook("version", ({ cmd }) => {
157
- console.log(getCommandAndAncestors.getCommandAndAncestors(cmd).find((c) => {
158
- return c.version;
159
- })?.version);
160
- process.exitCode = 0;
161
- });
162
- }
163
- /** sets the command summary */
164
- setSummary(summary) {
165
- this.summary = summary;
166
- return this;
167
- }
168
- /** sets command description, joining variadic lines */
169
- setDescription(...lines) {
170
- this.description = lines.join("\n");
171
- return this;
172
- }
173
- /** sets whether command is hidden from help */
174
- setHidden(hidden = true) {
175
- this.hidden = hidden;
176
- return this;
177
- }
178
- /** sets the command group for help organization */
179
- setGroup(group) {
180
- this.group = group;
181
- return this;
182
- }
183
- /** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
184
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
185
- command(name, cb) {
186
- if (this.arguments.length) {
187
- throw new Error(`Cannot add subcommand "${name}" to "${this.name}" because it already has arguments defined.`);
188
- }
189
- const sub = this.createSubcommand(name);
190
- const inherit = this.options;
191
- sub.options.push(...inherit);
192
- const inheritHooks = this.hooks.filter((t) => {
193
- return inherit.some((i) => {
194
- return i.name === t.name;
195
- });
196
- });
197
- sub.hooks.push(...inheritHooks);
198
- const taken = object.valuesOf(this.commands).flatMap((c) => {
199
- return [
200
- c.name,
201
- ...c.aliases
202
- ];
203
- });
204
- if (taken.includes(name)) {
205
- throw new Error(`Command name "${getCommandAndAncestors.getCommandAndAncestors(sub).map((c) => {
206
- return c.name;
207
- })}" is already used by this command or its aliases: ${taken.join(", ")}`);
208
- }
209
- const kebab = string.kebabCase(name);
210
- const words = kebab.split("-");
211
- const initials = words.map((s) => {
212
- return s[0];
213
- }).join("");
214
- if (taken.includes(initials)) {
215
- const initials2 = words.map((s) => {
216
- return s[0] + s[1];
217
- }).join("");
218
- if (!taken.includes(initials2)) {
219
- sub.addAliases(initials2);
220
- }
221
- } else {
222
- sub.addAliases(initials);
223
- }
224
- this.commands[name] = sub;
225
- return cb ? cb(sub, this) : sub;
226
- }
227
- /** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
228
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
229
- addCommand(name, cb) {
230
- this.command(name, cb);
231
- return this;
232
- }
233
- // implementation
234
- addArgument(usage, options = {}) {
235
- if (!/^<(.*?)>$|^\[(.*?)]$/.test(usage)) {
236
- throw new Error(`Invalid argument format: ${usage}`);
237
- }
238
- const name = usage.slice(1, -1).replace(/\.{3}$/, "");
239
- const required = usage.startsWith("<");
240
- const variadic = usage.slice(0, -1).endsWith("...");
241
- const prevArg = this.arguments[this.arguments.length - 1];
242
- if (prevArg?.variadic) {
243
- throw new Error(`Cannot add argument ${usage} after variadic argument ${prevArg.usage}`);
244
- }
245
- if (required && prevArg && !prevArg?.required) {
246
- throw new Error(`Cannot add required argument ${usage} after optional argument ${prevArg?.usage}`);
247
- }
248
- if (required && prevArg?.defaultValue) {
249
- throw new Error(`Cannot add required argument ${usage} after optional argument with default value ${prevArg.usage}`);
250
- }
251
- const arg = {
252
- usage,
253
- name,
254
- required,
255
- variadic,
256
- ...options
257
- };
258
- if (variadic && !arg.defaultValue) {
259
- arg.defaultValue = [];
260
- }
261
- this.arguments.push(arg);
262
- return this;
263
- }
264
- /**
265
- * adds command-line option with type inference. Parses format: `-s, --long [<value>|[value]|<value...>|[value...]]`
266
- */
267
- addOption(flags, opts = {}) {
268
- const ins = {};
269
- const { short, long, name, argName } = parseOptionFlags.parseOptionFlags(flags);
270
- for (const opt of this.options) {
271
- if (opt.long === long) {
272
- throw new Error(`Option long name, --${long} already in use by: ${opt.flags}`);
273
- }
274
- if (opt.short === short) {
275
- throw new Error(`Option short name, -${short} already in use by: ${opt.flags}`);
276
- }
277
- }
278
- ins.flags = flags;
279
- ins.short = short;
280
- ins.long = long;
281
- ins.name = name;
282
- ins.description = "";
283
- if (argName) {
284
- ins.type = "string";
285
- ins.argName = argName;
286
- if (flags.endsWith(">")) {
287
- if (flags.endsWith("...>")) {
288
- ins.required = true;
289
- ins.variadic = true;
290
- } else {
291
- ins.required = true;
292
- }
293
- } else if (flags.endsWith("]") && flags.endsWith("...]")) {
294
- ins.variadic = true;
295
- ins.defaultValue = opts.defaultValue ?? [];
296
- }
297
- } else {
298
- ins.type = "boolean";
299
- }
300
- for (const [key, value] of Object.entries(opts)) {
301
- if (value !== void 0) {
302
- Reflect.set(ins, key, value);
303
- }
304
- }
305
- if (ins.env && ins.defaultValue === void 0 && typeof process.env[ins.env] === "string") {
306
- ins.required = false;
307
- ins.flags = ins.flags.replace("<", "[").replace(">", "]");
308
- if (ins.type === "boolean") {
309
- ins.defaultValue = /^(t(rue)?|y(es)?|1)$/i.test(process.env[ins.env]);
310
- } else if (ins.variadic) {
311
- ins.defaultValue = process.env[ins.env].replace(/\[]/, "").split(",").map((v) => {
312
- return v.trim();
313
- });
314
- } else {
315
- ins.defaultValue = process.env[ins.env];
316
- }
317
- }
318
- this.options.push(ins);
319
- return this;
320
- }
321
- /**
322
- * register an action to be invoked when an option is set to true or string value.
323
- *
324
- * Hooks execute in addition to or instead of the main action handler,
325
- * allowing for option-driven behavior. For example, `--help` and `--version`
326
- * are implemented as hooks.
327
- */
328
- addOptionHook(optionName, action) {
329
- const def = findOption.findOption(this, optionName);
330
- if (!def.group && /process\.exitCode ?= ?.+;?\s*}$/.test(action.toString())) {
331
- def.group = "Command Options";
332
- }
333
- this.hooks.push({
334
- name: optionName,
335
- predicate: fn.setName(`has${string.upperFirst(optionName)}`, ({ opts }) => {
336
- return opts[optionName] !== void 0 && opts[optionName] !== false && !(Array.isArray(opts[optionName]) && opts[optionName].length === 0);
337
- }),
338
- action: fn.setName(optionName, action)
339
- });
340
- return this;
341
- }
342
- /** parses command-line arguments with subcommand support and type-safe validation. */
343
- parseArgv(argv = process.argv.slice(2)) {
344
- const sub = findCommand.findCommand(this, argv[0]);
345
- if (sub) {
346
- return sub.parseArgv(argv.slice(1));
347
- }
348
- argv = normalizeArgv.normalizeArgv(argv, this.options);
349
- const parsed = util.parseArgs({
350
- args: argv,
351
- options: Object.fromEntries(this.options.map((o) => {
352
- return [
353
- o.name,
354
- {
355
- type: o.type,
356
- short: o.short,
357
- default: o.defaultValue,
358
- multiple: !!o.variadic
359
- }
360
- ];
361
- })),
362
- allowPositionals: true,
363
- tokens: true,
364
- strict: false,
365
- allowNegative: true
366
- });
367
- collectVariadicOptionValues.collectVariadicOptionValues(parsed, this.options);
368
- mergeOptionDefaults.mergeOptionDefaults(parsed.values, this.options);
369
- parsed.values = object.objSortKeys(parsed.values, (a, b) => {
370
- return a[1] === false ? 1 : b[1] === false ? -1 : a[1] === true ? 1 : b[1] === true ? -1 : 0;
371
- });
372
- const args = resolveArguments.resolveArguments(parsed.positionals, this.arguments);
373
- const opts = object.filterObject(parsed.values, (value) => {
374
- return value !== void 0;
375
- });
376
- const errors = validateParsed.validateParsed(args, parsed.values, this.arguments, this.options);
377
- const path = getCommandAncestors.getCommandAncestors(this).map((c) => {
378
- return c.name;
379
- });
380
- const data = {
381
- path,
382
- name: this.name,
383
- argv,
384
- args,
385
- opts,
386
- errors,
387
- cmd: this
388
- };
389
- const hooks = this.hooks.filter((t) => {
390
- return t.predicate(data);
391
- });
392
- const execute = /* @__PURE__ */ __name(async () => {
393
- for (const hook of hooks) {
394
- await hook.action(data);
395
- if (process.exitCode !== void 0) {
396
- return;
397
- }
398
- }
399
- await node.timer([
400
- [
401
- ...path,
402
- this.name
403
- ].join(" "),
404
- this.description
405
- ], async (logger) => {
406
- if (errors) {
407
- errors.forEach((msg) => {
408
- return logger.error(colors__default.default.red(msg));
409
- });
410
- process.exitCode = 1;
411
- return;
412
- }
413
- if (this.action) {
414
- return await this.action(...args, opts, {
415
- ...data,
416
- args,
417
- opts,
418
- cmd: this,
419
- logger
420
- });
421
- }
422
- console.log(this.renderHelp());
423
- });
424
- }, "execute");
425
- return {
426
- ...data,
427
- hooks,
428
- execute
429
- };
430
- }
431
- /**
432
- * sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
433
- * The handler receives parsed arguments and options with correct typings.
434
- */
435
- setAction(fn$1) {
436
- this.action = fn.setName(this.name, fn$1);
437
- return this;
438
- }
439
- /** returns a new Command instance. Override this method in subclasses. */
440
- createSubcommand(name) {
441
- return new Command(name, this);
442
- }
443
- }
444
- _ts_decorate([
445
- decorators.lazyProp,
446
- _ts_metadata("design:type", typeof Help.Help === "undefined" ? Object : Help.Help),
447
- _ts_metadata("design:paramtypes", [])
448
- ], Command.prototype, "help", null);
449
-
450
- exports.Command = Command;
@@ -1 +0,0 @@
1
- export { C as Command } from '../Command--Ojy3KHE.cjs';
@@ -1 +0,0 @@
1
- export { C as Command } from '../Command--Ojy3KHE.js';