@bemoje/cli 0.2.0 → 0.3.0

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 (121) hide show
  1. package/index.d.ts +6 -0
  2. package/index.js +6 -0
  3. package/lib/Command.d.ts +293 -0
  4. package/lib/Command.js +435 -0
  5. package/lib/CommandHelpAdapter.d.ts +157 -0
  6. package/lib/CommandHelpAdapter.js +100 -0
  7. package/lib/CommanderHelpAdapter.d.ts +56 -0
  8. package/lib/CommanderHelpAdapter.js +90 -0
  9. package/lib/Help.d.ts +263 -0
  10. package/lib/Help.js +477 -0
  11. package/lib/internal/lazyProp.d.ts +5 -0
  12. package/lib/internal/lazyProp.js +24 -0
  13. package/lib/renderHelp.d.ts +6 -0
  14. package/lib/renderHelp.js +12 -0
  15. package/package.json +25 -37
  16. package/LICENSE +0 -21
  17. package/README.md +0 -34
  18. package/cjs/arg/ArgumentBuilder.d.ts +0 -23
  19. package/cjs/arg/ArgumentBuilder.d.ts.map +0 -1
  20. package/cjs/arg/ArgumentBuilder.js +0 -52
  21. package/cjs/arg/ArgumentBuilder.js.map +0 -1
  22. package/cjs/arg/ArgumentParserSelector.d.ts +0 -9
  23. package/cjs/arg/ArgumentParserSelector.d.ts.map +0 -1
  24. package/cjs/arg/ArgumentParserSelector.js +0 -15
  25. package/cjs/arg/ArgumentParserSelector.js.map +0 -1
  26. package/cjs/arg/ArgumentReader.d.ts +0 -15
  27. package/cjs/arg/ArgumentReader.d.ts.map +0 -1
  28. package/cjs/arg/ArgumentReader.js +0 -38
  29. package/cjs/arg/ArgumentReader.js.map +0 -1
  30. package/cjs/arg/ArgumentValidatorSelector.d.ts +0 -8
  31. package/cjs/arg/ArgumentValidatorSelector.d.ts.map +0 -1
  32. package/cjs/arg/ArgumentValidatorSelector.js +0 -16
  33. package/cjs/arg/ArgumentValidatorSelector.js.map +0 -1
  34. package/cjs/cmd/CommandBuilder.d.ts +0 -410
  35. package/cjs/cmd/CommandBuilder.d.ts.map +0 -1
  36. package/cjs/cmd/CommandBuilder.js +0 -1277
  37. package/cjs/cmd/CommandBuilder.js.map +0 -1
  38. package/cjs/cmd/CommandBuilderMetaData.d.ts +0 -26
  39. package/cjs/cmd/CommandBuilderMetaData.d.ts.map +0 -1
  40. package/cjs/cmd/CommandBuilderMetaData.js +0 -45
  41. package/cjs/cmd/CommandBuilderMetaData.js.map +0 -1
  42. package/cjs/cmd/CommandFeatureSelector.d.ts +0 -80
  43. package/cjs/cmd/CommandFeatureSelector.d.ts.map +0 -1
  44. package/cjs/cmd/CommandFeatureSelector.js +0 -114
  45. package/cjs/cmd/CommandFeatureSelector.js.map +0 -1
  46. package/cjs/cmd/DefaultHelpConfig.d.ts +0 -29
  47. package/cjs/cmd/DefaultHelpConfig.d.ts.map +0 -1
  48. package/cjs/cmd/DefaultHelpConfig.js +0 -177
  49. package/cjs/cmd/DefaultHelpConfig.js.map +0 -1
  50. package/cjs/cmd/commanderBackRefs.d.ts +0 -10
  51. package/cjs/cmd/commanderBackRefs.d.ts.map +0 -1
  52. package/cjs/cmd/commanderBackRefs.js +0 -38
  53. package/cjs/cmd/commanderBackRefs.js.map +0 -1
  54. package/cjs/core/OutputManager.d.ts +0 -64
  55. package/cjs/core/OutputManager.d.ts.map +0 -1
  56. package/cjs/core/OutputManager.js +0 -92
  57. package/cjs/core/OutputManager.js.map +0 -1
  58. package/cjs/core/ParserSelector.d.ts +0 -23
  59. package/cjs/core/ParserSelector.d.ts.map +0 -1
  60. package/cjs/core/ParserSelector.js +0 -46
  61. package/cjs/core/ParserSelector.js.map +0 -1
  62. package/cjs/core/ValidatorSelector.d.ts +0 -19
  63. package/cjs/core/ValidatorSelector.d.ts.map +0 -1
  64. package/cjs/core/ValidatorSelector.js +0 -42
  65. package/cjs/core/ValidatorSelector.js.map +0 -1
  66. package/cjs/core/splitCombinedArgvShorts.d.ts +0 -2
  67. package/cjs/core/splitCombinedArgvShorts.d.ts.map +0 -1
  68. package/cjs/core/splitCombinedArgvShorts.js +0 -15
  69. package/cjs/core/splitCombinedArgvShorts.js.map +0 -1
  70. package/cjs/db/AbstractJsonFileSection.d.ts +0 -136
  71. package/cjs/db/AbstractJsonFileSection.d.ts.map +0 -1
  72. package/cjs/db/AbstractJsonFileSection.js +0 -190
  73. package/cjs/db/AbstractJsonFileSection.js.map +0 -1
  74. package/cjs/db/AppDataSection.d.ts +0 -31
  75. package/cjs/db/AppDataSection.d.ts.map +0 -1
  76. package/cjs/db/AppDataSection.js +0 -49
  77. package/cjs/db/AppDataSection.js.map +0 -1
  78. package/cjs/db/ConfigSection.d.ts +0 -46
  79. package/cjs/db/ConfigSection.d.ts.map +0 -1
  80. package/cjs/db/ConfigSection.js +0 -71
  81. package/cjs/db/ConfigSection.js.map +0 -1
  82. package/cjs/db/JsonFile.d.ts +0 -36
  83. package/cjs/db/JsonFile.d.ts.map +0 -1
  84. package/cjs/db/JsonFile.js +0 -60
  85. package/cjs/db/JsonFile.js.map +0 -1
  86. package/cjs/db/PresetsSection.d.ts +0 -45
  87. package/cjs/db/PresetsSection.d.ts.map +0 -1
  88. package/cjs/db/PresetsSection.js +0 -82
  89. package/cjs/db/PresetsSection.js.map +0 -1
  90. package/cjs/index.d.ts +0 -26
  91. package/cjs/index.d.ts.map +0 -1
  92. package/cjs/index.js +0 -29
  93. package/cjs/index.js.map +0 -1
  94. package/cjs/opt/OptionArgumentParserSelector.d.ts +0 -8
  95. package/cjs/opt/OptionArgumentParserSelector.d.ts.map +0 -1
  96. package/cjs/opt/OptionArgumentParserSelector.js +0 -16
  97. package/cjs/opt/OptionArgumentParserSelector.js.map +0 -1
  98. package/cjs/opt/OptionArgumentValidatorSelector.d.ts +0 -8
  99. package/cjs/opt/OptionArgumentValidatorSelector.d.ts.map +0 -1
  100. package/cjs/opt/OptionArgumentValidatorSelector.js +0 -19
  101. package/cjs/opt/OptionArgumentValidatorSelector.js.map +0 -1
  102. package/cjs/opt/OptionBuilder.d.ts +0 -32
  103. package/cjs/opt/OptionBuilder.d.ts.map +0 -1
  104. package/cjs/opt/OptionBuilder.js +0 -97
  105. package/cjs/opt/OptionBuilder.js.map +0 -1
  106. package/cjs/opt/OptionHelpers.d.ts +0 -33
  107. package/cjs/opt/OptionHelpers.d.ts.map +0 -1
  108. package/cjs/opt/OptionHelpers.js +0 -57
  109. package/cjs/opt/OptionHelpers.js.map +0 -1
  110. package/cjs/opt/OptionReader.d.ts +0 -24
  111. package/cjs/opt/OptionReader.d.ts.map +0 -1
  112. package/cjs/opt/OptionReader.js +0 -66
  113. package/cjs/opt/OptionReader.js.map +0 -1
  114. package/cjs/types/IConfig.d.ts +0 -22
  115. package/cjs/types/IConfig.d.ts.map +0 -1
  116. package/cjs/types/IConfig.js +0 -3
  117. package/cjs/types/IConfig.js.map +0 -1
  118. package/cjs/types/IPreset.d.ts +0 -15
  119. package/cjs/types/IPreset.d.ts.map +0 -1
  120. package/cjs/types/IPreset.js +0 -3
  121. package/cjs/types/IPreset.js.map +0 -1
