@oclif/core 5.1.0 → 5.1.1

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 (90) hide show
  1. package/lib/args.d.ts +2 -2
  2. package/lib/cache.d.ts +2 -2
  3. package/lib/command.d.ts +10 -14
  4. package/lib/command.js +9 -7
  5. package/lib/config/config.d.ts +10 -10
  6. package/lib/config/config.js +17 -13
  7. package/lib/config/plugin-loader.d.ts +5 -5
  8. package/lib/config/plugin-loader.js +31 -29
  9. package/lib/config/plugin.d.ts +7 -8
  10. package/lib/config/plugin.js +14 -15
  11. package/lib/config/ts-path.d.ts +2 -2
  12. package/lib/config/ts-path.js +1 -1
  13. package/lib/config/util.d.ts +1 -1
  14. package/lib/config/util.js +4 -3
  15. package/lib/constraints.d.ts +19 -19
  16. package/lib/constraints.js +14 -14
  17. package/lib/errors/error.d.ts +1 -1
  18. package/lib/errors/errors/cli.d.ts +1 -1
  19. package/lib/errors/errors/exit.d.ts +1 -1
  20. package/lib/errors/errors/module-load.d.ts +1 -1
  21. package/lib/errors/errors/pretty-print.d.ts +1 -1
  22. package/lib/errors/errors/pretty-print.js +1 -1
  23. package/lib/errors/handle.d.ts +2 -2
  24. package/lib/errors/index.d.ts +1 -1
  25. package/lib/execute.d.ts +1 -1
  26. package/lib/flags.d.ts +7 -7
  27. package/lib/flush.js +10 -6
  28. package/lib/help/command.d.ts +9 -11
  29. package/lib/help/command.js +9 -10
  30. package/lib/help/docopts.d.ts +4 -4
  31. package/lib/help/docopts.js +2 -2
  32. package/lib/help/formatter.d.ts +7 -7
  33. package/lib/help/index.d.ts +4 -6
  34. package/lib/help/index.js +8 -7
  35. package/lib/help/root.d.ts +1 -1
  36. package/lib/help/root.js +1 -1
  37. package/lib/help/util.d.ts +1 -1
  38. package/lib/help/util.js +1 -1
  39. package/lib/index.js +1 -0
  40. package/lib/interfaces/args.d.ts +1 -1
  41. package/lib/interfaces/config.d.ts +8 -8
  42. package/lib/interfaces/errors.d.ts +4 -4
  43. package/lib/interfaces/flags.d.ts +1 -1
  44. package/lib/interfaces/help.d.ts +3 -3
  45. package/lib/interfaces/hooks.d.ts +12 -12
  46. package/lib/interfaces/manifest.d.ts +2 -4
  47. package/lib/interfaces/parser.d.ts +13 -25
  48. package/lib/interfaces/pjson.d.ts +12 -22
  49. package/lib/interfaces/plugin.d.ts +11 -13
  50. package/lib/interfaces/s3-manifest.d.ts +2 -2
  51. package/lib/interfaces/topic.d.ts +2 -2
  52. package/lib/interfaces/ts-config.d.ts +2 -2
  53. package/lib/logger.d.ts +2 -2
  54. package/lib/logger.js +6 -2
  55. package/lib/main.d.ts +1 -1
  56. package/lib/main.js +3 -5
  57. package/lib/module-loader.d.ts +2 -2
  58. package/lib/module-loader.js +6 -5
  59. package/lib/parser/errors.d.ts +3 -3
  60. package/lib/parser/help.d.ts +2 -2
  61. package/lib/parser/parse.d.ts +2 -2
  62. package/lib/parser/parse.js +24 -24
  63. package/lib/parser/validate.d.ts +1 -1
  64. package/lib/parser/validate.js +25 -24
  65. package/lib/performance.d.ts +4 -4
  66. package/lib/performance.js +3 -3
  67. package/lib/util/aggregate-flags.d.ts +1 -1
  68. package/lib/util/cache-command.d.ts +2 -2
  69. package/lib/util/cache-command.js +3 -3
  70. package/lib/util/cache-default-value.d.ts +1 -1
  71. package/lib/util/determine-priority.d.ts +1 -1
  72. package/lib/util/ensure-arg-object.d.ts +3 -5
  73. package/lib/util/ensure-arg-object.js +1 -1
  74. package/lib/util/find-root.js +3 -1
  75. package/lib/util/read-pjson.d.ts +1 -1
  76. package/lib/util/read-tsconfig.d.ts +1 -1
  77. package/lib/util/util.d.ts +3 -5
  78. package/lib/util/util.js +1 -1
  79. package/lib/ux/action/base.d.ts +2 -2
  80. package/lib/ux/action/base.js +4 -4
  81. package/lib/ux/action/simple.d.ts +1 -1
  82. package/lib/ux/action/spinner.d.ts +2 -2
  83. package/lib/ux/action/spinner.js +4 -1
  84. package/lib/ux/action/types.d.ts +1 -1
  85. package/lib/ux/colorize-json.js +4 -4
  86. package/lib/ux/index.d.ts +2 -2
  87. package/lib/ux/list.js +1 -0
  88. package/lib/ux/theme.d.ts +1 -1
  89. package/lib/ux/write.d.ts +2 -2
  90. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import { Constraint, FlagGroup, FlagOutput, MultiFlagTester, SingleFlagTester } from './interfaces/parser';
