@bemoje/cli 1.0.4 → 1.0.6

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/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./lib/Command.js";
2
+ export * from "./lib/CommandHelpAdapter.js";
3
+ export * from "./lib/CommanderHelpAdapter.js";
4
+ export * from "./lib/Help.js";
5
+ export * from "./lib/renderHelp.js";
6
+ //# sourceMappingURL=index.js.map
@@ -1,6 +1,11 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
3
  import { parseArgs } from "node:util";
2
- import { CommandHelpAdapter } from "./CommandHelpAdapter";
4
+ import { CommandHelpAdapter } from "./CommandHelpAdapter.js";
3
5
  class Command {
6
+ static {
7
+ __name(this, "Command");
8
+ }
4
9
  /** Command name used for invocation */
5
10
  name;
6
11
  /** Optional version string */
@@ -426,4 +431,4 @@ class Command {
426
431
  export {
427
432
  Command
428
433
  };
429
- //# sourceMappingURL=Command.mjs.map
434
+ //# sourceMappingURL=Command.js.map
@@ -1,5 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
4
  var __decorateClass = (decorators, target, key, kind) => {
4
5
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
6
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
@@ -8,13 +9,16 @@ var __decorateClass = (decorators, target, key, kind) => {
8
9
  if (kind && result) __defProp(target, key, result);
9
10
  return result;
10
11
  };
11
- import lazyProp from "./internal/lazyProp";
12
- import { Help } from "./Help";
13
- import { renderHelp } from "./renderHelp";
12
+ import lazyProp from "./internal/lazyProp.js";
13
+ import { Help } from "./Help.js";
14
+ import { renderHelp } from "./renderHelp.js";
14
15
  const _CommandHelpAdapter = class _CommandHelpAdapter {
15
16
  constructor(cmd) {
16
17
  this.cmd = cmd;
17
18
  }
19
+ static {
20
+ __name(this, "CommandHelpAdapter");
21
+ }
18
22
  renderHelp(help = new Help()) {
19
23
  return renderHelp(this, help);
20
24
  }
@@ -95,4 +99,4 @@ let CommandHelpAdapter = _CommandHelpAdapter;
95
99
  export {
96
100
  CommandHelpAdapter
97
101
  };
98
- //# sourceMappingURL=CommandHelpAdapter.mjs.map
102
+ //# sourceMappingURL=CommandHelpAdapter.js.map
@@ -1,5 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
4
  var __decorateClass = (decorators, target, key, kind) => {
4
5
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
6
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
@@ -8,13 +9,16 @@ var __decorateClass = (decorators, target, key, kind) => {
8
9
  if (kind && result) __defProp(target, key, result);
9
10
  return result;
10
11
  };
11
- import { Help } from "./Help";
12
- import lazyProp from "./internal/lazyProp";
13
- import { renderHelp } from "./renderHelp";
12
+ import { Help } from "./Help.js";
13
+ import lazyProp from "./internal/lazyProp.js";
14
+ import { renderHelp } from "./renderHelp.js";
14
15
  const _CommanderHelpAdapter = class _CommanderHelpAdapter {
15
16
  constructor(cmd) {
16
17
  this.cmd = cmd;
17
18
  }
19
+ static {
20
+ __name(this, "CommanderHelpAdapter");
21
+ }
18
22
  renderHelp(help = new Help()) {
19
23
  return renderHelp(this, help);
20
24
  }
@@ -85,4 +89,4 @@ let CommanderHelpAdapter = _CommanderHelpAdapter;
85
89
  export {
86
90
  CommanderHelpAdapter
87
91
  };
88
- //# sourceMappingURL=CommanderHelpAdapter.mjs.map
92
+ //# sourceMappingURL=CommanderHelpAdapter.js.map
@@ -1,4 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
3
  class Help {
4
+ static {
5
+ __name(this, "Help");
6
+ }
2
7
  /** output helpWidth, long lines are wrapped to fit */
3
8
  helpWidth = process.stdout.isTTY ? process.stdout.columns : 80;
4
9
  minWidthToWrap = 40;
@@ -21,9 +26,9 @@ class Help {
21
26
  * Compare options for sort.
22
27
  */
23
28
  compareOptions(a, b) {
24
- const getSortKey = (option) => {
29
+ const getSortKey = /* @__PURE__ */ __name((option) => {
25
30
  return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
26
- };
31
+ }, "getSortKey");
27
32
  return getSortKey(a).localeCompare(getSortKey(b));
28
33
  }
29
34
  /**
@@ -226,6 +231,7 @@ class Help {
226
231
  function callFormatItem(term, description) {
227
232
  return helper.formatItem(term, termWidth, description, helper);
228
233
  }
234
+ __name(callFormatItem, "callFormatItem");
229
235
  let output = [`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`, ""];
230
236
  const commandDescription = helper.commandDescription(cmd);
231
237
  if (commandDescription.length > 0) {
@@ -456,11 +462,13 @@ function stripColor(str) {
456
462
  const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
457
463
  return str.replace(sgrPattern, "");
458
464
  }
465
+ __name(stripColor, "stripColor");
459
466
  function humanReadableArgName(arg) {
460
467
  const nameOutput = arg.name + (arg.variadic === true ? "..." : "");
461
468
  return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
462
469
  }
470
+ __name(humanReadableArgName, "humanReadableArgName");
463
471
  export {
464
472
  Help
465
473
  };
466
- //# sourceMappingURL=Help.mjs.map
474
+ //# sourceMappingURL=Help.js.map
@@ -1,3 +1,5 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
3
  function lazyProp(target, key, descriptor) {
2
4
  const orig = descriptor.get;
3
5
  if (typeof orig !== "function") {
@@ -15,7 +17,8 @@ function lazyProp(target, key, descriptor) {
15
17
  };
16
18
  return descriptor;
17
19
  }
20
+ __name(lazyProp, "lazyProp");
18
21
  export {
19
22
  lazyProp as default
20
23
  };
21
- //# sourceMappingURL=lazyProp.mjs.map
24
+ //# sourceMappingURL=lazyProp.js.map
@@ -0,0 +1,12 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { Help } from "./Help.js";
4
+ function renderHelp(cmd, help = new Help()) {
5
+ const helper = Object.assign(help, cmd.helpConfiguration);
6
+ return helper.formatHelp(cmd, helper);
7
+ }
8
+ __name(renderHelp, "renderHelp");
9
+ export {
10
+ renderHelp
11
+ };
12
+ //# sourceMappingURL=renderHelp.js.map
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@bemoje/cli",
3
3
  "description": "A type-safe CLI builder focused on command composition and help generation without execution coupling. Parse arguments, generate help, and integrate with existing CLI frameworks through a clean, fluent API.",
4
- "version": "1.0.4",
4
+ "version": "1.0.6",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "type": "module",
8
- "module": "./esm/index.mjs",
9
- "main": "./cjs/index.cjs",
10
- "typings": "./typings/index.d.ts",
8
+ "module": "./index.js",
9
+ "main": "./index.js",
10
+ "exports": {
11
+ ".": "./index.js",
12
+ "./*": "./lib/*.js",
13
+ "./package.json": "./package.json",
14
+ "./index.d.ts": "./index.d.ts"
15
+ },
16
+ "typings": "./index.d.ts",
11
17
  "dependencies": {},
12
18
  "devDependencies": {
13
19
  "commander": "^14.0.0"
package/cjs/index.cjs DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var src_exports = {};
17
- module.exports = __toCommonJS(src_exports);
18
- __reExport(src_exports, require("./lib/Command"), module.exports);
19
- __reExport(src_exports, require("./lib/CommandHelpAdapter"), module.exports);
20
- __reExport(src_exports, require("./lib/CommanderHelpAdapter"), module.exports);
21
- __reExport(src_exports, require("./lib/Help"), module.exports);
22
- __reExport(src_exports, require("./lib/renderHelp"), module.exports);
23
- // Annotate the CommonJS export names for ESM import in node:
24
- 0 && (module.exports = {
25
- ...require("./lib/Command"),
26
- ...require("./lib/CommandHelpAdapter"),
27
- ...require("./lib/CommanderHelpAdapter"),
28
- ...require("./lib/Help"),
29
- ...require("./lib/renderHelp")
30
- });
31
- //# sourceMappingURL=index.cjs.map
@@ -1,453 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var Command_exports = {};
20
- __export(Command_exports, {
21
- Command: () => Command
22
- });
23
- module.exports = __toCommonJS(Command_exports);
24
- var import_node_util = require("node:util");
25
- var import_CommandHelpAdapter = require("./CommandHelpAdapter");
26
- class Command {
27
- /** Command name used for invocation */
28
- name;
29
- /** Optional version string */
30
- version;
31
- /** Alternative names for this command */
32
- aliases;
33
- /** Brief single-line description */
34
- summary;
35
- /** Full command description */
36
- description;
37
- /** Whether command should be hidden from help */
38
- hidden;
39
- /** Group name for organizing commands in help */
40
- group;
41
- /** Parent command if this is a subcommand */
42
- parent;
43
- /** Child subcommands */
44
- commands;
45
- /** Positional arguments */
46
- arguments;
47
- /** Named options/flags */
48
- options;
49
- /** Help system configuration */
50
- helpConfiguration;
51
- constructor(name = "", parent = null) {
52
- this.name = name;
53
- this.parent = parent;
54
- this.aliases = [];
55
- this.description = "";
56
- this.commands = [];
57
- this.arguments = [];
58
- this.options = [];
59
- this.helpConfiguration = { showGlobalOptions: true, sortOptions: true, sortSubcommands: true };
60
- Object.defineProperty(this, "parent", { enumerable: false });
61
- }
62
- /** Updates multiple command properties at once */
63
- setState(state) {
64
- Object.assign(this, state);
65
- if (state.commands) {
66
- state.commands = state.commands.map((cmd) => new Command(cmd.name, this).setState(cmd));
67
- }
68
- return this;
69
- }
70
- /** Serializes command to JSON, maintaining compatibility with previous state-based structure */
71
- toJSON() {
72
- const result = {
73
- name: this.name,
74
- version: this.version,
75
- aliases: this.aliases,
76
- summary: this.summary,
77
- description: this.description,
78
- hidden: this.hidden,
79
- group: this.group,
80
- commands: this.commands,
81
- arguments: this.arguments,
82
- options: this.options,
83
- helpConfiguration: this.helpConfiguration
84
- };
85
- Object.defineProperty(result, "parent", {
86
- value: this.parent,
87
- writable: true,
88
- enumerable: false,
89
- configurable: true
90
- });
91
- return result;
92
- }
93
- /** Sets the command name */
94
- setName(name) {
95
- this.name = name;
96
- }
97
- /** Sets command aliases, flattening nested arrays */
98
- setAliases(...aliases) {
99
- this.aliases = aliases.flat();
100
- return this;
101
- }
102
- /** Adds aliases to existing ones */
103
- addAliases(...aliases) {
104
- this.aliases.push(...aliases.flat());
105
- return this;
106
- }
107
- /** Sets the command version */
108
- setVersion(version) {
109
- this.version = version;
110
- return this;
111
- }
112
- /** Sets the command summary */
113
- setSummary(summary) {
114
- this.summary = summary;
115
- return this;
116
- }
117
- /** Sets command description, joining multiple lines */
118
- setDescription(...lines) {
119
- this.description = lines.join("\n");
120
- return this;
121
- }
122
- /** Sets whether command is hidden from help */
123
- setHidden(hidden = true) {
124
- this.hidden = hidden;
125
- return this;
126
- }
127
- /** Sets the command group for help organization */
128
- setGroup(group) {
129
- this.group = group;
130
- return this;
131
- }
132
- /** Sets the parent command */
133
- setParent(parent) {
134
- this.parent = parent;
135
- return this;
136
- }
137
- /** Extends existing help configuration with new settings */
138
- extendHelpConfiguration(config) {
139
- this.helpConfiguration = { ...this.helpConfiguration, ...config };
140
- return this;
141
- }
142
- /** Sets help configuration, using defaults if not provided */
143
- setHelpConfiguration(config) {
144
- this.helpConfiguration = config ? { ...config } : { showGlobalOptions: true, sortOptions: true, sortSubcommands: true };
145
- return this;
146
- }
147
- /** Creates and adds a subcommand */
148
- subcommand(name) {
149
- const sub = new Command(name, this);
150
- this.commands.push(sub);
151
- return sub;
152
- }
153
- /**
154
- * Adds positional argument with type inference and CLI ordering validation.
155
- */
156
- argument(usage, description, options = {}) {
157
- const match = usage.match(/^<(.*?)>$|^\[(.*?)\]$/);
158
- if (!match) throw new Error(`Invalid argument format: ${usage}`);
159
- const nameMatch = match[1] || match[2];
160
- const name = nameMatch.replace(/\.\.\.$/, "");
161
- this.assertArgumentNameNotInUse(name);
162
- if (usage.startsWith("<")) {
163
- if (nameMatch.endsWith("...")) {
164
- this.assertNoMultipleVariadicArguments();
165
- this.arguments.push({
166
- name,
167
- description,
168
- required: true,
169
- multiple: true,
170
- ...options
171
- });
172
- } else {
173
- this.assertNoOptionalOrVariadicArguments();
174
- this.arguments.push({
175
- name,
176
- description,
177
- required: true,
178
- multiple: false,
179
- ...options
180
- });
181
- }
182
- } else if (usage.startsWith("[")) {
183
- if (nameMatch.endsWith("...")) {
184
- this.assertNoMultipleVariadicArguments();
185
- this.arguments.push({
186
- name,
187
- description,
188
- required: false,
189
- multiple: true,
190
- defaultValue: options.defaultValue ?? [],
191
- ...options
192
- });
193
- } else {
194
- this.assertNoVariadicArgument();
195
- this.arguments.push({
196
- name,
197
- description,
198
- required: false,
199
- multiple: false,
200
- ...options
201
- });
202
- }
203
- }
204
- return this;
205
- }
206
- /**
207
- * Adds command-line option with type inference. Parses format: `-s, --long [<value>|[value]|<value...>|[value...]]`
208
- */
209
- option(usage, description, opts = {}) {
210
- const match = usage.match(/^-(.+?), --([a-zA-Z][\w-]*)(?:\s*(<(.+?)>|\[(.+?)\]))?$/);
211
- if (!match) throw new Error(`Invalid option format: ${usage}`);
212
- const short = match[1];
213
- this.assertOptionShortNameIsValid(short);
214
- this.assertOptionShortNameNotInUse(short);
215
- const name = match[2];
216
- const argName = (match[4] || match[5])?.replace(/\.\.\.$/, "");
217
- this.assertOptionNameNotInUse(name);
218
- if (!argName) {
219
- this.options.push({
220
- type: "boolean",
221
- short,
222
- name,
223
- description,
224
- required: false,
225
- multiple: false,
226
- ...opts
227
- });
228
- } else if (usage.endsWith(">")) {
229
- if (usage.endsWith("...>")) {
230
- this.options.push({
231
- type: "string",
232
- short,
233
- name,
234
- argName,
235
- description,
236
- required: true,
237
- multiple: true,
238
- ...opts
239
- });
240
- } else {
241
- this.options.push({
242
- type: "string",
243
- short,
244
- name,
245
- argName,
246
- description,
247
- required: true,
248
- multiple: false,
249
- ...opts
250
- });
251
- }
252
- } else if (usage.endsWith("]")) {
253
- if (usage.endsWith("...]")) {
254
- this.options.push({
255
- type: "string",
256
- short,
257
- name,
258
- argName,
259
- description,
260
- required: false,
261
- multiple: true,
262
- defaultValue: opts.defaultValue ?? [],
263
- ...opts
264
- });
265
- } else {
266
- this.options.push({
267
- type: "string",
268
- short,
269
- name,
270
- argName,
271
- description,
272
- required: false,
273
- multiple: false,
274
- ...opts
275
- });
276
- }
277
- }
278
- return this;
279
- }
280
- /**
281
- * Parses command-line arguments with subcommand support and type-safe validation.
282
- *
283
- * @example
284
- * ```typescript
285
- * const result = cmd.parse(['input.txt', '-v', '--format', 'json'])
286
- * // { arguments: ['input.txt'], options: { verbose: true, format: 'json' } }
287
- * ```
288
- */
289
- parse(argv = process.argv.slice(2), globalOptions = []) {
290
- const maybeSubArg = (0, import_node_util.parseArgs)({
291
- args: argv,
292
- allowPositionals: true,
293
- tokens: false,
294
- strict: false,
295
- allowNegative: true
296
- }).positionals[0];
297
- const sub = this.findCommand(maybeSubArg);
298
- if (sub) {
299
- return sub.parse(
300
- argv?.filter((a) => a !== maybeSubArg),
301
- [...globalOptions, ...this.options]
302
- );
303
- }
304
- const parsed = (0, import_node_util.parseArgs)({
305
- args: argv,
306
- options: Object.fromEntries(
307
- [...globalOptions, ...this.options].map((o) => {
308
- return [o.name, o];
309
- })
310
- ),
311
- allowPositionals: true,
312
- tokens: true,
313
- strict: true,
314
- allowNegative: true
315
- });
316
- for (let i = 0; i < parsed.tokens.length; i++) {
317
- const token = parsed.tokens[i];
318
- if (token.kind === "option") {
319
- const optionDescriptor = this.options.find((o) => o.name === token.name);
320
- if (optionDescriptor && optionDescriptor.multiple && optionDescriptor.type === "string") {
321
- const values = [token.value];
322
- let j = i + 1;
323
- while (j < parsed.tokens.length && parsed.tokens[j].kind === "positional") {
324
- const positionalToken = parsed.tokens[j];
325
- if (positionalToken.kind === "positional") {
326
- values.push(positionalToken.value);
327
- const posIndex = parsed.positionals.indexOf(positionalToken.value);
328
- if (posIndex !== -1) {
329
- parsed.positionals.splice(posIndex, 1);
330
- }
331
- }
332
- j++;
333
- }
334
- Reflect.set(
335
- parsed.values,
336
- token.name,
337
- values.filter((v) => v !== void 0)
338
- );
339
- }
340
- }
341
- }
342
- const parsedArguments = this.arguments.map((arg, index) => {
343
- if (arg.multiple) {
344
- const remainingArgs = parsed.positionals.slice(index);
345
- return remainingArgs.length > 0 ? remainingArgs : arg.defaultValue ?? [];
346
- } else {
347
- return parsed.positionals[index] ?? arg.defaultValue;
348
- }
349
- });
350
- for (const option of this.options) {
351
- if (!(option.name in parsed.values) && "defaultValue" in option) {
352
- Reflect.set(parsed.values, option.name, option.defaultValue);
353
- }
354
- }
355
- const self = this;
356
- return {
357
- get command() {
358
- return self;
359
- },
360
- arguments: parsedArguments,
361
- options: { ...parsed.values }
362
- };
363
- }
364
- /** Validates CLI argument ordering */
365
- assertNoOptionalOrVariadicArguments() {
366
- if (this.arguments.some((arg) => !arg.required)) {
367
- throw new Error("Cannot add required argument after optional or variadic arguments");
368
- }
369
- }
370
- /** Validates optional args don't follow variadic args */
371
- assertNoVariadicArgument() {
372
- if (this.arguments.some((arg) => arg.multiple)) {
373
- throw new Error("Cannot add optional argument after variadic argument");
374
- }
375
- }
376
- /** Ensures only one variadic argument per command */
377
- assertNoMultipleVariadicArguments() {
378
- if (this.arguments.some((arg) => arg.multiple)) {
379
- throw new Error("Cannot add more than one variadic argument");
380
- }
381
- }
382
- /** Ensures unique argument names across arguments and options */
383
- assertArgumentNameNotInUse(name) {
384
- if (this.arguments.some((arg) => arg.name === name)) {
385
- throw new Error(`Argument name already in use: ${name}`);
386
- }
387
- if (this.options.some((opt) => opt.name === name)) {
388
- throw new Error(`Argument name already in use: ${name}`);
389
- }
390
- }
391
- /** Validates option short names are single alphanumeric characters */
392
- assertOptionShortNameIsValid(short) {
393
- const isSingleAlphaNumericChar = /^[a-zA-Z0-9]$/.test(short);
394
- if (!isSingleAlphaNumericChar) {
395
- throw new Error(`Expected short name to be a single alpha-numeric character. Got: ${short}`);
396
- }
397
- }
398
- /** Validates option short names are unique across command hierarchy */
399
- assertOptionShortNameNotInUse(short) {
400
- for (const opt of this.options) {
401
- if (opt.short === short) {
402
- throw new Error(`Option short name already in use: -${short}`);
403
- }
404
- }
405
- this.parent?.assertOptionShortNameNotInUse(short);
406
- }
407
- /** Validates option names are unique across command hierarchy */
408
- assertOptionNameNotInUse(name) {
409
- if (this.options.some((opt) => opt.name === name)) {
410
- throw new Error(`Option name already in use: --${name}`);
411
- }
412
- this.parent?.assertOptionNameNotInUse(name);
413
- }
414
- /** Returns command and all ancestor commands in hierarchy */
415
- getCommandAndAncestors() {
416
- const result = [];
417
- let command = this;
418
- for (; command; command = command.parent) {
419
- result.push(command);
420
- }
421
- return result;
422
- }
423
- /** Returns all ancestor commands excluding this command */
424
- getAncestors() {
425
- return this.getCommandAndAncestors().slice(1);
426
- }
427
- /** Returns all options from this command and ancestors */
428
- getOptionsInclAncestors() {
429
- return this.getCommandAndAncestors().flatMap((cmd) => cmd.options);
430
- }
431
- /** Finds subcommand by name or alias */
432
- findCommand(name) {
433
- if (!name) return void 0;
434
- return this.commands.find((cmd) => cmd.name === name || cmd.aliases.includes(name));
435
- }
436
- /** Finds option by short or long name */
437
- findOption(arg) {
438
- return this.options.find((option) => option.short === arg || option.name === arg);
439
- }
440
- /** Returns a view that is compliant with the CommandHelp interface */
441
- createHelpAdapter() {
442
- return new import_CommandHelpAdapter.CommandHelpAdapter(this);
443
- }
444
- /** Renders formatted help text using provided help definition */
445
- renderHelp(help) {
446
- return this.createHelpAdapter().renderHelp(help);
447
- }
448
- }
449
- // Annotate the CommonJS export names for ESM import in node:
450
- 0 && (module.exports = {
451
- Command
452
- });
453
- //# sourceMappingURL=Command.cjs.map