@oclif/core 3.0.0-beta.9 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +4 -2
  2. package/flush.d.ts +3 -0
  3. package/flush.js +1 -0
  4. package/handle.js +1 -0
  5. package/lib/args.d.ts +2 -2
  6. package/lib/args.js +17 -18
  7. package/lib/{ux → cli-ux}/action/base.d.ts +19 -21
  8. package/lib/{ux → cli-ux}/action/base.js +126 -120
  9. package/lib/{ux → cli-ux}/action/simple.js +25 -30
  10. package/lib/{ux → cli-ux}/action/spinner.d.ts +9 -7
  11. package/lib/{ux → cli-ux}/action/spinner.js +45 -37
  12. package/lib/{ux → cli-ux}/action/spinners.js +187 -187
  13. package/lib/cli-ux/action/types.d.ts +5 -0
  14. package/lib/cli-ux/action/types.js +2 -0
  15. package/lib/{ux → cli-ux}/config.d.ts +5 -5
  16. package/lib/{ux → cli-ux}/config.js +17 -17
  17. package/lib/{ux → cli-ux}/exit.js +3 -0
  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 +39 -0
  21. package/lib/{ux → cli-ux}/index.js +74 -88
  22. package/lib/{ux → cli-ux}/list.js +3 -3
  23. package/lib/{ux → cli-ux}/prompt.d.ts +3 -3
  24. package/lib/{ux → cli-ux}/prompt.js +35 -25
  25. package/lib/{ux → cli-ux}/stream.d.ts +6 -6
  26. package/lib/{ux → cli-ux}/stream.js +11 -10
  27. package/lib/cli-ux/styled/index.d.ts +4 -0
  28. package/lib/cli-ux/styled/index.js +11 -0
  29. package/lib/{ux → cli-ux}/styled/object.js +7 -9
  30. package/lib/{ux → cli-ux}/styled/table.d.ts +10 -10
  31. package/lib/{ux → cli-ux}/styled/table.js +130 -133
  32. package/lib/{ux → cli-ux}/styled/tree.js +11 -13
  33. package/lib/cli-ux/wait.js +5 -0
  34. package/lib/command.d.ts +82 -88
  35. package/lib/command.js +196 -175
  36. package/lib/config/config.d.ts +89 -90
  37. package/lib/config/config.js +466 -566
  38. package/lib/config/index.d.ts +0 -1
  39. package/lib/config/index.js +1 -3
  40. package/lib/config/plugin-loader.d.ts +12 -12
  41. package/lib/config/plugin-loader.js +72 -56
  42. package/lib/config/plugin.d.ts +25 -24
  43. package/lib/config/plugin.js +188 -154
  44. package/lib/config/ts-node.d.ts +2 -1
  45. package/lib/config/ts-node.js +71 -58
  46. package/lib/config/util.d.ts +1 -11
  47. package/lib/config/util.js +6 -59
  48. package/lib/errors/config.d.ts +1 -1
  49. package/lib/errors/config.js +6 -6
  50. package/lib/errors/errors/cli.d.ts +7 -7
  51. package/lib/errors/errors/cli.js +20 -16
  52. package/lib/errors/errors/exit.d.ts +1 -4
  53. package/lib/errors/errors/exit.js +1 -1
  54. package/lib/errors/errors/module-load.d.ts +1 -4
  55. package/lib/errors/errors/module-load.js +1 -1
  56. package/lib/errors/errors/pretty-print.d.ts +1 -1
  57. package/lib/errors/errors/pretty-print.js +12 -10
  58. package/lib/errors/handle.d.ts +12 -2
  59. package/lib/errors/handle.js +26 -14
  60. package/lib/errors/index.d.ts +10 -10
  61. package/lib/errors/index.js +25 -24
  62. package/lib/errors/logger.d.ts +2 -2
  63. package/lib/errors/logger.js +14 -13
  64. package/lib/execute.d.ts +6 -6
  65. package/lib/execute.js +10 -9
  66. package/lib/flags.d.ts +103 -32
  67. package/lib/flags.js +79 -45
  68. package/lib/help/command.d.ts +16 -14
  69. package/lib/help/command.js +178 -163
  70. package/lib/help/docopts.d.ts +5 -5
  71. package/lib/help/docopts.js +50 -54
  72. package/lib/help/formatter.d.ts +37 -37
  73. package/lib/help/formatter.js +66 -55
  74. package/lib/help/index.d.ts +25 -21
  75. package/lib/help/index.js +169 -147
  76. package/lib/help/root.d.ts +1 -1
  77. package/lib/help/root.js +15 -17
  78. package/lib/help/util.d.ts +2 -8
  79. package/lib/help/util.js +8 -28
  80. package/lib/index.d.ts +19 -20
  81. package/lib/index.js +37 -43
  82. package/lib/interfaces/config.d.ts +67 -66
  83. package/lib/interfaces/errors.d.ts +5 -5
  84. package/lib/interfaces/help.d.ts +17 -17
  85. package/lib/interfaces/hooks.d.ts +49 -49
  86. package/lib/interfaces/index.d.ts +7 -7
  87. package/lib/interfaces/manifest.d.ts +1 -1
  88. package/lib/interfaces/parser.d.ts +175 -51
  89. package/lib/interfaces/pjson.d.ts +41 -41
  90. package/lib/interfaces/plugin.d.ts +47 -41
  91. package/lib/interfaces/s3-manifest.d.ts +7 -7
  92. package/lib/interfaces/topic.d.ts +1 -1
  93. package/lib/interfaces/ts-config.d.ts +7 -7
  94. package/lib/main.d.ts +2 -2
  95. package/lib/main.js +16 -16
  96. package/lib/module-loader.d.ts +67 -77
  97. package/lib/module-loader.js +183 -150
  98. package/lib/parser/errors.d.ts +7 -7
  99. package/lib/parser/errors.js +29 -22
  100. package/lib/parser/help.js +5 -5
  101. package/lib/parser/index.js +2 -2
  102. package/lib/parser/parse.d.ts +9 -6
  103. package/lib/parser/parse.js +253 -221
  104. package/lib/parser/validate.js +53 -33
  105. package/lib/performance.d.ts +43 -32
  106. package/lib/performance.js +133 -91
  107. package/lib/screen.js +2 -2
  108. package/lib/settings.d.ts +11 -12
  109. package/lib/settings.js +2 -2
  110. package/lib/util/aggregate-flags.d.ts +2 -0
  111. package/lib/util/aggregate-flags.js +13 -0
  112. package/lib/util/cache-command.d.ts +3 -0
  113. package/lib/util/cache-command.js +109 -0
  114. package/lib/util/cache-default-value.d.ts +2 -0
  115. package/lib/util/cache-default-value.js +28 -0
  116. package/lib/util/ensure-arg-object.d.ts +12 -0
  117. package/lib/util/ensure-arg-object.js +14 -0
  118. package/lib/util/fs.d.ts +7 -0
  119. package/lib/util/fs.js +54 -0
  120. package/lib/util/os.d.ts +19 -0
  121. package/lib/util/os.js +28 -0
  122. package/lib/{util.d.ts → util/util.d.ts} +7 -16
  123. package/lib/util/util.js +98 -0
  124. package/package.json +35 -37
  125. package/lib/util.js +0 -126
  126. package/lib/ux/flush.d.ts +0 -1
  127. package/lib/ux/flush.js +0 -27
  128. package/lib/ux/index.d.ts +0 -58
  129. package/lib/ux/styled/index.d.ts +0 -6
  130. package/lib/ux/styled/index.js +0 -13
  131. package/lib/ux/styled/json.d.ts +0 -1
  132. package/lib/ux/styled/json.js +0 -15
  133. package/lib/ux/wait.js +0 -7
  134. package/lib/{ux → cli-ux}/action/simple.d.ts +4 -4
  135. package/lib/{ux → cli-ux}/action/spinners.d.ts +117 -117
  136. package/lib/{ux → cli-ux}/exit.d.ts +2 -2
  137. package/lib/{ux → cli-ux}/list.d.ts +0 -0
  138. package/lib/{ux → cli-ux}/styled/object.d.ts +0 -0
  139. package/lib/{ux → cli-ux}/styled/progress.d.ts +0 -0
  140. package/lib/{ux → cli-ux}/styled/progress.js +0 -0
  141. package/lib/{ux → cli-ux}/styled/tree.d.ts +1 -1
  142. /package/lib/{ux → cli-ux}/wait.d.ts +0 -0
