@oclif/core 3.0.0-beta.2 → 3.0.0-beta.21

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 (112) hide show
  1. package/README.md +10 -6
  2. package/flush.js +1 -1
  3. package/handle.js +1 -1
  4. package/lib/args.d.ts +1 -1
  5. package/lib/args.js +17 -18
  6. package/lib/cli-ux/action/base.d.ts +3 -5
  7. package/lib/cli-ux/action/base.js +32 -26
  8. package/lib/cli-ux/action/simple.js +13 -18
  9. package/lib/cli-ux/action/spinner.d.ts +4 -2
  10. package/lib/cli-ux/action/spinner.js +27 -19
  11. package/lib/cli-ux/action/spinners.js +1 -1
  12. package/lib/cli-ux/action/types.d.ts +5 -0
  13. package/lib/cli-ux/action/types.js +2 -0
  14. package/lib/cli-ux/config.d.ts +0 -1
  15. package/lib/cli-ux/config.js +17 -21
  16. package/lib/cli-ux/exit.d.ts +1 -1
  17. package/lib/cli-ux/exit.js +4 -1
  18. package/lib/cli-ux/flush.d.ts +1 -0
  19. package/lib/cli-ux/flush.js +28 -0
  20. package/lib/cli-ux/index.d.ts +10 -30
  21. package/lib/cli-ux/index.js +32 -75
  22. package/lib/cli-ux/list.js +3 -3
  23. package/lib/cli-ux/prompt.js +32 -22
  24. package/lib/cli-ux/stream.js +1 -0
  25. package/lib/cli-ux/styled/index.d.ts +5 -6
  26. package/lib/cli-ux/styled/index.js +11 -11
  27. package/lib/cli-ux/styled/json.js +8 -5
  28. package/lib/cli-ux/styled/object.js +7 -9
  29. package/lib/cli-ux/styled/table.d.ts +4 -4
  30. package/lib/cli-ux/styled/table.js +61 -64
  31. package/lib/cli-ux/styled/tree.js +1 -3
  32. package/lib/cli-ux/wait.js +3 -5
  33. package/lib/command.d.ts +15 -19
  34. package/lib/command.js +117 -96
  35. package/lib/config/config.d.ts +16 -23
  36. package/lib/config/config.js +180 -334
  37. package/lib/config/index.d.ts +1 -1
  38. package/lib/config/index.js +1 -2
  39. package/lib/config/plugin-loader.d.ts +30 -0
  40. package/lib/config/plugin-loader.js +145 -0
  41. package/lib/config/plugin.d.ts +6 -11
  42. package/lib/config/plugin.js +112 -78
  43. package/lib/config/ts-node.d.ts +2 -1
  44. package/lib/config/ts-node.js +64 -51
  45. package/lib/config/util.d.ts +1 -11
  46. package/lib/config/util.js +6 -59
  47. package/lib/errors/config.js +1 -1
  48. package/lib/errors/errors/cli.d.ts +1 -1
  49. package/lib/errors/errors/cli.js +18 -14
  50. package/lib/errors/errors/exit.d.ts +0 -3
  51. package/lib/errors/errors/exit.js +1 -1
  52. package/lib/errors/errors/module-load.d.ts +0 -3
  53. package/lib/errors/errors/module-load.js +1 -1
  54. package/lib/errors/errors/pretty-print.js +11 -9
  55. package/lib/errors/handle.d.ts +12 -2
  56. package/lib/errors/handle.js +28 -18
  57. package/lib/errors/index.d.ts +2 -2
  58. package/lib/errors/index.js +20 -19
  59. package/lib/errors/logger.js +9 -8
  60. package/lib/execute.d.ts +49 -0
  61. package/lib/execute.js +63 -0
  62. package/lib/flags.d.ts +102 -31
  63. package/lib/flags.js +81 -46
  64. package/lib/help/command.d.ts +2 -0
  65. package/lib/help/command.js +68 -53
  66. package/lib/help/docopts.js +9 -13
  67. package/lib/help/formatter.d.ts +1 -1
  68. package/lib/help/formatter.js +35 -24
  69. package/lib/help/index.d.ts +7 -3
  70. package/lib/help/index.js +77 -55
  71. package/lib/help/root.js +7 -9
  72. package/lib/help/util.d.ts +1 -7
  73. package/lib/help/util.js +8 -28
  74. package/lib/index.d.ts +19 -18
  75. package/lib/index.js +36 -48
  76. package/lib/interfaces/config.d.ts +30 -30
  77. package/lib/interfaces/errors.d.ts +1 -1
  78. package/lib/interfaces/hooks.d.ts +3 -3
  79. package/lib/interfaces/index.d.ts +14 -14
  80. package/lib/interfaces/parser.d.ts +188 -116
  81. package/lib/interfaces/pjson.d.ts +2 -1
  82. package/lib/interfaces/plugin.d.ts +10 -1
  83. package/lib/main.d.ts +0 -48
  84. package/lib/main.js +11 -66
  85. package/lib/module-loader.d.ts +68 -79
  86. package/lib/module-loader.js +183 -150
  87. package/lib/parser/errors.d.ts +3 -3
  88. package/lib/parser/errors.js +17 -10
  89. package/lib/parser/help.js +5 -5
  90. package/lib/parser/parse.d.ts +3 -0
  91. package/lib/parser/parse.js +114 -115
  92. package/lib/parser/validate.js +45 -25
  93. package/lib/performance.d.ts +5 -1
  94. package/lib/performance.js +40 -19
  95. package/lib/util/aggregate-flags.d.ts +2 -0
  96. package/lib/util/aggregate-flags.js +13 -0
  97. package/lib/util/cache-command.d.ts +3 -0
  98. package/lib/util/cache-command.js +109 -0
  99. package/lib/util/cache-default-value.d.ts +2 -0
  100. package/lib/util/cache-default-value.js +28 -0
  101. package/lib/util/ensure-arg-object.d.ts +12 -0
  102. package/lib/util/ensure-arg-object.js +14 -0
  103. package/lib/util/fs.d.ts +7 -0
  104. package/lib/util/fs.js +54 -0
  105. package/lib/util/os.d.ts +19 -0
  106. package/lib/util/os.js +28 -0
  107. package/lib/{util.d.ts → util/util.d.ts} +6 -15
  108. package/lib/util/util.js +98 -0
  109. package/package.json +32 -34
  110. package/lib/cli-ux/action/pride-spinner.d.ts +0 -4
  111. package/lib/cli-ux/action/pride-spinner.js +0 -30
  112. package/lib/util.js +0 -126