2
- import { Validation } from './parser/errors';
1
+ import { type Constraint, type FlagGroup, type FlagOutput, type MultiFlagTester, type SingleFlagTester } from './interfaces/parser';
2
+ import { type Validation } from './parser/errors';
3
3
  /**
4
4
  * Establish a constraint on a single flag.
5
5
  *
@@ -43,7 +43,7 @@ declare class ConstraintImpl implements Constraint {
43
43
  */
44
44
  readonly is: ConstraintImpl;
45
45
  private readonly constrainedFlags;
46
- private constraintApplicatorFunctionHolder;
46
+ private readonly constraintApplicatorFunctionHolder;
47
47
  private topLevelCondition;
48
48
  private underConstructionCondition;
49
49
  constructor(constrainedFlags: string[]);
@@ -61,7 +61,7 @@ declare class ConstraintImpl implements Constraint {
61
61
  * @example <caption>--foo requires --bar when fnA returns true AND (fnB returns true OR fnC returns true)</caption>
62
62
  * flag('foo').is.dependentOn('bar').when.thisIsTrue(fnA).and.when.thisIsTrue(fnB).or.thisIsTrue(fnC)
63
63
  */
64
- get and(): ConstraintImpl;
64
+ get and(): this;
65
65
  /**
66
66
  * Chain property allowing constraint conditions to be combined with logical OR.
67
67
  *
@@ -77,21 +77,21 @@ declare class ConstraintImpl implements Constraint {
77
77
  * flag('foo').is.dependentOn('bar').when.thisIsTrue(fnA).and.when.thisIsTrue(fnB).or.thisIsTrue(fnC)
78
78
  *
79
79
  */
80
- get or(): ConstraintImpl;
80
+ get or(): this;
81
81
  /**
82
82
  * Chain property allowing constraints to be conditional upon a certain criterion NOT being met.
83
83
  *
84
84
  * @example
85
85
  * flag('foo').is.dependentOn('bar').unless.thisIsTrue(someFn)
86
86
  */
87
- get unless(): ConstraintImpl;
87
+ get unless(): this;
88
88
  /**
89
89
  * Chain property allowing constraints to be conditional upon a certain criterion being met.
90
90
  *
91
91
  * @example
92
92
  * flag('foo').is.dependentOn('bar').when.thisIsTrue(someFn)
93
93
  */
94
- get when(): ConstraintImpl;
94
+ get when(): this;
95
95
  _evaluateAgainstFlags(flags: FlagOutput): Validation;
96
96
  /**
97
97
  * Chain method allowing constraint to be made conditional upon EVERY established criterion being true.
@@ -105,7 +105,7 @@ declare class ConstraintImpl implements Constraint {
105
105
  * @param criterionTester An object whose keys are flag names and whose values are functions that accept the
106
106
  * value of that flag and return a boolean.
107
107
  */
108
- allFlagCriteriaSatisfied(criterionTester: SingleFlagTester): ConstraintImpl;
108
+ allFlagCriteriaSatisfied(criterionTester: SingleFlagTester): this;
109
109
  /**
110
110
  * Chain method allowing constraint to be made conditional upon ANY established criterion being true.
111
111
  *
@@ -118,7 +118,7 @@ declare class ConstraintImpl implements Constraint {
118
118
  * @param criterionTester An object whose keys are flag names and whose values are functions that accept the
119
119
  * value of that flag and return a boolean.
120
120
  */
121
- anyFlagCriterionSatisfied(criterionTester: SingleFlagTester): ConstraintImpl;
121
+ anyFlagCriterionSatisfied(criterionTester: SingleFlagTester): this;
122
122
  /**
123
123
  * Chain method allowing the constrained flags to require the presence of at least one of the flags specified here.
124
124
  *
@@ -133,7 +133,7 @@ declare class ConstraintImpl implements Constraint {
133
133
  *
134
134
  * @param dependencyFlagGroups
135
135
  */
136
- dependentOn(...dependencyFlagGroups: FlagGroup[]): ConstraintImpl;
136
+ dependentOn(...dependencyFlagGroups: FlagGroup[]): this;
137
137
  /**
138
138
  * Chain method allowing the constrained flags to be made exclusive with the flags provided here.
139
139
  *
@@ -148,35 +148,35 @@ declare class ConstraintImpl implements Constraint {
148
148
  *
149
149
  * @param exclusionFlagGroups
150
150
  */
151
- exclusiveWith(...exclusionFlagGroups: FlagGroup[]): ConstraintImpl;
151
+ exclusiveWith(...exclusionFlagGroups: FlagGroup[]): this;
152
152
  /**
153
153
  * Establish a group of flags as mutually dependent, meaning that they must either be used together or not at all.
154
154
  *
155
155
  * @example <caption>--foo cannot be used without --bar, and vice versa</caption>
156
156
  * flags('foo', 'bar').are.mutuallyDependent()
157
157
  */
158
- mutuallyDependent(): ConstraintImpl;
158
+ mutuallyDependent(): this;
159
159
  /**
160
160
  * Establish a group of flags as mutually exclusive, meaning that at most one of them can be used simultaneously.
161
161
  *
162
162
  * @example <caption>--foo and --bar cannot both be used at the same time</caption>
163
163
  * flags('foo', 'bar').are.mutuallyExclusive()
164
164
  */
165
- mutuallyExclusive(): ConstraintImpl;
165
+ mutuallyExclusive(): this;
166
166
  /**
167
167
  * Establish a group of flags as being collectively required.
168
168
  *
169
169
  * @example <caption>--foo and --bar are both always required</caption>
170
170
  * flags('foo', 'bar').are.requiredAll()
171
171
  */
172
- requiredAll(): ConstraintImpl;
172
+ requiredAll(): this;
173
173
  /**
174
174
  * Establish that at least one of the constrained flags must always be used.
175
175
  *
176
176
  * @example <caption>Must use at least one of --foo, --bar, or --baz</caption>
177
177
  * flags('foo', 'bar', 'baz').are.requiredAny()
178
178
  */
179
- requiredAny(): ConstraintImpl;
179
+ requiredAny(): this;
180
180
  /**
181
181
  * Establish that at least N of the specified flags must be used.
182
182
  *
@@ -185,7 +185,7 @@ declare class ConstraintImpl implements Constraint {
185
185
  *
186
186
  * @param n
187
187
  */
188
- requiredAtLeastN(n: number): ConstraintImpl;
188
+ requiredAtLeastN(n: number): this;
189
189
  /**
190
190
  * Establish that at most N of the specified flags must be used.
191
191
  *
@@ -194,7 +194,7 @@ declare class ConstraintImpl implements Constraint {
194
194
  *
195
195
  * @param n
196
196
  */
197
- requiredAtMostN(n: number): ConstraintImpl;
197
+ requiredAtMostN(n: number): this;
198
198
  /**
199
199
  * Establish that exactly N of the specified flags must be used.
200
200
  *
@@ -203,7 +203,7 @@ declare class ConstraintImpl implements Constraint {
203
203
  *
204
204
  * @param n
205
205
  */
206
- requiredExactlyN(n: number): ConstraintImpl;
206
+ requiredExactlyN(n: number): this;
207
207
  /**
208
208
  * Chain method allowing the constraint to be made contingent on the return of a method that accepts all flags.
209
209
  *
@@ -212,6 +212,6 @@ declare class ConstraintImpl implements Constraint {
212
212
  *
213
213
  * @param flagTester A method that accepts the flag values mapped by their name, and returns a boolean
214
214
  */
215
- thisIsTrue(flagTester: MultiFlagTester): ConstraintImpl;
215
+ thisIsTrue(flagTester: MultiFlagTester): this;
216
216
  }