package/lib/help/index.js CHANGED
@@ -1,23 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Help = exports.HelpBase = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.loadHelpClass = exports.standardizeIDFromArgv = exports.CommandHelp = void 0;
4
- const stripAnsi = require("strip-ansi");
5
- const util = require("util");
3
+ exports.loadHelpClass = exports.Help = exports.HelpBase = exports.standardizeIDFromArgv = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.CommandHelp = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_util_1 = require("node:util");
6
+ const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
7
+ const stream_1 = require("../cli-ux/stream");
6
8
  const errors_1 = require("../errors");
9
+ const module_loader_1 = require("../module-loader");
10
+ const cache_default_value_1 = require("../util/cache-default-value");
11
+ const util_1 = require("../util/util");
7
12
  const command_1 = require("./command");
8
- const root_1 = require("./root");
9
- const util_1 = require("../util");
10
- const util_2 = require("./util");
11
13
  const formatter_1 = require("./formatter");
12
- const config_1 = require("../config/config");
13
- const stream_1 = require("../ux/stream");
14
+ const root_1 = tslib_1.__importDefault(require("./root"));
15
+ const util_2 = require("./util");
14
16
  var command_2 = require("./command");
15
17
  Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return command_2.CommandHelp; } });
16
18
  var util_3 = require("./util");