@@ -1,22 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandHelp = void 0;
4
- const chalk = require("chalk");
5
- const stripAnsi = require("strip-ansi");
6
- const util_1 = require("../util");
4
+ const tslib_1 = require("tslib");
7
5
  const formatter_1 = require("./formatter");
6
+ const util_1 = require("../util/util");
8
7
  const docopts_1 = require("./docopts");
8
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
9
+ const ensure_arg_object_1 = require("../util/ensure-arg-object");
10
+ const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
9
11
  // Don't use os.EOL because we need to ensure that a string
10
12
  // written on any platform, that may use \r\n or \n, will be
11
13
  // split on any platform, not just the os specific EOL at runtime.
12
14
  const POSSIBLE_LINE_FEED = /\r\n|\n/;
13
- const { underline, } = chalk;
14
- let { dim, } = chalk;
15
+ let { dim } = chalk_1.default;
15
16
  if (process.env.ConEmuANSI === 'ON') {
16
17
  // eslint-disable-next-line unicorn/consistent-destructuring
17
- dim = chalk.gray;
18
+ dim = chalk_1.default.gray;
18
19
  }
19
20
  class CommandHelp extends formatter_1.HelpFormatter {
21
+ command;
22
+ config;
23
+ opts;
20
24
  constructor(command, config, opts) {
21
25
  super(config, opts);
22
26
  this.command = command;
@@ -30,13 +34,15 @@ class CommandHelp extends formatter_1.HelpFormatter {
30
34
  .map(([k, v]) => {
31
35
  v.name = k;
32
36
  return v;
33
- }), f => [!f.char, f.char, f.name]);
34
- const args = Object.values((0, util_1.ensureArgObject)(cmd.args)).filter(a => !a.hidden);
37
+ }), (f) => [!f.char, f.char, f.name]);
38
+ const args = Object.values((0, ensure_arg_object_1.ensureArgObject)(cmd.args)).filter((a) => !a.hidden);
35
39
  const output = (0, util_1.compact)(this.sections().map(({ header, generate }) => {
36
40
  const body = generate({ cmd, flags, args }, header);
37
41
  // Generate can return a list of sections
38
42
  if (Array.isArray(body)) {
39
- return body.map(helpSection => helpSection && helpSection.body && this.section(helpSection.header, helpSection.body)).join('\n\n');
43
+ return body
44
+ .map((helpSection) => helpSection && helpSection.body && this.section(helpSection.header, helpSection.body))
45
+ .join('\n\n');
40
46
  }
41
47
  return body && this.section(header, body);
42
48
  })).join('\n\n');
