commander 12.0.0 → 13.0.0-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.
package/lib/option.js CHANGED
@@ -93,7 +93,7 @@ class Option {
93
93
  * .addOption(new Option('--log', 'write logging information to file'))
94
94
  * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
95
95
  *
96
- * @param {Object} impliedOptionValues
96
+ * @param {object} impliedOptionValues
97
97
  * @return {Option}
98
98
  */
99
99
  implies(impliedOptionValues) {
@@ -158,7 +158,7 @@ class Option {
158
158
  }
159
159
 
160
160
  /**
161
- * @package internal use only
161
+ * @package
162
162
  */
163
163
 
164
164
  _concatValue(value, previous) {
@@ -180,7 +180,9 @@ class Option {
180
180
  this.argChoices = values.slice();
181
181
  this.parseArg = (arg, previous) => {
182
182
  if (!this.argChoices.includes(arg)) {
183
- throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(', ')}.`);
183
+ throw new InvalidArgumentError(
184
+ `Allowed choices are ${this.argChoices.join(', ')}.`,
185
+ );
184
186
  }
185
187
  if (this.variadic) {
186
188
  return this._concatValue(arg, previous);
@@ -205,13 +207,16 @@ class Option {
205
207
 
206
208
  /**
207
209
  * Return option name, in a camelcase format that can be used
208
- * as a object attribute key.
210
+ * as an object attribute key.
209
211
  *
210
212
  * @return {string}
211
213
  */
212
214
 
213
215
  attributeName() {
214
- return camelcase(this.name().replace(/^no-/, ''));
216
+ if (this.negate) {
217
+ return camelcase(this.name().replace(/^no-/, ''));
218
+ }
219
+ return camelcase(this.name());
215
220
  }
216
221
 
217
222
  /**
@@ -219,7 +224,7 @@ class Option {
219
224
  *
220
225
  * @param {string} arg
221
226
  * @return {boolean}
222
- * @package internal use only
227
+ * @package
223
228
  */
224
229
 
225
230
  is(arg) {
@@ -232,7 +237,7 @@ class Option {
232
237
  * Options are one of boolean, negated, required argument, or optional argument.
233
238
  *
234
239
  * @return {boolean}
235
- * @package internal use only
240
+ * @package
236
241
  */
237
242
 
238
243
  isBoolean() {
@@ -255,7 +260,7 @@ class DualOptions {
255
260
  this.positiveOptions = new Map();
256
261
  this.negativeOptions = new Map();
257
262
  this.dualOptions = new Set();
258
- options.forEach(option => {
263
+ options.forEach((option) => {
259
264
  if (option.negate) {
260
265
  this.negativeOptions.set(option.attributeName(), option);
261
266
  } else {
@@ -282,7 +287,7 @@ class DualOptions {
282
287
 
283
288
  // Use the value to deduce if (probably) came from the option.
284
289
  const preset = this.negativeOptions.get(optionKey).presetArg;
285
- const negativeValue = (preset !== undefined) ? preset : false;
290
+ const negativeValue = preset !== undefined ? preset : false;
286
291
  return option.negate === (negativeValue === value);
287
292
  }
288
293
  }
@@ -310,16 +315,32 @@ function camelcase(str) {
310
315
  function splitOptionFlags(flags) {
311
316
  let shortFlag;
312
317
  let longFlag;
313
- // Use original very loose parsing to maintain backwards compatibility for now,
314
- // which allowed for example unintended `-sw, --short-word` [sic].
315
- const flagParts = flags.split(/[ |,]+/);
316
- if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1])) shortFlag = flagParts.shift();
317
- longFlag = flagParts.shift();
318
- // Add support for lone short flag without significantly changing parsing!
319
- if (!shortFlag && /^-[^-]$/.test(longFlag)) {
320
- shortFlag = longFlag;
321
- longFlag = undefined;
322
- }
318
+ // short flag, single dash and single character
319
+ const shortFlagExp = /^-[^-]$/;
320
+ // long flag, double dash and at least one character
321
+ const longFlagExp = /^--[^-]/;
322
+
323
+ const flagParts = flags.split(/[ |,]+/).concat('guard');
324
+ if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
325
+ if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
326
+
327
+ // Check for some unsupported flags that people try.
328
+ if (/^-[^-][^-]/.test(flagParts[0]))
329
+ throw new Error(
330
+ `invalid Option flags, short option is dash and single character: '${flags}'`,
331
+ );
332
+ if (shortFlag && shortFlagExp.test(flagParts[0]))
333
+ throw new Error(
334
+ `invalid Option flags, more than one short flag: '${flags}'`,
335
+ );
336
+ if (longFlag && longFlagExp.test(flagParts[0]))
337
+ throw new Error(
338
+ `invalid Option flags, more than one long flag: '${flags}'`,
339
+ );
340
+ // Generic error if failed to find a flag or an unexpected flag left over.
341
+ if (!(shortFlag || longFlag) || flagParts[0].startsWith('-'))
342
+ throw new Error(`invalid Option flags: '${flags}'`);
343
+
323
344
  return { shortFlag, longFlag };
324
345
  }
325
346
 
@@ -6,7 +6,8 @@ function editDistance(a, b) {
6
6
  // (Simple implementation.)
7
7
 
8
8
  // Quick early exit, return worst case.
9
- if (Math.abs(a.length - b.length) > maxDistance) return Math.max(a.length, b.length);
9
+ if (Math.abs(a.length - b.length) > maxDistance)
10
+ return Math.max(a.length, b.length);
10
11
 
11
12
  // distance between prefix substrings of a and b
12
13
  const d = [];
@@ -32,7 +33,7 @@ function editDistance(a, b) {
32
33
  d[i][j] = Math.min(
33
34
  d[i - 1][j] + 1, // deletion
34
35
  d[i][j - 1] + 1, // insertion
35
- d[i - 1][j - 1] + cost // substitution
36
+ d[i - 1][j - 1] + cost, // substitution
36
37
  );
37
38
  // transposition
38
39
  if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
@@ -60,7 +61,7 @@ function suggestSimilar(word, candidates) {
60
61
  const searchingOptions = word.startsWith('--');
61
62
  if (searchingOptions) {
62
63
  word = word.slice(2);
63
- candidates = candidates.map(candidate => candidate.slice(2));
64
+ candidates = candidates.map((candidate) => candidate.slice(2));
64
65
  }
65
66
 
66
67
  let similar = [];
@@ -85,7 +86,7 @@ function suggestSimilar(word, candidates) {
85
86
 
86
87
  similar.sort((a, b) => a.localeCompare(b));
87
88
  if (searchingOptions) {
88
- similar = similar.map(candidate => `--${candidate}`);
89
+ similar = similar.map((candidate) => `--${candidate}`);
89
90
  }
90
91
 
91
92
  if (similar.length > 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commander",
3
- "version": "12.0.0",
3
+ "version": "13.0.0-0",
4
4
  "description": "the complete solution for node.js command-line programs",
5
5
  "keywords": [
6
6
  "commander",
@@ -19,14 +19,18 @@
19
19
  "url": "git+https://github.com/tj/commander.js.git"
20
20
  },
21
21
  "scripts": {
22
- "lint": "npm run lint:javascript && npm run lint:typescript",
23
- "lint:javascript": "eslint index.js esm.mjs \"lib/*.js\" \"tests/**/*.js\"",
24
- "lint:typescript": "eslint typings/*.ts tests/*.ts",
25
- "test": "jest && npm run typecheck-ts",
26
- "test-esm": "node ./tests/esm-imports-test.mjs",
27
- "typecheck-ts": "tsd && tsc -p tsconfig.ts.json",
28
- "typecheck-js": "tsc -p tsconfig.js.json",
29
- "test-all": "npm run test && npm run lint && npm run typecheck-js && npm run test-esm"
22
+ "check": "npm run check:type && npm run check:lint && npm run check:format",
23
+ "check:format": "prettier --check .",
24
+ "check:lint": "eslint .",
25
+ "check:type": "npm run check:type:js && npm run check:type:ts",
26
+ "check:type:ts": "tsd && tsc -p tsconfig.ts.json",
27
+ "check:type:js": "tsc -p tsconfig.js.json",
28
+ "fix": "npm run fix:lint && npm run fix:format",
29
+ "fix:format": "prettier --write .",
30
+ "fix:lint": "eslint --fix .",
31
+ "test": "jest && npm run check:type:ts",
32
+ "test-all": "jest && npm run test-esm && npm run check",
33
+ "test-esm": "node ./tests/esm-imports-test.mjs"
30
34
  },
31
35
  "files": [
32
36
  "index.js",
@@ -56,21 +60,19 @@
56
60
  }
57
61
  },
58
62
  "devDependencies": {
63
+ "@eslint/js": "^9.4.0",
59
64
  "@types/jest": "^29.2.4",
60
- "@types/node": "^20.2.5",
61
- "@typescript-eslint/eslint-plugin": "^6.7.5",
62
- "@typescript-eslint/parser": "^6.7.5",
63
- "eslint": "^8.30.0",
64
- "eslint-config-standard": "^17.0.0",
65
- "eslint-config-standard-with-typescript": "^40.0.0",
66
- "eslint-plugin-import": "^2.26.0",
67
- "eslint-plugin-jest": "^27.1.7",
68
- "eslint-plugin-n": "^16.2.0",
69
- "eslint-plugin-promise": "^6.1.1",
65
+ "@types/node": "^22.7.4",
66
+ "eslint": "^8.57.1",
67
+ "eslint-config-prettier": "^9.1.0",
68
+ "eslint-plugin-jest": "^28.3.0",
69
+ "globals": "^15.7.0",
70
70
  "jest": "^29.3.1",
71
+ "prettier": "^3.2.5",
71
72
  "ts-jest": "^29.0.3",
72
- "tsd": "^0.30.4",
73
- "typescript": "^5.0.4"
73
+ "tsd": "^0.31.0",
74
+ "typescript": "^5.0.4",
75
+ "typescript-eslint": "^8.12.2"
74
76
  },
75
77
  "types": "typings/index.d.ts",
76
78
  "engines": {
@@ -11,7 +11,9 @@
11
11
  // - https://github.com/microsoft/TypeScript/issues/29729
12
12
  // - https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts
13
13
  // - https://github.com/sindresorhus/type-fest/blob/main/source/primitive.d.ts
14
- type LiteralUnion<LiteralType, BaseType extends string | number> = LiteralType | (BaseType & Record<never, never>);
14
+ type LiteralUnion<LiteralType, BaseType extends string | number> =
15
+ | LiteralType
16
+ | (BaseType & Record<never, never>);
15
17
 
16
18
  export class CommanderError extends Error {
17
19
  code: string;
@@ -24,7 +26,6 @@ export class CommanderError extends Error {
24
26
  * @param exitCode - suggested exit code which could be used with process.exit
25
27
  * @param code - an id string representing the error
26
28
  * @param message - human-readable description of the error
27
- * @constructor
28
29
  */
29
30
  constructor(exitCode: number, code: string, message: string);
30
31
  }
@@ -33,13 +34,13 @@ export class InvalidArgumentError extends CommanderError {
33
34
  /**
34
35
  * Constructs the InvalidArgumentError class
35
36
  * @param message - explanation of why argument is invalid
36
- * @constructor
37
37
  */
38
38
  constructor(message: string);
39
39
  }
40
40
  export { InvalidArgumentError as InvalidOptionArgumentError }; // deprecated old name
41
41
 
42
- export interface ErrorOptions { // optional parameter for error()
42
+ export interface ErrorOptions {
43
+ // optional parameter for error()
43
44
  /** an id string representing the error */
44
45
  code?: string;
45
46
  /** suggested exit code which could be used with process.exit */
@@ -162,11 +163,6 @@ export class Option {
162
163
  */
163
164
  env(name: string): this;
164
165
 
165
- /**
166
- * Calculate the full description, including defaultValue etc.
167
- */
168
- fullDescription(): string;
169
-
170
166
  /**
171
167
  * Set the custom handler for processing CLI option arguments into option values.
172
168
  */
@@ -194,7 +190,7 @@ export class Option {
194
190
 
195
191
  /**
196
192
  * Return option name, in a camelcase format that can be used
197
- * as a object attribute key.
193
+ * as an object attribute key.
198
194
  */
199
195
  attributeName(): string;
200
196
 
@@ -209,12 +205,25 @@ export class Option {
209
205
  export class Help {
210
206
  /** output helpWidth, long lines are wrapped to fit */
211
207
  helpWidth?: number;
208
+ minWidthToWrap: number;
212
209
  sortSubcommands: boolean;
213
210
  sortOptions: boolean;
214
211
  showGlobalOptions: boolean;
215
212
 
216
213
  constructor();
217
214
 
215
+ /*
216
+ * prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
217
+ * and just before calling `formatHelp()`.
218
+ *
219
+ * Commander just uses the helpWidth and the others are provided for subclasses.
220
+ */
221
+ prepareContext(contextOptions: {
222
+ error?: boolean;
223
+ helpWidth?: number;
224
+ outputHasColors?: boolean;
225
+ }): void;
226
+
218
227
  /** Get the command term to show in the list of subcommands. */
219
228
  subcommandTerm(cmd: Command): string;
220
229
  /** Get the command summary to show in the list of subcommands. */
@@ -250,14 +259,61 @@ export class Help {
250
259
  longestGlobalOptionTermLength(cmd: Command, helper: Help): number;
251
260
  /** Get the longest argument term length. */
252
261
  longestArgumentTermLength(cmd: Command, helper: Help): number;
262
+
263
+ /** Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations. */
264
+ displayWidth(str: string): number;
265
+
266
+ /** Style the titles. Called with 'Usage:', 'Options:', etc. */
267
+ styleTitle(title: string): string;
268
+
269
+ /** Usage: <str> */
270
+ styleUsage(str: string): string;
271
+ /** Style for command name in usage string. */
272
+ styleCommandText(str: string): string;
273
+
274
+ styleCommandDescription(str: string): string;
275
+ styleOptionDescription(str: string): string;
276
+ styleSubcommandDescription(str: string): string;
277
+ styleArgumentDescription(str: string): string;
278
+ /** Base style used by descriptions. */
279
+ styleDescriptionText(str: string): string;
280
+
281
+ styleOptionTerm(str: string): string;
282
+ styleSubcommandTerm(str: string): string;
283
+ styleArgumentTerm(str: string): string;
284
+
285
+ /** Base style used in terms and usage for options. */
286
+ styleOptionText(str: string): string;
287
+ /** Base style used in terms and usage for subcommands. */
288
+ styleSubcommandText(str: string): string;
289
+ /** Base style used in terms and usage for arguments. */
290
+ styleArgumentText(str: string): string;
291
+
253
292
  /** Calculate the pad width from the maximum term length. */
254
293
  padWidth(cmd: Command, helper: Help): number;
255
294
 
256
295
  /**
257
- * Wrap the given string to width characters per line, with lines after the first indented.
258
- * Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
296
+ * Wrap a string at whitespace, preserving existing line breaks.
297
+ * Wrapping is skipped if the width is less than `minWidthToWrap`.
298
+ */
299
+ boxWrap(str: string, width: number): string;
300
+
301
+ /** Detect manually wrapped and indented strings by checking for line break followed by whitespace. */
302
+ preformatted(str: string): boolean;
303
+
304
+ /**
305
+ * Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
306
+ *
307
+ * So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
308
+ * TTT DDD DDDD
309
+ * DD DDD
259
310
  */
260
- wrap(str: string, width: number, indent: number, minColumnWidth?: number): string;
311
+ formatItem(
312
+ term: string,
313
+ termWidth: number,
314
+ description: string,
315
+ helper: Help,
316
+ ): string;
261
317
 
262
318
  /** Generate the built-in help text. */
263
319
  formatHelp(cmd: Command, helper: Help): string;
@@ -267,26 +323,34 @@ export type HelpConfiguration = Partial<Help>;
267
323
  export interface ParseOptions {
268
324
  from: 'node' | 'electron' | 'user';
269
325
  }
270
- export interface HelpContext { // optional parameter for .help() and .outputHelp()
326
+ export interface HelpContext {
327
+ // optional parameter for .help() and .outputHelp()
271
328
  error: boolean;
272
329
  }
273
- export interface AddHelpTextContext { // passed to text function used with .addHelpText()
330
+ export interface AddHelpTextContext {
331
+ // passed to text function used with .addHelpText()
274
332
  error: boolean;
275
333
  command: Command;
276
334
  }
277
335
  export interface OutputConfiguration {
278
336
  writeOut?(str: string): void;
279
337
  writeErr?(str: string): void;
338
+ outputError?(str: string, write: (str: string) => void): void;
339
+
280
340
  getOutHelpWidth?(): number;
281
341
  getErrHelpWidth?(): number;
282
- outputError?(str: string, write: (str: string) => void): void;
283
342
 
343
+ getOutHasColors?(): boolean;
344
+ getErrHasColors?(): boolean;
345
+ stripColor?(str: string): string;
284
346
  }
285
347
 
286
348
  export type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';
287
349
  export type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';
288
350
  // The source is a string so author can define their own too.
289
- export type OptionValueSource = LiteralUnion<'default' | 'config' | 'env' | 'cli' | 'implied', string> | undefined;
351
+ export type OptionValueSource =
352
+ | LiteralUnion<'default' | 'config' | 'env' | 'cli' | 'implied', string>
353
+ | undefined;
290
354
 
291
355
  export type OptionValues = Record<string, any>;
292
356
 
@@ -334,7 +398,10 @@ export class Command {
334
398
  * @param opts - configuration options
335
399
  * @returns new command
336
400
  */
337
- command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>;
401
+ command(
402
+ nameAndArgs: string,
403
+ opts?: CommandOptions,
404
+ ): ReturnType<this['createCommand']>;
338
405
  /**
339
406
  * Define a command, implemented in a separate executable file.
340
407
  *
@@ -353,7 +420,11 @@ export class Command {
353
420
  * @param opts - configuration options
354
421
  * @returns `this` command for chaining
355
422
  */
356
- command(nameAndArgs: string, description: string, opts?: ExecutableCommandOptions): this;
423
+ command(
424
+ nameAndArgs: string,
425
+ description: string,
426
+ opts?: ExecutableCommandOptions,
427
+ ): this;
357
428
 
358
429
  /**
359
430
  * Factory routine to create a new unattached command.
@@ -394,7 +465,12 @@ export class Command {
394
465
  *
395
466
  * @returns `this` command for chaining
396
467
  */
397
- argument<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
468
+ argument<T>(
469
+ flags: string,
470
+ description: string,
471
+ fn: (value: string, previous: T) => T,
472
+ defaultValue?: T,
473
+ ): this;
398
474
  argument(name: string, description?: string, defaultValue?: unknown): this;
399
475
 
400
476
  /**
@@ -444,7 +520,13 @@ export class Command {
444
520
  /**
445
521
  * Add hook for life cycle event.
446
522
  */
447
- hook(event: HookEvent, listener: (thisCommand: Command, actionCommand: Command) => void | Promise<void>): this;
523
+ hook(
524
+ event: HookEvent,
525
+ listener: (
526
+ thisCommand: Command,
527
+ actionCommand: Command,
528
+ ) => void | Promise<void>,
529
+ ): this;
448
530
 
449
531
  /**
450
532
  * Register callback to use as replacement for calling process.exit.
@@ -522,7 +604,7 @@ export class Command {
522
604
  *
523
605
  * @returns `this` command for chaining
524
606
  */
525
- action(fn: (...args: any[]) => void | Promise<void>): this;
607
+ action(fn: (this: this, ...args: any[]) => void | Promise<void>): this;
526
608
 
527
609
  /**
528
610
  * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
@@ -544,10 +626,24 @@ export class Command {
544
626
  *
545
627
  * @returns `this` command for chaining
546
628
  */
547
- option(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
548
- option<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
629
+ option(
630
+ flags: string,
631
+ description?: string,
632
+ defaultValue?: string | boolean | string[],
633
+ ): this;
634
+ option<T>(
635
+ flags: string,
636
+ description: string,
637
+ parseArg: (value: string, previous: T) => T,
638
+ defaultValue?: T,
639
+ ): this;
549
640
  /** @deprecated since v7, instead use choices or a custom function */
550
- option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;
641
+ option(
642
+ flags: string,
643
+ description: string,
644
+ regexp: RegExp,
645
+ defaultValue?: string | boolean | string[],
646
+ ): this;
551
647
 
552
648
  /**
553
649
  * Define a required option, which must have a value after parsing. This usually means
@@ -555,10 +651,24 @@ export class Command {
555
651
  *
556
652
  * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
557
653
  */
558
- requiredOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
559
- requiredOption<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
654
+ requiredOption(
655
+ flags: string,
656
+ description?: string,
657
+ defaultValue?: string | boolean | string[],
658
+ ): this;
659
+ requiredOption<T>(
660
+ flags: string,
661
+ description: string,
662
+ parseArg: (value: string, previous: T) => T,
663
+ defaultValue?: T,
664
+ ): this;
560
665
  /** @deprecated since v7, instead use choices or a custom function */
561
- requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;
666
+ requiredOption(
667
+ flags: string,
668
+ description: string,
669
+ regexp: RegExp,
670
+ defaultValue?: string | boolean | string[],
671
+ ): this;
562
672
 
563
673
  /**
564
674
  * Factory routine to create a new unattached option.
@@ -583,7 +693,9 @@ export class Command {
583
693
  * @returns `this` command for chaining
584
694
  */
585
695
  storeOptionsAsProperties<T extends OptionValues>(): this & T;
586
- storeOptionsAsProperties<T extends OptionValues>(storeAsProperties: true): this & T;
696
+ storeOptionsAsProperties<T extends OptionValues>(
697
+ storeAsProperties: true,
698
+ ): this & T;
587
699
  storeOptionsAsProperties(storeAsProperties?: boolean): this;
588
700
 
589
701
  /**
@@ -599,7 +711,11 @@ export class Command {
599
711
  /**
600
712
  * Store option value and where the value came from.
601
713
  */
602
- setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this;
714
+ setOptionValueWithSource(
715
+ key: string,
716
+ value: unknown,
717
+ source: OptionValueSource,
718
+ ): this;
603
719
 
604
720
  /**
605
721
  * Get source of option value.
@@ -607,7 +723,7 @@ export class Command {
607
723
  getOptionValueSource(key: string): OptionValueSource | undefined;
608
724
 
609
725
  /**
610
- * Get source of option value. See also .optsWithGlobals().
726
+ * Get source of option value. See also .optsWithGlobals().
611
727
  */
612
728
  getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined;
613
729
 
@@ -663,38 +779,49 @@ export class Command {
663
779
  /**
664
780
  * Parse `argv`, setting options and invoking commands when defined.
665
781
  *
666
- * The default expectation is that the arguments are from node and have the application as argv[0]
667
- * and the script being run in argv[1], with user parameters after that.
782
+ * Use parseAsync instead of parse if any of your action handlers are async.
783
+ *
784
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
785
+ *
786
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
787
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
788
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
789
+ * - `'user'`: just user arguments
668
790
  *
669
791
  * @example
670
792
  * ```
671
- * program.parse(process.argv);
672
- * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
793
+ * program.parse(); // parse process.argv and auto-detect electron and special node flags
794
+ * program.parse(process.argv); // assume argv[0] is app and argv[1] is script
673
795
  * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
674
796
  * ```
675
797
  *
676
798
  * @returns `this` command for chaining
677
799
  */
678
- parse(argv?: readonly string[], options?: ParseOptions): this;
800
+ parse(argv?: readonly string[], parseOptions?: ParseOptions): this;
679
801
 
680
802
  /**
681
803
  * Parse `argv`, setting options and invoking commands when defined.
682
804
  *
683
- * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
805
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
684
806
  *
685
- * The default expectation is that the arguments are from node and have the application as argv[0]
686
- * and the script being run in argv[1], with user parameters after that.
807
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
808
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
809
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
810
+ * - `'user'`: just user arguments
687
811
  *
688
812
  * @example
689
813
  * ```
690
- * program.parseAsync(process.argv);
691
- * program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
692
- * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
814
+ * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
815
+ * await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
816
+ * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
693
817
  * ```
694
818
  *
695
819
  * @returns Promise
696
820
  */
697
- parseAsync(argv?: readonly string[], options?: ParseOptions): Promise<this>;
821
+ parseAsync(
822
+ argv?: readonly string[],
823
+ parseOptions?: ParseOptions,
824
+ ): Promise<this>;
698
825
 
699
826
  /**
700
827
  * Parse options from `argv` removing known options,
@@ -869,7 +996,10 @@ export class Command {
869
996
  * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
870
997
  */
871
998
  addHelpText(position: AddHelpTextPosition, text: string): this;
872
- addHelpText(position: AddHelpTextPosition, text: (context: AddHelpTextContext) => string): this;
999
+ addHelpText(
1000
+ position: AddHelpTextPosition,
1001
+ text: (context: AddHelpTextContext) => string,
1002
+ ): this;
873
1003
 
874
1004
  /**
875
1005
  * Add a listener (callback) for when events occur. (Implemented using EventEmitter.)