@oclif/core 3.0.0-beta.17 → 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.
- package/lib/args.js +4 -4
- package/lib/cli-ux/action/base.js +8 -7
- package/lib/cli-ux/action/simple.js +1 -4
- package/lib/cli-ux/action/spinner.js +8 -7
- package/lib/cli-ux/action/spinners.js +1 -1
- package/lib/cli-ux/config.js +11 -12
- package/lib/cli-ux/exit.js +3 -0
- package/lib/cli-ux/flush.js +7 -6
- package/lib/cli-ux/index.js +2 -2
- package/lib/cli-ux/list.js +3 -3
- package/lib/cli-ux/prompt.js +8 -3
- package/lib/cli-ux/stream.js +1 -0
- package/lib/cli-ux/styled/json.js +5 -3
- package/lib/cli-ux/styled/object.js +2 -2
- package/lib/cli-ux/styled/table.js +26 -20
- package/lib/cli-ux/styled/tree.js +1 -3
- package/lib/cli-ux/wait.js +1 -1
- package/lib/command.d.ts +6 -14
- package/lib/command.js +86 -73
- package/lib/config/config.d.ts +8 -9
- package/lib/config/config.js +85 -199
- package/lib/config/index.d.ts +0 -1
- package/lib/config/index.js +1 -3
- package/lib/config/plugin-loader.js +12 -11
- package/lib/config/plugin.d.ts +1 -0
- package/lib/config/plugin.js +54 -34
- package/lib/config/ts-node.js +17 -13
- package/lib/config/util.d.ts +0 -6
- package/lib/config/util.js +3 -15
- package/lib/errors/errors/cli.js +4 -1
- package/lib/errors/errors/exit.js +1 -1
- package/lib/errors/errors/module-load.js +1 -1
- package/lib/errors/errors/pretty-print.js +2 -1
- package/lib/errors/handle.js +4 -3
- package/lib/errors/logger.js +5 -4
- package/lib/flags.d.ts +6 -6
- package/lib/flags.js +3 -3
- package/lib/help/command.js +46 -32
- package/lib/help/docopts.js +8 -5
- package/lib/help/formatter.js +19 -8
- package/lib/help/index.d.ts +5 -1
- package/lib/help/index.js +70 -49
- package/lib/help/root.js +7 -9
- package/lib/help/util.d.ts +1 -7
- package/lib/help/util.js +2 -22
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -3
- package/lib/interfaces/hooks.d.ts +3 -3
- package/lib/interfaces/index.d.ts +1 -1
- package/lib/interfaces/parser.d.ts +19 -18
- package/lib/interfaces/pjson.d.ts +1 -1
- package/lib/interfaces/plugin.d.ts +5 -0
- package/lib/module-loader.d.ts +8 -8
- package/lib/module-loader.js +13 -10
- package/lib/parser/errors.d.ts +1 -1
- package/lib/parser/errors.js +15 -9
- package/lib/parser/help.js +2 -3
- package/lib/parser/parse.js +72 -44
- package/lib/parser/validate.js +37 -21
- package/lib/performance.js +20 -9
- 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 +108 -0
- package/lib/util/cache-default-value.d.ts +2 -0
- package/lib/util/cache-default-value.js +28 -0
- package/lib/{util.d.ts → util/index.d.ts} +7 -2
- package/lib/{util.js → util/index.js} +15 -20
- package/package.json +19 -13
package/lib/command.js
CHANGED
|
@@ -6,14 +6,14 @@ const Errors = tslib_1.__importStar(require("./errors"));
|
|
|
6
6
|
const Parser = tslib_1.__importStar(require("./parser"));
|
|
7
7
|
const node_util_1 = require("node:util");
|
|
8
8
|
const util_1 = require("./help/util");
|
|
9
|
-
const
|
|
9
|
+
const index_1 = require("./util/index");
|
|
10
10
|
const stream_1 = require("./cli-ux/stream");
|
|
11
11
|
const config_1 = require("./config");
|
|
12
|
-
const
|
|
12
|
+
const aggregate_flags_1 = require("./util/aggregate-flags");
|
|
13
13
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
14
14
|
const node_url_1 = require("node:url");
|
|
15
15
|
const cli_ux_1 = require("./cli-ux");
|
|
16
|
-
const pjson = (0,
|
|
16
|
+
const pjson = (0, index_1.requireJson)(__dirname, '..', 'package.json');
|
|
17
17
|
/**
|
|
18
18
|
* swallows stdout epipe errors
|
|
19
19
|
* this occurs when stdout closes such as when piping to head
|
|
@@ -23,40 +23,68 @@ stream_1.stdout.on('error', (err) => {
|
|
|
23
23
|
return;
|
|
24
24
|
throw err;
|
|
25
25
|
});
|
|
26
|
-
const jsonFlag = {
|
|
27
|
-
json: (0, flags_1.boolean)({
|
|
28
|
-
description: 'Format output as json.',
|
|
29
|
-
helpGroup: 'GLOBAL',
|
|
30
|
-
}),
|
|
31
|
-
};
|
|
32
26
|
/**
|
|
33
27
|
* An abstract class which acts as the base for each command
|
|
34
28
|
* in your project.
|
|
35
29
|
*/
|
|
36
30
|
class Command {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
static
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
31
|
+
argv;
|
|
32
|
+
config;
|
|
33
|
+
static _base = `${pjson.name}@${pjson.version}`;
|
|
34
|
+
/** A command ID, used mostly in error or verbose reporting. */
|
|
35
|
+
static id;
|
|
36
|
+
/**
|
|
37
|
+
* The tweet-sized description for your class, used in a parent-commands
|
|
38
|
+
* sub-command listing and as the header for the command help.
|
|
39
|
+
*/
|
|
40
|
+
static summary;
|
|
41
|
+
/**
|
|
42
|
+
* A full description of how to use the command.
|
|
43
|
+
*
|
|
44
|
+
* If no summary, the first line of the description will be used as the summary.
|
|
45
|
+
*/
|
|
46
|
+
static description;
|
|
47
|
+
/** Hide the command from help */
|
|
48
|
+
static hidden;
|
|
49
|
+
/** Mark the command as a given state (e.g. beta or deprecated) in help */
|
|
50
|
+
static state;
|
|
51
|
+
static deprecationOptions;
|
|
52
|
+
/**
|
|
53
|
+
* Emit deprecation warning when a command alias is used
|
|
54
|
+
*/
|
|
55
|
+
static deprecateAliases;
|
|
56
|
+
/**
|
|
57
|
+
* An override string (or strings) for the default usage documentation.
|
|
58
|
+
*/
|
|
59
|
+
static usage;
|
|
60
|
+
static help;
|
|
61
|
+
/** An array of aliases for this command. */
|
|
62
|
+
static aliases = [];
|
|
63
|
+
/** When set to false, allows a variable amount of arguments */
|
|
64
|
+
static strict = true;
|
|
65
|
+
/** An order-dependent object of arguments for the command */
|
|
66
|
+
static args = {};
|
|
67
|
+
static plugin;
|
|
68
|
+
static pluginName;
|
|
69
|
+
static pluginType;
|
|
70
|
+
static pluginAlias;
|
|
71
|
+
/**
|
|
72
|
+
* An array of examples to show at the end of the command's help.
|
|
73
|
+
*
|
|
74
|
+
* IF only a string is provided, it will try to look for a line that starts
|
|
75
|
+
* with the cmd.bin as the example command and the rest as the description.
|
|
76
|
+
* If found, the command will be formatted appropriately.
|
|
77
|
+
*
|
|
78
|
+
* ```
|
|
79
|
+
* EXAMPLES:
|
|
80
|
+
* A description of a particular use case.
|
|
81
|
+
*
|
|
82
|
+
* $ <%= config.bin => command flags
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
static examples;
|
|
86
|
+
static hasDynamicHelp = false;
|
|
87
|
+
static enableJsonFlag = false;
|
|
60
88
|
/**
|
|
61
89
|
* instantiate and run the command
|
|
62
90
|
*
|
|
@@ -81,21 +109,11 @@ class Command {
|
|
|
81
109
|
}
|
|
82
110
|
return cmd._run();
|
|
83
111
|
}
|
|
84
|
-
static
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this._baseFlags = Object.assign({}, this.baseFlags, flags);
|
|
90
|
-
this.flags = {}; // force the flags setter to run
|
|
91
|
-
}
|
|
92
|
-
static get flags() {
|
|
93
|
-
return this._flags;
|
|
94
|
-
}
|
|
95
|
-
static set flags(flags) {
|
|
96
|
-
// eslint-disable-next-line prefer-object-spread
|
|
97
|
-
this._flags = Object.assign({}, this._flags ?? {}, this.baseFlags, flags);
|
|
98
|
-
}
|
|
112
|
+
static baseFlags;
|
|
113
|
+
/** A hash of flags for the command */
|
|
114
|
+
static flags;
|
|
115
|
+
id;
|
|
116
|
+
debug;
|
|
99
117
|
constructor(argv, config) {
|
|
100
118
|
this.argv = argv;
|
|
101
119
|
this.config = config;
|
|
@@ -161,16 +179,19 @@ class Command {
|
|
|
161
179
|
* @returns {boolean} true if the command supports json and the --json flag is present
|
|
162
180
|
*/
|
|
163
181
|
jsonEnabled() {
|
|
164
|
-
//
|
|
182
|
+
// If the command doesn't support json, return false
|
|
165
183
|
if (!this.ctor.enableJsonFlag)
|
|
166
184
|
return false;
|
|
167
|
-
//
|
|
168
|
-
if (this.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
185
|
+
// If the CONTENT_TYPE env var is set to json, return true
|
|
186
|
+
if (this.config.scopedEnvVar?.('CONTENT_TYPE')?.toLowerCase() === 'json')
|
|
187
|
+
return true;
|
|
188
|
+
const passThroughIndex = this.argv.indexOf('--');
|
|
189
|
+
const jsonIndex = this.argv.indexOf('--json');
|
|
190
|
+
return passThroughIndex === -1
|
|
191
|
+
? // If '--' is not present, then check for `--json` in this.argv
|
|
192
|
+
jsonIndex > -1
|
|
193
|
+
: // If '--' is present, return true only the --json flag exists and is before the '--'
|
|
194
|
+
jsonIndex > -1 && jsonIndex < passThroughIndex;
|
|
174
195
|
}
|
|
175
196
|
async init() {
|
|
176
197
|
this.debug('init version: %s argv: %o', this.ctor._base, this.argv);
|
|
@@ -184,18 +205,19 @@ class Command {
|
|
|
184
205
|
this.warnIfCommandDeprecated();
|
|
185
206
|
}
|
|
186
207
|
warnIfFlagDeprecated(flags) {
|
|
208
|
+
const allFlags = (0, aggregate_flags_1.aggregateFlags)(this.ctor.flags, this.ctor.baseFlags, this.ctor.enableJsonFlag);
|
|
187
209
|
for (const flag of Object.keys(flags)) {
|
|
188
|
-
const flagDef =
|
|
210
|
+
const flagDef = allFlags[flag];
|
|
189
211
|
const deprecated = flagDef?.deprecated;
|
|
190
212
|
if (deprecated) {
|
|
191
213
|
this.warn((0, util_1.formatFlagDeprecationWarning)(flag, deprecated));
|
|
192
214
|
}
|
|
193
215
|
const deprecateAliases = flagDef?.deprecateAliases;
|
|
194
216
|
if (deprecateAliases) {
|
|
195
|
-
const aliases = (0,
|
|
217
|
+
const aliases = (0, index_1.uniq)([...(flagDef?.aliases ?? []), ...(flagDef?.charAliases ?? [])]).map((a) => a.length === 1 ? `-${a}` : `--${a}`);
|
|
196
218
|
if (aliases.length === 0)
|
|
197
219
|
return;
|
|
198
|
-
const foundAliases = aliases.filter(alias => this.argv.some(a => a.startsWith(alias)));
|
|
220
|
+
const foundAliases = aliases.filter((alias) => this.argv.some((a) => a.startsWith(alias)));
|
|
199
221
|
for (const alias of foundAliases) {
|
|
200
222
|
let preferredUsage = `--${flagDef?.name}`;
|
|
201
223
|
if (flagDef?.char) {
|
|
@@ -221,10 +243,11 @@ class Command {
|
|
|
221
243
|
async parse(options, argv = this.argv) {
|
|
222
244
|
if (!options)
|
|
223
245
|
options = this.ctor;
|
|
224
|
-
const opts = {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
246
|
+
const opts = {
|
|
247
|
+
context: this,
|
|
248
|
+
...options,
|
|
249
|
+
flags: (0, aggregate_flags_1.aggregateFlags)(options.flags, options.baseFlags, options.enableJsonFlag),
|
|
250
|
+
};
|
|
228
251
|
const results = await Parser.parse(argv, opts);
|
|
229
252
|
this.warnIfFlagDeprecated(results.flags ?? {});
|
|
230
253
|
return results;
|
|
@@ -271,17 +294,7 @@ class Command {
|
|
|
271
294
|
catch {
|
|
272
295
|
keys.push(this.config.scopedEnvVarKey(envVar));
|
|
273
296
|
}
|
|
274
|
-
keys.map(key => delete process.env[key]);
|
|
297
|
+
keys.map((key) => delete process.env[key]);
|
|
275
298
|
}
|
|
276
299
|
}
|
|
277
300
|
exports.Command = Command;
|
|
278
|
-
Command._base = `${pjson.name}@${pjson.version}`;
|
|
279
|
-
/** An array of aliases for this command. */
|
|
280
|
-
Command.aliases = [];
|
|
281
|
-
/** When set to false, allows a variable amount of arguments */
|
|
282
|
-
Command.strict = true;
|
|
283
|
-
/** An order-dependent object of arguments for the command */
|
|
284
|
-
Command.args = {};
|
|
285
|
-
Command.hasDynamicHelp = false;
|
|
286
|
-
Command['_--'] = false;
|
|
287
|
-
Command._enableJsonFlag = false;
|
package/lib/config/config.d.ts
CHANGED
|
@@ -144,14 +144,13 @@ export declare class Config implements IConfig {
|
|
|
144
144
|
*/
|
|
145
145
|
private determinePriority;
|
|
146
146
|
/**
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
* Insert legacy plugins
|
|
148
|
+
*
|
|
149
|
+
* Replace invalid CLI plugins (cli-engine plugins, mostly Heroku) loaded via `this.loadPlugins`
|
|
150
|
+
* with oclif-compatible ones returned by @oclif/plugin-legacy init hook.
|
|
151
|
+
*
|
|
152
|
+
* @param plugins array of oclif-compatible plugins
|
|
153
|
+
* @returns void
|
|
154
|
+
*/
|
|
155
155
|
private insertLegacyPlugins;
|
|
156
156
|
}
|
|
157
|
-
export declare function toCached(c: Command.Class, plugin?: IPlugin, respectNoCacheDefault?: boolean): Promise<Command.Cached>;
|