@@ -106,15 +112,16 @@ class CommandHelp extends formatter_1.HelpFormatter {
106
112
  ];
107
113
  }
108
114
  usage() {
109
- const usage = this.command.usage;
115
+ const { usage } = this.command;
110
116
  const body = (usage ? (0, util_1.castArray)(usage) : [this.defaultUsage()])
111
- .map(u => {
117
+ .map((u) => {
112
118
  const allowedSpacing = this.opts.maxWidth - this.indentSpacing;
113
119
  const line = `$ ${this.config.bin} ${u}`.trim();
114
120
  if (line.length > allowedSpacing) {
115
121
  const splitIndex = line.slice(0, Math.max(0, allowedSpacing)).lastIndexOf(' ');
116
- return line.slice(0, Math.max(0, splitIndex)) + '\n' +
117
- this.indent(this.wrap(line.slice(Math.max(0, splitIndex)), this.indentSpacing * 2));
122
+ return (line.slice(0, Math.max(0, splitIndex)) +
123
+ '\n' +
124
+ this.indent(this.wrap(line.slice(Math.max(0, splitIndex)), this.indentSpacing * 2)));
118
125
  }
119
126
  return this.wrap(line);
120
127
  })
@@ -128,7 +135,10 @@ class CommandHelp extends formatter_1.HelpFormatter {
128
135
  }
129
136
  return (0, util_1.compact)([
130
137
  this.command.id,
131
- Object.values(this.command.args ?? {})?.filter(a => !a.hidden).map(a => this.arg(a)).join(' '),
138
+ Object.values(this.command.args ?? {})
139
+ ?.filter((a) => !a.hidden)
140
+ .map((a) => this.arg(a))
141
+ .join(' '),
132
142
  ]).join(' ');
133
143
  }
134
144
  description() {
@@ -139,10 +149,9 @@ class CommandHelp extends formatter_1.HelpFormatter {
139
149
  }
140
150
  else if (cmd.description) {
141
151
  const summary = cmd.summary ? `${cmd.summary}\n` : null;
142
- description = summary ? [
143
- ...summary.split(POSSIBLE_LINE_FEED),
144
- ...(cmd.description || '').split(POSSIBLE_LINE_FEED),
145
- ] : (cmd.description || '').split(POSSIBLE_LINE_FEED);
152
+ description = summary
153
+ ? [...summary.split(POSSIBLE_LINE_FEED), ...(cmd.description || '').split(POSSIBLE_LINE_FEED)]
154
+ : (cmd.description || '').split(POSSIBLE_LINE_FEED);
146
155
  }
147
156
  if (description) {
148
157
  return this.wrap(description.join('\n'));
@@ -151,61 +160,51 @@ class CommandHelp extends formatter_1.HelpFormatter {
151
160
  aliases(aliases) {
152
161
  if (!aliases || aliases.length === 0)
153
162
  return;
154
- const body = aliases.map(a => ['$', this.config.bin, a].join(' ')).join('\n');
163
+ const body = aliases.map((a) => ['$', this.config.bin, a].join(' ')).join('\n');
155
164
  return body;
156
165
  }
157
166
  examples(examples) {
158
167
  if (!examples || examples.length === 0)
159
168
  return;
160
- const formatIfCommand = (example) => {
161
- example = this.render(example);
162
- if (example.startsWith(this.config.bin))
163
- return dim(`$ ${example}`);
164
- if (example.startsWith(`$ ${this.config.bin}`))
165
- return dim(example);
166
- return example;
167
- };
168
- const isCommand = (example) => stripAnsi(formatIfCommand(example)).startsWith(`$ ${this.config.bin}`);
169
- const body = (0, util_1.castArray)(examples).map(a => {
169
+ const body = (0, util_1.castArray)(examples)
170
+ .map((a) => {
170
171
  let description;
171
172
  let commands;
172
173
  if (typeof a === 'string') {
173
- const lines = a
174
- .split(POSSIBLE_LINE_FEED)
175
- .filter(line => Boolean(line));
174
+ const lines = a.split(POSSIBLE_LINE_FEED).filter(Boolean);
176
175
  // If the example is <description>\n<command> then format correctly
177
- // eslint-disable-next-line unicorn/no-array-callback-reference
178
- if (lines.length >= 2 && !isCommand(lines[0]) && lines.slice(1).every(isCommand)) {
176
+ if (lines.length >= 2 && !this.isCommand(lines[0]) && lines.slice(1).every((i) => this.isCommand(i))) {
179
177
  description = lines[0];
180
178
  commands = lines.slice(1);
181
179
  }
182
180
  else {
183
- return lines.map(line => formatIfCommand(line)).join('\n');
181
+ return lines.map((line) => this.formatIfCommand(line)).join('\n');
184
182
  }
185
183
  }
186
184
  else {
187
185
  description = a.description;
188
186
  commands = [a.command];
189
187
  }
190
- const multilineSeparator = this.config.platform === 'win32' ?
191
- (this.config.shell.includes('powershell') ? '`' : '^') :
192
- '\\';
188
+ const multilineSeparator = this.config.platform === 'win32' ? (this.config.shell.includes('powershell') ? '`' : '^') : '\\';
193
189
  // The command will be indented in the section, which is also indented
194
190
  const finalIndentedSpacing = this.indentSpacing * 2;
195
- const multilineCommands = commands.map(c => {
196
- // First indent keeping room for escaped newlines
197
- return this.indent(this.wrap(formatIfCommand(c), finalIndentedSpacing + 4))
198
- // Then add the escaped newline
199
- .split(POSSIBLE_LINE_FEED).join(` ${multilineSeparator}\n `);
200
- }).join('\n');
191
+ const multilineCommands = commands
192
+ .map((c) =>
193
+ // First indent keeping room for escaped newlines
194
+ this.indent(this.wrap(this.formatIfCommand(c), finalIndentedSpacing + 4))
195
+ // Then add the escaped newline
196
+ .split(POSSIBLE_LINE_FEED)
197
+ .join(` ${multilineSeparator}\n `))
198
+ .join('\n');
201
199
  return `${this.wrap(description, finalIndentedSpacing)}\n\n${multilineCommands}`;
202
- }).join('\n\n');
200
+ })
201
+ .join('\n\n');
203
202
  return body;
204
203
  }
205
204
  args(args) {
206
- if (args.filter(a => a.description).length === 0)
205
+ if (args.filter((a) => a.description).length === 0)
207
206
  return;
208
- return args.map(a => {
207
+ return args.map((a) => {
209
208
  const name = a.name.toUpperCase();
210
209
  let description = a.description || '';
211
210
  if (a.default)
@@ -245,7 +244,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
245
244
  if (flag.multiple)
246
245
  value += '...';
247
246
  if (!value.includes('|'))
248
- value = underline(value);
247
+ value = chalk_1.default.underline(value);
249
248
  label += `=${value}`;
250
249
  }
251
250
  return label;
@@ -253,7 +252,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
253
252
  flags(flags) {
254
253
  if (flags.length === 0)
255
254
  return;
256
- return flags.map(flag => {
255
+ return flags.map((flag) => {
257
256
  const left = this.flagHelpLabel(flag);
258
257
  let right = flag.summary || flag.description || '';
259
258
  if (flag.type === 'option' && flag.default) {
@@ -268,18 +267,34 @@ class CommandHelp extends formatter_1.HelpFormatter {
268
267
  });
269
268
  }
270
269
  flagsDescriptions(flags) {
271
- const flagsWithExtendedDescriptions = flags.filter(flag => flag.summary && flag.description);
270
+ const flagsWithExtendedDescriptions = flags.filter((flag) => flag.summary && flag.description);
272
271
  if (flagsWithExtendedDescriptions.length === 0)
273
272
  return;
274
- const body = flagsWithExtendedDescriptions.map(flag => {
273
+ const body = flagsWithExtendedDescriptions
274
+ .map((flag) => {
275
275
  // Guaranteed to be set because of the filter above, but make ts happy
276
276
  const summary = flag.summary || '';
277
277
  let flagHelp = this.flagHelpLabel(flag, true);
278
- flagHelp += flagHelp.length + summary.length + 2 < this.opts.maxWidth ? ' ' + summary : '\n\n' + this.indent(this.wrap(summary, this.indentSpacing * 2));
278
+ flagHelp +=
279
+ flagHelp.length + summary.length + 2 < this.opts.maxWidth
280
+ ? ' ' + summary
281
+ : '\n\n' + this.indent(this.wrap(summary, this.indentSpacing * 2));
279
282
  return `${flagHelp}\n\n${this.indent(this.wrap(flag.description || '', this.indentSpacing * 2))}`;
280
- }).join('\n\n');
283
+ })
284
+ .join('\n\n');
281
285
  return body;
282
286
  }
287
+ formatIfCommand(example) {
288
+ example = this.render(example);
289
+ if (example.startsWith(this.config.bin))
290
+ return dim(`$ ${example}`);
291
+ if (example.startsWith(`$ ${this.config.bin}`))
292
+ return dim(example);
293
+ return example;
294
+ }
295
+ isCommand(example) {
296
+ return (0, strip_ansi_1.default)(this.formatIfCommand(example)).startsWith(`$ ${this.config.bin}`);
297
+ }
283
298
  }
284
299
  exports.CommandHelp = CommandHelp;
285
300
  exports.default = CommandHelp;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocOpts = void 0;
4
- const util_1 = require("../util");
4
+ const ensure_arg_object_1 = require("../util/ensure-arg-object");
5
5
  /**
6
6
  * DocOpts - See http://docopt.org/.
7
7
  *
@@ -59,6 +59,9 @@ const util_1 = require("../util");
59
59
  *
60
60
  */
61
61
  class DocOpts {
62
+ cmd;
63
+ flagMap;
64
+ flagList;
62
65
  constructor(cmd) {
63
66
  this.cmd = cmd;
64
67
  // Create a new map with references to the flags that we can manipulate.
@@ -76,9 +79,7 @@ class DocOpts {
76
79
  toString() {
77
80
  const opts = this.cmd.id === '.' || this.cmd.id === '' ? [] : ['<%= command.id %>'];
78
81
  if (this.cmd.args) {
79
- const a = Object.values((0, util_1.ensureArgObject)(this.cmd.args)).map(arg => {
80
- return arg.required ? arg.name.toUpperCase() : `[${arg.name.toUpperCase()}]`;
81
- }) || [];
82
+ const a = Object.values((0, ensure_arg_object_1.ensureArgObject)(this.cmd.args)).map((arg) => arg.required ? arg.name.toUpperCase() : `[${arg.name.toUpperCase()}]`) || [];
82
83
  opts.push(...a);
83
84
  }
84
85
  try {
@@ -86,7 +87,7 @@ class DocOpts {
86
87
  }
87
88
  catch {
88
89
  // If there is an error, just return no usage so we don't fail command help.
89
- opts.push(...this.flagList.map(flag => {
90
+ opts.push(...this.flagList.map((flag) => {
90
91
  const name = flag.char ? `-${flag.char}` : `--${flag.name}`;
91
92
  if (flag.type === 'boolean')
92
93
  return name;
@@ -99,9 +100,9 @@ class DocOpts {
99
100
  const elementMap = {};
100
101
  // Generate all doc opt elements for combining
101
102
  // Show required flags first
102
- this.generateElements(elementMap, this.flagList.filter(flag => flag.required));
103
+ this.generateElements(elementMap, this.flagList.filter((flag) => flag.required));
103
104
  // Then show optional flags
104
- this.generateElements(elementMap, this.flagList.filter(flag => !flag.required));
105
+ this.generateElements(elementMap, this.flagList.filter((flag) => !flag.required));
105
106
  for (const flag of this.flagList) {
106
107
  if (Array.isArray(flag.dependsOn)) {
107
108
  this.combineElementsToFlag(elementMap, flag.name, flag.dependsOn, ' ');
@@ -134,12 +135,7 @@ class DocOpts {
134
135
  delete elementMap[toCombine];
135
136
  delete this.flagMap[toCombine];
136
137
  }
137
- if (isRequired) {
138
- elementMap[flagName] = `(${elementMap[flagName] || ''})`;
139
- }
140
- else {
141
- elementMap[flagName] = `[${elementMap[flagName] || ''}]`;
142
- }
138
+ elementMap[flagName] = isRequired ? `(${elementMap[flagName] || ''})` : `[${elementMap[flagName] || ''}]`;
143
139
  // We handled this flag, don't handle it again
144
140
  delete this.flagMap[flagName];
145
141
  }
@@ -1,5 +1,5 @@
1
- import { Command } from '../command';
2
1
  import * as Interfaces from '../interfaces';
2
+ import { Command } from '../command';
3
3
  export type HelpSectionKeyValueTable = {
4
4
  name: string;
5
5
  description: string;
@@ -1,22 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HelpFormatter = void 0;
4
- const Chalk = require("chalk");
5
- const indent = require("indent-string");
6
- const stripAnsi = require("strip-ansi");
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const indent_string_1 = tslib_1.__importDefault(require("indent-string"));
7
7
  const screen_1 = require("../screen");
8
+ const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
8
9
  const util_1 = require("./util");
9
- const width = require('string-width');
10
- const widestLine = require('widest-line');
11
- const wrap = require('wrap-ansi');
12
- const { bold, } = Chalk;
10
+ const widest_line_1 = tslib_1.__importDefault(require("widest-line"));
11
+ const string_width_1 = tslib_1.__importDefault(require("string-width"));
12
+ const wrap_ansi_1 = tslib_1.__importDefault(require("wrap-ansi"));
13
13
  class HelpFormatter {
14
+ indentSpacing = 2;
15
+ /**
16
+ * Takes a string and replaces `<%= prop =>` with the value of prop, where prop is anything on
17
+ * `config=Interfaces.Config` or `opts=Interface.HelpOptions`.
18
+ *
19
+ * ```javascript
20
+ * `<%= config.bin =>` // will resolve to the bin defined in `pjson.oclif`.
21
+ * ```
22
+ */
23
+ render;
14
24
  constructor(config, opts = {}) {
15
- this.indentSpacing = 2;
16
25
  this.config = config;
17
26
  this.opts = { maxWidth: screen_1.stdtermwidth, ...opts };
18
27
  this.render = (0, util_1.template)(this);
19
28
  }
29
+ config;
30
+ opts;
20
31
  /**
21
32
  * Wrap text according to `opts.maxWidth` which is typically set to the terminal width. All text
22
33
  * will be rendered before bring wrapped, otherwise it could mess up the lengths.
@@ -46,7 +57,7 @@ class HelpFormatter {
46
57
  * @returns the formatted wrapped text
47
58
  */
48
59
  wrap(body, spacing = this.indentSpacing) {
49
- return wrap(this.render(body), this.opts.maxWidth - spacing, { hard: true });
60
+ return (0, wrap_ansi_1.default)(this.render(body), this.opts.maxWidth - spacing, { hard: true });
50
61
  }
51
62
  /**
52
63
  * Indent by `this.indentSpacing`. The text should be wrap based on terminal width before indented.
@@ -78,7 +89,7 @@ class HelpFormatter {
78
89
  * @return the formatted indented text
79
90
  */
80
91
  indent(body, spacing = this.indentSpacing) {
81
- return indent(body, spacing);
92
+ return (0, indent_string_1.default)(body, spacing);
82
93
  }
83
94
  renderList(input, opts) {
84
95
  if (input.length === 0) {
@@ -91,12 +102,12 @@ class HelpFormatter {
91
102
  continue;
92
103
  if (left) {
93
104
  if (opts.stripAnsi)
94
- left = stripAnsi(left);
105
+ left = (0, strip_ansi_1.default)(left);
95
106
  output += this.wrap(left.trim(), opts.indentation);
96
107
  }
97
108
  if (right) {
98
109
  if (opts.stripAnsi)
99
- right = stripAnsi(right);
110
+ right = (0, strip_ansi_1.default)(right);
100
111
  output += '\n';
101
112
  output += this.indent(this.wrap(right.trim(), opts.indentation + 2), 4);
102
113
  }
@@ -106,7 +117,7 @@ class HelpFormatter {
106
117
  };
107
118
  if (opts.multiline)
108
119
  return renderMultiline();
109
- const maxLength = widestLine(input.map(i => i[0]).join('\n'));
120
+ const maxLength = (0, widest_line_1.default)(input.map((i) => i[0]).join('\n'));
110
121
  let output = '';
111
122
  let spacer = opts.spacer || '\n';
112
123
  let cur = '';
@@ -118,16 +129,16 @@ class HelpFormatter {
118
129
  }
119
130
  cur = left || '';
120
131
  if (opts.stripAnsi)
121
- cur = stripAnsi(cur);
132
+ cur = (0, strip_ansi_1.default)(cur);
122
133
  if (!right) {
123
134
  cur = cur.trim();
124
135
  continue;
125
136
  }
126
137
  if (opts.stripAnsi)
127
- right = stripAnsi(right);
138
+ right = (0, strip_ansi_1.default)(right);
128
139
  right = this.wrap(right.trim(), opts.indentation + maxLength + 2);
129
- const [first, ...lines] = right.split('\n').map(s => s.trim());
130
- cur += ' '.repeat(maxLength - width(cur) + 2);
140
+ const [first, ...lines] = right.split('\n').map((s) => s.trim());
141
+ cur += ' '.repeat(maxLength - (0, string_width_1.default)(cur) + 2);
131
142
  cur += first;
132
143
  if (lines.length === 0) {
133
144
  continue;
@@ -154,13 +165,13 @@ class HelpFormatter {
154
165
  newBody = this.render(body);
155
166
  }
156
167
  else if (Array.isArray(body)) {
157
- newBody = body.map(entry => {
168
+ newBody = body.map((entry) => {
158
169
  if ('name' in entry) {
159
170
  const tableEntry = entry;
160
- return ([this.render(tableEntry.name), this.render(tableEntry.description)]);
171
+ return [this.render(tableEntry.name), this.render(tableEntry.description)];
161
172
  }
162
173
  const [left, right] = entry;
163
- return ([this.render(left), right && this.render(right)]);
174
+ return [this.render(left), right && this.render(right)];
164
175
  });
165
176
  }
166
177
  else if ('header' in body) {
@@ -168,14 +179,14 @@ class HelpFormatter {
168
179
  }
169
180
  else {
170
181
  newBody = body
171
- .map((entry) => ([entry.name, entry.description]))
172
- .map(([left, right]) => ([this.render(left), right && this.render(right)]));
182
+ .map((entry) => [entry.name, entry.description])
183
+ .map(([left, right]) => [this.render(left), right && this.render(right)]);
173
184
  }
174
185
  const output = [
175
- bold(header),
186
+ chalk_1.default.bold(header),
176
187
  this.indent(Array.isArray(newBody) ? this.renderList(newBody, { stripAnsi: this.opts.stripAnsi, indentation: 2 }) : newBody),
177
188
  ].join('\n');
178
- return this.opts.stripAnsi ? stripAnsi(output) : output;
189
+ return this.opts.stripAnsi ? (0, strip_ansi_1.default)(output) : output;
179
190
  }
180
191
  }
181
192
  exports.HelpFormatter = HelpFormatter;
@@ -1,9 +1,9 @@
1
1
  import * as Interfaces from '../interfaces';
2
- import CommandHelp from './command';
3
- import { HelpFormatter } from './formatter';
4
2
  import { Command } from '../command';
3
+ import { CommandHelp } from './command';
4
+ import { HelpFormatter } from './formatter';
5
5
  export { CommandHelp } from './command';
6
- export { standardizeIDFromArgv, loadHelpClass, getHelpFlagAdditions, normalizeArgv } from './util';
6
+ export { standardizeIDFromArgv, getHelpFlagAdditions, normalizeArgv } from './util';
7
7
  export declare abstract class HelpBase extends HelpFormatter {
8
8
  constructor(config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>);
9
9
  /**
@@ -39,3 +39,7 @@ export declare class Help extends HelpBase {
39
39
  protected command(command: Command.Class): string;
40
40
  protected log(...args: string[]): void;
41
41
  }
42
+ interface HelpBaseDerived {
43
+ new (config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>): HelpBase;
44
+ }
45
+ export declare function loadHelpClass(config: Interfaces.Config): Promise<HelpBaseDerived>;