@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/args.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.string = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.custom = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("./util/index");
|
|
5
5
|
const node_url_1 = require("node:url");
|
|
6
6
|
function custom(defaults) {
|
|
7
7
|
return (options = {}) => ({
|
|
@@ -14,7 +14,7 @@ function custom(defaults) {
|
|
|
14
14
|
}
|
|
15
15
|
exports.custom = custom;
|
|
16
16
|
exports.boolean = custom({
|
|
17
|
-
parse: async (b) => Boolean(b) && (0,
|
|
17
|
+
parse: async (b) => Boolean(b) && (0, index_1.isNotFalsy)(b),
|
|
18
18
|
});
|
|
19
19
|
exports.integer = custom({
|
|
20
20
|
async parse(input, _, opts) {
|
|
@@ -31,14 +31,14 @@ exports.integer = custom({
|
|
|
31
31
|
exports.directory = custom({
|
|
32
32
|
async parse(input, _, opts) {
|
|
33
33
|
if (opts.exists)
|
|
34
|
-
return (0,
|
|
34
|
+
return (0, index_1.dirExists)(input);
|
|
35
35
|
return input;
|
|
36
36
|
},
|
|
37
37
|
});
|
|
38
38
|
exports.file = custom({
|
|
39
39
|
async parse(input, _, opts) {
|
|
40
40
|
if (opts.exists)
|
|
41
|
-
return (0,
|
|
41
|
+
return (0, index_1.fileExists)(input);
|
|
42
42
|
return input;
|
|
43
43
|
},
|
|
44
44
|
});
|
|
@@ -5,13 +5,13 @@ const stream_1 = require("../stream");
|
|
|
5
5
|
const util_1 = require("../../util");
|
|
6
6
|
const node_util_1 = require("node:util");
|
|
7
7
|
class ActionBase {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
8
|
+
type;
|
|
9
|
+
std = 'stderr';
|
|
10
|
+
stdmocks;
|
|
11
|
+
stdmockOrigs = {
|
|
12
|
+
stdout: stream_1.stdout.write,
|
|
13
|
+
stderr: stream_1.stderr.write,
|
|
14
|
+
};
|
|
15
15
|
start(action, status, opts = {}) {
|
|
16
16
|
this.std = opts.stdout ? 'stdout' : 'stderr';
|
|
17
17
|
const task = { action, status, active: Boolean(this.task && this.task.active) };
|
|
@@ -31,6 +31,7 @@ class ActionBase {
|
|
|
31
31
|
this._stdout(false);
|
|
32
32
|
}
|
|
33
33
|
get globals() {
|
|
34
|
+
;
|
|
34
35
|
global.ux = global.ux || {};
|
|
35
36
|
const globals = global.ux;
|
|
36
37
|
globals.action = globals.action || {};
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const base_1 = require("./base");
|
|
4
4
|
class SimpleAction extends base_1.ActionBase {
|
|
5
|
-
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.type = 'simple';
|
|
8
|
-
}
|
|
5
|
+
type = 'simple';
|
|
9
6
|
_start() {
|
|
10
7
|
if (!this.task)
|
|
11
8
|
return;
|
|
@@ -8,6 +8,7 @@ const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
|
8
8
|
const screen_1 = require("../../screen");
|
|
9
9
|
const spinners_1 = tslib_1.__importDefault(require("./spinners"));
|
|
10
10
|
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
11
|
+
const ansiEscapes = require('ansi-escapes');
|
|
11
12
|
function color(s) {
|
|
12
13
|
if (!supportsColor)
|
|
13
14
|
return s;
|
|
@@ -15,9 +16,12 @@ function color(s) {
|
|
|
15
16
|
return has256 ? `\u001B[38;5;104m${s}${ansi_styles_1.default.reset.open}` : chalk_1.default.magenta(s);
|
|
16
17
|
}
|
|
17
18
|
class SpinnerAction extends base_1.ActionBase {
|
|
19
|
+
type = 'spinner';
|
|
20
|
+
spinner;
|
|
21
|
+
frames;
|
|
22
|
+
frameIndex;
|
|
18
23
|
constructor() {
|
|
19
24
|
super();
|
|
20
|
-
this.type = 'spinner';
|
|
21
25
|
this.frames = this.getFrames();
|
|
22
26
|
this.frameIndex = 0;
|
|
23
27
|
}
|
|
@@ -28,7 +32,7 @@ class SpinnerAction extends base_1.ActionBase {
|
|
|
28
32
|
if (this.spinner)
|
|
29
33
|
clearInterval(this.spinner);
|
|
30
34
|
this._render();
|
|
31
|
-
this.spinner = setInterval(icon => this._render.bind(this)(icon), process.platform === 'win32' ? 500 : 100, 'spinner');
|
|
35
|
+
this.spinner = setInterval((icon) => this._render.bind(this)(icon), process.platform === 'win32' ? 500 : 100, 'spinner');
|
|
32
36
|
const interval = this.spinner;
|
|
33
37
|
interval.unref();
|
|
34
38
|
}
|
|
@@ -55,7 +59,7 @@ class SpinnerAction extends base_1.ActionBase {
|
|
|
55
59
|
}
|
|
56
60
|
getFrames(opts) {
|
|
57
61
|
if (opts?.style)
|
|
58
|
-
return spinners_1.default[
|
|
62
|
+
return spinners_1.default[opts.style].frames;
|
|
59
63
|
return spinners_1.default[process.platform === 'win32' ? 'line' : 'dots2'].frames;
|
|
60
64
|
}
|
|
61
65
|
_render(icon) {
|
|
@@ -71,15 +75,12 @@ class SpinnerAction extends base_1.ActionBase {
|
|
|
71
75
|
_reset() {
|
|
72
76
|
if (!this.output)
|
|
73
77
|
return;
|
|
74
|
-
const ansiEscapes = require('ansi-escapes');
|
|
75
78
|
const lines = this._lines(this.output);
|
|
76
79
|
this._write(this.std, ansiEscapes.cursorLeft + ansiEscapes.cursorUp(lines) + ansiEscapes.eraseDown);
|
|
77
80
|
this.output = undefined;
|
|
78
81
|
}
|
|
79
82
|
_lines(s) {
|
|
80
|
-
return (0, strip_ansi_1.default)(s).split('\n')
|
|
81
|
-
.map(l => Math.ceil(l.length / screen_1.errtermwidth))
|
|
82
|
-
.reduce((c, i) => c + i, 0);
|
|
83
|
+
return (0, strip_ansi_1.default)(s).split('\n').map((l) => Math.ceil(l.length / screen_1.errtermwidth)).reduce((c, i) => c + i, 0);
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
exports.default = SpinnerAction;
|
package/lib/cli-ux/config.js
CHANGED
|
@@ -2,23 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.config = exports.Config = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("../util/index");
|
|
6
6
|
const simple_1 = tslib_1.__importDefault(require("./action/simple"));
|
|
7
7
|
const spinner_1 = tslib_1.__importDefault(require("./action/spinner"));
|
|
8
8
|
const g = global;
|
|
9
9
|
const globals = g.ux || (g.ux = {});
|
|
10
|
-
const actionType = (Boolean(process.stderr.isTTY)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const actionType = (Boolean(process.stderr.isTTY) &&
|
|
11
|
+
!process.env.CI &&
|
|
12
|
+
!['dumb', 'emacs-color'].includes(process.env.TERM) &&
|
|
13
|
+
'spinner') ||
|
|
14
|
+
'simple';
|
|
14
15
|
const Action = actionType === 'spinner' ? spinner_1.default : simple_1.default;
|
|
15
16
|
class Config {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.showStackTrace = true;
|
|
21
|
-
}
|
|
17
|
+
outputLevel = 'info';
|
|
18
|
+
action = new Action();
|
|
19
|
+
errorsHandled = false;
|
|
20
|
+
showStackTrace = true;
|
|
22
21
|
get debug() {
|
|
23
22
|
return globals.debug || process.env.DEBUG === '*';
|
|
24
23
|
}
|
|
@@ -34,7 +33,7 @@ class Config {
|
|
|
34
33
|
}
|
|
35
34
|
exports.Config = Config;
|
|
36
35
|
function fetch() {
|
|
37
|
-
const major = (0,
|
|
36
|
+
const major = (0, index_1.requireJson)(__dirname, '..', '..', 'package.json').version.split('.')[0];
|
|
38
37
|
if (globals[major])
|
|
39
38
|
return globals[major];
|
|
40
39
|
globals[major] = new Config();
|
package/lib/cli-ux/exit.js
CHANGED
package/lib/cli-ux/flush.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.flush = void 0;
|
|
4
|
-
const
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const stream_1 = require("./stream");
|
|
5
6
|
function timeout(p, ms) {
|
|
6
7
|
function wait(ms, unref = false) {
|
|
7
|
-
return new Promise(resolve => {
|
|
8
|
+
return new Promise((resolve) => {
|
|
8
9
|
const t = setTimeout(() => resolve(null), ms);
|
|
9
10
|
if (unref)
|
|
10
11
|
t.unref();
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
|
-
return Promise.race([p, wait(ms, true).then(() =>
|
|
14
|
+
return Promise.race([p, wait(ms, true).then(() => (0, errors_1.error)('timed out'))]);
|
|
14
15
|
}
|
|
15
16
|
async function _flush() {
|
|
16
|
-
const p = new Promise(resolve => {
|
|
17
|
-
|
|
17
|
+
const p = new Promise((resolve) => {
|
|
18
|
+
stream_1.stdout.once('drain', () => resolve(null));
|
|
18
19
|
});
|
|
19
|
-
const flushed =
|
|
20
|
+
const flushed = stream_1.stdout.write('');
|
|
20
21
|
if (flushed)
|
|
21
22
|
return;
|
|
22
23
|
return p;
|
package/lib/cli-ux/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const node_util_1 = require("node:util");
|
|
|
13
13
|
const wait_1 = tslib_1.__importDefault(require("./wait"));
|
|
14
14
|
const hyperlinker = require('hyperlinker');
|
|
15
15
|
class ux {
|
|
16
|
+
static config = config_1.config;
|
|
16
17
|
static get prompt() {
|
|
17
18
|
return uxPrompt.prompt;
|
|
18
19
|
}
|
|
@@ -92,7 +93,6 @@ class ux {
|
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
exports.ux = ux;
|
|
95
|
-
ux.config = config_1.config;
|
|
96
96
|
const { action, annotation, anykey, confirm, debug, done, flush, info, log, progress, prompt, styledHeader, styledJSON, styledObject, table, trace, tree, url, wait, } = ux;
|
|
97
97
|
exports.action = action;
|
|
98
98
|
exports.annotation = annotation;
|
|
@@ -128,7 +128,7 @@ const uxProcessExitHandler = async () => {
|
|
|
128
128
|
};
|
|
129
129
|
// to avoid MaxListenersExceededWarning
|
|
130
130
|
// only attach named listener once
|
|
131
|
-
const uxListener = process.listeners('exit').find(fn => fn.name === uxProcessExitHandler.name);
|
|
131
|
+
const uxListener = process.listeners('exit').find((fn) => fn.name === uxProcessExitHandler.name);
|
|
132
132
|
if (!uxListener) {
|
|
133
133
|
process.once('exit', uxProcessExitHandler);
|
|
134
134
|
}
|
package/lib/cli-ux/list.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renderList = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("../util/index");
|
|
5
5
|
const screen_1 = require("../screen");
|
|
6
6
|
const wordwrap = require('wordwrap');
|
|
7
7
|
function linewrap(length, s) {
|
|
@@ -13,8 +13,8 @@ function renderList(items) {
|
|
|
13
13
|
if (items.length === 0) {
|
|
14
14
|
return '';
|
|
15
15
|
}
|
|
16
|
-
const maxLength = (0,
|
|
17
|
-
const lines = items.map(i => {
|
|
16
|
+
const maxLength = (0, index_1.maxBy)(items, (item) => item[0].length)?.[0].length ?? 0;
|
|
17
|
+
const lines = items.map((i) => {
|
|
18
18
|
let left = i[0];
|
|
19
19
|
let right = i[1];
|
|
20
20
|
if (!right) {
|
package/lib/cli-ux/prompt.js
CHANGED
|
@@ -21,7 +21,7 @@ function normal(options, retries = 100) {
|
|
|
21
21
|
process.stdin.setEncoding('utf8');
|
|
22
22
|
stream_1.stderr.write(options.prompt);
|
|
23
23
|
process.stdin.resume();
|
|
24
|
-
process.stdin.once('data', b => {
|
|
24
|
+
process.stdin.once('data', (b) => {
|
|
25
25
|
if (timer)
|
|
26
26
|
clearTimeout(timer);
|
|
27
27
|
process.stdin.pause();
|
|
@@ -58,8 +58,13 @@ async function single(options) {
|
|
|
58
58
|
}
|
|
59
59
|
function replacePrompt(prompt) {
|
|
60
60
|
const ansiEscapes = require('ansi-escapes');
|
|
61
|
-
stream_1.stderr.write(ansiEscapes.cursorHide +
|
|
62
|
-
|
|
61
|
+
stream_1.stderr.write(ansiEscapes.cursorHide +
|
|
62
|
+
ansiEscapes.cursorUp(1) +
|
|
63
|
+
ansiEscapes.cursorLeft +
|
|
64
|
+
prompt +
|
|
65
|
+
ansiEscapes.cursorDown(1) +
|
|
66
|
+
ansiEscapes.cursorLeft +
|
|
67
|
+
ansiEscapes.cursorShow);
|
|
63
68
|
}
|
|
64
69
|
async function _prompt(name, inputOptions = {}) {
|
|
65
70
|
const prompt = getPrompt(name, inputOptions.type, inputOptions.default);
|
package/lib/cli-ux/stream.js
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
5
|
-
const
|
|
5
|
+
const node_util_1 = require("node:util");
|
|
6
|
+
const stream_1 = require("../stream");
|
|
7
|
+
const info = (output) => stream_1.stdout.write((0, node_util_1.format)(output) + '\n');
|
|
6
8
|
function styledJSON(obj) {
|
|
7
9
|
const json = JSON.stringify(obj, null, 2);
|
|
8
10
|
if (!chalk_1.default.level) {
|
|
9
|
-
|
|
11
|
+
info(json);
|
|
10
12
|
return;
|
|
11
13
|
}
|
|
12
14
|
const cardinal = require('cardinal');
|
|
13
15
|
const theme = require('cardinal/themes/jq');
|
|
14
|
-
|
|
16
|
+
info(cardinal.highlight(json, { json: true, theme }));
|
|
15
17
|
}
|
|
16
18
|
exports.default = styledJSON;
|
|
@@ -5,14 +5,14 @@ const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
|
5
5
|
const node_util_1 = require("node:util");
|
|
6
6
|
function styledObject(obj, keys) {
|
|
7
7
|
const output = [];
|
|
8
|
-
const keyLengths = Object.keys(obj).map(key => key.toString().length);
|
|
8
|
+
const keyLengths = Object.keys(obj).map((key) => key.toString().length);
|
|
9
9
|
const maxKeyLength = Math.max(...keyLengths) + 2;
|
|
10
10
|
function pp(obj) {
|
|
11
11
|
if (typeof obj === 'string' || typeof obj === 'number')
|
|
12
12
|
return obj;
|
|
13
13
|
if (typeof obj === 'object') {
|
|
14
14
|
return Object.keys(obj)
|
|
15
|
-
.map(k => k + ': ' + (0, node_util_1.inspect)(obj[k]))
|
|
15
|
+
.map((k) => k + ': ' + (0, node_util_1.inspect)(obj[k]))
|
|
16
16
|
.join(', ');
|
|
17
17
|
}
|
|
18
18
|
return (0, node_util_1.inspect)(obj);
|
|
@@ -13,6 +13,9 @@ const stream_1 = require("../stream");
|
|
|
13
13
|
const screen_1 = require("../../screen");
|
|
14
14
|
const string_width_1 = tslib_1.__importDefault(require("string-width"));
|
|
15
15
|
class Table {
|
|
16
|
+
data;
|
|
17
|
+
options;
|
|
18
|
+
columns;
|
|
16
19
|
constructor(data, columns, options = {}) {
|
|
17
20
|
this.data = data;
|
|
18
21
|
// assign columns
|
|
@@ -48,7 +51,7 @@ class Table {
|
|
|
48
51
|
}
|
|
49
52
|
display() {
|
|
50
53
|
// build table rows from input array data
|
|
51
|
-
let rows = this.data.map(d => {
|
|
54
|
+
let rows = this.data.map((d) => {
|
|
52
55
|
const row = {};
|
|
53
56
|
for (const col of this.columns) {
|
|
54
57
|
let val = col.get(d);
|
|
@@ -77,9 +80,9 @@ class Table {
|
|
|
77
80
|
// sort rows
|
|
78
81
|
if (this.options.sort) {
|
|
79
82
|
const sorters = this.options.sort.split(',');
|
|
80
|
-
const sortHeaders = sorters.map(k => k[0] === '-' ? k.slice(1) : k);
|
|
81
|
-
const sortKeys = this.filterColumnsFromHeaders(sortHeaders).map(c => (
|
|
82
|
-
const sortKeysOrder = sorters.map(k => k[0] === '-' ? 'desc' : 'asc');
|
|
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'));
|
|
83
86
|
rows = (0, natural_orderby_1.orderBy)(rows, sortKeys, sortKeysOrder);
|
|
84
87
|
}
|
|
85
88
|
// and filter columns
|
|
@@ -89,7 +92,7 @@ class Table {
|
|
|
89
92
|
}
|
|
90
93
|
else if (!this.options.extended) {
|
|
91
94
|
// show extented columns/properties
|
|
92
|
-
this.columns = this.columns.filter(c => !c.extended);
|
|
95
|
+
this.columns = this.columns.filter((c) => !c.extended);
|
|
93
96
|
}
|
|
94
97
|
this.data = rows;
|
|
95
98
|
switch (this.options.output) {
|
|
@@ -111,27 +114,27 @@ class Table {
|
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
findColumnFromHeader(header) {
|
|
114
|
-
return this.columns.find(c => c.header.toLowerCase() === header.toLowerCase());
|
|
117
|
+
return this.columns.find((c) => c.header.toLowerCase() === header.toLowerCase());
|
|
115
118
|
}
|
|
116
119
|
filterColumnsFromHeaders(filters) {
|
|
117
120
|
// unique
|
|
118
|
-
filters = [...
|
|
121
|
+
filters = [...new Set(filters)];
|
|
119
122
|
const cols = [];
|
|
120
123
|
for (const f of filters) {
|
|
121
|
-
const c = this.columns.find(c => c.header.toLowerCase() === f.toLowerCase());
|
|
124
|
+
const c = this.columns.find((c) => c.header.toLowerCase() === f.toLowerCase());
|
|
122
125
|
if (c)
|
|
123
126
|
cols.push(c);
|
|
124
127
|
}
|
|
125
128
|
return cols;
|
|
126
129
|
}
|
|
127
130
|
getCSVRow(d) {
|
|
128
|
-
const values = this.columns.map(col => d[col.key] || '');
|
|
131
|
+
const values = this.columns.map((col) => d[col.key] || '');
|
|
129
132
|
const lineToBeEscaped = values.find((e) => e.includes('"') || e.includes('\n') || e.includes('\r\n') || e.includes('\r') || e.includes(','));
|
|
130
|
-
return values.map(e => lineToBeEscaped ? `"${e.replace('"', '""')}"` : e);
|
|
133
|
+
return values.map((e) => (lineToBeEscaped ? `"${e.replace('"', '""')}"` : e));
|
|
131
134
|
}
|
|
132
135
|
resolveColumnsToObjectArray() {
|
|
133
136
|
const { data, columns } = this;
|
|
134
|
-
return data.map((d) => Object.fromEntries(columns.map(col => [col.key, d[col.key] ?? ''])));
|
|
137
|
+
return data.map((d) => Object.fromEntries(columns.map((col) => [col.key, d[col.key] ?? ''])));
|
|
135
138
|
}
|
|
136
139
|
outputJSON() {
|
|
137
140
|
this.options.printLine(JSON.stringify(this.resolveColumnsToObjectArray(), undefined, 2));
|
|
@@ -142,7 +145,7 @@ class Table {
|
|
|
142
145
|
outputCSV() {
|
|
143
146
|
const { data, columns, options } = this;
|
|
144
147
|
if (!options['no-header']) {
|
|
145
|
-
options.printLine(columns.map(c => c.header).join(','));
|
|
148
|
+
options.printLine(columns.map((c) => c.header).join(','));
|
|
146
149
|
}
|
|
147
150
|
for (const d of data) {
|
|
148
151
|
const row = this.getCSVRow(d);
|
|
@@ -154,7 +157,7 @@ class Table {
|
|
|
154
157
|
// column truncation
|
|
155
158
|
//
|
|
156
159
|
// find max width for each column
|
|
157
|
-
const columns = this.columns.map(c => {
|
|
160
|
+
const columns = this.columns.map((c) => {
|
|
158
161
|
const maxWidth = Math.max((0, string_width_1.default)('.'.padEnd(c.minWidth - 1)), (0, string_width_1.default)(c.header), getWidestColumnWith(data, c.key)) + 1;
|
|
159
162
|
return {
|
|
160
163
|
...c,
|
|
@@ -170,7 +173,7 @@ class Table {
|
|
|
170
173
|
if (options['no-truncate'] || (!stream_1.stdout.isTTY && !process.env.CLI_UX_SKIP_TTY_CHECK))
|
|
171
174
|
return;
|
|
172
175
|
// don't shorten if there is enough screen width
|
|
173
|
-
const dataMaxWidth = (0, util_1.sumBy)(columns, c => c.width);
|
|
176
|
+
const dataMaxWidth = (0, util_1.sumBy)(columns, (c) => c.width);
|
|
174
177
|
const overWidth = dataMaxWidth - maxWidth;
|
|
175
178
|
if (overWidth <= 0)
|
|
176
179
|
return;
|
|
@@ -181,16 +184,18 @@ class Table {
|
|
|
181
184
|
// if sum(minWidth's) is greater than term width
|
|
182
185
|
// nothing can be done so
|
|
183
186
|
// display all as minWidth
|
|
184
|
-
const dataMinWidth = (0, util_1.sumBy)(columns, c => c.minWidth);
|
|
187
|
+
const dataMinWidth = (0, util_1.sumBy)(columns, (c) => c.minWidth);
|
|
185
188
|
if (dataMinWidth >= maxWidth)
|
|
186
189
|
return;
|
|
187
190
|
// some wiggle room left, add it back to "needy" columns
|
|
188
191
|
let wiggleRoom = maxWidth - dataMinWidth;
|
|
189
|
-
const needyCols = columns
|
|
192
|
+
const needyCols = columns
|
|
193
|
+
.map((c) => ({ key: c.key, needs: c.maxWidth - c.width }))
|
|
194
|
+
.sort((a, b) => a.needs - b.needs);
|
|
190
195
|
for (const { key, needs } of needyCols) {
|
|
191
196
|
if (!needs)
|
|
192
197
|
continue;
|
|
193
|
-
const col = columns.find(c => key === c.key);
|
|
198
|
+
const col = columns.find((c) => key === c.key);
|
|
194
199
|
if (!col)
|
|
195
200
|
continue;
|
|
196
201
|
if (wiggleRoom > needs) {
|
|
@@ -250,9 +255,9 @@ class Table {
|
|
|
250
255
|
let d = row[col.key];
|
|
251
256
|
d = d.split('\n')[i] || '';
|
|
252
257
|
const visualWidth = (0, string_width_1.default)(d);
|
|
253
|
-
const colorWidth =
|
|
258
|
+
const colorWidth = d.length - visualWidth;
|
|
254
259
|
let cell = d.padEnd(width + colorWidth);
|
|
255
|
-
if (
|
|
260
|
+
if (cell.length - colorWidth > width || visualWidth === width) {
|
|
256
261
|
// truncate the cell, preserving ANSI escape sequences, and keeping
|
|
257
262
|
// into account the width of fullwidth unicode characters
|
|
258
263
|
cell = (0, slice_ansi_1.default)(cell, 0, width - 2) + '… ';
|
|
@@ -274,7 +279,7 @@ exports.table = table;
|
|
|
274
279
|
(function (table) {
|
|
275
280
|
table.Flags = {
|
|
276
281
|
columns: F.string({ exclusive: ['extended'], description: 'only show provided columns (comma-separated)' }),
|
|
277
|
-
sort: F.string({ description:
|
|
282
|
+
sort: F.string({ description: "property to sort by (prepend '-' for descending)" }),
|
|
278
283
|
filter: F.string({ description: 'filter property by partial string matching, ex: name=foo' }),
|
|
279
284
|
csv: F.boolean({ exclusive: ['no-truncate'], description: 'output is csv format [alias: --output=csv]' }),
|
|
280
285
|
output: F.string({
|
|
@@ -293,6 +298,7 @@ exports.table = table;
|
|
|
293
298
|
const e = (opts.except && typeof opts.except === 'string' ? [opts.except] : opts.except) || [];
|
|
294
299
|
for (const key of o) {
|
|
295
300
|
if (!e.includes(key)) {
|
|
301
|
+
;
|
|
296
302
|
f[key] = table.Flags[key];
|
|
297
303
|
}
|
|
298
304
|
}
|
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Tree = void 0;
|
|
4
4
|
const treeify = require('object-treeify');
|
|
5
5
|
class Tree {
|
|
6
|
-
|
|
7
|
-
this.nodes = {};
|
|
8
|
-
}
|
|
6
|
+
nodes = {};
|
|
9
7
|
insert(child, value = new Tree()) {
|
|
10
8
|
this.nodes[child] = value;
|
|
11
9
|
return this;
|
package/lib/cli-ux/wait.js
CHANGED
package/lib/command.d.ts
CHANGED
|
@@ -65,13 +65,7 @@ export declare abstract class Command {
|
|
|
65
65
|
*/
|
|
66
66
|
static examples: Command.Example[];
|
|
67
67
|
static hasDynamicHelp: boolean;
|
|
68
|
-
|
|
69
|
-
protected static _enableJsonFlag: boolean;
|
|
70
|
-
static get enableJsonFlag(): boolean;
|
|
71
|
-
static set enableJsonFlag(value: boolean);
|
|
72
|
-
static get '--'(): boolean;
|
|
73
|
-
static set '--'(value: boolean);
|
|
74
|
-
get passThroughEnabled(): boolean;
|
|
68
|
+
static enableJsonFlag: boolean;
|
|
75
69
|
/**
|
|
76
70
|
* instantiate and run the command
|
|
77
71
|
*
|
|
@@ -81,13 +75,9 @@ export declare abstract class Command {
|
|
|
81
75
|
* @returns {Promise<unknown>} result
|
|
82
76
|
*/
|
|
83
77
|
static run<T extends Command>(this: new (argv: string[], config: Config) => T, argv?: string[], opts?: LoadOptions): Promise<ReturnType<T['run']>>;
|
|
84
|
-
|
|
85
|
-
static get baseFlags(): FlagInput;
|
|
86
|
-
static set baseFlags(flags: FlagInput);
|
|
78
|
+
static baseFlags: FlagInput;
|
|
87
79
|
/** A hash of flags for the command */
|
|
88
|
-
|
|
89
|
-
static get flags(): FlagInput;
|
|
90
|
-
static set flags(flags: FlagInput);
|
|
80
|
+
static flags: FlagInput;
|
|
91
81
|
id: string | undefined;
|
|
92
82
|
protected debug: (...args: any[]) => void;
|
|
93
83
|
constructor(argv: string[], config: Config);
|
|
@@ -164,7 +154,9 @@ export declare namespace Command {
|
|
|
164
154
|
};
|
|
165
155
|
type Flag = IFlag<any>;
|
|
166
156
|
namespace Flag {
|
|
167
|
-
type Cached = Omit<Flag, 'parse' | 'input'> & (BooleanFlagProps | OptionFlagProps)
|
|
157
|
+
type Cached = Omit<Flag, 'parse' | 'input'> & (BooleanFlagProps | OptionFlagProps) & {
|
|
158
|
+
hasDynamicHelp?: boolean;
|
|
159
|
+
};
|
|
168
160
|
type Any = Flag | Cached;
|
|
169
161
|
}
|
|
170
162
|
type Arg = IArg<any>;
|