package/lib/Command.js ADDED
@@ -0,0 +1,435 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ import { parseArgs } from "node:util";
6
+ import { CommandHelpAdapter } from "./CommandHelpAdapter";
7
+ const _Command = class _Command {
8
+ constructor(name = "", parent = null) {
9
+ /** Command name used for invocation */
10
+ __publicField(this, "name");
11
+ /** Optional version string */
12
+ __publicField(this, "version");
13
+ /** Alternative names for this command */
14
+ __publicField(this, "aliases");
15
+ /** Brief single-line description */
16
+ __publicField(this, "summary");
17
+ /** Full command description */
18
+ __publicField(this, "description");
19
+ /** Whether command should be hidden from help */
20
+ __publicField(this, "hidden");
21
+ /** Group name for organizing commands in help */
22
+ __publicField(this, "group");
23
+ /** Parent command if this is a subcommand */
24
+ __publicField(this, "parent");
25
+ /** Child subcommands */
26
+ __publicField(this, "commands");
27
+ /** Positional arguments */
28
+ __publicField(this, "arguments");
29
+ /** Named options/flags */
30
+ __publicField(this, "options");
31
+ /** Help system configuration */
32
+ __publicField(this, "helpConfiguration");
33
+ this.name = name;
34
+ this.parent = parent;
35
+ this.aliases = [];
36
+ this.description = "";
37
+ this.commands = [];
38
+ this.arguments = [];
39
+ this.options = [];
40
+ this.helpConfiguration = { showGlobalOptions: true, sortOptions: true, sortSubcommands: true };
41
+ Object.defineProperty(this, "parent", { enumerable: false });
42
+ }
43
+ /** Updates multiple command properties at once */
44
+ setState(state) {
45
+ Object.assign(this, state);
46
+ if (state.commands) {
47
+ state.commands = state.commands.map((cmd) => new _Command(cmd.name, this).setState(cmd));
48
+ }
49
+ return this;
50
+ }
51
+ /** Serializes command to JSON, maintaining compatibility with previous state-based structure */
52
+ toJSON() {
53
+ const result = {
54
+ name: this.name,
55
+ version: this.version,
56
+ aliases: this.aliases,
57
+ summary: this.summary,
58
+ description: this.description,
59
+ hidden: this.hidden,
60
+ group: this.group,
61
+ commands: this.commands,
62
+ arguments: this.arguments,
63
+ options: this.options,
64
+ helpConfiguration: this.helpConfiguration
65
+ };
66
+ Object.defineProperty(result, "parent", {
67
+ value: this.parent,
68
+ writable: true,
69
+ enumerable: false,
70
+ configurable: true
71
+ });
72
+ return result;
73
+ }
74
+ /** Sets the command name */
75
+ setName(name) {
76
+ this.name = name;
77
+ }
78
+ /** Sets command aliases, flattening nested arrays */
79
+ setAliases(...aliases) {
80
+ this.aliases = aliases.flat();
81
+ return this;
82
+ }
83
+ /** Adds aliases to existing ones */
84
+ addAliases(...aliases) {
85
+ this.aliases.push(...aliases.flat());
86
+ return this;
87
+ }
88
+ /** Sets the command version */
89
+ setVersion(version) {
90
+ this.version = version;
91
+ return this;
92
+ }
93
+ /** Sets the command summary */
94
+ setSummary(summary) {
95
+ this.summary = summary;
96
+ return this;
97
+ }
98
+ /** Sets command description, joining multiple lines */
99
+ setDescription(...lines) {
100
+ this.description = lines.join("\n");
101
+ return this;
102
+ }
103
+ /** Sets whether command is hidden from help */
104
+ setHidden(hidden = true) {
105
+ this.hidden = hidden;
106
+ return this;
107
+ }
108
+ /** Sets the command group for help organization */
109
+ setGroup(group) {
110
+ this.group = group;
111
+ return this;
112
+ }
113
+ /** Sets the parent command */
114
+ setParent(parent) {
115
+ this.parent = parent;
116
+ return this;
117
+ }
118
+ /** Extends existing help configuration with new settings */
119
+ extendHelpConfiguration(config) {
120
+ this.helpConfiguration = { ...this.helpConfiguration, ...config };
121
+ return this;
122
+ }
123
+ /** Sets help configuration, using defaults if not provided */
124
+ setHelpConfiguration(config) {
125
+ this.helpConfiguration = config ? { ...config } : { showGlobalOptions: true, sortOptions: true, sortSubcommands: true };
126
+ return this;
127
+ }
128
+ /** Creates and adds a subcommand */
129
+ subcommand(name) {
130
+ const sub = new _Command(name, this);
131
+ this.commands.push(sub);
132
+ return sub;
133
+ }
134
+ /**
135
+ * Adds positional argument with type inference and CLI ordering validation.
136
+ */
137
+ argument(usage, description, options = {}) {
138
+ const match = usage.match(/^<(.*?)>$|^\[(.*?)\]$/);
139
+ if (!match) throw new Error(`Invalid argument format: ${usage}`);
140
+ const nameMatch = match[1] || match[2];
141
+ const name = nameMatch.replace(/\.\.\.$/, "");
142
+ this.assertArgumentNameNotInUse(name);
143
+ if (usage.startsWith("<")) {
144
+ if (nameMatch.endsWith("...")) {
145
+ this.assertNoMultipleVariadicArguments();
146
+ this.arguments.push({
147
+ name,
148
+ description,
149
+ required: true,
150
+ multiple: true,
151
+ ...options
152
+ });
153
+ } else {
154
+ this.assertNoOptionalOrVariadicArguments();
155
+ this.arguments.push({
156
+ name,
157
+ description,
158
+ required: true,
159
+ multiple: false,
160
+ ...options
161
+ });
162
+ }
163
+ } else if (usage.startsWith("[")) {
164
+ if (nameMatch.endsWith("...")) {
165
+ this.assertNoMultipleVariadicArguments();
166
+ this.arguments.push({
167
+ name,
168
+ description,
169
+ required: false,
170
+ multiple: true,
171
+ defaultValue: options.defaultValue ?? [],
172
+ ...options
173
+ });
174
+ } else {
175
+ this.assertNoVariadicArgument();
176
+ this.arguments.push({
177
+ name,
178
+ description,
179
+ required: false,
180
+ multiple: false,
181
+ ...options
182
+ });
183
+ }
184
+ }
185
+ return this;
186
+ }
187
+ /**
188
+ * Adds command-line option with type inference. Parses format: `-s, --long [<value>|[value]|<value...>|[value...]]`
189
+ */
190
+ option(usage, description, opts = {}) {
191
+ const match = usage.match(/^-(.+?), --([a-zA-Z][\w-]*)(?:\s*(<(.+?)>|\[(.+?)\]))?$/);
192
+ if (!match) throw new Error(`Invalid option format: ${usage}`);
193
+ const short = match[1];
194
+ this.assertOptionShortNameIsValid(short);
195
+ this.assertOptionShortNameNotInUse(short);
196
+ const name = match[2];
197
+ const argName = (match[4] || match[5])?.replace(/\.\.\.$/, "");
198
+ this.assertOptionNameNotInUse(name);
199
+ if (!argName) {
200
+ this.options.push({
201
+ type: "boolean",
202
+ short,
203
+ name,
204
+ description,
205
+ required: false,
206
+ multiple: false,
207
+ ...opts
208
+ });
209
+ } else if (usage.endsWith(">")) {
210
+ if (usage.endsWith("...>")) {
211
+ this.options.push({
212
+ type: "string",
213
+ short,
214
+ name,
215
+ argName,
216
+ description,
217
+ required: true,
218
+ multiple: true,
219
+ ...opts
220
+ });
221
+ } else {
222
+ this.options.push({
223
+ type: "string",
224
+ short,
225
+ name,
226
+ argName,
227
+ description,
228
+ required: true,
229
+ multiple: false,
230
+ ...opts
231
+ });
232
+ }
233
+ } else if (usage.endsWith("]")) {
234
+ if (usage.endsWith("...]")) {
235
+ this.options.push({
236
+ type: "string",
237
+ short,
238
+ name,
239
+ argName,
240
+ description,
241
+ required: false,
242
+ multiple: true,
243
+ defaultValue: opts.defaultValue ?? [],
244
+ ...opts
245
+ });
246
+ } else {
247
+ this.options.push({
248
+ type: "string",
249
+ short,
250
+ name,
251
+ argName,
252
+ description,
253
+ required: false,
254
+ multiple: false,
255
+ ...opts
256
+ });
257
+ }
258
+ }
259
+ return this;
260
+ }
261
+ /**
262
+ * Parses command-line arguments with subcommand support and type-safe validation.
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * const result = cmd.parse(['input.txt', '-v', '--format', 'json'])
267
+ * // { arguments: ['input.txt'], options: { verbose: true, format: 'json' } }
268
+ * ```
269
+ */
270
+ parse(argv = process.argv.slice(2), globalOptions = []) {
271
+ const maybeSubArg = parseArgs({
272
+ args: argv,
273
+ allowPositionals: true,
274
+ tokens: false,
275
+ strict: false,
276
+ allowNegative: true
277
+ }).positionals[0];
278
+ const sub = this.findCommand(maybeSubArg);
279
+ if (sub) {
280
+ return sub.parse(
281
+ argv?.filter((a) => a !== maybeSubArg),
282
+ [...globalOptions, ...this.options]
283
+ );
284
+ }
285
+ const parsed = parseArgs({
286
+ args: argv,
287
+ options: Object.fromEntries(
288
+ [...globalOptions, ...this.options].map((o) => {
289
+ return [o.name, o];
290
+ })
291
+ ),
292
+ allowPositionals: true,
293
+ tokens: true,
294
+ strict: true,
295
+ allowNegative: true
296
+ });
297
+ for (let i = 0; i < parsed.tokens.length; i++) {
298
+ const token = parsed.tokens[i];
299
+ if (token.kind === "option") {
300
+ const optionDescriptor = this.options.find((o) => o.name === token.name);
301
+ if (optionDescriptor && optionDescriptor.multiple && optionDescriptor.type === "string") {
302
+ const values = [token.value];
303
+ let j = i + 1;
304
+ while (j < parsed.tokens.length && parsed.tokens[j].kind === "positional") {
305
+ const positionalToken = parsed.tokens[j];
306
+ if (positionalToken.kind === "positional") {
307
+ values.push(positionalToken.value);
308
+ const posIndex = parsed.positionals.indexOf(positionalToken.value);
309
+ if (posIndex !== -1) {
310
+ parsed.positionals.splice(posIndex, 1);
311
+ }
312
+ }
313
+ j++;
314
+ }
315
+ Reflect.set(
316
+ parsed.values,
317
+ token.name,
318
+ values.filter((v) => v !== void 0)
319
+ );
320
+ }
321
+ }
322
+ }
323
+ const parsedArguments = this.arguments.map((arg, index) => {
324
+ if (arg.multiple) {
325
+ const remainingArgs = parsed.positionals.slice(index);
326
+ return remainingArgs.length > 0 ? remainingArgs : arg.defaultValue ?? [];
327
+ } else {
328
+ return parsed.positionals[index] ?? arg.defaultValue;
329
+ }
330
+ });
331
+ for (const option of this.options) {
332
+ if (!(option.name in parsed.values) && "defaultValue" in option) {
333
+ Reflect.set(parsed.values, option.name, option.defaultValue);
334
+ }
335
+ }
336
+ const self = this;
337
+ return {
338
+ get command() {
339
+ return self;
340
+ },
341
+ arguments: parsedArguments,
342
+ options: { ...parsed.values }
343
+ };
344
+ }
345
+ /** Validates CLI argument ordering */
346
+ assertNoOptionalOrVariadicArguments() {
347
+ if (this.arguments.some((arg) => !arg.required)) {
348
+ throw new Error("Cannot add required argument after optional or variadic arguments");
349
+ }
350
+ }
351
+ /** Validates optional args don't follow variadic args */
352
+ assertNoVariadicArgument() {
353
+ if (this.arguments.some((arg) => arg.multiple)) {
354
+ throw new Error("Cannot add optional argument after variadic argument");
355
+ }
356
+ }
357
+ /** Ensures only one variadic argument per command */
358
+ assertNoMultipleVariadicArguments() {
359
+ if (this.arguments.some((arg) => arg.multiple)) {
360
+ throw new Error("Cannot add more than one variadic argument");
361
+ }
362
+ }
363
+ /** Ensures unique argument names across arguments and options */
364
+ assertArgumentNameNotInUse(name) {
365
+ if (this.arguments.some((arg) => arg.name === name)) {
366
+ throw new Error(`Argument name already in use: ${name}`);
367
+ }
368
+ if (this.options.some((opt) => opt.name === name)) {
369
+ throw new Error(`Argument name already in use: ${name}`);
370
+ }
371
+ }
372
+ /** Validates option short names are single alphanumeric characters */
373
+ assertOptionShortNameIsValid(short) {
374
+ const isSingleAlphaNumericChar = /^[a-zA-Z0-9]$/.test(short);
375
+ if (!isSingleAlphaNumericChar) {
376
+ throw new Error(`Expected short name to be a single alpha-numeric character. Got: ${short}`);
377
+ }
378
+ }
379
+ /** Validates option short names are unique across command hierarchy */
380
+ assertOptionShortNameNotInUse(short) {
381
+ for (const opt of this.options) {
382
+ if (opt.short === short) {
383
+ throw new Error(`Option short name already in use: -${short}`);
384
+ }
385
+ }
386
+ this.parent?.assertOptionShortNameNotInUse(short);
387
+ }
388
+ /** Validates option names are unique across command hierarchy */
389
+ assertOptionNameNotInUse(name) {
390
+ if (this.options.some((opt) => opt.name === name)) {
391
+ throw new Error(`Option name already in use: --${name}`);
392
+ }
393
+ this.parent?.assertOptionNameNotInUse(name);
394
+ }
395
+ /** Returns command and all ancestor commands in hierarchy */
396
+ getCommandAndAncestors() {
397
+ const result = [];
398
+ let command = this;
399
+ for (; command; command = command.parent) {
400
+ result.push(command);
401
+ }
402
+ return result;
403
+ }
404
+ /** Returns all ancestor commands excluding this command */
405
+ getAncestors() {
406
+ return this.getCommandAndAncestors().slice(1);
407
+ }
408
+ /** Returns all options from this command and ancestors */
409
+ getOptionsInclAncestors() {
410
+ return this.getCommandAndAncestors().flatMap((cmd) => cmd.options);
411
+ }
412
+ /** Finds subcommand by name or alias */
413
+ findCommand(name) {
414
+ if (!name) return void 0;
415
+ return this.commands.find((cmd) => cmd.name === name || cmd.aliases.includes(name));
416
+ }
417
+ /** Finds option by short or long name */
418
+ findOption(arg) {
419
+ return this.options.find((option) => option.short === arg || option.name === arg);
420
+ }
421
+ /** Returns a view that is compliant with the CommandHelp interface */
422
+ createHelpAdapter() {
423
+ return new CommandHelpAdapter(this);
424
+ }
425
+ /** Renders formatted help text using provided help definition */
426
+ renderHelp(help) {
427
+ return this.createHelpAdapter().renderHelp(help);
428
+ }
429
+ };
430
+ __name(_Command, "Command");
431
+ let Command = _Command;
432
+ export {
433
+ Command
434
+ };
435
+ //# sourceMappingURL=Command.js.map
@@ -0,0 +1,157 @@
1
+ import { Command, ArgumentDescriptor, ArgumentUsage, OptionDescriptor, OptionUsage } from './Command';
2
+ import { type ICommandHelp, type IHelp } from './Help';
3
+ /**
4
+ * Adapter for @see Command instances that implements the @see ICommandHelp interface required by the Help system.
5
+ * Used internally by the @see Command.prototype.renderHelp method.
6
+ */
7
+ export declare class CommandHelpAdapter implements ICommandHelp {
8
+ cmd: Command;
9
+ constructor(cmd: Command);
10
+ renderHelp(help?: IHelp): string;
11
+ get name(): string;
12
+ get aliases(): string[];
13
+ get summary(): string;
14
+ get description(): string;
15
+ get hidden(): boolean;
16
+ get usage(): string;
17
+ get group(): string;
18
+ get commands(): ICommandHelp[];
19
+ get options(): ({
20
+ flags: string;
21
+ long: string;
22
+ optional: boolean;
23
+ negate: boolean;
24
+ variadic: boolean;
25
+ type: "boolean";
26
+ argName?: never;
27
+ required: false;
28
+ multiple: false;
29
+ defaultValue?: boolean;
30
+ defaultValueDescription?: string;
31
+ short: string;
32
+ name: string;
33
+ description: string;
34
+ env?: string;
35
+ hidden?: boolean;
36
+ choices?: string[];
37
+ group?: string;
38
+ } | {
39
+ flags: string;
40
+ long: string;
41
+ optional: boolean;
42
+ negate: boolean;
43
+ variadic: boolean;
44
+ type: "string";
45
+ argName: string;
46
+ required: true;
47
+ multiple: false;
48
+ defaultValue?: never;
49
+ defaultValueDescription?: never;
50
+ short: string;
51
+ name: string;
52
+ description: string;
53
+ env?: string;
54
+ hidden?: boolean;
55
+ choices?: string[];
56
+ group?: string;
57
+ } | {
58
+ flags: string;
59
+ long: string;
60
+ optional: boolean;
61
+ negate: boolean;
62
+ variadic: boolean;
63
+ type: "string";
64
+ argName: string;
65
+ required: false;
66
+ multiple: false;
67
+ defaultValue?: string;
68
+ defaultValueDescription?: string;
69
+ short: string;
70
+ name: string;
71
+ description: string;
72
+ env?: string;
73
+ hidden?: boolean;
74
+ choices?: string[];
75
+ group?: string;
76
+ } | {
77
+ flags: string;
78
+ long: string;
79
+ optional: boolean;
80
+ negate: boolean;
81
+ variadic: boolean;
82
+ type: "string";
83
+ argName: string;
84
+ required: true;
85
+ multiple: true;
86
+ defaultValue?: never;
87
+ defaultValueDescription?: never;
88
+ short: string;
89
+ name: string;
90
+ description: string;
91
+ env?: string;
92
+ hidden?: boolean;
93
+ choices?: string[];
94
+ group?: string;
95
+ } | {
96
+ flags: string;
97
+ long: string;
98
+ optional: boolean;
99
+ negate: boolean;
100
+ variadic: boolean;
101
+ type: "string";
102
+ argName: string;
103
+ required: false;
104
+ multiple: true;
105
+ defaultValue?: string[];
106
+ defaultValueDescription?: string;
107
+ short: string;
108
+ name: string;
109
+ description: string;
110
+ env?: string;
111
+ hidden?: boolean;
112
+ choices?: string[];
113
+ group?: string;
114
+ })[];
115
+ get arguments(): ({
116
+ variadic: boolean;
117
+ multiple: false;
118
+ required: true;
119
+ defaultValue?: never;
120
+ defaultValueDescription?: never;
121
+ name: string;
122
+ description: string;
123
+ choices?: string[];
124
+ } | {
125
+ variadic: boolean;
126
+ required: false;
127
+ multiple: false;
128
+ defaultValue?: string;
129
+ defaultValueDescription?: string;
130
+ name: string;
131
+ description: string;
132
+ choices?: string[];
133
+ } | {
134
+ variadic: boolean;
135
+ required: true;
136
+ multiple: true;
137
+ defaultValue?: never;
138
+ defaultValueDescription?: never;
139
+ name: string;
140
+ description: string;
141
+ choices?: string[];
142
+ } | {
143
+ variadic: boolean;
144
+ required: false;
145
+ multiple: true;
146
+ defaultValue?: string[];
147
+ defaultValueDescription?: string;
148
+ name: string;
149
+ description: string;
150
+ choices?: string[];
151
+ })[];
152
+ get parent(): ICommandHelp | null;
153
+ get helpConfiguration(): Partial<IHelp>;
154
+ renderArgumentFlags(arg: ArgumentDescriptor): ArgumentUsage;
155
+ renderOptionFlags(opt: OptionDescriptor): OptionUsage;
156
+ }
157
+ //# sourceMappingURL=CommandHelpAdapter.d.ts.map
@@ -0,0 +1,100 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __decorateClass = (decorators, target, key, kind) => {
5
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
6
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
7
+ if (decorator = decorators[i])
8
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9
+ if (kind && result) __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ import lazyProp from "./internal/lazyProp";
13
+ import { Help } from "./Help";
14
+ import { renderHelp } from "./renderHelp";
15
+ const _CommandHelpAdapter = class _CommandHelpAdapter {
16
+ constructor(cmd) {
17
+ this.cmd = cmd;
18
+ }
19
+ renderHelp(help = new Help()) {
20
+ return renderHelp(this, help);
21
+ }
22
+ get name() {
23
+ return this.cmd.name;
24
+ }
25
+ get aliases() {
26
+ return this.cmd.aliases;
27
+ }
28
+ get summary() {
29
+ return this.cmd.summary ?? (this.cmd.description.includes("\n") ? this.cmd.description.split("\n")[0] : void 0);
30
+ }
31
+ get description() {
32
+ return this.cmd.description;
33
+ }
34
+ get hidden() {
35
+ return this.cmd.hidden;
36
+ }
37
+ get usage() {
38
+ return [
39
+ ...this.cmd.options.length ? ["[options]"] : [],
40
+ ...this.cmd.commands.length ? ["[command]"] : [],
41
+ ...this.cmd.arguments.map((arg) => this.renderArgumentFlags(arg))
42
+ ].join(" ");
43
+ }
44
+ get group() {
45
+ return this.cmd.group;
46
+ }
47
+ get commands() {
48
+ return this.cmd.commands.map((c) => new _CommandHelpAdapter(c));
49
+ }
50
+ get options() {
51
+ return this.cmd.options.map((opt) => ({
52
+ ...opt,
53
+ flags: this.renderOptionFlags(opt),
54
+ long: opt.name,
55
+ optional: !opt.required,
56
+ negate: false,
57
+ variadic: opt.multiple
58
+ }));
59
+ }
60
+ get arguments() {
61
+ return this.cmd.arguments.map((arg) => ({
62
+ ...arg,
63
+ variadic: arg.multiple
64
+ }));
65
+ }
66
+ get parent() {
67
+ return this.cmd.parent ? new _CommandHelpAdapter(this.cmd.parent) : null;
68
+ }
69
+ get helpConfiguration() {
70
+ return { ...this.cmd.helpConfiguration };
71
+ }
72
+ renderArgumentFlags(arg) {
73
+ return arg.required ? arg.multiple ? `<${arg.name}...>` : `<${arg.name}>` : arg.multiple ? `[${arg.name}...]` : `[${arg.name}]`;
74
+ }
75
+ renderOptionFlags(opt) {
76
+ const flags = `-${opt.short}, --${opt.name}`;
77
+ return opt.type === "boolean" ? flags : opt.required ? opt.multiple ? flags + ` <${opt.argName}...>` : flags + ` <${opt.argName}>` : opt.multiple ? flags + ` [${opt.argName}...]` : flags + ` [${opt.argName}]`;
78
+ }
79
+ };
80
+ __name(_CommandHelpAdapter, "CommandHelpAdapter");
81
+ __decorateClass([
82
+ lazyProp
83
+ ], _CommandHelpAdapter.prototype, "usage", 1);
84
+ __decorateClass([
85
+ lazyProp
86
+ ], _CommandHelpAdapter.prototype, "commands", 1);
87
+ __decorateClass([
88
+ lazyProp
89
+ ], _CommandHelpAdapter.prototype, "arguments", 1);
90
+ __decorateClass([
91
+ lazyProp
92
+ ], _CommandHelpAdapter.prototype, "parent", 1);
93
+ __decorateClass([
94
+ lazyProp
95
+ ], _CommandHelpAdapter.prototype, "helpConfiguration", 1);
96
+ let CommandHelpAdapter = _CommandHelpAdapter;
97
+ export {
98
+ CommandHelpAdapter
99
+ };
100
+ //# sourceMappingURL=CommandHelpAdapter.js.map