@oclif/core 1.1.1 → 1.3.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.
- package/CHANGELOG.md +23 -0
- package/README.md +8 -4
- package/lib/cli-ux/action/base.d.ts +35 -0
- package/lib/cli-ux/action/base.js +166 -0
- package/lib/cli-ux/action/pride-spinner.d.ts +4 -0
- package/lib/cli-ux/action/pride-spinner.js +31 -0
- package/lib/cli-ux/action/simple.d.ts +11 -0
- package/lib/cli-ux/action/simple.js +52 -0
- package/lib/cli-ux/action/spinner.d.ts +16 -0
- package/lib/cli-ux/action/spinner.js +79 -0
- package/lib/cli-ux/action/spinners.d.ts +0 -0
- package/lib/cli-ux/action/spinners.js +373 -0
- package/lib/cli-ux/config.d.ts +20 -0
- package/lib/cli-ux/config.js +45 -0
- package/lib/cli-ux/deps.d.ts +22 -0
- package/lib/cli-ux/deps.js +47 -0
- package/lib/cli-ux/exit.d.ts +8 -0
- package/lib/cli-ux/exit.js +13 -0
- package/lib/cli-ux/index.d.ts +37 -0
- package/lib/cli-ux/index.js +139 -0
- package/lib/cli-ux/list.d.ts +3 -0
- package/lib/cli-ux/list.js +30 -0
- package/lib/cli-ux/open.d.ts +6 -0
- package/lib/cli-ux/open.js +70 -0
- package/lib/cli-ux/prompt.d.ts +29 -0
- package/lib/cli-ux/prompt.js +150 -0
- package/lib/cli-ux/styled/header.d.ts +1 -0
- package/lib/cli-ux/styled/header.js +8 -0
- package/lib/cli-ux/styled/json.d.ts +1 -0
- package/lib/cli-ux/styled/json.js +16 -0
- package/lib/cli-ux/styled/object.d.ts +1 -0
- package/lib/cli-ux/styled/object.js +39 -0
- package/lib/cli-ux/styled/progress.d.ts +1 -0
- package/lib/cli-ux/styled/progress.js +14 -0
- package/lib/cli-ux/styled/table.d.ts +45 -0
- package/lib/cli-ux/styled/table.js +312 -0
- package/lib/cli-ux/styled/tree.d.ts +9 -0
- package/lib/cli-ux/styled/tree.js +40 -0
- package/lib/cli-ux/wait.d.ts +2 -0
- package/lib/cli-ux/wait.js +8 -0
- package/lib/command.js +4 -5
- package/lib/config/config.js +10 -5
- package/lib/config/plugin.js +1 -1
- package/lib/help/util.js +2 -2
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/interfaces/hooks.d.ts +3 -1
- package/lib/interfaces/index.d.ts +1 -0
- package/lib/interfaces/s3-manifest.d.ts +14 -0
- package/lib/interfaces/s3-manifest.js +2 -0
- package/package.json +21 -4
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.table = void 0;
|
|
4
|
+
const F = require("../../flags");
|
|
5
|
+
const screen_1 = require("@oclif/screen");
|
|
6
|
+
const chalk = require("chalk");
|
|
7
|
+
const lodash_1 = require("lodash");
|
|
8
|
+
const js_yaml_1 = require("js-yaml");
|
|
9
|
+
const util_1 = require("util");
|
|
10
|
+
const sw = require('string-width');
|
|
11
|
+
const { orderBy } = require('natural-orderby');
|
|
12
|
+
class Table {
|
|
13
|
+
constructor(data, columns, options = {}) {
|
|
14
|
+
this.data = data;
|
|
15
|
+
// assign columns
|
|
16
|
+
this.columns = Object.keys(columns).map((key) => {
|
|
17
|
+
const col = columns[key];
|
|
18
|
+
const extended = col.extended || false;
|
|
19
|
+
const get = col.get || ((row) => row[key]);
|
|
20
|
+
const header = typeof col.header === 'string' ? col.header : (0, lodash_1.capitalize)(key.replace(/_/g, ' '));
|
|
21
|
+
const minWidth = Math.max(col.minWidth || 0, sw(header) + 1);
|
|
22
|
+
return {
|
|
23
|
+
extended,
|
|
24
|
+
get,
|
|
25
|
+
header,
|
|
26
|
+
key,
|
|
27
|
+
minWidth,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
// assign options
|
|
31
|
+
const { columns: cols, filter, csv, output, extended, sort, title, printLine } = options;
|
|
32
|
+
this.options = {
|
|
33
|
+
columns: cols,
|
|
34
|
+
output: csv ? 'csv' : output,
|
|
35
|
+
extended,
|
|
36
|
+
filter,
|
|
37
|
+
'no-header': options['no-header'] || false,
|
|
38
|
+
'no-truncate': options['no-truncate'] || false,
|
|
39
|
+
printLine: printLine || ((s) => process.stdout.write(s + '\n')),
|
|
40
|
+
rowStart: ' ',
|
|
41
|
+
sort,
|
|
42
|
+
title,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
display() {
|
|
46
|
+
// build table rows from input array data
|
|
47
|
+
let rows = this.data.map(d => {
|
|
48
|
+
const row = {};
|
|
49
|
+
for (const col of this.columns) {
|
|
50
|
+
let val = col.get(d);
|
|
51
|
+
if (typeof val !== 'string')
|
|
52
|
+
val = (0, util_1.inspect)(val, { breakLength: Number.POSITIVE_INFINITY });
|
|
53
|
+
row[col.key] = val;
|
|
54
|
+
}
|
|
55
|
+
return row;
|
|
56
|
+
});
|
|
57
|
+
// filter rows
|
|
58
|
+
if (this.options.filter) {
|
|
59
|
+
/* eslint-disable-next-line prefer-const */
|
|
60
|
+
let [header, regex] = this.options.filter.split('=');
|
|
61
|
+
const isNot = header[0] === '-';
|
|
62
|
+
if (isNot)
|
|
63
|
+
header = header.slice(1);
|
|
64
|
+
const col = this.findColumnFromHeader(header);
|
|
65
|
+
if (!col || !regex)
|
|
66
|
+
throw new Error('Filter flag has an invalid value');
|
|
67
|
+
rows = rows.filter((d) => {
|
|
68
|
+
const re = new RegExp(regex);
|
|
69
|
+
const val = d[col.key];
|
|
70
|
+
const match = val.match(re);
|
|
71
|
+
return isNot ? !match : match;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// sort rows
|
|
75
|
+
if (this.options.sort) {
|
|
76
|
+
const sorters = this.options.sort.split(',');
|
|
77
|
+
const sortHeaders = sorters.map(k => k[0] === '-' ? k.slice(1) : k);
|
|
78
|
+
const sortKeys = this.filterColumnsFromHeaders(sortHeaders).map(c => {
|
|
79
|
+
return ((v) => v[c.key]);
|
|
80
|
+
});
|
|
81
|
+
const sortKeysOrder = sorters.map(k => k[0] === '-' ? 'desc' : 'asc');
|
|
82
|
+
rows = orderBy(rows, sortKeys, sortKeysOrder);
|
|
83
|
+
}
|
|
84
|
+
// and filter columns
|
|
85
|
+
if (this.options.columns) {
|
|
86
|
+
const filters = this.options.columns.split(',');
|
|
87
|
+
this.columns = this.filterColumnsFromHeaders(filters);
|
|
88
|
+
}
|
|
89
|
+
else if (!this.options.extended) {
|
|
90
|
+
// show extented columns/properties
|
|
91
|
+
this.columns = this.columns.filter(c => !c.extended);
|
|
92
|
+
}
|
|
93
|
+
this.data = rows;
|
|
94
|
+
switch (this.options.output) {
|
|
95
|
+
case 'csv':
|
|
96
|
+
this.outputCSV();
|
|
97
|
+
break;
|
|
98
|
+
case 'json':
|
|
99
|
+
this.outputJSON();
|
|
100
|
+
break;
|
|
101
|
+
case 'yaml':
|
|
102
|
+
this.outputYAML();
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
this.outputTable();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
findColumnFromHeader(header) {
|
|
109
|
+
return this.columns.find(c => c.header.toLowerCase() === header.toLowerCase());
|
|
110
|
+
}
|
|
111
|
+
filterColumnsFromHeaders(filters) {
|
|
112
|
+
// unique
|
|
113
|
+
filters = [...(new Set(filters))];
|
|
114
|
+
const cols = [];
|
|
115
|
+
for (const f of filters) {
|
|
116
|
+
const c = this.columns.find(c => c.header.toLowerCase() === f.toLowerCase());
|
|
117
|
+
if (c)
|
|
118
|
+
cols.push(c);
|
|
119
|
+
}
|
|
120
|
+
return cols;
|
|
121
|
+
}
|
|
122
|
+
getCSVRow(d) {
|
|
123
|
+
const values = this.columns.map(col => d[col.key] || '');
|
|
124
|
+
const lineToBeEscaped = values.find((e) => e.includes('"') || e.includes('\n') || e.includes('\r\n') || e.includes('\r') || e.includes(','));
|
|
125
|
+
return values.map(e => lineToBeEscaped ? `"${e.replace('"', '""')}"` : e);
|
|
126
|
+
}
|
|
127
|
+
resolveColumnsToObjectArray() {
|
|
128
|
+
// tslint:disable-next-line:no-this-assignment
|
|
129
|
+
const { data, columns } = this;
|
|
130
|
+
return data.map((d) => {
|
|
131
|
+
// eslint-disable-next-line unicorn/prefer-object-from-entries
|
|
132
|
+
return columns.reduce((obj, col) => {
|
|
133
|
+
return {
|
|
134
|
+
...obj,
|
|
135
|
+
[col.key]: d[col.key] || '',
|
|
136
|
+
};
|
|
137
|
+
}, {});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
outputJSON() {
|
|
141
|
+
this.options.printLine(JSON.stringify(this.resolveColumnsToObjectArray(), undefined, 2));
|
|
142
|
+
}
|
|
143
|
+
outputYAML() {
|
|
144
|
+
this.options.printLine((0, js_yaml_1.safeDump)(this.resolveColumnsToObjectArray()));
|
|
145
|
+
}
|
|
146
|
+
outputCSV() {
|
|
147
|
+
// tslint:disable-next-line:no-this-assignment
|
|
148
|
+
const { data, columns, options } = this;
|
|
149
|
+
if (!options['no-header']) {
|
|
150
|
+
options.printLine(columns.map(c => c.header).join(','));
|
|
151
|
+
}
|
|
152
|
+
for (const d of data) {
|
|
153
|
+
const row = this.getCSVRow(d);
|
|
154
|
+
options.printLine(row.join(','));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
outputTable() {
|
|
158
|
+
// tslint:disable-next-line:no-this-assignment
|
|
159
|
+
const { data, columns, options } = this;
|
|
160
|
+
// column truncation
|
|
161
|
+
//
|
|
162
|
+
// find max width for each column
|
|
163
|
+
for (const col of columns) {
|
|
164
|
+
// convert multi-line cell to single longest line
|
|
165
|
+
// for width calculations
|
|
166
|
+
const widthData = data.map((row) => {
|
|
167
|
+
const d = row[col.key];
|
|
168
|
+
const manyLines = d.split('\n');
|
|
169
|
+
if (manyLines.length > 1) {
|
|
170
|
+
return '*'.repeat(Math.max(...manyLines.map((r) => sw(r))));
|
|
171
|
+
}
|
|
172
|
+
return d;
|
|
173
|
+
});
|
|
174
|
+
const widths = ['.'.padEnd(col.minWidth - 1), col.header, ...widthData.map((row) => row)].map(r => sw(r));
|
|
175
|
+
col.maxWidth = Math.max(...widths) + 1;
|
|
176
|
+
col.width = col.maxWidth;
|
|
177
|
+
}
|
|
178
|
+
// terminal width
|
|
179
|
+
const maxWidth = screen_1.stdtermwidth - 2;
|
|
180
|
+
// truncation logic
|
|
181
|
+
const shouldShorten = () => {
|
|
182
|
+
// don't shorten if full mode
|
|
183
|
+
if (options['no-truncate'] || (!process.stdout.isTTY && !process.env.CLI_UX_SKIP_TTY_CHECK))
|
|
184
|
+
return;
|
|
185
|
+
// don't shorten if there is enough screen width
|
|
186
|
+
const dataMaxWidth = (0, lodash_1.sumBy)(columns, c => c.width);
|
|
187
|
+
const overWidth = dataMaxWidth - maxWidth;
|
|
188
|
+
if (overWidth <= 0)
|
|
189
|
+
return;
|
|
190
|
+
// not enough room, short all columns to minWidth
|
|
191
|
+
for (const col of columns) {
|
|
192
|
+
col.width = col.minWidth;
|
|
193
|
+
}
|
|
194
|
+
// if sum(minWidth's) is greater than term width
|
|
195
|
+
// nothing can be done so
|
|
196
|
+
// display all as minWidth
|
|
197
|
+
const dataMinWidth = (0, lodash_1.sumBy)(columns, c => c.minWidth);
|
|
198
|
+
if (dataMinWidth >= maxWidth)
|
|
199
|
+
return;
|
|
200
|
+
// some wiggle room left, add it back to "needy" columns
|
|
201
|
+
let wiggleRoom = maxWidth - dataMinWidth;
|
|
202
|
+
const needyCols = columns.map(c => ({ key: c.key, needs: c.maxWidth - c.width })).sort((a, b) => a.needs - b.needs);
|
|
203
|
+
for (const { key, needs } of needyCols) {
|
|
204
|
+
if (!needs)
|
|
205
|
+
continue;
|
|
206
|
+
const col = columns.find(c => key === c.key);
|
|
207
|
+
if (!col)
|
|
208
|
+
continue;
|
|
209
|
+
if (wiggleRoom > needs) {
|
|
210
|
+
col.width = col.width + needs;
|
|
211
|
+
wiggleRoom -= needs;
|
|
212
|
+
}
|
|
213
|
+
else if (wiggleRoom) {
|
|
214
|
+
col.width = col.width + wiggleRoom;
|
|
215
|
+
wiggleRoom = 0;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
shouldShorten();
|
|
220
|
+
// print table title
|
|
221
|
+
if (options.title) {
|
|
222
|
+
options.printLine(options.title);
|
|
223
|
+
// print title divider
|
|
224
|
+
options.printLine(''.padEnd(columns.reduce((sum, col) => sum + col.width, 1), '='));
|
|
225
|
+
options.rowStart = '| ';
|
|
226
|
+
}
|
|
227
|
+
// print headers
|
|
228
|
+
if (!options['no-header']) {
|
|
229
|
+
let headers = options.rowStart;
|
|
230
|
+
for (const col of columns) {
|
|
231
|
+
const header = col.header;
|
|
232
|
+
headers += header.padEnd(col.width);
|
|
233
|
+
}
|
|
234
|
+
options.printLine(chalk.bold(headers));
|
|
235
|
+
// print header dividers
|
|
236
|
+
let dividers = options.rowStart;
|
|
237
|
+
for (const col of columns) {
|
|
238
|
+
const divider = ''.padEnd(col.width - 1, '─') + ' ';
|
|
239
|
+
dividers += divider.padEnd(col.width);
|
|
240
|
+
}
|
|
241
|
+
options.printLine(chalk.bold(dividers));
|
|
242
|
+
}
|
|
243
|
+
// print rows
|
|
244
|
+
for (const row of data) {
|
|
245
|
+
// find max number of lines
|
|
246
|
+
// for all cells in a row
|
|
247
|
+
// with multi-line strings
|
|
248
|
+
let numOfLines = 1;
|
|
249
|
+
for (const col of columns) {
|
|
250
|
+
const d = row[col.key];
|
|
251
|
+
const lines = d.split('\n').length;
|
|
252
|
+
if (lines > numOfLines)
|
|
253
|
+
numOfLines = lines;
|
|
254
|
+
}
|
|
255
|
+
// eslint-disable-next-line unicorn/no-new-array
|
|
256
|
+
const linesIndexess = [...new Array(numOfLines).keys()];
|
|
257
|
+
// print row
|
|
258
|
+
// including multi-lines
|
|
259
|
+
for (const i of linesIndexess) {
|
|
260
|
+
let l = options.rowStart;
|
|
261
|
+
for (const col of columns) {
|
|
262
|
+
const width = col.width;
|
|
263
|
+
let d = row[col.key];
|
|
264
|
+
d = d.split('\n')[i] || '';
|
|
265
|
+
const visualWidth = sw(d);
|
|
266
|
+
const colorWidth = (d.length - visualWidth);
|
|
267
|
+
let cell = d.padEnd(width + colorWidth);
|
|
268
|
+
if ((cell.length - colorWidth) > width || visualWidth === width) {
|
|
269
|
+
cell = cell.slice(0, width - 2) + '… ';
|
|
270
|
+
}
|
|
271
|
+
l += cell;
|
|
272
|
+
}
|
|
273
|
+
options.printLine(l);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function table(data, columns, options = {}) {
|
|
279
|
+
new Table(data, columns, options).display();
|
|
280
|
+
}
|
|
281
|
+
exports.table = table;
|
|
282
|
+
(function (table) {
|
|
283
|
+
table.Flags = {
|
|
284
|
+
columns: F.string({ exclusive: ['extended'], description: 'only show provided columns (comma-separated)' }),
|
|
285
|
+
sort: F.string({ description: 'property to sort by (prepend \'-\' for descending)' }),
|
|
286
|
+
filter: F.string({ description: 'filter property by partial string matching, ex: name=foo' }),
|
|
287
|
+
csv: F.boolean({ exclusive: ['no-truncate'], description: 'output is csv format [alias: --output=csv]' }),
|
|
288
|
+
output: F.string({
|
|
289
|
+
exclusive: ['no-truncate', 'csv'],
|
|
290
|
+
description: 'output in a more machine friendly format',
|
|
291
|
+
options: ['csv', 'json', 'yaml'],
|
|
292
|
+
}),
|
|
293
|
+
extended: F.boolean({ exclusive: ['columns'], char: 'x', description: 'show extra columns' }),
|
|
294
|
+
'no-truncate': F.boolean({ exclusive: ['csv'], description: 'do not truncate output to fit screen' }),
|
|
295
|
+
'no-header': F.boolean({ exclusive: ['csv'], description: 'hide table header from output' }),
|
|
296
|
+
};
|
|
297
|
+
function flags(opts) {
|
|
298
|
+
if (opts) {
|
|
299
|
+
const f = {};
|
|
300
|
+
const o = (opts.only && typeof opts.only === 'string' ? [opts.only] : opts.only) || Object.keys(table.Flags);
|
|
301
|
+
const e = (opts.except && typeof opts.except === 'string' ? [opts.except] : opts.except) || [];
|
|
302
|
+
for (const key of o) {
|
|
303
|
+
if (!e.includes(key)) {
|
|
304
|
+
f[key] = table.Flags[key];
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return f;
|
|
308
|
+
}
|
|
309
|
+
return table.Flags;
|
|
310
|
+
}
|
|
311
|
+
table.flags = flags;
|
|
312
|
+
})(table = exports.table || (exports.table = {}));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tree = void 0;
|
|
4
|
+
const treeify = require('object-treeify');
|
|
5
|
+
class Tree {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.nodes = {};
|
|
8
|
+
}
|
|
9
|
+
insert(child, value = new Tree()) {
|
|
10
|
+
this.nodes[child] = value;
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
search(key) {
|
|
14
|
+
for (const child of Object.keys(this.nodes)) {
|
|
15
|
+
if (child === key) {
|
|
16
|
+
return this.nodes[child];
|
|
17
|
+
}
|
|
18
|
+
const c = this.nodes[child].search(key);
|
|
19
|
+
if (c)
|
|
20
|
+
return c;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// tslint:disable-next-line:no-console
|
|
24
|
+
display(logger = console.log) {
|
|
25
|
+
const addNodes = function (nodes) {
|
|
26
|
+
const tree = {};
|
|
27
|
+
for (const p of Object.keys(nodes)) {
|
|
28
|
+
tree[p] = addNodes(nodes[p].nodes);
|
|
29
|
+
}
|
|
30
|
+
return tree;
|
|
31
|
+
};
|
|
32
|
+
const tree = addNodes(this.nodes);
|
|
33
|
+
logger(treeify(tree));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.Tree = Tree;
|
|
37
|
+
function tree() {
|
|
38
|
+
return new Tree();
|
|
39
|
+
}
|
|
40
|
+
exports.default = tree;
|
package/lib/command.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const url_1 = require("url");
|
|
4
4
|
const util_1 = require("util");
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("./index");
|
|
6
6
|
const config_1 = require("./config");
|
|
7
7
|
const Errors = require("./errors");
|
|
8
8
|
const Parser = require("./parser");
|
|
@@ -59,7 +59,7 @@ class Command {
|
|
|
59
59
|
await this.finally(err);
|
|
60
60
|
}
|
|
61
61
|
if (result && this.jsonEnabled()) {
|
|
62
|
-
|
|
62
|
+
index_1.CliUx.ux.styledJSON(this.toSuccessJson(result));
|
|
63
63
|
}
|
|
64
64
|
return result;
|
|
65
65
|
}
|
|
@@ -110,15 +110,14 @@ class Command {
|
|
|
110
110
|
var _a, _b;
|
|
111
111
|
process.exitCode = (_b = (_a = process.exitCode) !== null && _a !== void 0 ? _a : err.exitCode) !== null && _b !== void 0 ? _b : 1;
|
|
112
112
|
if (this.jsonEnabled()) {
|
|
113
|
-
|
|
113
|
+
index_1.CliUx.ux.styledJSON(this.toErrorJson(err));
|
|
114
114
|
}
|
|
115
115
|
else {
|
|
116
116
|
if (!err.message)
|
|
117
117
|
throw err;
|
|
118
118
|
try {
|
|
119
|
-
const { cli } = require('cli-ux');
|
|
120
119
|
const chalk = require('chalk');
|
|
121
|
-
|
|
120
|
+
index_1.CliUx.ux.action.stop(chalk.bold.red('!'));
|
|
122
121
|
}
|
|
123
122
|
catch { }
|
|
124
123
|
throw err;
|
package/lib/config/config.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toCached = exports.Config = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
|
-
const
|
|
5
|
+
const ejs = require("ejs");
|
|
6
6
|
const os = require("os");
|
|
7
7
|
const path = require("path");
|
|
8
8
|
const url_1 = require("url");
|
|
@@ -214,7 +214,11 @@ class Config {
|
|
|
214
214
|
debug('runCommand %s %o', id, argv);
|
|
215
215
|
const c = cachedCommand || this.findCommand(id);
|
|
216
216
|
if (!c) {
|
|
217
|
-
await this.runHook('command_not_found', { id, argv });
|
|
217
|
+
const hookResult = await this.runHook('command_not_found', { id, argv });
|
|
218
|
+
if (hookResult.successes[0]) {
|
|
219
|
+
const cmdResult = hookResult.successes[0].result;
|
|
220
|
+
return cmdResult;
|
|
221
|
+
}
|
|
218
222
|
throw new errors_1.CLIError(`command ${id} not found`);
|
|
219
223
|
}
|
|
220
224
|
const command = await c.load();
|
|
@@ -304,7 +308,7 @@ class Config {
|
|
|
304
308
|
get commandIDs() {
|
|
305
309
|
if (this._commandIDs)
|
|
306
310
|
return this._commandIDs;
|
|
307
|
-
const ids =
|
|
311
|
+
const ids = this.commands.flatMap(c => [c.id, ...c.aliases]);
|
|
308
312
|
this._commandIDs = (0, util_3.uniq)(ids);
|
|
309
313
|
return this._commandIDs;
|
|
310
314
|
}
|
|
@@ -338,12 +342,13 @@ class Config {
|
|
|
338
342
|
return this._topics;
|
|
339
343
|
}
|
|
340
344
|
s3Key(type, ext, options = {}) {
|
|
345
|
+
var _a;
|
|
341
346
|
if (typeof ext === 'object')
|
|
342
347
|
options = ext;
|
|
343
348
|
else if (ext)
|
|
344
349
|
options.ext = ext;
|
|
345
|
-
const
|
|
346
|
-
return
|
|
350
|
+
const template = (_a = this.pjson.oclif.update.s3.templates[options.platform ? 'target' : 'vanilla'][type]) !== null && _a !== void 0 ? _a : '';
|
|
351
|
+
return ejs.render(template, { ...this, ...options });
|
|
347
352
|
}
|
|
348
353
|
s3Url(key) {
|
|
349
354
|
const host = this.pjson.oclif.update.s3.host;
|
package/lib/config/plugin.js
CHANGED
|
@@ -78,7 +78,7 @@ async function findRoot(name, root) {
|
|
|
78
78
|
if (name) {
|
|
79
79
|
let pkgPath;
|
|
80
80
|
try {
|
|
81
|
-
pkgPath = (0, util_3.resolvePackage)(name, { paths: [
|
|
81
|
+
pkgPath = (0, util_3.resolvePackage)(name, { paths: [root] });
|
|
82
82
|
}
|
|
83
83
|
catch { }
|
|
84
84
|
return pkgPath ? findSourcesRoot(path.dirname(pkgPath)) : findRootLegacy(name, root);
|
package/lib/help/util.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.standardizeIDFromArgv = exports.toConfiguredId = exports.toStandardizedId = exports.template = exports.loadHelpClass = void 0;
|
|
4
|
-
const
|
|
4
|
+
const ejs = require("ejs");
|
|
5
5
|
const _1 = require(".");
|
|
6
6
|
const module_loader_1 = require("../module-loader");
|
|
7
7
|
function extractClass(exported) {
|
|
@@ -24,7 +24,7 @@ async function loadHelpClass(config) {
|
|
|
24
24
|
exports.loadHelpClass = loadHelpClass;
|
|
25
25
|
function template(context) {
|
|
26
26
|
function render(t) {
|
|
27
|
-
return
|
|
27
|
+
return ejs.render(t, context);
|
|
28
28
|
}
|
|
29
29
|
return render;
|
|
30
30
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ import * as Parser from './parser';
|
|
|
10
10
|
import { Hook } from './interfaces/hooks';
|
|
11
11
|
import { settings, Settings } from './settings';
|
|
12
12
|
import { HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable } from './help/formatter';
|
|
13
|
+
import * as cliUx from './cli-ux';
|
|
13
14
|
declare const flush: any;
|
|
14
|
-
export { Command, CommandHelp, Config, Errors, Flags, loadHelpClass, Help, HelpBase, HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable, Hook, Interfaces, Parser, Plugin, run, toCached, tsPath, toStandardizedId, toConfiguredId, settings, Settings, flush, };
|
|
15
|
+
export { Command, CommandHelp, Config, Errors, Flags, loadHelpClass, Help, HelpBase, HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable, Hook, Interfaces, Parser, Plugin, run, toCached, tsPath, toStandardizedId, toConfiguredId, settings, Settings, flush, cliUx as CliUx, };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.tsPath = exports.toCached = exports.run = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Command = void 0;
|
|
3
|
+
exports.CliUx = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.tsPath = exports.toCached = exports.run = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Command = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const semver = require("semver");
|
|
6
6
|
const command_1 = require("./command");
|
|
@@ -30,6 +30,8 @@ const Parser = require("./parser");
|
|
|
30
30
|
exports.Parser = Parser;
|
|
31
31
|
const settings_1 = require("./settings");
|
|
32
32
|
Object.defineProperty(exports, "settings", { enumerable: true, get: function () { return settings_1.settings; } });
|
|
33
|
+
const cliUx = require("./cli-ux");
|
|
34
|
+
exports.CliUx = cliUx;
|
|
33
35
|
const flush = require('../flush');
|
|
34
36
|
exports.flush = flush;
|
|
35
37
|
function checkCWD() {
|
|
@@ -32,12 +32,14 @@ export interface Hooks {
|
|
|
32
32
|
preupdate: {
|
|
33
33
|
options: {
|
|
34
34
|
channel: string;
|
|
35
|
+
version: string;
|
|
35
36
|
};
|
|
36
37
|
return: void;
|
|
37
38
|
};
|
|
38
39
|
update: {
|
|
39
40
|
options: {
|
|
40
41
|
channel: string;
|
|
42
|
+
version: string;
|
|
41
43
|
};
|
|
42
44
|
return: void;
|
|
43
45
|
};
|
|
@@ -46,7 +48,7 @@ export interface Hooks {
|
|
|
46
48
|
id: string;
|
|
47
49
|
argv?: string[];
|
|
48
50
|
};
|
|
49
|
-
return:
|
|
51
|
+
return: unknown;
|
|
50
52
|
};
|
|
51
53
|
'plugins:preinstall': {
|
|
52
54
|
options: {
|
|
@@ -5,6 +5,7 @@ export { OclifError, PrettyPrintableError } from './errors';
|
|
|
5
5
|
export { HelpOptions } from './help';
|
|
6
6
|
export { Hook, Hooks } from './hooks';
|
|
7
7
|
export { Manifest } from './manifest';
|
|
8
|
+
export { S3Manifest } from './s3-manifest';
|
|
8
9
|
export { ParserArg, Arg, ParseFn, ParserOutput, ParserInput, ArgToken, OptionalArg, FlagOutput, OutputArgs, OutputFlags, FlagUsageOptions, CLIParseErrorOptions, ArgInput, RequiredArg, Metadata, ParsingToken, FlagToken, List, ListItem, BooleanFlag, Flag, FlagBase, OptionFlag, Input, EnumFlagOptions, DefaultContext, Default, Definition, CompletableOptionFlag, Completion, CompletionContext, FlagInput, CompletableFlag, } from './parser';
|
|
9
10
|
export { PJSON } from './pjson';
|
|
10
11
|
export { Plugin, PluginOptions, Options } from './plugin';
|
package/package.json
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/core",
|
|
3
3
|
"description": "base library for oclif CLIs",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@oclif/linewrap": "^1.0.0",
|
|
9
|
+
"@oclif/screen": "^3.0.2",
|
|
10
|
+
"ansi-escapes": "^4.3.0",
|
|
11
|
+
"ansi-styles": "^4.2.0",
|
|
12
|
+
"cardinal": "^2.1.1",
|
|
9
13
|
"chalk": "^4.1.2",
|
|
10
14
|
"clean-stack": "^3.0.1",
|
|
11
|
-
"cli-
|
|
15
|
+
"cli-progress": "^3.10.0",
|
|
12
16
|
"debug": "^4.3.3",
|
|
17
|
+
"ejs": "^3.1.6",
|
|
13
18
|
"fs-extra": "^9.1.0",
|
|
14
19
|
"get-package-type": "^0.1.0",
|
|
15
20
|
"globby": "^11.0.4",
|
|
21
|
+
"hyperlinker": "^1.0.0",
|
|
16
22
|
"indent-string": "^4.0.0",
|
|
17
23
|
"is-wsl": "^2.2.0",
|
|
24
|
+
"js-yaml": "^3.13.1",
|
|
18
25
|
"lodash": "^4.17.21",
|
|
26
|
+
"natural-orderby": "^2.0.3",
|
|
27
|
+
"object-treeify": "^1.1.4",
|
|
28
|
+
"password-prompt": "^1.1.2",
|
|
19
29
|
"semver": "^7.3.5",
|
|
20
30
|
"string-width": "^4.2.3",
|
|
21
31
|
"strip-ansi": "^6.0.1",
|
|
32
|
+
"supports-color": "^8.1.1",
|
|
33
|
+
"supports-hyperlinks": "^2.2.0",
|
|
22
34
|
"tslib": "^2.3.1",
|
|
23
35
|
"widest-line": "^3.1.0",
|
|
24
36
|
"wrap-ansi": "^7.0.0"
|
|
@@ -28,12 +40,16 @@
|
|
|
28
40
|
"@oclif/plugin-help": "^5.1.7",
|
|
29
41
|
"@oclif/plugin-plugins": "^2.0.8",
|
|
30
42
|
"@oclif/test": "^1.2.8",
|
|
43
|
+
"@types/ansi-styles": "^3.2.1",
|
|
31
44
|
"@types/chai": "^4.2.22",
|
|
32
45
|
"@types/chai-as-promised": "^7.1.4",
|
|
33
46
|
"@types/clean-stack": "^2.1.1",
|
|
47
|
+
"@types/cli-progress": "^3.9.2",
|
|
48
|
+
"@types/ejs": "^3.1.0",
|
|
34
49
|
"@types/fs-extra": "^9.0.13",
|
|
35
50
|
"@types/indent-string": "^4.0.1",
|
|
36
|
-
"@types/
|
|
51
|
+
"@types/js-yaml": "^3.12.1",
|
|
52
|
+
"@types/lodash": "^4.14.117",
|
|
37
53
|
"@types/mocha": "^8.2.3",
|
|
38
54
|
"@types/nock": "^11.1.0",
|
|
39
55
|
"@types/node": "^15.14.9",
|
|
@@ -42,6 +58,7 @@
|
|
|
42
58
|
"@types/semver": "^7.3.9",
|
|
43
59
|
"@types/shelljs": "^0.8.10",
|
|
44
60
|
"@types/strip-ansi": "^5.2.1",
|
|
61
|
+
"@types/supports-color": "^8.1.1",
|
|
45
62
|
"@types/wrap-ansi": "^3.0.0",
|
|
46
63
|
"chai": "^4.3.4",
|
|
47
64
|
"chai-as-promised": "^7.1.1",
|
|
@@ -59,7 +76,7 @@
|
|
|
59
76
|
"shx": "^0.3.3",
|
|
60
77
|
"sinon": "^11.1.2",
|
|
61
78
|
"ts-node": "^9.1.1",
|
|
62
|
-
"typescript": "4.
|
|
79
|
+
"typescript": "4.4.4"
|
|
63
80
|
},
|
|
64
81
|
"resolutions": {
|
|
65
82
|
"@oclif/command": "1.8.9",
|