17
- Object.defineProperty(exports, "standardizeIDFromArgv", { enumerable: true, get: function () { return util_3.standardizeIDFromArgv; } });
18
- Object.defineProperty(exports, "loadHelpClass", { enumerable: true, get: function () { return util_3.loadHelpClass; } });
19
19
  Object.defineProperty(exports, "getHelpFlagAdditions", { enumerable: true, get: function () { return util_3.getHelpFlagAdditions; } });
20
20
  Object.defineProperty(exports, "normalizeArgv", { enumerable: true, get: function () { return util_3.normalizeArgv; } });
21
+ Object.defineProperty(exports, "standardizeIDFromArgv", { enumerable: true, get: function () { return util_3.standardizeIDFromArgv; } });
21
22
  function getHelpSubject(args, config) {
22
23
  // for each help flag that starts with '--' create a new flag with same name sans '--'
23
24
  const mergedHelpFlags = (0, util_2.getHelpFlagAdditions)(config);
@@ -40,6 +41,10 @@ class HelpBase extends formatter_1.HelpFormatter {
40
41
  }
41
42
  exports.HelpBase = HelpBase;
42
43
  class Help extends HelpBase {
44
+ CommandHelpClass = command_1.CommandHelp;
45
+ constructor(config, opts = {}) {
46
+ super(config, opts);
47
+ }
43
48
  /*
44
49
  * _topics is to work around Interfaces.topics mistakenly including commands that do
45
50
  * not have children, as well as topics. A topic has children, either commands or other topics. When
@@ -49,31 +54,122 @@ class Help extends HelpBase {
49
54
  get _topics() {
50
55
  return this.config.topics.filter((topic) => {
51
56
  // it is assumed a topic has a child if it has children
52
- const hasChild = this.config.topics.some(subTopic => subTopic.name.includes(`${topic.name}:`));
57
+ const hasChild = this.config.topics.some((subTopic) => subTopic.name.includes(`${topic.name}:`));
53
58
  return hasChild;
54
59
  });
55
60
  }
56
- get sortedCommands() {
57
- let commands = this.config.commands;
58
- commands = commands.filter(c => this.opts.all || !c.hidden);
59
- commands = (0, util_1.sortBy)(commands, c => c.id);
60
- commands = (0, util_1.uniqBy)(commands, c => c.id);
61
- return commands;
61
+ command(command) {
62
+ return this.formatCommand(command);
62
63
  }
63
- get sortedTopics() {
64
- let topics = this._topics;
65
- topics = topics.filter(t => this.opts.all || !t.hidden);
66
- topics = (0, util_1.sortBy)(topics, t => t.name);
67
- topics = (0, util_1.uniqBy)(topics, t => t.name);
68
- return topics;
64
+ description(c) {
65
+ const description = this.render(c.description || '');
66
+ if (c.summary) {
67
+ return description;
68
+ }
69
+ return description.split('\n').slice(1).join('\n');
69
70
  }
70
- constructor(config, opts = {}) {
71
- super(config, opts);
72
- this.CommandHelpClass = command_1.default;
71
+ formatCommand(command) {
72
+ if (this.config.topicSeparator !== ':') {
73
+ command.id = command.id.replaceAll(':', this.config.topicSeparator);
74
+ command.aliases = command.aliases && command.aliases.map((a) => a.replaceAll(':', this.config.topicSeparator));
75
+ }
76
+ const help = this.getCommandHelpClass(command);
77
+ return help.generate();
78
+ }
79
+ formatCommands(commands) {
80
+ if (commands.length === 0)
81
+ return '';
82
+ const body = this.renderList(commands.map((c) => {
83
+ if (this.config.topicSeparator !== ':')
84
+ c.id = c.id.replaceAll(':', this.config.topicSeparator);
85
+ return [c.id, this.summary(c)];
86
+ }), {
87
+ indentation: 2,
88
+ spacer: '\n',
89
+ stripAnsi: this.opts.stripAnsi,
90
+ });
91
+ return this.section('COMMANDS', body);
92
+ }
93
+ formatRoot() {
94
+ const help = new root_1.default(this.config, this.opts);
95
+ return help.root();
96
+ }
97
+ formatTopic(topic) {
98
+ let description = this.render(topic.description || '');
99
+ const summary = description.split('\n')[0];
100
+ description = description.split('\n').slice(1).join('\n');
101
+ let topicID = `${topic.name}:COMMAND`;
102
+ if (this.config.topicSeparator !== ':')
103
+ topicID = topicID.replaceAll(':', this.config.topicSeparator);
104
+ let output = (0, util_1.compact)([
105
+ summary,
106
+ this.section(this.opts.usageHeader || 'USAGE', `$ ${this.config.bin} ${topicID}`),
107
+ description && this.section('DESCRIPTION', this.wrap(description)),
108
+ ]).join('\n\n');
109
+ if (this.opts.stripAnsi)
110
+ output = (0, strip_ansi_1.default)(output);
111
+ return output + '\n';
112
+ }
113
+ formatTopics(topics) {
114
+ if (topics.length === 0)
115
+ return '';
116
+ const body = this.renderList(topics.map((c) => {
117
+ if (this.config.topicSeparator !== ':')
118
+ c.name = c.name.replaceAll(':', this.config.topicSeparator);
119
+ return [c.name, c.description && this.render(c.description.split('\n')[0])];
120
+ }), {
121
+ indentation: 2,
122
+ spacer: '\n',
123
+ stripAnsi: this.opts.stripAnsi,
124
+ });
125
+ return this.section('TOPICS', body);
126
+ }
127
+ getCommandHelpClass(command) {
128
+ return new this.CommandHelpClass(command, this.config, this.opts);
129
+ }
130
+ log(...args) {
131
+ stream_1.stdout.write(node_util_1.format.apply(this, args) + '\n');
132
+ }
133
+ async showCommandHelp(command) {
134
+ const name = command.id;
135
+ const depth = name.split(':').length;
136
+ const subTopics = this.sortedTopics.filter((t) => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
137
+ const subCommands = this.sortedCommands.filter((c) => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
138
+ const plugin = this.config.plugins.get(command.pluginName);
139
+ const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state;
140
+ if (state) {
141
+ this.log(state === 'deprecated'
142
+ ? `${(0, util_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), command.deprecationOptions)}\n`
143
+ : `This command is in ${state}.\n`);
144
+ }
145
+ if (command.deprecateAliases && command.aliases.includes(name)) {
146
+ const actualCmd = this.config.commands.find((c) => c.aliases.includes(name));
147
+ const opts = { ...command.deprecationOptions, ...(actualCmd ? { to: actualCmd.id } : {}) };
148
+ this.log(`${(0, util_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), opts)}\n`);
149
+ }
150
+ const summary = this.summary(command);
151
+ if (summary) {
152
+ this.log(summary + '\n');
153
+ }
154
+ this.log(this.formatCommand(command));
155
+ this.log('');
156
+ if (subTopics.length > 0) {
157
+ this.log(this.formatTopics(subTopics));
158
+ this.log('');
159
+ }
160
+ if (subCommands.length > 0) {
161
+ const aliases = [];
162
+ const uniqueSubCommands = subCommands.filter((p) => {
163
+ aliases.push(...p.aliases);
164
+ return !aliases.includes(p.id);
165
+ });
166
+ this.log(this.formatCommands(uniqueSubCommands));
167
+ this.log('');
168
+ }
73
169
  }
74
170
  async showHelp(argv) {
75
171
  const originalArgv = argv.slice(1);
76
- argv = argv.filter(arg => !(0, util_2.getHelpFlagAdditions)(this.config).includes(arg));
172
+ argv = argv.filter((arg) => !(0, util_2.getHelpFlagAdditions)(this.config).includes(arg));
77
173
  if (this.config.topicSeparator !== ':')
78
174
  argv = (0, util_2.standardizeIDFromArgv)(argv, this.config);
79
175
  const subject = getHelpSubject(argv, this.config);
@@ -91,8 +187,14 @@ class Help extends HelpBase {
91
187
  const command = this.config.findCommand(subject);
92
188
  if (command) {
93
189
  if (command.hasDynamicHelp && command.pluginType !== 'jit') {
94
- const dynamicCommand = await (0, config_1.toCached)(await command.load());
95
- await this.showCommandHelp(dynamicCommand);
190
+ const loaded = await command.load();
191
+ for (const [name, flag] of Object.entries(loaded.flags)) {
192
+ if (flag.type === 'boolean' || !command.flags[name].hasDynamicHelp)
193
+ continue;
194
+ // eslint-disable-next-line no-await-in-loop
195
+ command.flags[name].default = await (0, cache_default_value_1.cacheDefaultValue)(flag, false);
196
+ }
197
+ await this.showCommandHelp(command);
96
198
  }
97
199
  else {
98
200
  await this.showCommandHelp(command);
@@ -108,8 +210,8 @@ class Help extends HelpBase {
108
210
  const matches = this.config.findMatches(subject, originalArgv);
109
211
  if (matches.length > 0) {
110
212
  const result = await this.config.runHook('command_incomplete', {
213
+ argv: originalArgv.filter((o) => !subject.split(':').includes(o)),
111
214
  id: subject,
112
- argv: originalArgv.filter(o => !subject.split(':').includes(o)),
113
215
  matches,
114
216
  });
115
217
  if (result.successes.length > 0)
@@ -118,68 +220,34 @@ class Help extends HelpBase {
118
220
  }
119
221
  (0, errors_1.error)(`Command ${subject} not found.`);
120
222
  }
121
- async showCommandHelp(command) {
122
- const name = command.id;
123
- const depth = name.split(':').length;
124
- const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
125
- const subCommands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
126
- const plugin = this.config.plugins.get(command.pluginName);
127
- const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state;
128
- if (state) {
129
- this.log(state === 'deprecated' ?
130
- `${(0, util_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), command.deprecationOptions)}` :
131
- `This command is in ${state}.\n`);
132
- }
133
- const summary = this.summary(command);
134
- if (summary) {
135
- this.log(summary + '\n');
136
- }
137
- this.log(this.formatCommand(command));
138
- this.log('');
139
- if (subTopics.length > 0) {
140
- this.log(this.formatTopics(subTopics));
141
- this.log('');
142
- }
143
- if (subCommands.length > 0) {
144
- const aliases = [];
145
- const uniqueSubCommands = subCommands.filter(p => {
146
- aliases.push(...p.aliases);
147
- return !aliases.includes(p.id);
148
- });
149
- this.log(this.formatCommands(uniqueSubCommands));
150
- this.log('');
151
- }
152
- }
153
223
  async showRootHelp() {
154
224
  let rootTopics = this.sortedTopics;
155
225
  let rootCommands = this.sortedCommands;
156
226
  const state = this.config.pjson?.oclif?.state;
157
227
  if (state) {
158
- this.log(state === 'deprecated' ?
159
- `${this.config.bin} is deprecated` :
160
- `${this.config.bin} is in ${state}.\n`);
228
+ this.log(state === 'deprecated' ? `${this.config.bin} is deprecated` : `${this.config.bin} is in ${state}.\n`);
161
229
  }
162
230
  this.log(this.formatRoot());
163
231
  this.log('');
164
232
  if (!this.opts.all) {
165
- rootTopics = rootTopics.filter(t => !t.name.includes(':'));
166
- rootCommands = rootCommands.filter(c => !c.id.includes(':'));
233
+ rootTopics = rootTopics.filter((t) => !t.name.includes(':'));
234
+ rootCommands = rootCommands.filter((c) => !c.id.includes(':'));
167
235
  }
168
236
  if (rootTopics.length > 0) {
169
237
  this.log(this.formatTopics(rootTopics));
170
238
  this.log('');
171
239
  }
172
240
  if (rootCommands.length > 0) {
173
- rootCommands = rootCommands.filter(c => c.id);
241
+ rootCommands = rootCommands.filter((c) => c.id);
174
242
  this.log(this.formatCommands(rootCommands));
175
243
  this.log('');
176
244
  }
177
245
  }
178
246
  async showTopicHelp(topic) {
179
- const name = topic.name;
247
+ const { name } = topic;
180
248
  const depth = name.split(':').length;
181
- const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
182
- const commands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
249
+ const subTopics = this.sortedTopics.filter((t) => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
250
+ const commands = this.sortedCommands.filter((c) => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
183
251
  const state = this.config.pjson?.oclif?.state;
184
252
  if (state)
185
253
  this.log(`This topic is in ${state}.\n`);
@@ -193,88 +261,42 @@ class Help extends HelpBase {
193
261
  this.log('');
194
262
  }
195
263
  }
196
- formatRoot() {
197
- const help = new root_1.default(this.config, this.opts);
198
- return help.root();
199
- }
200
- formatCommand(command) {
201
- if (this.config.topicSeparator !== ':') {
202
- command.id = command.id.replace(/:/g, this.config.topicSeparator);
203
- command.aliases = command.aliases && command.aliases.map(a => a.replace(/:/g, this.config.topicSeparator));
204
- }
205
- const help = this.getCommandHelpClass(command);
206
- return help.generate();
207
- }
208
- getCommandHelpClass(command) {
209
- return new this.CommandHelpClass(command, this.config, this.opts);
210
- }
211
- formatCommands(commands) {
212
- if (commands.length === 0)
213
- return '';
214
- const body = this.renderList(commands.map(c => {
215
- if (this.config.topicSeparator !== ':')
216
- c.id = c.id.replace(/:/g, this.config.topicSeparator);
217
- return [
218
- c.id,
219
- this.summary(c),
220
- ];
221
- }), {
222
- spacer: '\n',
223
- stripAnsi: this.opts.stripAnsi,
224
- indentation: 2,
225
- });
226
- return this.section('COMMANDS', body);
227
- }
228
264
  summary(c) {
229
265
  if (c.summary)
230
266
  return this.render(c.summary.split('\n')[0]);
231
267
  return c.description && this.render(c.description).split('\n')[0];
232
268
  }
233
- description(c) {
234
- const description = this.render(c.description || '');
235
- if (c.summary) {
236
- return description;
237
- }
238
- return description.split('\n').slice(1).join('\n');
239
- }
240
- formatTopic(topic) {
241
- let description = this.render(topic.description || '');
242
- const summary = description.split('\n')[0];
243
- description = description.split('\n').slice(1).join('\n');
244
- let topicID = `${topic.name}:COMMAND`;
245
- if (this.config.topicSeparator !== ':')
246
- topicID = topicID.replace(/:/g, this.config.topicSeparator);
247
- let output = (0, util_1.compact)([
248
- summary,
249
- this.section(this.opts.usageHeader || 'USAGE', `$ ${this.config.bin} ${topicID}`),
250
- description && this.section('DESCRIPTION', this.wrap(description)),
251
- ]).join('\n\n');
252
- if (this.opts.stripAnsi)
253
- output = stripAnsi(output);
254
- return output + '\n';
255
- }
256
- formatTopics(topics) {
257
- if (topics.length === 0)
258
- return '';
259
- const body = this.renderList(topics.map(c => {
260
- if (this.config.topicSeparator !== ':')
261
- c.name = c.name.replace(/:/g, this.config.topicSeparator);
262
- return [
263
- c.name,
264
- c.description && this.render(c.description.split('\n')[0]),
265
- ];
266
- }), {
267
- spacer: '\n',
268
- stripAnsi: this.opts.stripAnsi,
269
- indentation: 2,
270
- });
271
- return this.section('TOPICS', body);
272
- }
273
- command(command) {
274
- return this.formatCommand(command);
269
+ get sortedCommands() {
270
+ let { commands } = this.config;
271
+ commands = commands.filter((c) => this.opts.all || !c.hidden);
272
+ commands = (0, util_1.sortBy)(commands, (c) => c.id);
273
+ commands = (0, util_1.uniqBy)(commands, (c) => c.id);
274
+ return commands;
275
275
  }
276
- log(...args) {
277
- stream_1.stdout.write(util.format.apply(this, args) + '\n');
276
+ get sortedTopics() {
277
+ let topics = this._topics;
278
+ topics = topics.filter((t) => this.opts.all || !t.hidden);
279
+ topics = (0, util_1.sortBy)(topics, (t) => t.name);
280
+ topics = (0, util_1.uniqBy)(topics, (t) => t.name);
281
+ return topics;
278
282
  }
279
283
  }
280
284
  exports.Help = Help;
285
+ function extractClass(exported) {
286
+ return exported && exported.default ? exported.default : exported;
287
+ }
288
+ async function loadHelpClass(config) {
289
+ const { pjson } = config;
290
+ const configuredClass = pjson.oclif?.helpClass;
291
+ if (configuredClass) {
292
+ try {
293
+ const exported = (await (0, module_loader_1.load)(config, configuredClass));
294
+ return extractClass(exported);
295
+ }
296
+ catch (error) {
297
+ throw new Error(`Unable to load configured help class "${configuredClass}", failed with message:\n${error.message}`);
298
+ }
299
+ }
300
+ return Help;
301
+ }
302
+ exports.loadHelpClass = loadHelpClass;
@@ -4,8 +4,8 @@ export default class RootHelp extends HelpFormatter {
4
4
  config: Interfaces.Config;
5
5
  opts: Interfaces.HelpOptions;
6
6
  constructor(config: Interfaces.Config, opts: Interfaces.HelpOptions);
7
+ protected description(): string | undefined;
7
8
  root(): string;
8
9
  protected usage(): string;
9
- protected description(): string | undefined;
10
10
  protected version(): string;
11
11
  }
package/lib/help/root.js CHANGED
@@ -1,39 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const stripAnsi = require("strip-ansi");
4
- const util_1 = require("../util");
3
+ const tslib_1 = require("tslib");
4
+ const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
5
+ const util_1 = require("../util/util");
5
6
  const formatter_1 = require("./formatter");
6
7
  class RootHelp extends formatter_1.HelpFormatter {
8
+ config;
9
+ opts;
7
10
  constructor(config, opts) {
8
11
  super(config, opts);
9
12
  this.config = config;
10
13
  this.opts = opts;
11
14
  }
15
+ description() {
16
+ let description = this.config.pjson.oclif.description || this.config.pjson.description || '';
17
+ description = this.render(description);
18
+ description = description.split('\n').slice(1).join('\n');
19
+ if (!description)
20
+ return;
21
+ return this.section('DESCRIPTION', this.wrap(description));
22
+ }
12
23
  root() {
13
24
  let description = this.config.pjson.oclif.description || this.config.pjson.description || '';
14
25
  description = this.render(description);
15
26
  description = description.split('\n')[0];
16
- let output = (0, util_1.compact)([
17
- description,
18
- this.version(),
19
- this.usage(),
20
- this.description(),
21
- ]).join('\n\n');
27
+ let output = (0, util_1.compact)([description, this.version(), this.usage(), this.description()]).join('\n\n');
22
28
  if (this.opts.stripAnsi)
23
- output = stripAnsi(output);
29
+ output = (0, strip_ansi_1.default)(output);
24
30
  return output;
25
31
  }
26
32
  usage() {
27
33
  return this.section(this.opts.usageHeader || 'USAGE', this.wrap(`$ ${this.config.bin} [COMMAND]`));
28
34
  }
29
- description() {
30
- let description = this.config.pjson.oclif.description || this.config.pjson.description || '';
31
- description = this.render(description);
32
- description = description.split('\n').slice(1).join('\n');
33
- if (!description)
34
- return;
35
- return this.section('DESCRIPTION', this.wrap(description));
36
- }
37
35
  version() {
38
36
  return this.section('VERSION', this.wrap(this.config.userAgent));
39
37
  }
@@ -1,15 +1,9 @@
1
- import { Config as IConfig, HelpOptions, Deprecation } from '../interfaces';
2
- import { HelpBase } from '.';
3
- interface HelpBaseDerived {
4
- new (config: IConfig, opts?: Partial<HelpOptions>): HelpBase;
5
- }
6
- export declare function loadHelpClass(config: IConfig): Promise<HelpBaseDerived>;
1
+ import { Deprecation, Config as IConfig } from '../interfaces';
7
2
  export declare function template(context: any): (t: string) => string;
8
3
  export declare function toStandardizedId(commandID: string, config: IConfig): string;
9
4
  export declare function toConfiguredId(commandID: string, config: IConfig): string;
10
5
  export declare function standardizeIDFromArgv(argv: string[], config: IConfig): string[];
11
6
  export declare function getHelpFlagAdditions(config: IConfig): string[];
12
- export declare function formatFlagDeprecationWarning(flag: string, opts: true | Deprecation): string;
7
+ export declare function formatFlagDeprecationWarning(flag: string, opts: Deprecation | true): string;
13
8
  export declare function formatCommandDeprecationWarning(command: string, opts?: Deprecation): string;
14
9
  export declare function normalizeArgv(config: IConfig, argv?: string[]): string[];
15
- export {};
package/lib/help/util.js CHANGED
@@ -1,29 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeArgv = exports.formatCommandDeprecationWarning = exports.formatFlagDeprecationWarning = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.toConfiguredId = exports.toStandardizedId = exports.template = exports.loadHelpClass = void 0;
4
- const ejs = require("ejs");
5
- const _1 = require(".");
6
- const module_loader_1 = require("../module-loader");
3
+ exports.normalizeArgv = exports.formatCommandDeprecationWarning = exports.formatFlagDeprecationWarning = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.toConfiguredId = exports.toStandardizedId = exports.template = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const ejs = tslib_1.__importStar(require("ejs"));
7
6
  const util_1 = require("../config/util");
8
- function extractClass(exported) {
9
- return exported && exported.default ? exported.default : exported;
10
- }
11
- async function loadHelpClass(config) {
12
- const pjson = config.pjson;
13
- const configuredClass = pjson && pjson.oclif && pjson.oclif.helpClass;
14
- if (configuredClass) {
15
- try {
16
- const exported = await module_loader_1.default.load(config, configuredClass);
17
- return extractClass(exported);
18
- }
19
- catch (error) {
20
- throw new Error(`Unable to load configured help class "${configuredClass}", failed with message:\n${error.message}`);
21
- }
22
- }
23
- return _1.Help;
24
- }
25
- exports.loadHelpClass = loadHelpClass;
26
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
27
7
  function template(context) {
28
8
  function render(t) {
29
9
  return ejs.render(t, context);
@@ -31,6 +11,8 @@ function template(context) {
31
11
  return render;
32
12
  }
33
13
  exports.template = template;
14
+ const isFlag = (s) => s.startsWith('-');
15
+ const isArgWithValue = (s) => s.includes('=');
34
16
  function collateSpacedCmdIDFromArgs(argv, config) {
35
17
  if (argv.length === 1)
36
18
  return argv;
@@ -38,9 +20,7 @@ function collateSpacedCmdIDFromArgs(argv, config) {
38
20
  const ids = (0, util_1.collectUsableIds)(config.commandIDs);
39
21
  const final = [];
40
22
  const idPresent = (id) => ids.has(id);
41
- const isFlag = (s) => s.startsWith('-');
42
- const isArgWithValue = (s) => s.includes('=');
43
- const finalizeId = (s) => s ? [...final, s].join(':') : final.join(':');
23
+ const finalizeId = (s) => (s ? [...final, s].join(':') : final.join(':'));
44
24
  const hasArgs = () => {
45
25
  const id = finalizeId();
46
26
  if (!id)
@@ -68,12 +48,12 @@ function collateSpacedCmdIDFromArgs(argv, config) {
68
48
  return argv; // ID is argv[0]
69
49
  }
70
50
  function toStandardizedId(commandID, config) {
71
- return commandID.replace(new RegExp(config.topicSeparator, 'g'), ':');
51
+ return commandID.replaceAll(new RegExp(config.topicSeparator, 'g'), ':');
72
52
  }
73
53
  exports.toStandardizedId = toStandardizedId;
74
54
  function toConfiguredId(commandID, config) {
75
55
  const defaultTopicSeparator = ':';
76
- return commandID.replace(new RegExp(defaultTopicSeparator, 'g'), config.topicSeparator || defaultTopicSeparator);
56
+ return commandID.replaceAll(new RegExp(defaultTopicSeparator, 'g'), config.topicSeparator || defaultTopicSeparator);
77
57
  }
78
58
  exports.toConfiguredId = toConfiguredId;
79
59
  function standardizeIDFromArgv(argv, config) {
package/lib/index.d.ts CHANGED
@@ -1,20 +1,19 @@
1
- import { Command } from './command';
2
- import run from './main';
3
- import execute from './execute';
4
- import handle from './errors/handle';
5
- import { Config, Plugin, tsPath, toCached } from './config';
6
- import * as Interfaces from './interfaces';
7
- import * as Errors from './errors';
8
- import * as Flags from './flags';
9
- import * as Args from './args';
10
- import { CommandHelp, HelpBase, Help, loadHelpClass } from './help';
11
- import { toStandardizedId, toConfiguredId } from './help/util';
12
- import * as Parser from './parser';
13
- import { Hook } from './interfaces/hooks';
14
- import settings, { Settings } from './settings';
15
- import { HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable } from './help/formatter';
16
- import * as ux from './ux';
17
- import { stderr, stdout } from './ux/stream';
18
- import Performance from './performance';
19
- import flush from './ux/flush';
20
- export { Args, Command, CommandHelp, Config, Errors, execute, Flags, flush, handle, Help, HelpBase, HelpSection, HelpSectionKeyValueTable, HelpSectionRenderer, Hook, Interfaces, loadHelpClass, Parser, Performance, Plugin, run, settings, Settings, stderr, stdout, toCached, toConfiguredId, toStandardizedId, tsPath, ux, };
1
+ export * as Args from './args';
2
+ export * as ux from './cli-ux';
3
+ export { flush } from './cli-ux/flush';
4
+ export { stderr, stdout } from './cli-ux/stream';
5
+ export { Command } from './command';
6
+ export { Config, Plugin } from './config';
7
+ export * as Errors from './errors';
8
+ export { handle } from './errors/handle';
9
+ export { execute } from './execute';
10
+ export * as Flags from './flags';
11
+ export { CommandHelp, Help, HelpBase, loadHelpClass } from './help';
12
+ export { HelpSection, HelpSectionKeyValueTable, HelpSectionRenderer } from './help/formatter';
13
+ export { toConfiguredId, toStandardizedId } from './help/util';
14
+ export * as Interfaces from './interfaces';
15
+ export { Hook } from './interfaces/hooks';
16
+ export { run } from './main';
17
+ export * as Parser from './parser';
18
+ export { Performance } from './performance';
19
+ export { Settings, settings } from './settings';