@oclif/core 3.0.4 → 3.0.5
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/cli-ux/action/base.d.ts +12 -12
- package/lib/cli-ux/action/base.js +78 -78
- package/lib/cli-ux/stream.d.ts +1 -1
- package/lib/cli-ux/stream.js +3 -3
- package/lib/cli-ux/styled/table.js +64 -64
- package/lib/command.d.ts +8 -8
- package/lib/command.js +32 -32
- package/lib/config/config.d.ts +50 -50
- package/lib/config/config.js +210 -210
- package/lib/config/plugin-loader.d.ts +5 -5
- package/lib/config/plugin-loader.js +32 -32
- package/lib/config/plugin.d.ts +10 -10
- package/lib/config/plugin.js +145 -133
- package/lib/errors/errors/cli.d.ts +2 -2
- package/lib/errors/errors/cli.js +9 -9
- package/lib/help/command.d.ts +2 -2
- package/lib/help/command.js +11 -11
- package/lib/help/docopts.d.ts +1 -1
- package/lib/help/docopts.js +20 -20
- package/lib/help/index.d.ts +3 -3
- package/lib/help/index.js +25 -25
- package/lib/parser/parse.d.ts +2 -2
- package/lib/parser/parse.js +89 -89
- package/lib/performance.d.ts +2 -2
- package/lib/performance.js +2 -2
- package/lib/util/fs.d.ts +13 -1
- package/lib/util/fs.js +29 -14
- package/package.json +2 -3
|
@@ -6,10 +6,21 @@ export interface ITask {
|
|
|
6
6
|
}
|
|
7
7
|
export type ActionType = 'debug' | 'simple' | 'spinner';
|
|
8
8
|
export declare class ActionBase {
|
|
9
|
-
private stdmockOrigs;
|
|
10
9
|
std: 'stderr' | 'stdout';
|
|
11
10
|
protected stdmocks?: ['stderr' | 'stdout', string[]][];
|
|
12
11
|
type: ActionType;
|
|
12
|
+
private stdmockOrigs;
|
|
13
|
+
protected get output(): string | undefined;
|
|
14
|
+
protected set output(output: string | undefined);
|
|
15
|
+
get running(): boolean;
|
|
16
|
+
get status(): string | undefined;
|
|
17
|
+
set status(status: string | undefined);
|
|
18
|
+
get task(): ITask | undefined;
|
|
19
|
+
set task(task: ITask | undefined);
|
|
20
|
+
pause(fn: () => any, icon?: string): Promise<any>;
|
|
21
|
+
pauseAsync<T>(fn: () => Promise<T>, icon?: string): Promise<T>;
|
|
22
|
+
start(action: string, status?: string, opts?: Options): void;
|
|
23
|
+
stop(msg?: string): void;
|
|
13
24
|
protected _flushStdout(): void;
|
|
14
25
|
protected _pause(_?: string): void;
|
|
15
26
|
protected _resume(): void;
|
|
@@ -19,15 +30,4 @@ export declare class ActionBase {
|
|
|
19
30
|
protected _updateStatus(_: string | undefined, __?: string): void;
|
|
20
31
|
protected _write(std: 'stderr' | 'stdout', s: string | string[]): void;
|
|
21
32
|
private get globals();
|
|
22
|
-
pause(fn: () => any, icon?: string): Promise<any>;
|
|
23
|
-
pauseAsync<T>(fn: () => Promise<T>, icon?: string): Promise<T>;
|
|
24
|
-
start(action: string, status?: string, opts?: Options): void;
|
|
25
|
-
stop(msg?: string): void;
|
|
26
|
-
protected get output(): string | undefined;
|
|
27
|
-
protected set output(output: string | undefined);
|
|
28
|
-
get running(): boolean;
|
|
29
|
-
get status(): string | undefined;
|
|
30
|
-
set status(status: string | undefined);
|
|
31
|
-
get task(): ITask | undefined;
|
|
32
|
-
set task(task: ITask | undefined);
|
|
33
33
|
}
|
|
@@ -5,13 +5,88 @@ const node_util_1 = require("node:util");
|
|
|
5
5
|
const util_1 = require("../../util/util");
|
|
6
6
|
const stream_1 = require("../stream");
|
|
7
7
|
class ActionBase {
|
|
8
|
+
std = 'stderr';
|
|
9
|
+
stdmocks;
|
|
10
|
+
type;
|
|
8
11
|
stdmockOrigs = {
|
|
9
12
|
stderr: stream_1.stderr.write,
|
|
10
13
|
stdout: stream_1.stdout.write,
|
|
11
14
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
get output() {
|
|
16
|
+
return this.globals.output;
|
|
17
|
+
}
|
|
18
|
+
set output(output) {
|
|
19
|
+
this.globals.output = output;
|
|
20
|
+
}
|
|
21
|
+
get running() {
|
|
22
|
+
return Boolean(this.task);
|
|
23
|
+
}
|
|
24
|
+
get status() {
|
|
25
|
+
return this.task ? this.task.status : undefined;
|
|
26
|
+
}
|
|
27
|
+
set status(status) {
|
|
28
|
+
const { task } = this;
|
|
29
|
+
if (!task) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (task.status === status) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
this._updateStatus(status, task.status);
|
|
36
|
+
task.status = status;
|
|
37
|
+
}
|
|
38
|
+
get task() {
|
|
39
|
+
return this.globals.action.task;
|
|
40
|
+
}
|
|
41
|
+
set task(task) {
|
|
42
|
+
this.globals.action.task = task;
|
|
43
|
+
}
|
|
44
|
+
pause(fn, icon) {
|
|
45
|
+
const { task } = this;
|
|
46
|
+
const active = task && task.active;
|
|
47
|
+
if (task && active) {
|
|
48
|
+
this._pause(icon);
|
|
49
|
+
this._stdout(false);
|
|
50
|
+
task.active = false;
|
|
51
|
+
}
|
|
52
|
+
const ret = fn();
|
|
53
|
+
if (task && active) {
|
|
54
|
+
this._resume();
|
|
55
|
+
}
|
|
56
|
+
return ret;
|
|
57
|
+
}
|
|
58
|
+
async pauseAsync(fn, icon) {
|
|
59
|
+
const { task } = this;
|
|
60
|
+
const active = task && task.active;
|
|
61
|
+
if (task && active) {
|
|
62
|
+
this._pause(icon);
|
|
63
|
+
this._stdout(false);
|
|
64
|
+
task.active = false;
|
|
65
|
+
}
|
|
66
|
+
const ret = await fn();
|
|
67
|
+
if (task && active) {
|
|
68
|
+
this._resume();
|
|
69
|
+
}
|
|
70
|
+
return ret;
|
|
71
|
+
}
|
|
72
|
+
start(action, status, opts = {}) {
|
|
73
|
+
this.std = opts.stdout ? 'stdout' : 'stderr';
|
|
74
|
+
const task = { action, active: Boolean(this.task && this.task.active), status };
|
|
75
|
+
this.task = task;
|
|
76
|
+
this._start(opts);
|
|
77
|
+
task.active = true;
|
|
78
|
+
this._stdout(true);
|
|
79
|
+
}
|
|
80
|
+
stop(msg = 'done') {
|
|
81
|
+
const { task } = this;
|
|
82
|
+
if (!task) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this._stop(msg);
|
|
86
|
+
task.active = false;
|
|
87
|
+
this.task = undefined;
|
|
88
|
+
this._stdout(false);
|
|
89
|
+
}
|
|
15
90
|
// flush mocked stdout/stderr
|
|
16
91
|
_flushStdout() {
|
|
17
92
|
try {
|
|
@@ -105,80 +180,5 @@ class ActionBase {
|
|
|
105
180
|
globals.action = globals.action || {};
|
|
106
181
|
return globals;
|
|
107
182
|
}
|
|
108
|
-
pause(fn, icon) {
|
|
109
|
-
const { task } = this;
|
|
110
|
-
const active = task && task.active;
|
|
111
|
-
if (task && active) {
|
|
112
|
-
this._pause(icon);
|
|
113
|
-
this._stdout(false);
|
|
114
|
-
task.active = false;
|
|
115
|
-
}
|
|
116
|
-
const ret = fn();
|
|
117
|
-
if (task && active) {
|
|
118
|
-
this._resume();
|
|
119
|
-
}
|
|
120
|
-
return ret;
|
|
121
|
-
}
|
|
122
|
-
async pauseAsync(fn, icon) {
|
|
123
|
-
const { task } = this;
|
|
124
|
-
const active = task && task.active;
|
|
125
|
-
if (task && active) {
|
|
126
|
-
this._pause(icon);
|
|
127
|
-
this._stdout(false);
|
|
128
|
-
task.active = false;
|
|
129
|
-
}
|
|
130
|
-
const ret = await fn();
|
|
131
|
-
if (task && active) {
|
|
132
|
-
this._resume();
|
|
133
|
-
}
|
|
134
|
-
return ret;
|
|
135
|
-
}
|
|
136
|
-
start(action, status, opts = {}) {
|
|
137
|
-
this.std = opts.stdout ? 'stdout' : 'stderr';
|
|
138
|
-
const task = { action, active: Boolean(this.task && this.task.active), status };
|
|
139
|
-
this.task = task;
|
|
140
|
-
this._start(opts);
|
|
141
|
-
task.active = true;
|
|
142
|
-
this._stdout(true);
|
|
143
|
-
}
|
|
144
|
-
stop(msg = 'done') {
|
|
145
|
-
const { task } = this;
|
|
146
|
-
if (!task) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
this._stop(msg);
|
|
150
|
-
task.active = false;
|
|
151
|
-
this.task = undefined;
|
|
152
|
-
this._stdout(false);
|
|
153
|
-
}
|
|
154
|
-
get output() {
|
|
155
|
-
return this.globals.output;
|
|
156
|
-
}
|
|
157
|
-
set output(output) {
|
|
158
|
-
this.globals.output = output;
|
|
159
|
-
}
|
|
160
|
-
get running() {
|
|
161
|
-
return Boolean(this.task);
|
|
162
|
-
}
|
|
163
|
-
get status() {
|
|
164
|
-
return this.task ? this.task.status : undefined;
|
|
165
|
-
}
|
|
166
|
-
set status(status) {
|
|
167
|
-
const { task } = this;
|
|
168
|
-
if (!task) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (task.status === status) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
this._updateStatus(status, task.status);
|
|
175
|
-
task.status = status;
|
|
176
|
-
}
|
|
177
|
-
get task() {
|
|
178
|
-
return this.globals.action.task;
|
|
179
|
-
}
|
|
180
|
-
set task(task) {
|
|
181
|
-
this.globals.action.task = task;
|
|
182
|
-
}
|
|
183
183
|
}
|
|
184
184
|
exports.ActionBase = ActionBase;
|
package/lib/cli-ux/stream.d.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
declare class Stream {
|
|
5
5
|
channel: 'stderr' | 'stdout';
|
|
6
6
|
constructor(channel: 'stderr' | 'stdout');
|
|
7
|
+
get isTTY(): boolean;
|
|
7
8
|
emit(event: string, ...args: any[]): boolean;
|
|
8
9
|
getWindowSize(): number[];
|
|
9
10
|
on(event: string, listener: (...args: any[]) => void): Stream;
|
|
10
11
|
once(event: string, listener: (...args: any[]) => void): Stream;
|
|
11
12
|
read(): boolean;
|
|
12
13
|
write(data: string): boolean;
|
|
13
|
-
get isTTY(): boolean;
|
|
14
14
|
}
|
|
15
15
|
export declare const stdout: Stream;
|
|
16
16
|
export declare const stderr: Stream;
|
package/lib/cli-ux/stream.js
CHANGED
|
@@ -9,6 +9,9 @@ class Stream {
|
|
|
9
9
|
constructor(channel) {
|
|
10
10
|
this.channel = channel;
|
|
11
11
|
}
|
|
12
|
+
get isTTY() {
|
|
13
|
+
return process[this.channel].isTTY;
|
|
14
|
+
}
|
|
12
15
|
emit(event, ...args) {
|
|
13
16
|
return process[this.channel].emit(event, ...args);
|
|
14
17
|
}
|
|
@@ -29,9 +32,6 @@ class Stream {
|
|
|
29
32
|
write(data) {
|
|
30
33
|
return process[this.channel].write(data);
|
|
31
34
|
}
|
|
32
|
-
get isTTY() {
|
|
33
|
-
return process[this.channel].isTTY;
|
|
34
|
-
}
|
|
35
35
|
}
|
|
36
36
|
exports.stdout = new Stream('stdout');
|
|
37
37
|
exports.stderr = new Stream('stderr');
|
|
@@ -49,6 +49,70 @@ class Table {
|
|
|
49
49
|
title,
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
display() {
|
|
53
|
+
// build table rows from input array data
|
|
54
|
+
let rows = this.data.map((d) => {
|
|
55
|
+
const row = {};
|
|
56
|
+
for (const col of this.columns) {
|
|
57
|
+
let val = col.get(d);
|
|
58
|
+
if (typeof val !== 'string')
|
|
59
|
+
val = (0, node_util_1.inspect)(val, { breakLength: Number.POSITIVE_INFINITY });
|
|
60
|
+
row[col.key] = val;
|
|
61
|
+
}
|
|
62
|
+
return row;
|
|
63
|
+
});
|
|
64
|
+
// filter rows
|
|
65
|
+
if (this.options.filter) {
|
|
66
|
+
let [header, regex] = this.options.filter.split('=');
|
|
67
|
+
const isNot = header[0] === '-';
|
|
68
|
+
if (isNot)
|
|
69
|
+
header = header.slice(1);
|
|
70
|
+
const col = this.findColumnFromHeader(header);
|
|
71
|
+
if (!col || !regex)
|
|
72
|
+
throw new Error('Filter flag has an invalid value');
|
|
73
|
+
rows = rows.filter((d) => {
|
|
74
|
+
const re = new RegExp(regex);
|
|
75
|
+
const val = d[col.key];
|
|
76
|
+
const match = val.match(re);
|
|
77
|
+
return isNot ? !match : match;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// sort rows
|
|
81
|
+
if (this.options.sort) {
|
|
82
|
+
const sorters = this.options.sort.split(',');
|
|
83
|
+
const sortHeaders = sorters.map((k) => (k[0] === '-' ? k.slice(1) : k));
|
|
84
|
+
const sortKeys = this.filterColumnsFromHeaders(sortHeaders).map((c) => (v) => v[c.key]);
|
|
85
|
+
const sortKeysOrder = sorters.map((k) => (k[0] === '-' ? 'desc' : 'asc'));
|
|
86
|
+
rows = (0, natural_orderby_1.orderBy)(rows, sortKeys, sortKeysOrder);
|
|
87
|
+
}
|
|
88
|
+
// and filter columns
|
|
89
|
+
if (this.options.columns) {
|
|
90
|
+
const filters = this.options.columns.split(',');
|
|
91
|
+
this.columns = this.filterColumnsFromHeaders(filters);
|
|
92
|
+
}
|
|
93
|
+
else if (!this.options.extended) {
|
|
94
|
+
// show extented columns/properties
|
|
95
|
+
this.columns = this.columns.filter((c) => !c.extended);
|
|
96
|
+
}
|
|
97
|
+
this.data = rows;
|
|
98
|
+
switch (this.options.output) {
|
|
99
|
+
case 'csv': {
|
|
100
|
+
this.outputCSV();
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case 'json': {
|
|
104
|
+
this.outputJSON();
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case 'yaml': {
|
|
108
|
+
this.outputYAML();
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
default: {
|
|
112
|
+
this.outputTable();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
52
116
|
filterColumnsFromHeaders(filters) {
|
|
53
117
|
// unique
|
|
54
118
|
filters = [...new Set(filters)];
|
|
@@ -207,70 +271,6 @@ class Table {
|
|
|
207
271
|
const { columns, data } = this;
|
|
208
272
|
return data.map((d) => Object.fromEntries(columns.map((col) => [col.key, d[col.key] ?? ''])));
|
|
209
273
|
}
|
|
210
|
-
display() {
|
|
211
|
-
// build table rows from input array data
|
|
212
|
-
let rows = this.data.map((d) => {
|
|
213
|
-
const row = {};
|
|
214
|
-
for (const col of this.columns) {
|
|
215
|
-
let val = col.get(d);
|
|
216
|
-
if (typeof val !== 'string')
|
|
217
|
-
val = (0, node_util_1.inspect)(val, { breakLength: Number.POSITIVE_INFINITY });
|
|
218
|
-
row[col.key] = val;
|
|
219
|
-
}
|
|
220
|
-
return row;
|
|
221
|
-
});
|
|
222
|
-
// filter rows
|
|
223
|
-
if (this.options.filter) {
|
|
224
|
-
let [header, regex] = this.options.filter.split('=');
|
|
225
|
-
const isNot = header[0] === '-';
|
|
226
|
-
if (isNot)
|
|
227
|
-
header = header.slice(1);
|
|
228
|
-
const col = this.findColumnFromHeader(header);
|
|
229
|
-
if (!col || !regex)
|
|
230
|
-
throw new Error('Filter flag has an invalid value');
|
|
231
|
-
rows = rows.filter((d) => {
|
|
232
|
-
const re = new RegExp(regex);
|
|
233
|
-
const val = d[col.key];
|
|
234
|
-
const match = val.match(re);
|
|
235
|
-
return isNot ? !match : match;
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
// sort rows
|
|
239
|
-
if (this.options.sort) {
|
|
240
|
-
const sorters = this.options.sort.split(',');
|
|
241
|
-
const sortHeaders = sorters.map((k) => (k[0] === '-' ? k.slice(1) : k));
|
|
242
|
-
const sortKeys = this.filterColumnsFromHeaders(sortHeaders).map((c) => (v) => v[c.key]);
|
|
243
|
-
const sortKeysOrder = sorters.map((k) => (k[0] === '-' ? 'desc' : 'asc'));
|
|
244
|
-
rows = (0, natural_orderby_1.orderBy)(rows, sortKeys, sortKeysOrder);
|
|
245
|
-
}
|
|
246
|
-
// and filter columns
|
|
247
|
-
if (this.options.columns) {
|
|
248
|
-
const filters = this.options.columns.split(',');
|
|
249
|
-
this.columns = this.filterColumnsFromHeaders(filters);
|
|
250
|
-
}
|
|
251
|
-
else if (!this.options.extended) {
|
|
252
|
-
// show extented columns/properties
|
|
253
|
-
this.columns = this.columns.filter((c) => !c.extended);
|
|
254
|
-
}
|
|
255
|
-
this.data = rows;
|
|
256
|
-
switch (this.options.output) {
|
|
257
|
-
case 'csv': {
|
|
258
|
-
this.outputCSV();
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
case 'json': {
|
|
262
|
-
this.outputJSON();
|
|
263
|
-
break;
|
|
264
|
-
}
|
|
265
|
-
case 'yaml': {
|
|
266
|
-
this.outputYAML();
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
default: {
|
|
270
|
-
this.outputTable();
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
274
|
}
|
|
275
275
|
function table(data, columns, options = {}) {
|
|
276
276
|
new Table(data, columns, options).display();
|
package/lib/command.d.ts
CHANGED
|
@@ -68,10 +68,14 @@ export declare abstract class Command {
|
|
|
68
68
|
* An override string (or strings) for the default usage documentation.
|
|
69
69
|
*/
|
|
70
70
|
static usage: string | string[] | undefined;
|
|
71
|
-
private static readonly _base;
|
|
72
71
|
protected debug: (...args: any[]) => void;
|
|
73
72
|
id: string | undefined;
|
|
73
|
+
private static readonly _base;
|
|
74
74
|
constructor(argv: string[], config: Config);
|
|
75
|
+
/**
|
|
76
|
+
* actual command run code goes here
|
|
77
|
+
*/
|
|
78
|
+
abstract run(): Promise<any>;
|
|
75
79
|
/**
|
|
76
80
|
* instantiate and run the command
|
|
77
81
|
*
|
|
@@ -81,8 +85,7 @@ export declare abstract class Command {
|
|
|
81
85
|
* @returns {Promise<unknown>} result
|
|
82
86
|
*/
|
|
83
87
|
static run<T extends Command>(this: new (argv: string[], config: Config) => T, argv?: string[], opts?: LoadOptions): Promise<ReturnType<T['run']>>;
|
|
84
|
-
protected
|
|
85
|
-
private removeEnvVar;
|
|
88
|
+
protected get ctor(): typeof Command;
|
|
86
89
|
protected catch(err: CommandError): Promise<any>;
|
|
87
90
|
error(input: Error | string, options: {
|
|
88
91
|
code?: string;
|
|
@@ -110,11 +113,8 @@ export declare abstract class Command {
|
|
|
110
113
|
warn(input: Error | string): Error | string;
|
|
111
114
|
protected warnIfCommandDeprecated(): void;
|
|
112
115
|
protected warnIfFlagDeprecated(flags: Record<string, unknown>): void;
|
|
113
|
-
protected
|
|
114
|
-
|
|
115
|
-
* actual command run code goes here
|
|
116
|
-
*/
|
|
117
|
-
abstract run(): Promise<any>;
|
|
116
|
+
protected _run<T>(): Promise<T>;
|
|
117
|
+
private removeEnvVar;
|
|
118
118
|
}
|
|
119
119
|
export declare namespace Command {
|
|
120
120
|
/**
|
package/lib/command.js
CHANGED
|
@@ -88,9 +88,9 @@ class Command {
|
|
|
88
88
|
* An override string (or strings) for the default usage documentation.
|
|
89
89
|
*/
|
|
90
90
|
static usage;
|
|
91
|
-
static _base = `${pjson.name}@${pjson.version}`;
|
|
92
91
|
debug;
|
|
93
92
|
id;
|
|
93
|
+
static _base = `${pjson.name}@${pjson.version}`;
|
|
94
94
|
constructor(argv, config) {
|
|
95
95
|
this.argv = argv;
|
|
96
96
|
this.config = config;
|
|
@@ -128,35 +128,8 @@ class Command {
|
|
|
128
128
|
}
|
|
129
129
|
return cmd._run();
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
let result;
|
|
134
|
-
try {
|
|
135
|
-
// remove redirected env var to allow subsessions to run autoupdated client
|
|
136
|
-
this.removeEnvVar('REDIRECTED');
|
|
137
|
-
await this.init();
|
|
138
|
-
result = await this.run();
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
err = error;
|
|
142
|
-
await this.catch(error);
|
|
143
|
-
}
|
|
144
|
-
finally {
|
|
145
|
-
await this.finally(err);
|
|
146
|
-
}
|
|
147
|
-
if (result && this.jsonEnabled())
|
|
148
|
-
this.logJson(this.toSuccessJson(result));
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
removeEnvVar(envVar) {
|
|
152
|
-
const keys = [];
|
|
153
|
-
try {
|
|
154
|
-
keys.push(...this.config.scopedEnvVarKeys(envVar));
|
|
155
|
-
}
|
|
156
|
-
catch {
|
|
157
|
-
keys.push(this.config.scopedEnvVarKey(envVar));
|
|
158
|
-
}
|
|
159
|
-
keys.map((key) => delete process.env[key]);
|
|
131
|
+
get ctor() {
|
|
132
|
+
return this.constructor;
|
|
160
133
|
}
|
|
161
134
|
async catch(err) {
|
|
162
135
|
process.exitCode = process.exitCode ?? err.exitCode ?? 1;
|
|
@@ -294,8 +267,35 @@ class Command {
|
|
|
294
267
|
}
|
|
295
268
|
}
|
|
296
269
|
}
|
|
297
|
-
|
|
298
|
-
|
|
270
|
+
async _run() {
|
|
271
|
+
let err;
|
|
272
|
+
let result;
|
|
273
|
+
try {
|
|
274
|
+
// remove redirected env var to allow subsessions to run autoupdated client
|
|
275
|
+
this.removeEnvVar('REDIRECTED');
|
|
276
|
+
await this.init();
|
|
277
|
+
result = await this.run();
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
err = error;
|
|
281
|
+
await this.catch(error);
|
|
282
|
+
}
|
|
283
|
+
finally {
|
|
284
|
+
await this.finally(err);
|
|
285
|
+
}
|
|
286
|
+
if (result && this.jsonEnabled())
|
|
287
|
+
this.logJson(this.toSuccessJson(result));
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
removeEnvVar(envVar) {
|
|
291
|
+
const keys = [];
|
|
292
|
+
try {
|
|
293
|
+
keys.push(...this.config.scopedEnvVarKeys(envVar));
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
keys.push(this.config.scopedEnvVarKey(envVar));
|
|
297
|
+
}
|
|
298
|
+
keys.map((key) => delete process.env[key]);
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
exports.Command = Command;
|
package/lib/config/config.d.ts
CHANGED
|
@@ -4,14 +4,6 @@ import { ArchTypes, Config as IConfig, LoadOptions, PlatformTypes, VersionDetail
|
|
|
4
4
|
import { Plugin as IPlugin, Options } from '../interfaces/plugin';
|
|
5
5
|
export declare class Config implements IConfig {
|
|
6
6
|
options: Options;
|
|
7
|
-
private _base;
|
|
8
|
-
private _commandIDs;
|
|
9
|
-
private _commands;
|
|
10
|
-
private static _rootPlugin;
|
|
11
|
-
private _topics;
|
|
12
|
-
private commandPermutations;
|
|
13
|
-
private pluginLoader;
|
|
14
|
-
private topicPermutations;
|
|
15
7
|
arch: ArchTypes;
|
|
16
8
|
bin: string;
|
|
17
9
|
binAliases?: string[];
|
|
@@ -40,46 +32,22 @@ export declare class Config implements IConfig {
|
|
|
40
32
|
version: string;
|
|
41
33
|
protected warned: boolean;
|
|
42
34
|
windows: boolean;
|
|
35
|
+
private _base;
|
|
36
|
+
private _commandIDs;
|
|
37
|
+
private _commands;
|
|
38
|
+
private static _rootPlugin;
|
|
39
|
+
private _topics;
|
|
40
|
+
private commandPermutations;
|
|
41
|
+
private pluginLoader;
|
|
42
|
+
private topicPermutations;
|
|
43
43
|
constructor(options: Options);
|
|
44
44
|
static load(opts?: LoadOptions): Promise<Config>;
|
|
45
45
|
static get rootPlugin(): IPlugin | undefined;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* It is possible that more than one command will be found. This is due the ability of two distinct plugins to
|
|
52
|
-
* create the same command or command alias.
|
|
53
|
-
*
|
|
54
|
-
* In the case of more than one found command, the function will select the command based on the order in which
|
|
55
|
-
* the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
|
|
56
|
-
* is selected as the command to run.
|
|
57
|
-
*
|
|
58
|
-
* Commands can also be present from either an install or a link. When a command is one of these and a core plugin
|
|
59
|
-
* is present, this function defers to the core plugin.
|
|
60
|
-
*
|
|
61
|
-
* If there is not a core plugin command present, this function will return the first
|
|
62
|
-
* plugin as discovered (will not change the order)
|
|
63
|
-
*
|
|
64
|
-
* @param commands commands to determine the priority of
|
|
65
|
-
* @returns command instance {Command.Loadable} or undefined
|
|
66
|
-
*/
|
|
67
|
-
private determinePriority;
|
|
68
|
-
private getCmdLookupId;
|
|
69
|
-
private getTopicLookupId;
|
|
70
|
-
/**
|
|
71
|
-
* Insert legacy plugins
|
|
72
|
-
*
|
|
73
|
-
* Replace invalid CLI plugins (cli-engine plugins, mostly Heroku) loaded via `this.loadPlugins`
|
|
74
|
-
* with oclif-compatible ones returned by @oclif/plugin-legacy init hook.
|
|
75
|
-
*
|
|
76
|
-
* @param plugins array of oclif-compatible plugins
|
|
77
|
-
* @returns void
|
|
78
|
-
*/
|
|
79
|
-
private insertLegacyPlugins;
|
|
80
|
-
private isJitPluginCommand;
|
|
81
|
-
private loadCommands;
|
|
82
|
-
private loadTopics;
|
|
46
|
+
get commandIDs(): string[];
|
|
47
|
+
get commands(): Command.Loadable[];
|
|
48
|
+
protected get isProd(): boolean;
|
|
49
|
+
get topics(): Topic[];
|
|
50
|
+
get versionDetails(): VersionDetails;
|
|
83
51
|
protected dir(category: 'cache' | 'config' | 'data'): string;
|
|
84
52
|
findCommand(id: string, opts: {
|
|
85
53
|
must: true;
|
|
@@ -148,9 +116,41 @@ export declare class Config implements IConfig {
|
|
|
148
116
|
protected windowsHome(): string | undefined;
|
|
149
117
|
protected windowsHomedriveHome(): string | undefined;
|
|
150
118
|
protected windowsUserprofileHome(): string | undefined;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
119
|
+
protected _debug(): number;
|
|
120
|
+
protected _shell(): string;
|
|
121
|
+
/**
|
|
122
|
+
* This method is responsible for locating the correct plugin to use for a named command id
|
|
123
|
+
* It searches the {Config} registered commands to match either the raw command id or the command alias
|
|
124
|
+
* It is possible that more than one command will be found. This is due the ability of two distinct plugins to
|
|
125
|
+
* create the same command or command alias.
|
|
126
|
+
*
|
|
127
|
+
* In the case of more than one found command, the function will select the command based on the order in which
|
|
128
|
+
* the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
|
|
129
|
+
* is selected as the command to run.
|
|
130
|
+
*
|
|
131
|
+
* Commands can also be present from either an install or a link. When a command is one of these and a core plugin
|
|
132
|
+
* is present, this function defers to the core plugin.
|
|
133
|
+
*
|
|
134
|
+
* If there is not a core plugin command present, this function will return the first
|
|
135
|
+
* plugin as discovered (will not change the order)
|
|
136
|
+
*
|
|
137
|
+
* @param commands commands to determine the priority of
|
|
138
|
+
* @returns command instance {Command.Loadable} or undefined
|
|
139
|
+
*/
|
|
140
|
+
private determinePriority;
|
|
141
|
+
private getCmdLookupId;
|
|
142
|
+
private getTopicLookupId;
|
|
143
|
+
/**
|
|
144
|
+
* Insert legacy plugins
|
|
145
|
+
*
|
|
146
|
+
* Replace invalid CLI plugins (cli-engine plugins, mostly Heroku) loaded via `this.loadPlugins`
|
|
147
|
+
* with oclif-compatible ones returned by @oclif/plugin-legacy init hook.
|
|
148
|
+
*
|
|
149
|
+
* @param plugins array of oclif-compatible plugins
|
|
150
|
+
* @returns void
|
|
151
|
+
*/
|
|
152
|
+
private insertLegacyPlugins;
|
|
153
|
+
private isJitPluginCommand;
|
|
154
|
+
private loadCommands;
|
|
155
|
+
private loadTopics;
|
|
156
156
|
}
|