@oclif/core 3.0.0-beta.18 → 3.0.0-beta.19

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 (47) hide show
  1. package/lib/args.js +4 -4
  2. package/lib/cli-ux/action/base.js +1 -0
  3. package/lib/cli-ux/action/spinner.js +3 -5
  4. package/lib/cli-ux/action/spinners.js +1 -1
  5. package/lib/cli-ux/config.js +7 -6
  6. package/lib/cli-ux/flush.js +2 -2
  7. package/lib/cli-ux/index.js +1 -1
  8. package/lib/cli-ux/list.js +3 -3
  9. package/lib/cli-ux/prompt.js +8 -3
  10. package/lib/cli-ux/styled/object.js +2 -2
  11. package/lib/cli-ux/styled/table.js +23 -20
  12. package/lib/cli-ux/wait.js +1 -1
  13. package/lib/command.js +9 -9
  14. package/lib/config/config.d.ts +8 -8
  15. package/lib/config/config.js +45 -39
  16. package/lib/config/plugin-loader.js +7 -7
  17. package/lib/config/plugin.js +26 -23
  18. package/lib/config/ts-node.js +8 -10
  19. package/lib/config/util.js +2 -2
  20. package/lib/errors/errors/cli.js +1 -0
  21. package/lib/errors/errors/pretty-print.js +2 -1
  22. package/lib/errors/handle.js +2 -1
  23. package/lib/errors/logger.js +2 -2
  24. package/lib/flags.d.ts +4 -4
  25. package/lib/flags.js +3 -3
  26. package/lib/help/command.js +43 -32
  27. package/lib/help/docopts.js +5 -5
  28. package/lib/help/formatter.js +7 -7
  29. package/lib/help/index.js +39 -42
  30. package/lib/help/root.js +2 -7
  31. package/lib/help/util.js +1 -1
  32. package/lib/interfaces/hooks.d.ts +3 -3
  33. package/lib/interfaces/index.d.ts +1 -1
  34. package/lib/interfaces/parser.d.ts +15 -15
  35. package/lib/interfaces/pjson.d.ts +1 -1
  36. package/lib/module-loader.d.ts +8 -8
  37. package/lib/module-loader.js +12 -9
  38. package/lib/parser/errors.d.ts +1 -1
  39. package/lib/parser/errors.js +9 -9
  40. package/lib/parser/help.js +2 -3
  41. package/lib/parser/parse.js +64 -43
  42. package/lib/parser/validate.js +37 -21
  43. package/lib/performance.js +9 -6
  44. package/lib/util/aggregate-flags.js +1 -3
  45. package/lib/util/cache-command.js +28 -20
  46. package/lib/util/index.js +4 -6
  47. package/package.json +13 -11
@@ -11,7 +11,7 @@ const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
11
11
  // written on any platform, that may use \r\n or \n, will be
12
12
  // split on any platform, not just the os specific EOL at runtime.
13
13
  const POSSIBLE_LINE_FEED = /\r\n|\n/;
14
- let { dim, } = chalk_1.default;
14
+ let { dim } = chalk_1.default;
15
15
  if (process.env.ConEmuANSI === 'ON') {
16
16
  // eslint-disable-next-line unicorn/consistent-destructuring
17
17
  dim = chalk_1.default.gray;
@@ -33,13 +33,15 @@ class CommandHelp extends formatter_1.HelpFormatter {
33
33
  .map(([k, v]) => {
34
34
  v.name = k;
35
35
  return v;
36
- }), f => [!f.char, f.char, f.name]);
37
- const args = Object.values((0, util_1.ensureArgObject)(cmd.args)).filter(a => !a.hidden);
36
+ }), (f) => [!f.char, f.char, f.name]);
37
+ const args = Object.values((0, util_1.ensureArgObject)(cmd.args)).filter((a) => !a.hidden);
38
38
  const output = (0, util_1.compact)(this.sections().map(({ header, generate }) => {
39
39
  const body = generate({ cmd, flags, args }, header);
40
40
  // Generate can return a list of sections
41
41
  if (Array.isArray(body)) {
42
- return body.map(helpSection => helpSection && helpSection.body && this.section(helpSection.header, helpSection.body)).join('\n\n');
42
+ return body
43
+ .map((helpSection) => helpSection && helpSection.body && this.section(helpSection.header, helpSection.body))
44
+ .join('\n\n');
43
45
  }
44
46
  return body && this.section(header, body);
45
47
  })).join('\n\n');