217
217
  export {};
@@ -169,9 +169,9 @@ class ConstraintImpl {
169
169
  return this;
170
170
  }
171
171
  _evaluateAgainstFlags(flags) {
172
- let conditionSatisfied = false;
172
+ let isConditionSatisfied = false;
173
173
  try {
174
- conditionSatisfied = this.topLevelCondition ? this.topLevelCondition.isSatisfied(flags) : true;
174
+ isConditionSatisfied = this.topLevelCondition ? this.topLevelCondition.isSatisfied(flags) : true;
175
175
  }
176
176
  catch (error) {
177
177
  return {
@@ -186,7 +186,7 @@ class ConstraintImpl {
186
186
  return {
187
187
  name: this.constrainedFlags.join(','),
188
188
  reason: applicationResult,
189
- status: conditionSatisfied && applicationResult !== '' ? 'failed' : 'success',
189
+ status: isConditionSatisfied && applicationResult !== '' ? 'failed' : 'success',
190
190
  validationFn: this.constraintApplicatorFunctionHolder.constraintType ?? '',
191
191
  };
192
192
  }
@@ -217,7 +217,7 @@ class ConstraintImpl {
217
217
  if (this.underConstructionCondition === undefined) {
218
218
  throw new Error(`Misconfigured constraint condition on ${createFlagString(this.constrainedFlags)}: allFlagCriteriaSatisfied must immediately follow a when/unless/and/or`);
219
219
  }
220
- else if (this.underConstructionCondition instanceof UnaryOpCondition) {
220
+ if (this.underConstructionCondition instanceof UnaryOpCondition) {
221
221
  this.underConstructionCondition.setCondition(new AllFlagCriteriaSatisfiedCondition(criterionTester));
222
222
  this.underConstructionCondition = undefined;
223
223
  }
@@ -247,7 +247,7 @@ class ConstraintImpl {
247
247
  if (this.underConstructionCondition === undefined) {
248
248
  throw new Error(`Misconfigured constraint condition on ${createFlagString(this.constrainedFlags)}: anyFlagCriterionSatisfied must immediately follow a when/unless/and/or`);
249
249
  }
250
- else if (this.underConstructionCondition instanceof UnaryOpCondition) {
250
+ if (this.underConstructionCondition instanceof UnaryOpCondition) {
251
251
  this.underConstructionCondition.setCondition(new AnyFlagCriterionSatisfiedCondition(criterionTester));
252
252
  this.underConstructionCondition = undefined;
253
253
  }
@@ -293,8 +293,8 @@ class ConstraintImpl {
293
293
  }
294
294
  }
295
295
  }
296
- const multipleConstrainedFlags = this.constrainedFlags.length > 1;
297
- const header = multipleConstrainedFlags
296
+ const isMultipleConstrainedFlags = this.constrainedFlags.length > 1;
297
+ const header = isMultipleConstrainedFlags
298
298
  ? `Flags ${createFlagString(this.constrainedFlags)} require`
299
299
  : `Flag ${createFlagString(this.constrainedFlags)} requires`;
300
300
  return `${header} at least one of the following${this.topLevelCondition ? ' under current circumstances:' : ':'} ${createFlagString(dependencyFlagGroups)}.`;
@@ -321,27 +321,27 @@ class ConstraintImpl {
321
321
  if (foundConstraintFlags.length === 0) {
322
322
  return '';
323
323
  }
324
- let exclusionGroupFound = false;
324
+ let isExclusionGroupFound = false;
325
325
  for (const exclusionFlagGroup of exclusionFlagGroups) {
326
326
  if (typeof exclusionFlagGroup === 'string') {
327
327
  if (exclusionFlagGroup in flags && flags[exclusionFlagGroup] !== undefined) {
328
- exclusionGroupFound = true;
328
+ isExclusionGroupFound = true;
329
329
  break;
330
330
  }
331
331
  }
332
332
  else {
333
333
  const foundFlagsInExclusionGroup = filterFlagsPresentInInput(exclusionFlagGroup.flags, flags);
334
334
  if (foundFlagsInExclusionGroup.length === exclusionFlagGroup.flags.length) {
335
- exclusionGroupFound = true;
335
+ isExclusionGroupFound = true;
336
336
  break;
337
337
  }
338
338
  }
339
339
  }
340
- if (!exclusionGroupFound) {
340
+ if (!isExclusionGroupFound) {
341
341
  return '';
342
342
  }
343
- const multipleConstrainedFlags = this.constrainedFlags.length > 1;
344
- const header = multipleConstrainedFlags ? 'Flags' : 'Flag';
343
+ const isMultipleConstrainedFlags = this.constrainedFlags.length > 1;
344
+ const header = isMultipleConstrainedFlags ? 'Flags' : 'Flag';
345
345
  return `${header} ${createFlagString(this.constrainedFlags)} cannot be used with any of the following${this.topLevelCondition ? ' under current circumstances:' : ':'} ${createFlagString(exclusionFlagGroups)}.`;
346
346
  });
347
347
  return this;
@@ -461,7 +461,7 @@ class ConstraintImpl {
461
461
  if (this.underConstructionCondition === undefined) {
462
462
  throw new Error(`Misconfigured constraint condition on ${createFlagString(this.constrainedFlags)}: thisIsTrue must immediately follow a when/unless/and/or`);
463
463
  }
464
- else if (this.underConstructionCondition instanceof UnaryOpCondition) {
464
+ if (this.underConstructionCondition instanceof UnaryOpCondition) {
465
465
  this.underConstructionCondition.setCondition(new ThisIsTrueCondition(flagTester));
466
466
  this.underConstructionCondition = undefined;
467
467
  }
@@ -1,4 +1,4 @@
1
- import { PrettyPrintableError } from '../interfaces';
1
+ import { type PrettyPrintableError } from '../interfaces';
2
2
  export declare function error(input: Error | string, options: {
3
3
  exit: false;
4
4
  } & PrettyPrintableError): void;
@@ -1,4 +1,4 @@
1
- import { OclifError, PrettyPrintableError } from '../../interfaces/errors';
1
+ import { type OclifError, type PrettyPrintableError } from '../../interfaces/errors';
2
2
  /**
3
3
  * properties specific to internal oclif error handling
4
4
  */
@@ -1,4 +1,4 @@
1
- import { OclifError } from '../../interfaces';
1
+ import { type OclifError } from '../../interfaces';
2
2
  import { CLIError } from './cli';
3
3
  export declare class ExitError extends CLIError implements OclifError {
4
4
  code: string;
@@ -1,4 +1,4 @@
1
- import { OclifError } from '../../interfaces';
1
+ import { type OclifError } from '../../interfaces';
2
2
  import { CLIError } from './cli';
3
3
  export declare class ModuleLoadError extends CLIError implements OclifError {
4
4
  code: string;
@@ -1,4 +1,4 @@
1
- import { PrettyPrintableError } from '../../interfaces/errors';
1
+ import { type PrettyPrintableError } from '../../interfaces/errors';
2
2
  type CLIErrorDisplayOptions = {
3
3
  bang?: string | undefined;
4
4
  name?: string | undefined;
@@ -21,9 +21,9 @@ function applyPrettyPrintOptions(error, options) {
21
21
  return error;
22
22
  }
23
23
  const formatSuggestions = (suggestions) => {
24
- const label = 'Try this:';
25
24
  if (!suggestions || suggestions.length === 0)
26
25
  return undefined;
26
+ const label = 'Try this:';
27
27
  if (suggestions.length === 1)
28
28
  return `${label} ${suggestions[0]}`;
29
29
  const multiple = suggestions.map((suggestion) => `* ${suggestion}`).join('\n');
@@ -1,5 +1,5 @@
1
- import { OclifError, PrettyPrintableError } from '../interfaces';
2
- import { CLIParseError } from '../parser/errors';
1
+ import { type OclifError, type PrettyPrintableError } from '../interfaces';
2
+ import { type CLIParseError } from '../parser/errors';
3
3
  import { CLIError } from './errors/cli';
4
4
  /**
5
5
  * This is an odd abstraction for process.exit, but it allows us to stub it in tests.
@@ -1,4 +1,4 @@
1
- export { PrettyPrintableError } from '../interfaces';
1
+ export type { PrettyPrintableError } from '../interfaces';
2
2
  export { error } from './error';
3
3
  export { CLIError } from './errors/cli';
4
4
  export { ExitError } from './errors/exit';
package/lib/execute.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LoadOptions } from './interfaces';
1
+ import { type LoadOptions } from './interfaces';
2
2
  /**
3
3
  * Load and run oclif CLI
4
4
  *
package/lib/flags.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { URL } from 'node:url';
2
- import { BooleanFlag, CustomOptions, FlagDefinition, OptionFlag } from './interfaces';
3
- type NotArray<T> = T extends Array<any> ? never : T;
2
+ import { type BooleanFlag, type CustomOptions, type FlagDefinition, type OptionFlag } from './interfaces';
3
+ type NotArray<T> = T extends any[] ? never : T;
4
4
  /**
5
5
  * Create a custom flag.
6
6
  *
@@ -123,7 +123,7 @@ export declare const version: (opts?: Partial<BooleanFlag<boolean>>) => BooleanF
123
123
  * A help flag that will print the CLI help and exit.
124
124
  */
125
125
  export declare const help: (opts?: Partial<BooleanFlag<boolean>>) => BooleanFlag<void>;
126
- type ReadonlyElementOf<T extends ReadonlyArray<unknown>> = T[number];
126
+ type ReadonlyElementOf<T extends readonly unknown[]> = T[number];
127
127
  /**
128
128
  * Create a custom flag that infers the flag type from the provided options.
129
129
  *
@@ -138,11 +138,11 @@ type ReadonlyElementOf<T extends ReadonlyArray<unknown>> = T[number];
138
138
  * }
139
139
  * }
140
140
  */
141
- export declare function option<T extends readonly string[], P extends CustomOptions>(defaults: Partial<OptionFlag<ReadonlyElementOf<T>[], P>> & {
141
+ export declare function option<T extends readonly string[], P extends CustomOptions>(defaults: Partial<OptionFlag<Array<ReadonlyElementOf<T>>, P>> & {
142
142
  multiple: true;
143
143
  options: T;
144
144
  } & ({
145
- default: OptionFlag<ReadonlyElementOf<T>[], P>['default'] | undefined;
145
+ default: OptionFlag<Array<ReadonlyElementOf<T>>, P>['default'] | undefined;
146
146
  } | {
147
147
  required: true;
148
148
  })): FlagDefinition<(typeof defaults.options)[number], P, {
@@ -169,8 +169,8 @@ export declare function option<T extends readonly string[], P extends CustomOpti
169
169
  multiple: false;
170
170
  requiredOrDefaulted: false;
171
171
  }>;
172
- export declare function option<T extends readonly string[], P extends CustomOptions>(defaults: Partial<OptionFlag<ReadonlyElementOf<T>[], P>> & {
173
- default?: OptionFlag<ReadonlyElementOf<T>[], P>['default'] | undefined;
172
+ export declare function option<T extends readonly string[], P extends CustomOptions>(defaults: Partial<OptionFlag<Array<ReadonlyElementOf<T>>, P>> & {
173
+ default?: OptionFlag<Array<ReadonlyElementOf<T>>, P>['default'] | undefined;
174
174
  multiple: true;
175
175
  options: T;
176
176
  required?: false | undefined;
package/lib/flush.js CHANGED
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.flush = flush;
4
4
  const error_1 = require("./errors/error");
5
- function timeout(p, ms) {
6
- function wait(ms, unref = false) {
5
+ async function timeout(p, ms) {
6
+ async function wait(ms, unref = false) {
7
7
  return new Promise((resolve) => {
8
- const t = setTimeout(() => resolve(null), ms);
8
+ const t = setTimeout(() => {
9
+ resolve(null);
10
+ }, ms);
9
11
  if (unref)
10
12
  t.unref();
11
13
  });
@@ -14,10 +16,12 @@ function timeout(p, ms) {
14
16
  }
15
17
  async function _flush() {
16
18
  const p = new Promise((resolve) => {
17
- process.stdout.once('drain', () => resolve(null));
19
+ process.stdout.once('drain', () => {
20
+ resolve(null);
21
+ });
18
22
  });
19
- const flushed = process.stdout.write('');
20
- if (flushed)
23
+ const isFlushed = process.stdout.write('');
24
+ if (isFlushed)
21
25
  return;
22
26
  return p;
23
27
  }
@@ -1,6 +1,6 @@
1
- import { Command } from '../command';
2
- import * as Interfaces from '../interfaces';
3
- import { HelpFormatter, HelpSectionRenderer } from './formatter';
1
+ import type * as Interfaces from '../interfaces';
2
+ import { type Command } from '../command';
3
+ import { HelpFormatter, type HelpSectionRenderer } from './formatter';
4
4
  export declare class CommandHelp extends HelpFormatter {
5
5
  command: Command.Loadable;
6
6
  config: Interfaces.Config;
@@ -8,19 +8,17 @@ export declare class CommandHelp extends HelpFormatter {
8
8
  constructor(command: Command.Loadable, config: Interfaces.Config, opts: Interfaces.HelpOptions);
9
9
  protected aliases(aliases: string[] | undefined): string | undefined;
10
10
  protected arg(arg: Command.Arg.Any): string;
11
- protected args(args: Command.Arg.Any[]): [string, string | undefined][] | undefined;
11
+ protected args(args: Command.Arg.Any[]): Array<[string, string | undefined]> | undefined;
12
12
  protected defaultUsage(): string;
13
13
  protected description(): string | undefined;
14
14
  protected examples(examples: Command.Example[] | string | undefined): string | undefined;
15
15
  protected flagHelpLabel(flag: Command.Flag.Any, showOptions?: boolean): string;
16
- protected flags(flags: Array<Command.Flag.Any>): [string, string | undefined][] | undefined;
17
- protected flagsDescriptions(flags: Array<Command.Flag.Any>): string | undefined;
16
+ protected flags(flags: Command.Flag.Any[]): Array<[string, string | undefined]> | undefined;
17
+ protected flagsDescriptions(flags: Command.Flag.Any[]): string | undefined;
18
18
  generate(): string;
19
- protected groupFlags(flags: Array<Command.Flag.Any>): {
20
- flagGroups: {
21
- [name: string]: Array<Command.Flag.Any>;
22
- };
23
- mainFlags: Array<Command.Flag.Any>;
19
+ protected groupFlags(flags: Command.Flag.Any[]): {
20
+ flagGroups: Record<string, Command.Flag.Any[]>;
21
+ mainFlags: Command.Flag.Any[];
24
22
  };
25
23
  protected sections(): Array<{
26
24
  generate: HelpSectionRenderer;
@@ -50,7 +50,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
50
50
  arg(arg) {
51
51
  const name = arg.name.toUpperCase();
52
52
  if (arg.required)
53
- return `${name}`;
53
+ return name;
54
54
  return `[${name}]`;
55
55
  }
56
56
  args(args) {
@@ -58,9 +58,9 @@ class CommandHelp extends formatter_1.HelpFormatter {
58
58
  return;
59
59
  return args.map((a) => {
60
60
  // Add ellipsis for variadic args, or for all args when strict is false (backward compat)
61
- const suffix = a.multiple ? '...' : this.command.strict === false ? '...' : '';
61
+ const suffix = a.multiple || this.command.strict === false ? '...' : '';
62
62
  let name = `${a.name.toUpperCase()}${suffix}`;
63
- name = a.required ? `${name}` : `[${name}]`;
63
+ name = a.required ? name : `[${name}]`;
64
64
  let description = a.description || '';
65
65
  if (a.default)
66
66
  description = `${(0, theme_1.colorize)(this.config?.theme?.flagDefaultValue, `[default: ${a.default}]`)} ${description}`;
@@ -142,8 +142,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
142
142
  flagHelpLabel(flag, showOptions = false) {
143
143
  let label = flag.helpLabel;
144
144
  if (!label) {
145
- const labels = [];
146
- labels.push(flag.char ? `-${flag.char[0]}` : ' ');
145
+ const labels = [flag.char ? `-${flag.char[0]}` : ' '];
147
146
  if (flag.name) {
148
147
  if (flag.type === 'boolean' && flag.allowNo) {
149
148
  labels.push(`--[no-]${flag.name.trim()}`);
@@ -165,12 +164,12 @@ class CommandHelp extends formatter_1.HelpFormatter {
165
164
  flags(flags) {
166
165
  if (flags.length === 0)
167
166
  return;
168
- const noChar = flags.reduce((previous, current) => previous && current.char === undefined, true);
167
+ const isNoChar = flags.reduce((previous, current) => previous && current.char === undefined, true);
169
168
  // eslint-disable-next-line complexity
170
169
  return flags.map((flag) => {
171
170
  let left = this.flagHelpLabel(flag);
172
- if (noChar)
173
- left = left.replace(' ', '');
171
+ if (isNoChar)
172
+ left = left.replace(' '.repeat(4), '');
174
173
  let right = flag.summary || flag.description || '';
175
174
  // Build metadata string (default, env, or both)
176
175
  const metadata = [];
@@ -207,7 +206,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
207
206
  const summary = flag.summary || '';
208
207
  let flagHelp = this.flagHelpLabel(flag, true);
209
208
  if (!flag.char)
210
- flagHelp = flagHelp.replace(' ', '');
209
+ flagHelp = flagHelp.replace(' '.repeat(4), '');
211
210
  flagHelp +=
212
211
  flagHelp.length + summary.length + 2 < this.opts.maxWidth
213
212
  ? ' ' + summary
@@ -234,7 +233,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
234
233
  // Generate can return a list of sections
235
234
  if (Array.isArray(body)) {
236
235
  return body
237
- .map((helpSection) => helpSection && helpSection.body && this.section(helpSection.header, helpSection.body))
236
+ .map((helpSection) => helpSection?.body && this.section(helpSection.header, helpSection.body))
238
237
  .join('\n\n');
239
238
  }
240
239
  return body && this.section(header, body);
@@ -1,6 +1,6 @@
1
- import { Command } from '../command';
1
+ import { type Command } from '../command';
2
2
  /**
3
- * DocOpts - See http://docopt.org/.
3
+ * DocOpts - See https://docopt.org/.
4
4
  *
5
5
  * flag.exclusive: groups elements when one of the mutually exclusive cases is a required flag: (--apple | --orange)
6
6
  * flag.exclusive: groups elements when none of the mutually exclusive cases is required (optional flags): [--apple | --orange]
@@ -56,8 +56,8 @@ import { Command } from '../command';
56
56
  *
57
57
  */
58
58
  export declare class DocOpts {
59
- private cmd;
60
- private flagList;
59
+ private readonly cmd;
60
+ private readonly flagList;
61
61
  private flagMap;
62
62
  constructor(cmd: Command.Loadable);
63
63
  static formatUsageType(flag: Command.Flag.Any, showFlagName: boolean, showOptions: boolean): string;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocOpts = void 0;
4
4
  const ensure_arg_object_1 = require("../util/ensure-arg-object");
5
5
  /**
6
- * DocOpts - See http://docopt.org/.
6
+ * DocOpts - See https://docopt.org/.
7
7
  *
8
8
  * flag.exclusive: groups elements when one of the mutually exclusive cases is a required flag: (--apple | --orange)
9
9
  * flag.exclusive: groups elements when none of the mutually exclusive cases is required (optional flags): [--apple | --orange]
@@ -103,7 +103,7 @@ class DocOpts {
103
103
  const a = Object.values((0, ensure_arg_object_1.ensureArgObject)(this.cmd.args))
104
104
  .filter((arg) => !arg.hidden)
105
105
  .map((arg) => {
106
- const suffix = arg.multiple ? '...' : this.cmd.strict === false ? '...' : '';
106
+ const suffix = arg.multiple || this.cmd.strict === false ? '...' : '';
107
107
  return arg.required ? `${arg.name.toUpperCase()}${suffix}` : `[${arg.name.toUpperCase()}${suffix}]`;
108
108
  }) || [];
109
109
  opts.push(...a);
@@ -1,11 +1,11 @@
1
- import { Command } from '../command';
2
- import * as Interfaces from '../interfaces';
3
- export type HelpSectionKeyValueTable = {
1
+ import type * as Interfaces from '../interfaces';
2
+ import { type Command } from '../command';
3
+ export type HelpSectionKeyValueTable = Array<{
4
4
  description: string;
5
5
  name: string;
6
- }[];
6
+ }>;
7
7
  export type HelpSection = {
8
- body: [string, string | undefined][] | HelpSectionKeyValueTable | string | undefined;
8
+ body: Array<[string, string | undefined]> | HelpSectionKeyValueTable | string | undefined;
9
9
  header: string;
10
10
  } | undefined;
11
11
  export type HelpSectionRenderer = (data: {
@@ -57,13 +57,13 @@ export declare class HelpFormatter {
57
57
  * @returns the formatted indented text
58
58
  */
59
59
  indent(body: string, spacing?: number): string;
60
- renderList(input: (string | undefined)[][], opts: {
60
+ renderList(input: Array<Array<string | undefined>>, opts: {
61
61
  indentation: number;
62
62
  multiline?: boolean | undefined;
63
63
  spacer?: string | undefined;
64
64
  stripAnsi?: boolean | undefined;
65
65
  }): string;
66
- section(header: string, body: [string, string | undefined][] | HelpSection | HelpSectionKeyValueTable | string): string;
66
+ section(header: string, body: Array<[string, string | undefined]> | HelpSection | HelpSectionKeyValueTable | string): string;
67
67
  /**
68
68
  * Wrap text according to `opts.maxWidth` which is typically set to the terminal width. All text
69
69
  * will be rendered before bring wrapped, otherwise it could mess up the lengths.
@@ -1,5 +1,5 @@
1
- import { Command } from '../command';
2
- import * as Interfaces from '../interfaces';
1
+ import type * as Interfaces from '../interfaces';
2
+ import { type Command } from '../command';
3
3
  import { CommandHelp } from './command';
4
4
  import { HelpFormatter } from './formatter';
5
5
  export { CommandHelp } from './command';
@@ -28,7 +28,7 @@ export declare class Help extends HelpBase {
28
28
  protected command(command: Command.Loadable): string;
29
29
  protected description(c: Command.Loadable): string;
30
30
  protected formatCommand(command: Command.Loadable): string;
31
- protected formatCommands(commands: Array<Command.Loadable>): string;
31
+ protected formatCommands(commands: Command.Loadable[]): string;
32
32
  formatRoot(): string;
33
33
  protected formatTopic(topic: Interfaces.Topic): string;
34
34
  protected formatTopics(topics: Interfaces.Topic[]): string;
@@ -40,7 +40,5 @@ export declare class Help extends HelpBase {
40
40
  protected showTopicHelp(topic: Interfaces.Topic): Promise<void>;
41
41
  protected summary(c: Command.Loadable): string | undefined;
42
42
  }
43
- interface HelpBaseDerived {
44
- new (config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>): HelpBase;
45
- }
43
+ type HelpBaseDerived = new (config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>) => HelpBase;
46
44
  export declare function loadHelpClass(config: Interfaces.Config): Promise<HelpBaseDerived>;
package/lib/help/index.js CHANGED
@@ -125,7 +125,7 @@ class Help extends HelpBase {
125
125
  }
126
126
  formatTopic(topic) {
127
127
  let description = this.render(topic.description || '');
128
- const summary = description.split('\n')[0];
128
+ const summary = description.split('\n', 1)[0];
129
129
  description = description.split('\n').slice(1).join('\n');
130
130
  let topicID = `${topic.name}:COMMAND`;
131
131
  if (this.config.topicSeparator !== ':')
@@ -148,7 +148,8 @@ class Help extends HelpBase {
148
148
  c.name = c.name.replaceAll(':', this.config.topicSeparator);
149
149
  return [
150
150
  (0, theme_1.colorize)(this.config?.theme?.topic, c.name),
151
- c.description && this.render((0, theme_1.colorize)(this.config?.theme?.sectionDescription, c.description.split('\n')[0])),
151
+ c.description &&
152
+ this.render((0, theme_1.colorize)(this.config?.theme?.sectionDescription, c.description.split('\n', 1)[0])),
152
153
  ];
153
154
  }), {
154
155
  indentation: 2,
@@ -161,7 +162,7 @@ class Help extends HelpBase {
161
162
  return new this.CommandHelpClass(command, this.config, this.opts);
162
163
  }
163
164
  log(...args) {
164
- return this.opts.sendToStderr ? ux_1.ux.stderr(args) : ux_1.ux.stdout(args);
165
+ this.opts.sendToStderr ? ux_1.ux.stderr(args) : ux_1.ux.stdout(args);
165
166
  }
166
167
  async showCommandHelp(command) {
167
168
  const name = command.id;
@@ -178,7 +179,7 @@ class Help extends HelpBase {
178
179
  if (command.deprecateAliases && [...(command.aliases ?? []), ...(command.hiddenAliases ?? [])].includes(name)) {
179
180
  const actualCmd = this.config.commands.find((c) => [...(c.aliases ?? []), ...(c.hiddenAliases ?? [])].includes(name));
180
181
  const actualCmdName = actualCmd ? (0, ids_1.toConfiguredId)(actualCmd.id, this.config) : '';
181
- const opts = { ...command.deprecationOptions, ...(actualCmd ? { to: actualCmdName } : {}) };
182
+ const opts = { ...command.deprecationOptions, ...(actualCmd && { to: actualCmdName }) };
182
183
  this.log(`${(0, util_2.formatCommandDeprecationWarning)((0, ids_1.toConfiguredId)(name, this.config), opts)}\n`);
183
184
  }
184
185
  const summary = this.summary(command);
@@ -314,13 +315,13 @@ class Help extends HelpBase {
314
315
  if (this.opts.sections && !this.opts.sections.map((s) => s.toLowerCase()).includes('summary'))
315
316
  return;
316
317
  if (c.summary)
317
- return (0, theme_1.colorize)(this.config?.theme?.commandSummary, this.render(c.summary.split('\n')[0]));
318
- return c.description && (0, theme_1.colorize)(this.config?.theme?.commandSummary, this.render(c.description).split('\n')[0]);
318
+ return (0, theme_1.colorize)(this.config?.theme?.commandSummary, this.render(c.summary.split('\n', 1)[0]));
319
+ return c.description && (0, theme_1.colorize)(this.config?.theme?.commandSummary, this.render(c.description).split('\n', 1)[0]);
319
320
  }
320
321
  }
321
322
  exports.Help = Help;
322
323
  function extractClass(exported) {
323
- return exported && exported.default ? exported.default : exported;
324
+ return exported?.default ? exported.default : exported;
324
325
  }
325
326
  function determineLocation(helpClass) {
326
327
  if (typeof helpClass === 'string')