@oclif/core 1.9.0 → 1.9.3
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 +11 -0
- package/lib/cli-ux/styled/table.js +28 -23
- package/lib/config/plugin.js +2 -1
- package/lib/help/index.js +3 -1
- package/lib/main.js +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.9.3](https://github.com/oclif/core/compare/v1.9.2...v1.9.3) (2022-06-16)
|
|
6
|
+
|
|
7
|
+
### [1.9.2](https://github.com/oclif/core/compare/v1.9.1...v1.9.2) (2022-06-14)
|
|
8
|
+
|
|
9
|
+
### [1.9.1](https://github.com/oclif/core/compare/v1.9.0...v1.9.1) (2022-06-14)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* support CLIs with single top level command ([#426](https://github.com/oclif/core/issues/426)) ([44adb4d](https://github.com/oclif/core/commit/44adb4d387695548a017b38249b0bc3453aedbdf))
|
|
15
|
+
|
|
5
16
|
## [1.9.0](https://github.com/oclif/core/compare/v1.8.2...v1.9.0) (2022-05-20)
|
|
6
17
|
|
|
7
18
|
|
|
@@ -11,14 +11,16 @@ const sw = require('string-width');
|
|
|
11
11
|
const { orderBy } = require('natural-orderby');
|
|
12
12
|
class Table {
|
|
13
13
|
constructor(data, columns, options = {}) {
|
|
14
|
+
var _a, _b;
|
|
14
15
|
this.data = data;
|
|
15
16
|
// assign columns
|
|
16
17
|
this.columns = Object.keys(columns).map((key) => {
|
|
18
|
+
var _a, _b, _c;
|
|
17
19
|
const col = columns[key];
|
|
18
|
-
const extended = col.extended
|
|
19
|
-
const get = col.get
|
|
20
|
+
const extended = (_a = col.extended) !== null && _a !== void 0 ? _a : false;
|
|
21
|
+
const get = (_b = col.get) !== null && _b !== void 0 ? _b : ((row) => row[key]);
|
|
20
22
|
const header = typeof col.header === 'string' ? col.header : (0, util_1.capitalize)(key.replace(/_/g, ' '));
|
|
21
|
-
const minWidth = Math.max(col.minWidth
|
|
23
|
+
const minWidth = Math.max((_c = col.minWidth) !== null && _c !== void 0 ? _c : 0, sw(header) + 1);
|
|
22
24
|
return {
|
|
23
25
|
extended,
|
|
24
26
|
get,
|
|
@@ -34,9 +36,9 @@ class Table {
|
|
|
34
36
|
output: csv ? 'csv' : output,
|
|
35
37
|
extended,
|
|
36
38
|
filter,
|
|
37
|
-
'no-header': options['no-header']
|
|
38
|
-
'no-truncate': options['no-truncate']
|
|
39
|
-
printLine: printLine
|
|
39
|
+
'no-header': (_a = options['no-header']) !== null && _a !== void 0 ? _a : false,
|
|
40
|
+
'no-truncate': (_b = options['no-truncate']) !== null && _b !== void 0 ? _b : false,
|
|
41
|
+
printLine: printLine !== null && printLine !== void 0 ? printLine : ((s) => process.stdout.write(s + '\n')),
|
|
40
42
|
rowStart: ' ',
|
|
41
43
|
sort,
|
|
42
44
|
title,
|
|
@@ -130,9 +132,10 @@ class Table {
|
|
|
130
132
|
return data.map((d) => {
|
|
131
133
|
// eslint-disable-next-line unicorn/prefer-object-from-entries
|
|
132
134
|
return columns.reduce((obj, col) => {
|
|
135
|
+
var _a;
|
|
133
136
|
return {
|
|
134
137
|
...obj,
|
|
135
|
-
[col.key]: d[col.key]
|
|
138
|
+
[col.key]: (_a = d[col.key]) !== null && _a !== void 0 ? _a : '',
|
|
136
139
|
};
|
|
137
140
|
}, {});
|
|
138
141
|
});
|
|
@@ -156,25 +159,18 @@ class Table {
|
|
|
156
159
|
}
|
|
157
160
|
outputTable() {
|
|
158
161
|
// tslint:disable-next-line:no-this-assignment
|
|
159
|
-
const { data,
|
|
162
|
+
const { data, options } = this;
|
|
160
163
|
// column truncation
|
|
161
164
|
//
|
|
162
165
|
// find max width for each column
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
}
|
|
166
|
+
const columns = this.columns.map(c => {
|
|
167
|
+
const maxWidth = Math.max(sw('.'.padEnd(c.minWidth - 1)), sw(c.header), getWidestColumnWith(data, c.key)) + 1;
|
|
168
|
+
return {
|
|
169
|
+
...c,
|
|
170
|
+
maxWidth,
|
|
171
|
+
width: maxWidth,
|
|
172
|
+
};
|
|
173
|
+
});
|
|
178
174
|
// terminal width
|
|
179
175
|
const maxWidth = screen_1.stdtermwidth - 2;
|
|
180
176
|
// truncation logic
|
|
@@ -310,3 +306,12 @@ exports.table = table;
|
|
|
310
306
|
}
|
|
311
307
|
table.flags = flags;
|
|
312
308
|
})(table = exports.table || (exports.table = {}));
|
|
309
|
+
const getWidestColumnWith = (data, columnKey) => {
|
|
310
|
+
return data.reduce((previous, current) => {
|
|
311
|
+
const d = current[columnKey];
|
|
312
|
+
// convert multi-line cell to single longest line
|
|
313
|
+
// for width calculations
|
|
314
|
+
const manyLines = d.split('\n');
|
|
315
|
+
return Math.max(previous, manyLines.length > 1 ? Math.max(...manyLines.map((r) => sw(r))) : sw(d));
|
|
316
|
+
}, 0);
|
|
317
|
+
};
|
package/lib/config/plugin.js
CHANGED
|
@@ -159,7 +159,8 @@ class Plugin {
|
|
|
159
159
|
const p = path.parse(file);
|
|
160
160
|
const topics = p.dir.split('/');
|
|
161
161
|
const command = p.name !== 'index' && p.name;
|
|
162
|
-
|
|
162
|
+
const id = [...topics, command].filter(f => f).join(':');
|
|
163
|
+
return id === '' ? '.' : id;
|
|
163
164
|
});
|
|
164
165
|
this._debug('found commands', ids);
|
|
165
166
|
return ids;
|
package/lib/help/index.js
CHANGED
|
@@ -77,8 +77,10 @@ class Help extends HelpBase {
|
|
|
77
77
|
if (!subject) {
|
|
78
78
|
if (this.config.pjson.oclif.default) {
|
|
79
79
|
const rootCmd = this.config.findCommand(this.config.pjson.oclif.default);
|
|
80
|
-
if (rootCmd)
|
|
80
|
+
if (rootCmd) {
|
|
81
81
|
await this.showCommandHelp(rootCmd);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
82
84
|
}
|
|
83
85
|
await this.showRootHelp();
|
|
84
86
|
return;
|
package/lib/main.js
CHANGED
|
@@ -70,6 +70,11 @@ async function run(argv = process.argv.slice(2), options) {
|
|
|
70
70
|
argvSlice = argv;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
+
// If the the default command is '.' (signifying that the CLI is a single command CLI) and '.' is provided
|
|
74
|
+
// as an argument, we need to add back the '.' to argv since it was stripped out earlier as part of the
|
|
75
|
+
// command id.
|
|
76
|
+
if (config.pjson.oclif.default === '.' && id === '.' && argv[0] === '.')
|
|
77
|
+
argvSlice = ['.', ...argvSlice];
|
|
73
78
|
await config.runCommand(id, argvSlice, cmd);
|
|
74
79
|
}
|
|
75
80
|
exports.run = run;
|