@@ -111,13 +113,14 @@ class CommandHelp extends formatter_1.HelpFormatter {
111
113
  usage() {
112
114
  const { usage } = this.command;
113
115
  const body = (usage ? (0, util_1.castArray)(usage) : [this.defaultUsage()])
114
- .map(u => {
116
+ .map((u) => {
115
117
  const allowedSpacing = this.opts.maxWidth - this.indentSpacing;
116
118
  const line = `$ ${this.config.bin} ${u}`.trim();
117
119
  if (line.length > allowedSpacing) {
118
120
  const splitIndex = line.slice(0, Math.max(0, allowedSpacing)).lastIndexOf(' ');
119
- return line.slice(0, Math.max(0, splitIndex)) + '\n'
120
- + this.indent(this.wrap(line.slice(Math.max(0, splitIndex)), this.indentSpacing * 2));
121
+ return (line.slice(0, Math.max(0, splitIndex)) +
122
+ '\n' +
123
+ this.indent(this.wrap(line.slice(Math.max(0, splitIndex)), this.indentSpacing * 2)));
121
124
  }
122
125
  return this.wrap(line);
123
126
  })
@@ -131,7 +134,10 @@ class CommandHelp extends formatter_1.HelpFormatter {
131
134
  }
132
135
  return (0, util_1.compact)([
133
136
  this.command.id,
134
- Object.values(this.command.args ?? {})?.filter(a => !a.hidden).map(a => this.arg(a)).join(' '),
137
+ Object.values(this.command.args ?? {})
138
+ ?.filter((a) => !a.hidden)
139
+ .map((a) => this.arg(a))
140
+ .join(' '),
135
141
  ]).join(' ');
136
142
  }
137
143
  description() {
@@ -142,10 +148,9 @@ class CommandHelp extends formatter_1.HelpFormatter {
142
148
  }
143
149
  else if (cmd.description) {
144
150
  const summary = cmd.summary ? `${cmd.summary}\n` : null;
145
- description = summary ? [
146
- ...summary.split(POSSIBLE_LINE_FEED),
147
- ...(cmd.description || '').split(POSSIBLE_LINE_FEED),
148
- ] : (cmd.description || '').split(POSSIBLE_LINE_FEED);
151
+ description = summary
152
+ ? [...summary.split(POSSIBLE_LINE_FEED), ...(cmd.description || '').split(POSSIBLE_LINE_FEED)]
153
+ : (cmd.description || '').split(POSSIBLE_LINE_FEED);
149
154
  }
150
155
  if (description) {
151
156
  return this.wrap(description.join('\n'));
@@ -154,50 +159,51 @@ class CommandHelp extends formatter_1.HelpFormatter {
154
159
  aliases(aliases) {
155
160
  if (!aliases || aliases.length === 0)
156
161
  return;
157
- const body = aliases.map(a => ['$', this.config.bin, a].join(' ')).join('\n');
162
+ const body = aliases.map((a) => ['$', this.config.bin, a].join(' ')).join('\n');
158
163
  return body;
159
164
  }
160
165
  examples(examples) {
161
166
  if (!examples || examples.length === 0)
162
167
  return;
163
- const body = (0, util_1.castArray)(examples).map(a => {
168
+ const body = (0, util_1.castArray)(examples)
169
+ .map((a) => {
164
170
  let description;
165
171
  let commands;
166
172
  if (typeof a === 'string') {
167
- const lines = a
168
- .split(POSSIBLE_LINE_FEED)
169
- .filter(Boolean);
173
+ const lines = a.split(POSSIBLE_LINE_FEED).filter(Boolean);
170
174
  // If the example is <description>\n<command> then format correctly
171
- if (lines.length >= 2 && !this.isCommand(lines[0]) && lines.slice(1).every(i => this.isCommand(i))) {
175
+ if (lines.length >= 2 && !this.isCommand(lines[0]) && lines.slice(1).every((i) => this.isCommand(i))) {
172
176
  description = lines[0];
173
177
  commands = lines.slice(1);
174
178
  }
175
179
  else {
176
- return lines.map(line => this.formatIfCommand(line)).join('\n');
180
+ return lines.map((line) => this.formatIfCommand(line)).join('\n');
177
181
  }
178
182
  }
179
183
  else {
180
184
  description = a.description;
181
185
  commands = [a.command];
182
186
  }
183
- const multilineSeparator = this.config.platform === 'win32'
184
- ? (this.config.shell.includes('powershell') ? '`' : '^')
185
- : '\\';
187
+ const multilineSeparator = this.config.platform === 'win32' ? (this.config.shell.includes('powershell') ? '`' : '^') : '\\';
186
188
  // The command will be indented in the section, which is also indented
187
189
  const finalIndentedSpacing = this.indentSpacing * 2;
188
- const multilineCommands = commands.map(c =>
190
+ const multilineCommands = commands
191
+ .map((c) =>
189
192
  // First indent keeping room for escaped newlines
190
193
  this.indent(this.wrap(this.formatIfCommand(c), finalIndentedSpacing + 4))
191
194
  // Then add the escaped newline
192
- .split(POSSIBLE_LINE_FEED).join(` ${multilineSeparator}\n `)).join('\n');
195
+ .split(POSSIBLE_LINE_FEED)
196
+ .join(` ${multilineSeparator}\n `))
197
+ .join('\n');
193
198
  return `${this.wrap(description, finalIndentedSpacing)}\n\n${multilineCommands}`;
194
- }).join('\n\n');
199
+ })
200
+ .join('\n\n');
195
201
  return body;
196
202
  }
197
203
  args(args) {
198
- if (args.filter(a => a.description).length === 0)
204
+ if (args.filter((a) => a.description).length === 0)
199
205
  return;
200
- return args.map(a => {
206
+ return args.map((a) => {
201
207
  const name = a.name.toUpperCase();
202
208
  let description = a.description || '';
203
209
  if (a.default)
@@ -245,7 +251,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
245
251
  flags(flags) {
246
252
  if (flags.length === 0)
247
253
  return;
248
- return flags.map(flag => {
254
+ return flags.map((flag) => {
249
255
  const left = this.flagHelpLabel(flag);
250
256
  let right = flag.summary || flag.description || '';
251
257
  if (flag.type === 'option' && flag.default) {
@@ -260,16 +266,21 @@ class CommandHelp extends formatter_1.HelpFormatter {
260
266
  });
261
267
  }
262
268
  flagsDescriptions(flags) {
263
- const flagsWithExtendedDescriptions = flags.filter(flag => flag.summary && flag.description);
269
+ const flagsWithExtendedDescriptions = flags.filter((flag) => flag.summary && flag.description);
264
270
  if (flagsWithExtendedDescriptions.length === 0)
265
271
  return;
266
- const body = flagsWithExtendedDescriptions.map(flag => {
272
+ const body = flagsWithExtendedDescriptions
273
+ .map((flag) => {
267
274
  // Guaranteed to be set because of the filter above, but make ts happy
268
275
  const summary = flag.summary || '';
269
276
  let flagHelp = this.flagHelpLabel(flag, true);
270
- flagHelp += flagHelp.length + summary.length + 2 < this.opts.maxWidth ? ' ' + summary : '\n\n' + this.indent(this.wrap(summary, this.indentSpacing * 2));
277
+ flagHelp +=
278
+ flagHelp.length + summary.length + 2 < this.opts.maxWidth
279
+ ? ' ' + summary
280
+ : '\n\n' + this.indent(this.wrap(summary, this.indentSpacing * 2));
271
281
  return `${flagHelp}\n\n${this.indent(this.wrap(flag.description || '', this.indentSpacing * 2))}`;
272
- }).join('\n\n');
282
+ })
283
+ .join('\n\n');
273
284
  return body;
274
285
  }
275
286
  formatIfCommand(example) {
@@ -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 index_1 = require("../util/index");
5
5
  /**
6
6
  * DocOpts - See http://docopt.org/.
7
7
  *
@@ -79,7 +79,7 @@ class DocOpts {
79
79
  toString() {
80
80
  const opts = this.cmd.id === '.' || this.cmd.id === '' ? [] : ['<%= command.id %>'];
81
81
  if (this.cmd.args) {
82
- const a = Object.values((0, util_1.ensureArgObject)(this.cmd.args)).map(arg => arg.required ? arg.name.toUpperCase() : `[${arg.name.toUpperCase()}]`) || [];
82
+ const a = Object.values((0, index_1.ensureArgObject)(this.cmd.args)).map((arg) => arg.required ? arg.name.toUpperCase() : `[${arg.name.toUpperCase()}]`) || [];
83
83
  opts.push(...a);
84
84
  }
85
85
  try {
@@ -87,7 +87,7 @@ class DocOpts {
87
87
  }
88
88
  catch {
89
89
  // If there is an error, just return no usage so we don't fail command help.
90
- opts.push(...this.flagList.map(flag => {
90
+ opts.push(...this.flagList.map((flag) => {
91
91
  const name = flag.char ? `-${flag.char}` : `--${flag.name}`;
92
92
  if (flag.type === 'boolean')
93
93
  return name;
@@ -100,9 +100,9 @@ class DocOpts {
100
100
  const elementMap = {};
101
101
  // Generate all doc opt elements for combining
102
102
  // Show required flags first
103
- this.generateElements(elementMap, this.flagList.filter(flag => flag.required));
103
+ this.generateElements(elementMap, this.flagList.filter((flag) => flag.required));
104
104
  // Then show optional flags
105
- this.generateElements(elementMap, this.flagList.filter(flag => !flag.required));
105
+ this.generateElements(elementMap, this.flagList.filter((flag) => !flag.required));
106
106
  for (const flag of this.flagList) {
107
107
  if (Array.isArray(flag.dependsOn)) {
108
108
  this.combineElementsToFlag(elementMap, flag.name, flag.dependsOn, ' ');
@@ -117,7 +117,7 @@ class HelpFormatter {
117
117
  };
118
118
  if (opts.multiline)
119
119
  return renderMultiline();
120
- const maxLength = (0, widest_line_1.default)(input.map(i => i[0]).join('\n'));
120
+ const maxLength = (0, widest_line_1.default)(input.map((i) => i[0]).join('\n'));
121
121
  let output = '';
122
122
  let spacer = opts.spacer || '\n';
123
123
  let cur = '';
@@ -137,7 +137,7 @@ class HelpFormatter {
137
137
  if (opts.stripAnsi)
138
138
  right = (0, strip_ansi_1.default)(right);
139
139
  right = this.wrap(right.trim(), opts.indentation + maxLength + 2);
140
- const [first, ...lines] = right.split('\n').map(s => s.trim());
140
+ const [first, ...lines] = right.split('\n').map((s) => s.trim());
141
141
  cur += ' '.repeat(maxLength - (0, string_width_1.default)(cur) + 2);
142
142
  cur += first;
143
143
  if (lines.length === 0) {
@@ -165,13 +165,13 @@ class HelpFormatter {
165
165
  newBody = this.render(body);
166
166
  }
167
167
  else if (Array.isArray(body)) {
168
- newBody = body.map(entry => {
168
+ newBody = body.map((entry) => {
169
169
  if ('name' in entry) {
170
170
  const tableEntry = entry;
171
- return ([this.render(tableEntry.name), this.render(tableEntry.description)]);
171
+ return [this.render(tableEntry.name), this.render(tableEntry.description)];
172
172
  }
173
173
  const [left, right] = entry;
174
- return ([this.render(left), right && this.render(right)]);
174
+ return [this.render(left), right && this.render(right)];
175
175
  });
176
176
  }
177
177
  else if ('header' in body) {
@@ -179,8 +179,8 @@ class HelpFormatter {
179
179
  }
180
180
  else {
181
181
  newBody = body
182
- .map((entry) => ([entry.name, entry.description]))
183
- .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)]);
184
184
  }
185
185
  const output = [
186
186
  chalk_1.default.bold(header),
package/lib/help/index.js CHANGED
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadHelpClass = exports.Help = exports.HelpBase = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.CommandHelp = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const util_1 = require("../util");
6
- const util_2 = require("./util");
5
+ const index_1 = require("../util/index");
6
+ const util_1 = require("./util");
7
7
  const command_1 = require("./command");
8
8
  const formatter_1 = require("./formatter");
9
9
  const root_1 = tslib_1.__importDefault(require("./root"));
@@ -15,13 +15,13 @@ const stream_1 = require("../cli-ux/stream");
15
15
  const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
16
16
  var command_2 = require("./command");
17
17
  Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return command_2.CommandHelp; } });
18
- var util_3 = require("./util");
19
- Object.defineProperty(exports, "standardizeIDFromArgv", { enumerable: true, get: function () { return util_3.standardizeIDFromArgv; } });
20
- Object.defineProperty(exports, "getHelpFlagAdditions", { enumerable: true, get: function () { return util_3.getHelpFlagAdditions; } });
21
- Object.defineProperty(exports, "normalizeArgv", { enumerable: true, get: function () { return util_3.normalizeArgv; } });
18
+ var util_2 = require("./util");
19
+ Object.defineProperty(exports, "standardizeIDFromArgv", { enumerable: true, get: function () { return util_2.standardizeIDFromArgv; } });
20
+ Object.defineProperty(exports, "getHelpFlagAdditions", { enumerable: true, get: function () { return util_2.getHelpFlagAdditions; } });
21
+ Object.defineProperty(exports, "normalizeArgv", { enumerable: true, get: function () { return util_2.normalizeArgv; } });
22
22
  function getHelpSubject(args, config) {
23
23
  // for each help flag that starts with '--' create a new flag with same name sans '--'
24
- const mergedHelpFlags = (0, util_2.getHelpFlagAdditions)(config);
24
+ const mergedHelpFlags = (0, util_1.getHelpFlagAdditions)(config);
25
25
  for (const arg of args) {
26
26
  if (arg === '--')
27
27
  return;
@@ -51,22 +51,22 @@ class Help extends HelpBase {
51
51
  get _topics() {
52
52
  return this.config.topics.filter((topic) => {
53
53
  // it is assumed a topic has a child if it has children
54
- const hasChild = this.config.topics.some(subTopic => subTopic.name.includes(`${topic.name}:`));
54
+ const hasChild = this.config.topics.some((subTopic) => subTopic.name.includes(`${topic.name}:`));
55
55
  return hasChild;
56
56
  });
57
57
  }
58
58
  get sortedCommands() {
59
59
  let { commands } = this.config;
60
- commands = commands.filter(c => this.opts.all || !c.hidden);
61
- commands = (0, util_1.sortBy)(commands, c => c.id);
62
- commands = (0, util_1.uniqBy)(commands, c => c.id);
60
+ commands = commands.filter((c) => this.opts.all || !c.hidden);
61
+ commands = (0, index_1.sortBy)(commands, (c) => c.id);
62
+ commands = (0, index_1.uniqBy)(commands, (c) => c.id);
63
63
  return commands;
64
64
  }
65
65
  get sortedTopics() {
66
66
  let topics = this._topics;
67
- topics = topics.filter(t => this.opts.all || !t.hidden);
68
- topics = (0, util_1.sortBy)(topics, t => t.name);
69
- topics = (0, util_1.uniqBy)(topics, t => t.name);
67
+ topics = topics.filter((t) => this.opts.all || !t.hidden);
68
+ topics = (0, index_1.sortBy)(topics, (t) => t.name);
69
+ topics = (0, index_1.uniqBy)(topics, (t) => t.name);
70
70
  return topics;
71
71
  }
72
72
  constructor(config, opts = {}) {
@@ -74,9 +74,9 @@ class Help extends HelpBase {
74
74
  }
75
75
  async showHelp(argv) {
76
76
  const originalArgv = argv.slice(1);
77
- argv = argv.filter(arg => !(0, util_2.getHelpFlagAdditions)(this.config).includes(arg));
77
+ argv = argv.filter((arg) => !(0, util_1.getHelpFlagAdditions)(this.config).includes(arg));
78
78
  if (this.config.topicSeparator !== ':')
79
- argv = (0, util_2.standardizeIDFromArgv)(argv, this.config);
79
+ argv = (0, util_1.standardizeIDFromArgv)(argv, this.config);
80
80
  const subject = getHelpSubject(argv, this.config);
81
81
  if (!subject) {
82
82
  if (this.config.pjson.oclif.default) {
@@ -116,7 +116,7 @@ class Help extends HelpBase {
116
116
  if (matches.length > 0) {
117
117
  const result = await this.config.runHook('command_incomplete', {
118
118
  id: subject,
119
- argv: originalArgv.filter(o => !subject.split(':').includes(o)),
119
+ argv: originalArgv.filter((o) => !subject.split(':').includes(o)),
120
120
  matches,
121
121
  });
122
122
  if (result.successes.length > 0)
@@ -128,15 +128,20 @@ class Help extends HelpBase {
128
128
  async showCommandHelp(command) {
129
129
  const name = command.id;
130
130
  const depth = name.split(':').length;
131
- const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
132
- const subCommands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
131
+ const subTopics = this.sortedTopics.filter((t) => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
132
+ const subCommands = this.sortedCommands.filter((c) => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
133
133
  const plugin = this.config.plugins.get(command.pluginName);
134
134
  const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state;
135
135
  if (state) {
136
136
  this.log(state === 'deprecated'
137
- ? `${(0, util_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), command.deprecationOptions)}`
137
+ ? `${(0, util_1.formatCommandDeprecationWarning)((0, util_1.toConfiguredId)(name, this.config), command.deprecationOptions)}\n`
138
138
  : `This command is in ${state}.\n`);
139
139
  }
140
+ if (command.deprecateAliases && command.aliases.includes(name)) {
141
+ const actualCmd = this.config.commands.find((c) => c.aliases.includes(name));
142
+ const opts = { ...command.deprecationOptions, ...(actualCmd ? { to: actualCmd.id } : {}) };
143
+ this.log(`${(0, util_1.formatCommandDeprecationWarning)((0, util_1.toConfiguredId)(name, this.config), opts)}\n`);
144
+ }
140
145
  const summary = this.summary(command);
141
146
  if (summary) {
142
147
  this.log(summary + '\n');
@@ -149,7 +154,7 @@ class Help extends HelpBase {
149
154
  }
150
155
  if (subCommands.length > 0) {
151
156
  const aliases = [];
152
- const uniqueSubCommands = subCommands.filter(p => {
157
+ const uniqueSubCommands = subCommands.filter((p) => {
153
158
  aliases.push(...p.aliases);
154
159
  return !aliases.includes(p.id);
155
160
  });
@@ -162,22 +167,20 @@ class Help extends HelpBase {
162
167
  let rootCommands = this.sortedCommands;
163
168
  const state = this.config.pjson?.oclif?.state;
164
169
  if (state) {
165
- this.log(state === 'deprecated'
166
- ? `${this.config.bin} is deprecated`
167
- : `${this.config.bin} is in ${state}.\n`);
170
+ this.log(state === 'deprecated' ? `${this.config.bin} is deprecated` : `${this.config.bin} is in ${state}.\n`);
168
171
  }
169
172
  this.log(this.formatRoot());
170
173
  this.log('');
171
174
  if (!this.opts.all) {
172
- rootTopics = rootTopics.filter(t => !t.name.includes(':'));
173
- rootCommands = rootCommands.filter(c => !c.id.includes(':'));
175
+ rootTopics = rootTopics.filter((t) => !t.name.includes(':'));
176
+ rootCommands = rootCommands.filter((c) => !c.id.includes(':'));
174
177
  }
175
178
  if (rootTopics.length > 0) {
176
179
  this.log(this.formatTopics(rootTopics));
177
180
  this.log('');
178
181
  }
179
182
  if (rootCommands.length > 0) {
180
- rootCommands = rootCommands.filter(c => c.id);
183
+ rootCommands = rootCommands.filter((c) => c.id);
181
184
  this.log(this.formatCommands(rootCommands));
182
185
  this.log('');
183
186
  }
@@ -185,8 +188,8 @@ class Help extends HelpBase {
185
188
  async showTopicHelp(topic) {
186
189
  const { name } = topic;
187
190
  const depth = name.split(':').length;
188
- const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
189
- const commands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
191
+ const subTopics = this.sortedTopics.filter((t) => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
192
+ const commands = this.sortedCommands.filter((c) => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
190
193
  const state = this.config.pjson?.oclif?.state;
191
194
  if (state)
192
195
  this.log(`This topic is in ${state}.\n`);
@@ -207,7 +210,7 @@ class Help extends HelpBase {
207
210
  formatCommand(command) {
208
211
  if (this.config.topicSeparator !== ':') {
209
212
  command.id = command.id.replaceAll(':', this.config.topicSeparator);
210
- command.aliases = command.aliases && command.aliases.map(a => a.replaceAll(':', this.config.topicSeparator));
213
+ command.aliases = command.aliases && command.aliases.map((a) => a.replaceAll(':', this.config.topicSeparator));
211
214
  }
212
215
  const help = this.getCommandHelpClass(command);
213
216
  return help.generate();
@@ -218,13 +221,10 @@ class Help extends HelpBase {
218
221
  formatCommands(commands) {
219
222
  if (commands.length === 0)
220
223
  return '';
221
- const body = this.renderList(commands.map(c => {
224
+ const body = this.renderList(commands.map((c) => {
222
225
  if (this.config.topicSeparator !== ':')
223
226
  c.id = c.id.replaceAll(':', this.config.topicSeparator);
224
- return [
225
- c.id,
226
- this.summary(c),
227
- ];
227
+ return [c.id, this.summary(c)];
228
228
  }), {
229
229
  spacer: '\n',
230
230
  stripAnsi: this.opts.stripAnsi,
@@ -251,7 +251,7 @@ class Help extends HelpBase {
251
251
  let topicID = `${topic.name}:COMMAND`;
252
252
  if (this.config.topicSeparator !== ':')
253
253
  topicID = topicID.replaceAll(':', this.config.topicSeparator);
254
- let output = (0, util_1.compact)([
254
+ let output = (0, index_1.compact)([
255
255
  summary,
256
256
  this.section(this.opts.usageHeader || 'USAGE', `$ ${this.config.bin} ${topicID}`),
257
257
  description && this.section('DESCRIPTION', this.wrap(description)),
@@ -263,13 +263,10 @@ class Help extends HelpBase {
263
263
  formatTopics(topics) {
264
264
  if (topics.length === 0)
265
265
  return '';
266
- const body = this.renderList(topics.map(c => {
266
+ const body = this.renderList(topics.map((c) => {
267
267
  if (this.config.topicSeparator !== ':')
268
268
  c.name = c.name.replaceAll(':', this.config.topicSeparator);
269
- return [
270
- c.name,
271
- c.description && this.render(c.description.split('\n')[0]),
272
- ];
269
+ return [c.name, c.description && this.render(c.description.split('\n')[0])];
273
270
  }), {
274
271
  spacer: '\n',
275
272
  stripAnsi: this.opts.stripAnsi,
@@ -293,7 +290,7 @@ async function loadHelpClass(config) {
293
290
  const configuredClass = pjson.oclif?.helpClass;
294
291
  if (configuredClass) {
295
292
  try {
296
- const exported = await (0, module_loader_1.load)(config, configuredClass);
293
+ const exported = (await (0, module_loader_1.load)(config, configuredClass));
297
294
  return extractClass(exported);
298
295
  }
299
296
  catch (error) {
package/lib/help/root.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const formatter_1 = require("./formatter");
5
- const util_1 = require("../util");
5
+ const index_1 = require("../util/index");
6
6
  const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
7
7
  class RootHelp extends formatter_1.HelpFormatter {
8
8
  config;
@@ -16,12 +16,7 @@ class RootHelp extends formatter_1.HelpFormatter {
16
16
  let description = this.config.pjson.oclif.description || this.config.pjson.description || '';
17
17
  description = this.render(description);
18
18
  description = description.split('\n')[0];
19
- let output = (0, util_1.compact)([
20
- description,
21
- this.version(),
22
- this.usage(),
23
- this.description(),
24
- ]).join('\n\n');
19
+ let output = (0, index_1.compact)([description, this.version(), this.usage(), this.description()]).join('\n\n');
25
20
  if (this.opts.stripAnsi)
26
21
  output = (0, strip_ansi_1.default)(output);
27
22
  return output;
package/lib/help/util.js CHANGED
@@ -20,7 +20,7 @@ function collateSpacedCmdIDFromArgs(argv, config) {
20
20
  const ids = (0, util_1.collectUsableIds)(config.commandIDs);
21
21
  const final = [];
22
22
  const idPresent = (id) => ids.has(id);
23
- const finalizeId = (s) => s ? [...final, s].join(':') : final.join(':');
23
+ const finalizeId = (s) => (s ? [...final, s].join(':') : final.join(':'));
24
24
  const hasArgs = () => {
25
25
  const id = finalizeId();
26
26
  if (!id)
@@ -43,14 +43,14 @@ export interface Hooks {
43
43
  };
44
44
  return: void;
45
45
  };
46
- 'command_not_found': {
46
+ command_not_found: {
47
47
  options: {
48
48
  id: string;
49
49
  argv?: string[];
50
50
  };
51
51
  return: unknown;
52
52
  };
53
- 'command_incomplete': {
53
+ command_incomplete: {
54
54
  options: {
55
55
  id: string;
56
56
  argv: string[];
@@ -58,7 +58,7 @@ export interface Hooks {
58
58
  };
59
59
  return: unknown;
60
60
  };
61
- 'jit_plugin_not_installed': {
61
+ jit_plugin_not_installed: {
62
62
  options: {
63
63
  id: string;
64
64
  argv: string[];
@@ -5,7 +5,7 @@ export type { HelpOptions } from './help';
5
5
  export type { Hook, Hooks } from './hooks';
6
6
  export type { Manifest } from './manifest';
7
7
  export type { S3Manifest } from './s3-manifest';
8
- export type { Arg, BooleanFlag, CustomOptions, Deprecation, Flag, FlagDefinition, OptionFlag, } from './parser';
8
+ export type { Arg, BooleanFlag, CustomOptions, Deprecation, Flag, FlagDefinition, OptionFlag } from './parser';
9
9
  export type { PJSON } from './pjson';
10
10
  export type { Plugin, PluginOptions, Options } from './plugin';
11
11
  export type { Topic } from './topic';
@@ -154,8 +154,8 @@ export type FlagProps = {
154
154
  */
155
155
  aliases?: string[];
156
156
  /**
157
- * Alternate short chars that can be used for this flag.
158
- */
157
+ * Alternate short chars that can be used for this flag.
158
+ */
159
159
  charAliases?: (AlphabetLowercase | AlphabetUppercase)[];
160
160
  /**
161
161
  * Emit deprecation warning when a flag alias is provided
@@ -201,10 +201,10 @@ export type OptionFlagProps = FlagProps & {
201
201
  options?: readonly string[];
202
202
  multiple?: boolean;
203
203
  /**
204
- * Delimiter to separate the values for a multiple value flag.
205
- * Only respected if multiple is set to true. Default behavior is to
206
- * separate on spaces.
207
- */
204
+ * Delimiter to separate the values for a multiple value flag.
205
+ * Only respected if multiple is set to true. Default behavior is to
206
+ * separate on spaces.
207
+ */
208
208
  delimiter?: ',';
209
209
  };
210
210
  export type FlagParserContext = Command & {
@@ -256,11 +256,7 @@ type ReturnTypeSwitches = {
256
256
  * - It's possible that T extends an Array, if so we want to return T so that the return isn't T[][]
257
257
  * - If requiredOrDefaulted is false && multiple is false, then the return type is T | undefined
258
258
  */
259
- type FlagReturnType<T, R extends ReturnTypeSwitches> = R['requiredOrDefaulted'] extends true ? R['multiple'] extends true ? [
260
- T
261
- ] extends [Array<unknown>] ? T : T[] : T : R['multiple'] extends true ? [
262
- T
263
- ] extends [Array<unknown>] ? T | undefined : T[] | undefined : T | undefined;
259
+ type FlagReturnType<T, R extends ReturnTypeSwitches> = R['requiredOrDefaulted'] extends true ? R['multiple'] extends true ? [T] extends [Array<unknown>] ? T : T[] : T : R['multiple'] extends true ? [T] extends [Array<unknown>] ? T | undefined : T[] | undefined : T | undefined;
264
260
  /**
265
261
  * FlagDefinition types a function that takes `options` and returns an OptionFlag<T>.
266
262
  *
@@ -312,7 +308,8 @@ export type FlagDefinition<T, P = CustomOptions, R extends ReturnTypeSwitches =
312
308
  multiple: false;
313
309
  requiredOrDefaulted: false;
314
310
  }>>;
315
- (options: R['multiple'] extends true ? P & ({
311
+ (options: R['multiple'] extends true ? // `multiple` is defaulted to true and either `required=true` or `default` are provided in options
312
+ P & ({
316
313
  required: true;
317
314
  } | {
318
315
  default: OptionFlag<FlagReturnType<T, {
@@ -322,7 +319,8 @@ export type FlagDefinition<T, P = CustomOptions, R extends ReturnTypeSwitches =
322
319
  }) & Partial<OptionFlag<FlagReturnType<T, {
323
320
  multiple: R['multiple'];
324
321
  requiredOrDefaulted: true;
325
- }>, P>> : P & {
322
+ }>, P>> : // `multiple` is NOT defaulted to true and either `required=true` or `default` are provided in options
323
+ P & {
326
324
  multiple?: false | undefined;
327
325
  } & ({
328
326
  required: true;
@@ -338,7 +336,8 @@ export type FlagDefinition<T, P = CustomOptions, R extends ReturnTypeSwitches =
338
336
  multiple: R['multiple'];
339
337
  requiredOrDefaulted: true;
340
338
  }>>;
341
- (options: R['multiple'] extends true ? P & ({
339
+ (options: R['multiple'] extends true ? // `multiple` is defaulted to true and either `required=true` or `default` are provided in options
340
+ P & ({
342
341
  required: true;
343
342
  } | {
344
343
  default: OptionFlag<FlagReturnType<T, {
@@ -348,7 +347,8 @@ export type FlagDefinition<T, P = CustomOptions, R extends ReturnTypeSwitches =
348
347
  }) & Partial<OptionFlag<FlagReturnType<T, {
349
348
  multiple: true;
350
349
  requiredOrDefaulted: true;
351
- }>, P>> : P & {
350
+ }>, P>> : // `multiple` is NOT defaulted to true but `multiple=true` and either `required=true` or `default` are provided in options
351
+ P & {
352
352
  multiple: true;
353
353
  } & ({
354
354
  required: true;
@@ -26,7 +26,7 @@ export declare namespace PJSON {
26
26
  topicSeparator?: ':' | ' ';
27
27
  flexibleTaxonomy?: boolean;
28
28
  hooks?: {
29
- [name: string]: (string | string[]);
29
+ [name: string]: string | string[];
30
30
  };
31
31
  commands?: string;
32
32
  default?: string;
@@ -60,12 +60,12 @@ export declare function loadWithDataFromManifest(cached: Command.Cached, moduleP
60
60
  filePath: string;
61
61
  }>;
62
62
  /**
63
- * For `.js` files uses `getPackageType` to determine if `type` is set to `module` in associated `package.json`. If
64
- * the `modulePath` provided ends in `.mjs` it is assumed to be ESM.
65
- *
66
- * @param {string} filePath - File path to test.
67
- *
68
- * @returns {boolean} The modulePath is an ES Module.
69
- * @see https://www.npmjs.com/package/get-package-type
70
- */
63
+ * For `.js` files uses `getPackageType` to determine if `type` is set to `module` in associated `package.json`. If
64
+ * the `modulePath` provided ends in `.mjs` it is assumed to be ESM.
65
+ *
66
+ * @param {string} filePath - File path to test.
67
+ *
68
+ * @returns {boolean} The modulePath is an ES Module.
69
+ * @see https://www.npmjs.com/package/get-package-type
70
+ */
71
71
  export declare function isPathModule(filePath: string): boolean;