@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.
- package/README.md +10 -6
- package/flush.js +1 -1
- package/handle.js +1 -1
- package/lib/args.d.ts +1 -1
- package/lib/args.js +17 -18
- package/lib/cli-ux/action/base.d.ts +3 -5
- package/lib/cli-ux/action/base.js +32 -26
- package/lib/cli-ux/action/simple.js +13 -18
- package/lib/cli-ux/action/spinner.d.ts +4 -2
- package/lib/cli-ux/action/spinner.js +27 -19
- package/lib/cli-ux/action/spinners.js +1 -1
- package/lib/cli-ux/action/types.d.ts +5 -0
- package/lib/cli-ux/action/types.js +2 -0
- package/lib/cli-ux/config.d.ts +0 -1
- package/lib/cli-ux/config.js +17 -21
- package/lib/cli-ux/exit.d.ts +1 -1
- package/lib/cli-ux/exit.js +4 -1
- package/lib/cli-ux/flush.d.ts +1 -0
- package/lib/cli-ux/flush.js +28 -0
- package/lib/cli-ux/index.d.ts +10 -30
- package/lib/cli-ux/index.js +32 -75
- package/lib/cli-ux/list.js +3 -3
- package/lib/cli-ux/prompt.js +32 -22
- package/lib/cli-ux/stream.js +1 -0
- package/lib/cli-ux/styled/index.d.ts +5 -6
- package/lib/cli-ux/styled/index.js +11 -11
- package/lib/cli-ux/styled/json.js +8 -5
- package/lib/cli-ux/styled/object.js +7 -9
- package/lib/cli-ux/styled/table.d.ts +4 -4
- package/lib/cli-ux/styled/table.js +61 -64
- package/lib/cli-ux/styled/tree.js +1 -3
- package/lib/cli-ux/wait.js +3 -5
- package/lib/command.d.ts +15 -19
- package/lib/command.js +117 -96
- package/lib/config/config.d.ts +16 -23
- package/lib/config/config.js +180 -334
- package/lib/config/index.d.ts +1 -1
- package/lib/config/index.js +1 -2
- package/lib/config/plugin-loader.d.ts +30 -0
- package/lib/config/plugin-loader.js +145 -0
- package/lib/config/plugin.d.ts +6 -11
- package/lib/config/plugin.js +112 -78
- package/lib/config/ts-node.d.ts +2 -1
- package/lib/config/ts-node.js +64 -51
- package/lib/config/util.d.ts +1 -11
- package/lib/config/util.js +6 -59
- package/lib/errors/config.js +1 -1
- package/lib/errors/errors/cli.d.ts +1 -1
- package/lib/errors/errors/cli.js +18 -14
- package/lib/errors/errors/exit.d.ts +0 -3
- package/lib/errors/errors/exit.js +1 -1
- package/lib/errors/errors/module-load.d.ts +0 -3
- package/lib/errors/errors/module-load.js +1 -1
- package/lib/errors/errors/pretty-print.js +11 -9
- package/lib/errors/handle.d.ts +12 -2
- package/lib/errors/handle.js +28 -18
- package/lib/errors/index.d.ts +2 -2
- package/lib/errors/index.js +20 -19
- package/lib/errors/logger.js +9 -8
- package/lib/execute.d.ts +49 -0
- package/lib/execute.js +63 -0
- package/lib/flags.d.ts +102 -31
- package/lib/flags.js +81 -46
- package/lib/help/command.d.ts +2 -0
- package/lib/help/command.js +68 -53
- package/lib/help/docopts.js +9 -13
- package/lib/help/formatter.d.ts +1 -1
- package/lib/help/formatter.js +35 -24
- package/lib/help/index.d.ts +7 -3
- package/lib/help/index.js +77 -55
- package/lib/help/root.js +7 -9
- package/lib/help/util.d.ts +1 -7
- package/lib/help/util.js +8 -28
- package/lib/index.d.ts +19 -18
- package/lib/index.js +36 -48
- package/lib/interfaces/config.d.ts +30 -30
- package/lib/interfaces/errors.d.ts +1 -1
- package/lib/interfaces/hooks.d.ts +3 -3
- package/lib/interfaces/index.d.ts +14 -14
- package/lib/interfaces/parser.d.ts +188 -116
- package/lib/interfaces/pjson.d.ts +2 -1
- package/lib/interfaces/plugin.d.ts +10 -1
- package/lib/main.d.ts +0 -48
- package/lib/main.js +11 -66
- package/lib/module-loader.d.ts +68 -79
- package/lib/module-loader.js +183 -150
- package/lib/parser/errors.d.ts +3 -3
- package/lib/parser/errors.js +17 -10
- package/lib/parser/help.js +5 -5
- package/lib/parser/parse.d.ts +3 -0
- package/lib/parser/parse.js +114 -115
- package/lib/parser/validate.js +45 -25
- package/lib/performance.d.ts +5 -1
- package/lib/performance.js +40 -19
- package/lib/util/aggregate-flags.d.ts +2 -0
- package/lib/util/aggregate-flags.js +13 -0
- package/lib/util/cache-command.d.ts +3 -0
- package/lib/util/cache-command.js +109 -0
- package/lib/util/cache-default-value.d.ts +2 -0
- package/lib/util/cache-default-value.js +28 -0
- package/lib/util/ensure-arg-object.d.ts +12 -0
- package/lib/util/ensure-arg-object.js +14 -0
- package/lib/util/fs.d.ts +7 -0
- package/lib/util/fs.js +54 -0
- package/lib/util/os.d.ts +19 -0
- package/lib/util/os.js +28 -0
- package/lib/{util.d.ts → util/util.d.ts} +6 -15
- package/lib/util/util.js +98 -0
- package/package.json +32 -34
- package/lib/cli-ux/action/pride-spinner.d.ts +0 -4
- package/lib/cli-ux/action/pride-spinner.js +0 -30
- package/lib/util.js +0 -126
package/lib/help/index.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const errors_1 = require("../errors");
|
|
7
|
-
const command_1 = require("./command");
|
|
8
|
-
const root_1 = require("./root");
|
|
9
|
-
const util_1 = require("../util");
|
|
3
|
+
exports.loadHelpClass = exports.Help = exports.HelpBase = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.CommandHelp = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const util_1 = require("../util/util");
|
|
10
6
|
const util_2 = require("./util");
|
|
7
|
+
const command_1 = require("./command");
|
|
11
8
|
const formatter_1 = require("./formatter");
|
|
12
|
-
const
|
|
9
|
+
const root_1 = tslib_1.__importDefault(require("./root"));
|
|
10
|
+
const cache_default_value_1 = require("../util/cache-default-value");
|
|
11
|
+
const errors_1 = require("../errors");
|
|
12
|
+
const node_util_1 = require("node:util");
|
|
13
|
+
const module_loader_1 = require("../module-loader");
|
|
13
14
|
const stream_1 = require("../cli-ux/stream");
|
|
15
|
+
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
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
19
|
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
20
|
Object.defineProperty(exports, "getHelpFlagAdditions", { enumerable: true, get: function () { return util_3.getHelpFlagAdditions; } });
|
|
20
21
|
Object.defineProperty(exports, "normalizeArgv", { enumerable: true, get: function () { return util_3.normalizeArgv; } });
|
|
21
22
|
function getHelpSubject(args, config) {
|
|
@@ -40,6 +41,7 @@ class HelpBase extends formatter_1.HelpFormatter {
|
|
|
40
41
|
}
|
|
41
42
|
exports.HelpBase = HelpBase;
|
|
42
43
|
class Help extends HelpBase {
|
|
44
|
+
CommandHelpClass = command_1.CommandHelp;
|
|
43
45
|
/*
|
|
44
46
|
* _topics is to work around Interfaces.topics mistakenly including commands that do
|
|
45
47
|
* not have children, as well as topics. A topic has children, either commands or other topics. When
|
|
@@ -49,31 +51,30 @@ class Help extends HelpBase {
|
|
|
49
51
|
get _topics() {
|
|
50
52
|
return this.config.topics.filter((topic) => {
|
|
51
53
|
// 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}:`));
|
|
54
|
+
const hasChild = this.config.topics.some((subTopic) => subTopic.name.includes(`${topic.name}:`));
|
|
53
55
|
return hasChild;
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
get sortedCommands() {
|
|
57
|
-
let commands = this.config
|
|
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);
|
|
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);
|
|
61
63
|
return commands;
|
|
62
64
|
}
|
|
63
65
|
get sortedTopics() {
|
|
64
66
|
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);
|
|
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);
|
|
68
70
|
return topics;
|
|
69
71
|
}
|
|
70
72
|
constructor(config, opts = {}) {
|
|
71
73
|
super(config, opts);
|
|
72
|
-
this.CommandHelpClass = command_1.default;
|
|
73
74
|
}
|
|
74
75
|
async showHelp(argv) {
|
|
75
76
|
const originalArgv = argv.slice(1);
|
|
76
|
-
argv = argv.filter(arg => !(0, util_2.getHelpFlagAdditions)(this.config).includes(arg));
|
|
77
|
+
argv = argv.filter((arg) => !(0, util_2.getHelpFlagAdditions)(this.config).includes(arg));
|
|
77
78
|
if (this.config.topicSeparator !== ':')
|
|
78
79
|
argv = (0, util_2.standardizeIDFromArgv)(argv, this.config);
|
|
79
80
|
const subject = getHelpSubject(argv, this.config);
|
|
@@ -91,8 +92,14 @@ class Help extends HelpBase {
|
|
|
91
92
|
const command = this.config.findCommand(subject);
|
|
92
93
|
if (command) {
|
|
93
94
|
if (command.hasDynamicHelp && command.pluginType !== 'jit') {
|
|
94
|
-
const
|
|
95
|
-
|
|
95
|
+
const loaded = await command.load();
|
|
96
|
+
for (const [name, flag] of Object.entries(loaded.flags)) {
|
|
97
|
+
if (flag.type === 'boolean' || !command.flags[name].hasDynamicHelp)
|
|
98
|
+
continue;
|
|
99
|
+
// eslint-disable-next-line no-await-in-loop
|
|
100
|
+
command.flags[name].default = await (0, cache_default_value_1.cacheDefaultValue)(flag, false);
|
|
101
|
+
}
|
|
102
|
+
await this.showCommandHelp(command);
|
|
96
103
|
}
|
|
97
104
|
else {
|
|
98
105
|
await this.showCommandHelp(command);
|
|
@@ -109,7 +116,7 @@ class Help extends HelpBase {
|
|
|
109
116
|
if (matches.length > 0) {
|
|
110
117
|
const result = await this.config.runHook('command_incomplete', {
|
|
111
118
|
id: subject,
|
|
112
|
-
argv: originalArgv.filter(o => !subject.split(':').includes(o)),
|
|
119
|
+
argv: originalArgv.filter((o) => !subject.split(':').includes(o)),
|
|
113
120
|
matches,
|
|
114
121
|
});
|
|
115
122
|
if (result.successes.length > 0)
|
|
@@ -121,14 +128,19 @@ class Help extends HelpBase {
|
|
|
121
128
|
async showCommandHelp(command) {
|
|
122
129
|
const name = command.id;
|
|
123
130
|
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.
|
|
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
|
+
const plugin = this.config.plugins.get(command.pluginName);
|
|
127
134
|
const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state;
|
|
128
135
|
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`);
|
|
136
|
+
this.log(state === 'deprecated'
|
|
137
|
+
? `${(0, util_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), command.deprecationOptions)}\n`
|
|
138
|
+
: `This command is in ${state}.\n`);
|
|
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_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), opts)}\n`);
|
|
132
144
|
}
|
|
133
145
|
const summary = this.summary(command);
|
|
134
146
|
if (summary) {
|
|
@@ -142,7 +154,7 @@ class Help extends HelpBase {
|
|
|
142
154
|
}
|
|
143
155
|
if (subCommands.length > 0) {
|
|
144
156
|
const aliases = [];
|
|
145
|
-
const uniqueSubCommands = subCommands.filter(p => {
|
|
157
|
+
const uniqueSubCommands = subCommands.filter((p) => {
|
|
146
158
|
aliases.push(...p.aliases);
|
|
147
159
|
return !aliases.includes(p.id);
|
|
148
160
|
});
|
|
@@ -155,31 +167,29 @@ class Help extends HelpBase {
|
|
|
155
167
|
let rootCommands = this.sortedCommands;
|
|
156
168
|
const state = this.config.pjson?.oclif?.state;
|
|
157
169
|
if (state) {
|
|
158
|
-
this.log(state === 'deprecated' ?
|
|
159
|
-
`${this.config.bin} is deprecated` :
|
|
160
|
-
`${this.config.bin} is in ${state}.\n`);
|
|
170
|
+
this.log(state === 'deprecated' ? `${this.config.bin} is deprecated` : `${this.config.bin} is in ${state}.\n`);
|
|
161
171
|
}
|
|
162
172
|
this.log(this.formatRoot());
|
|
163
173
|
this.log('');
|
|
164
174
|
if (!this.opts.all) {
|
|
165
|
-
rootTopics = rootTopics.filter(t => !t.name.includes(':'));
|
|
166
|
-
rootCommands = rootCommands.filter(c => !c.id.includes(':'));
|
|
175
|
+
rootTopics = rootTopics.filter((t) => !t.name.includes(':'));
|
|
176
|
+
rootCommands = rootCommands.filter((c) => !c.id.includes(':'));
|
|
167
177
|
}
|
|
168
178
|
if (rootTopics.length > 0) {
|
|
169
179
|
this.log(this.formatTopics(rootTopics));
|
|
170
180
|
this.log('');
|
|
171
181
|
}
|
|
172
182
|
if (rootCommands.length > 0) {
|
|
173
|
-
rootCommands = rootCommands.filter(c => c.id);
|
|
183
|
+
rootCommands = rootCommands.filter((c) => c.id);
|
|
174
184
|
this.log(this.formatCommands(rootCommands));
|
|
175
185
|
this.log('');
|
|
176
186
|
}
|
|
177
187
|
}
|
|
178
188
|
async showTopicHelp(topic) {
|
|
179
|
-
const name = topic
|
|
189
|
+
const { name } = topic;
|
|
180
190
|
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);
|
|
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);
|
|
183
193
|
const state = this.config.pjson?.oclif?.state;
|
|
184
194
|
if (state)
|
|
185
195
|
this.log(`This topic is in ${state}.\n`);
|
|
@@ -199,8 +209,8 @@ class Help extends HelpBase {
|
|
|
199
209
|
}
|
|
200
210
|
formatCommand(command) {
|
|
201
211
|
if (this.config.topicSeparator !== ':') {
|
|
202
|
-
command.id = command.id.
|
|
203
|
-
command.aliases = command.aliases && command.aliases.map(a => a.
|
|
212
|
+
command.id = command.id.replaceAll(':', this.config.topicSeparator);
|
|
213
|
+
command.aliases = command.aliases && command.aliases.map((a) => a.replaceAll(':', this.config.topicSeparator));
|
|
204
214
|
}
|
|
205
215
|
const help = this.getCommandHelpClass(command);
|
|
206
216
|
return help.generate();
|
|
@@ -211,13 +221,10 @@ class Help extends HelpBase {
|
|
|
211
221
|
formatCommands(commands) {
|
|
212
222
|
if (commands.length === 0)
|
|
213
223
|
return '';
|
|
214
|
-
const body = this.renderList(commands.map(c => {
|
|
224
|
+
const body = this.renderList(commands.map((c) => {
|
|
215
225
|
if (this.config.topicSeparator !== ':')
|
|
216
|
-
c.id = c.id.
|
|
217
|
-
return [
|
|
218
|
-
c.id,
|
|
219
|
-
this.summary(c),
|
|
220
|
-
];
|
|
226
|
+
c.id = c.id.replaceAll(':', this.config.topicSeparator);
|
|
227
|
+
return [c.id, this.summary(c)];
|
|
221
228
|
}), {
|
|
222
229
|
spacer: '\n',
|
|
223
230
|
stripAnsi: this.opts.stripAnsi,
|
|
@@ -243,26 +250,23 @@ class Help extends HelpBase {
|
|
|
243
250
|
description = description.split('\n').slice(1).join('\n');
|
|
244
251
|
let topicID = `${topic.name}:COMMAND`;
|
|
245
252
|
if (this.config.topicSeparator !== ':')
|
|
246
|
-
topicID = topicID.
|
|
253
|
+
topicID = topicID.replaceAll(':', this.config.topicSeparator);
|
|
247
254
|
let output = (0, util_1.compact)([
|
|
248
255
|
summary,
|
|
249
256
|
this.section(this.opts.usageHeader || 'USAGE', `$ ${this.config.bin} ${topicID}`),
|
|
250
257
|
description && this.section('DESCRIPTION', this.wrap(description)),
|
|
251
258
|
]).join('\n\n');
|
|
252
259
|
if (this.opts.stripAnsi)
|
|
253
|
-
output =
|
|
260
|
+
output = (0, strip_ansi_1.default)(output);
|
|
254
261
|
return output + '\n';
|
|
255
262
|
}
|
|
256
263
|
formatTopics(topics) {
|
|
257
264
|
if (topics.length === 0)
|
|
258
265
|
return '';
|
|
259
|
-
const body = this.renderList(topics.map(c => {
|
|
266
|
+
const body = this.renderList(topics.map((c) => {
|
|
260
267
|
if (this.config.topicSeparator !== ':')
|
|
261
|
-
c.name = c.name.
|
|
262
|
-
return [
|
|
263
|
-
c.name,
|
|
264
|
-
c.description && this.render(c.description.split('\n')[0]),
|
|
265
|
-
];
|
|
268
|
+
c.name = c.name.replaceAll(':', this.config.topicSeparator);
|
|
269
|
+
return [c.name, c.description && this.render(c.description.split('\n')[0])];
|
|
266
270
|
}), {
|
|
267
271
|
spacer: '\n',
|
|
268
272
|
stripAnsi: this.opts.stripAnsi,
|
|
@@ -274,7 +278,25 @@ class Help extends HelpBase {
|
|
|
274
278
|
return this.formatCommand(command);
|
|
275
279
|
}
|
|
276
280
|
log(...args) {
|
|
277
|
-
stream_1.stdout.write(
|
|
281
|
+
stream_1.stdout.write(node_util_1.format.apply(this, args) + '\n');
|
|
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;
|
package/lib/help/root.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const util_1 = require("../util");
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
5
4
|
const formatter_1 = require("./formatter");
|
|
5
|
+
const util_1 = require("../util/util");
|
|
6
|
+
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
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;
|
|
@@ -13,14 +16,9 @@ class RootHelp extends formatter_1.HelpFormatter {
|
|
|
13
16
|
let description = this.config.pjson.oclif.description || this.config.pjson.description || '';
|
|
14
17
|
description = this.render(description);
|
|
15
18
|
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');
|
|
19
|
+
let output = (0, util_1.compact)([description, this.version(), this.usage(), this.description()]).join('\n\n');
|
|
22
20
|
if (this.opts.stripAnsi)
|
|
23
|
-
output =
|
|
21
|
+
output = (0, strip_ansi_1.default)(output);
|
|
24
22
|
return output;
|
|
25
23
|
}
|
|
26
24
|
usage() {
|
package/lib/help/util.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { Config as IConfig
|
|
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;
|
|
@@ -12,4 +7,3 @@ export declare function getHelpFlagAdditions(config: IConfig): string[];
|
|
|
12
7
|
export declare function formatFlagDeprecationWarning(flag: string, opts: true | Deprecation): 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 =
|
|
4
|
-
const
|
|
5
|
-
const
|
|
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
|
|
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.
|
|
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.
|
|
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,18 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export {
|
|
1
|
+
export * as Args from './args';
|
|
2
|
+
export * as Errors from './errors';
|
|
3
|
+
export * as Interfaces from './interfaces';
|
|
4
|
+
export * as Flags from './flags';
|
|
5
|
+
export * as Parser from './parser';
|
|
6
|
+
export * as ux from './cli-ux';
|
|
7
|
+
export { CommandHelp, HelpBase, Help, loadHelpClass } from './help';
|
|
8
|
+
export { Config, Plugin } from './config';
|
|
9
|
+
export { HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable } from './help/formatter';
|
|
10
|
+
export { Settings, settings } from './settings';
|
|
11
|
+
export { stdout, stderr } from './cli-ux/stream';
|
|
12
|
+
export { toConfiguredId, toStandardizedId } from './help/util';
|
|
13
|
+
export { Command } from './command';
|
|
14
|
+
export { Hook } from './interfaces/hooks';
|
|
15
|
+
export { Performance } from './performance';
|
|
16
|
+
export { execute } from './execute';
|
|
17
|
+
export { flush } from './cli-ux/flush';
|
|
18
|
+
export { handle } from './errors/handle';
|
|
19
|
+
export { run } from './main';
|
package/lib/index.js
CHANGED
|
@@ -1,47 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const command_1 = require("./command");
|
|
6
|
-
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return command_1.Command; } });
|
|
7
|
-
const main_1 = require("./main");
|
|
8
|
-
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return main_1.run; } });
|
|
9
|
-
Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return main_1.execute; } });
|
|
10
|
-
const config_1 = require("./config");
|
|
11
|
-
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
12
|
-
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return config_1.Plugin; } });
|
|
13
|
-
Object.defineProperty(exports, "tsPath", { enumerable: true, get: function () { return config_1.tsPath; } });
|
|
14
|
-
Object.defineProperty(exports, "toCached", { enumerable: true, get: function () { return config_1.toCached; } });
|
|
15
|
-
const Interfaces = require("./interfaces");
|
|
16
|
-
exports.Interfaces = Interfaces;
|
|
17
|
-
const Errors = require("./errors");
|
|
18
|
-
exports.Errors = Errors;
|
|
19
|
-
const Flags = require("./flags");
|
|
20
|
-
exports.Flags = Flags;
|
|
21
|
-
const Args = require("./args");
|
|
22
|
-
exports.Args = Args;
|
|
23
|
-
const help_1 = require("./help");
|
|
24
|
-
Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return help_1.CommandHelp; } });
|
|
25
|
-
Object.defineProperty(exports, "HelpBase", { enumerable: true, get: function () { return help_1.HelpBase; } });
|
|
26
|
-
Object.defineProperty(exports, "Help", { enumerable: true, get: function () { return help_1.Help; } });
|
|
27
|
-
Object.defineProperty(exports, "loadHelpClass", { enumerable: true, get: function () { return help_1.loadHelpClass; } });
|
|
28
|
-
const util_1 = require("./help/util");
|
|
29
|
-
Object.defineProperty(exports, "toStandardizedId", { enumerable: true, get: function () { return util_1.toStandardizedId; } });
|
|
30
|
-
Object.defineProperty(exports, "toConfiguredId", { enumerable: true, get: function () { return util_1.toConfiguredId; } });
|
|
31
|
-
const Parser = require("./parser");
|
|
32
|
-
exports.Parser = Parser;
|
|
33
|
-
const settings_1 = require("./settings");
|
|
34
|
-
Object.defineProperty(exports, "settings", { enumerable: true, get: function () { return settings_1.settings; } });
|
|
35
|
-
const ux = require("./cli-ux");
|
|
36
|
-
exports.ux = ux;
|
|
37
|
-
const util_2 = require("./util");
|
|
3
|
+
exports.run = exports.handle = exports.flush = exports.execute = exports.Performance = exports.Command = exports.toStandardizedId = exports.toConfiguredId = exports.stderr = exports.stdout = exports.settings = exports.Plugin = exports.Config = exports.loadHelpClass = exports.Help = exports.HelpBase = exports.CommandHelp = exports.ux = exports.Parser = exports.Flags = exports.Interfaces = exports.Errors = exports.Args = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
38
5
|
const stream_1 = require("./cli-ux/stream");
|
|
39
|
-
Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return stream_1.stderr; } });
|
|
40
|
-
Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return stream_1.stdout; } });
|
|
41
|
-
const performance_1 = require("./performance");
|
|
42
|
-
Object.defineProperty(exports, "Performance", { enumerable: true, get: function () { return performance_1.Performance; } });
|
|
43
|
-
const flush = ux.flush;
|
|
44
|
-
exports.flush = flush;
|
|
45
6
|
function checkCWD() {
|
|
46
7
|
try {
|
|
47
8
|
process.cwd();
|
|
@@ -52,11 +13,38 @@ function checkCWD() {
|
|
|
52
13
|
}
|
|
53
14
|
}
|
|
54
15
|
}
|
|
55
|
-
function checkNodeVersion() {
|
|
56
|
-
const pjson = (0, util_2.requireJson)(__dirname, '..', 'package.json');
|
|
57
|
-
if (!semver.satisfies(process.versions.node, pjson.engines.node)) {
|
|
58
|
-
stream_1.stderr.write(`WARNING\nWARNING Node version must be ${pjson.engines.node} to use this CLI\nWARNING Current node version: ${process.versions.node}\nWARNING\n`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
16
|
checkCWD();
|
|
62
|
-
|
|
17
|
+
exports.Args = tslib_1.__importStar(require("./args"));
|
|
18
|
+
exports.Errors = tslib_1.__importStar(require("./errors"));
|
|
19
|
+
exports.Interfaces = tslib_1.__importStar(require("./interfaces"));
|
|
20
|
+
exports.Flags = tslib_1.__importStar(require("./flags"));
|
|
21
|
+
exports.Parser = tslib_1.__importStar(require("./parser"));
|
|
22
|
+
exports.ux = tslib_1.__importStar(require("./cli-ux"));
|
|
23
|
+
var help_1 = require("./help");
|
|
24
|
+
Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return help_1.CommandHelp; } });
|
|
25
|
+
Object.defineProperty(exports, "HelpBase", { enumerable: true, get: function () { return help_1.HelpBase; } });
|
|
26
|
+
Object.defineProperty(exports, "Help", { enumerable: true, get: function () { return help_1.Help; } });
|
|
27
|
+
Object.defineProperty(exports, "loadHelpClass", { enumerable: true, get: function () { return help_1.loadHelpClass; } });
|
|
28
|
+
var config_1 = require("./config");
|
|
29
|
+
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
30
|
+
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return config_1.Plugin; } });
|
|
31
|
+
var settings_1 = require("./settings");
|
|
32
|
+
Object.defineProperty(exports, "settings", { enumerable: true, get: function () { return settings_1.settings; } });
|
|
33
|
+
var stream_2 = require("./cli-ux/stream");
|
|
34
|
+
Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return stream_2.stdout; } });
|
|
35
|
+
Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return stream_2.stderr; } });
|
|
36
|
+
var util_1 = require("./help/util");
|
|
37
|
+
Object.defineProperty(exports, "toConfiguredId", { enumerable: true, get: function () { return util_1.toConfiguredId; } });
|
|
38
|
+
Object.defineProperty(exports, "toStandardizedId", { enumerable: true, get: function () { return util_1.toStandardizedId; } });
|
|
39
|
+
var command_1 = require("./command");
|
|
40
|
+
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return command_1.Command; } });
|
|
41
|
+
var performance_1 = require("./performance");
|
|
42
|
+
Object.defineProperty(exports, "Performance", { enumerable: true, get: function () { return performance_1.Performance; } });
|
|
43
|
+
var execute_1 = require("./execute");
|
|
44
|
+
Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return execute_1.execute; } });
|
|
45
|
+
var flush_1 = require("./cli-ux/flush");
|
|
46
|
+
Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return flush_1.flush; } });
|
|
47
|
+
var handle_1 = require("./errors/handle");
|
|
48
|
+
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.handle; } });
|
|
49
|
+
var main_1 = require("./main");
|
|
50
|
+
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return main_1.run; } });
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Hook, Hooks } from './hooks';
|
|
3
|
+
import { Options, Plugin } from './plugin';
|
|
4
|
+
import { Command } from '../command';
|
|
1
5
|
import { PJSON } from './pjson';
|
|
2
|
-
import { Hooks, Hook } from './hooks';
|
|
3
|
-
import { Plugin, Options } from './plugin';
|
|
4
6
|
import { Topic } from './topic';
|
|
5
|
-
import { Command } from '../command';
|
|
6
7
|
export type LoadOptions = Options | string | Config | undefined;
|
|
7
|
-
export type PlatformTypes =
|
|
8
|
+
export type PlatformTypes = NodeJS.Platform | 'wsl';
|
|
8
9
|
export type ArchTypes = 'arm' | 'arm64' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | 'x86';
|
|
9
10
|
export type PluginVersionDetail = {
|
|
10
11
|
version: string;
|
|
@@ -21,91 +22,90 @@ export type VersionDetails = {
|
|
|
21
22
|
rootPath?: string;
|
|
22
23
|
};
|
|
23
24
|
export interface Config {
|
|
24
|
-
name: string;
|
|
25
|
-
version: string;
|
|
26
|
-
channel: string;
|
|
27
|
-
pjson: PJSON.CLI;
|
|
28
|
-
root: string;
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly version: string;
|
|
27
|
+
readonly channel: string;
|
|
28
|
+
readonly pjson: PJSON.CLI;
|
|
29
|
+
readonly root: string;
|
|
29
30
|
/**
|
|
30
31
|
* process.arch
|
|
31
32
|
*/
|
|
32
|
-
arch: ArchTypes;
|
|
33
|
+
readonly arch: ArchTypes;
|
|
33
34
|
/**
|
|
34
35
|
* bin name of CLI command
|
|
35
36
|
*/
|
|
36
|
-
bin: string;
|
|
37
|
+
readonly bin: string;
|
|
37
38
|
/**
|
|
38
39
|
* cache directory to use for CLI
|
|
39
40
|
*
|
|
40
41
|
* example ~/Library/Caches/mycli or ~/.cache/mycli
|
|
41
42
|
*/
|
|
42
|
-
cacheDir: string;
|
|
43
|
+
readonly cacheDir: string;
|
|
43
44
|
/**
|
|
44
45
|
* config directory to use for CLI
|
|
45
46
|
*
|
|
46
47
|
* example: ~/.config/mycli
|
|
47
48
|
*/
|
|
48
|
-
configDir: string;
|
|
49
|
+
readonly configDir: string;
|
|
49
50
|
/**
|
|
50
51
|
* data directory to use for CLI
|
|
51
52
|
*
|
|
52
53
|
* example: ~/.local/share/mycli
|
|
53
54
|
*/
|
|
54
|
-
dataDir: string;
|
|
55
|
+
readonly dataDir: string;
|
|
55
56
|
/**
|
|
56
57
|
* base dirname to use in cacheDir/configDir/dataDir
|
|
57
58
|
*/
|
|
58
|
-
dirname: string;
|
|
59
|
+
readonly dirname: string;
|
|
59
60
|
/**
|
|
60
61
|
* points to a file that should be appended to for error logs
|
|
61
62
|
*
|
|
62
63
|
* example: ~/Library/Caches/mycli/error.log
|
|
63
64
|
*/
|
|
64
|
-
errlog: string;
|
|
65
|
+
readonly errlog: string;
|
|
65
66
|
/**
|
|
66
67
|
* path to home directory
|
|
67
68
|
*
|
|
68
69
|
* example: /home/myuser
|
|
69
70
|
*/
|
|
70
|
-
home: string;
|
|
71
|
+
readonly home: string;
|
|
71
72
|
/**
|
|
72
73
|
* process.platform
|
|
73
74
|
*/
|
|
74
|
-
platform: PlatformTypes;
|
|
75
|
+
readonly platform: PlatformTypes;
|
|
75
76
|
/**
|
|
76
77
|
* active shell
|
|
77
78
|
*/
|
|
78
|
-
shell: string;
|
|
79
|
+
readonly shell: string;
|
|
79
80
|
/**
|
|
80
81
|
* user agent to use for http calls
|
|
81
82
|
*
|
|
82
83
|
* example: mycli/1.2.3 (darwin-x64) node-9.0.0
|
|
83
84
|
*/
|
|
84
|
-
userAgent: string;
|
|
85
|
+
readonly userAgent: string;
|
|
85
86
|
/**
|
|
86
87
|
* if windows
|
|
87
88
|
*/
|
|
88
|
-
windows: boolean;
|
|
89
|
+
readonly windows: boolean;
|
|
89
90
|
/**
|
|
90
91
|
* debugging level
|
|
91
92
|
*
|
|
92
93
|
* set by ${BIN}_DEBUG or DEBUG=$BIN
|
|
93
94
|
*/
|
|
94
|
-
debug: number;
|
|
95
|
+
readonly debug: number;
|
|
95
96
|
/**
|
|
96
97
|
* npm registry to use for installing plugins
|
|
97
98
|
*/
|
|
98
|
-
npmRegistry?: string;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
binPath?: string;
|
|
99
|
+
readonly npmRegistry?: string;
|
|
100
|
+
readonly plugins: Map<string, Plugin>;
|
|
101
|
+
readonly binPath?: string;
|
|
102
102
|
/**
|
|
103
103
|
* name of any bin aliases that will execute the cli
|
|
104
104
|
*/
|
|
105
|
-
binAliases?: string[];
|
|
106
|
-
nsisCustomization?: string;
|
|
107
|
-
valid: boolean;
|
|
108
|
-
flexibleTaxonomy?: boolean;
|
|
105
|
+
readonly binAliases?: string[];
|
|
106
|
+
readonly nsisCustomization?: string;
|
|
107
|
+
readonly valid: boolean;
|
|
108
|
+
readonly flexibleTaxonomy?: boolean;
|
|
109
109
|
topicSeparator: ':' | ' ';
|
|
110
110
|
readonly commands: Command.Loadable[];
|
|
111
111
|
readonly topics: Topic[];
|