@lark-apaas/miaoda-cli 0.1.1 → 0.1.2
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/dist/api/db/api.js +83 -6
- package/dist/api/db/client.js +40 -29
- package/dist/api/db/parsers.js +33 -20
- package/dist/api/db/sql-keywords.js +123 -0
- package/dist/api/file/api.js +78 -24
- package/dist/api/file/client.js +1 -5
- package/dist/api/file/parsers.js +1 -5
- package/dist/api/plugin/api.js +8 -3
- package/dist/cli/commands/db/index.js +1 -0
- package/dist/cli/commands/plugin/index.js +18 -6
- package/dist/cli/commands/shared.js +1 -3
- package/dist/cli/handlers/db/data.js +22 -2
- package/dist/cli/handlers/db/schema.js +22 -8
- package/dist/cli/handlers/db/sql.js +304 -16
- package/dist/cli/handlers/file/cp.js +39 -17
- package/dist/cli/handlers/file/ls.js +1 -3
- package/dist/cli/handlers/file/rm.js +4 -3
- package/dist/cli/handlers/plugin/plugin-local.js +23 -9
- package/dist/cli/handlers/plugin/plugin.js +21 -7
- package/dist/cli/help.js +5 -2
- package/dist/utils/colors.js +98 -0
- package/dist/utils/error.js +11 -0
- package/dist/utils/fuzzy-match.js +91 -0
- package/dist/utils/output.js +59 -5
- package/dist/utils/render.js +61 -41
- package/package.json +10 -2
package/dist/utils/render.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatSize = formatSize;
|
|
4
|
+
exports.formatTime = formatTime;
|
|
5
|
+
exports.visibleWidth = visibleWidth;
|
|
6
|
+
exports.renderAlignedTable = renderAlignedTable;
|
|
7
|
+
exports.renderTsv = renderTsv;
|
|
8
|
+
exports.renderKeyValue = renderKeyValue;
|
|
9
|
+
exports.isStdoutTty = isStdoutTty;
|
|
10
|
+
exports.parseDuration = parseDuration;
|
|
11
|
+
exports.parseSize = parseSize;
|
|
2
12
|
/**
|
|
3
13
|
* CLI 渲染 / 解析工具:跨域共用的格式化、表格渲染、字符串解析。
|
|
4
14
|
*
|
|
@@ -9,18 +19,12 @@
|
|
|
9
19
|
* - 终端探测:isStdoutTty
|
|
10
20
|
* - 字符串解析:parseDuration / parseSize
|
|
11
21
|
*
|
|
22
|
+
* 彩色高亮的语义层封装见 ./colors.ts。表头 / key 标签等结构性元素由本文件
|
|
23
|
+
* 主动调用 colors.c 染色;业务文案的染色(成功/失败 prefix 等)由 handler 自治。
|
|
24
|
+
*
|
|
12
25
|
* JSON envelope 输出(emit / emitOk / emitPaged / emitError)见 ./output.ts。
|
|
13
26
|
*/
|
|
14
|
-
|
|
15
|
-
exports.formatSize = formatSize;
|
|
16
|
-
exports.formatTime = formatTime;
|
|
17
|
-
exports.visibleWidth = visibleWidth;
|
|
18
|
-
exports.renderAlignedTable = renderAlignedTable;
|
|
19
|
-
exports.renderTsv = renderTsv;
|
|
20
|
-
exports.renderKeyValue = renderKeyValue;
|
|
21
|
-
exports.isStdoutTty = isStdoutTty;
|
|
22
|
-
exports.parseDuration = parseDuration;
|
|
23
|
-
exports.parseSize = parseSize;
|
|
27
|
+
const colors_1 = require("./colors");
|
|
24
28
|
/** 将字节数格式化为人类可读(`24 KB` / `2.1 MB` / `1.5 GB`)。 */
|
|
25
29
|
function formatSize(bytes) {
|
|
26
30
|
if (!Number.isFinite(bytes) || bytes < 0)
|
|
@@ -77,20 +81,21 @@ const ANSI_SGR_RE = /\[[0-9;]*m/g;
|
|
|
77
81
|
* 不实现合字 / 零宽字符(ZWJ / 变体选择符)等极端情况,CLI 表格场景够用。
|
|
78
82
|
*/
|
|
79
83
|
function charWidth(cp) {
|
|
80
|
-
if ((cp >= 0x1100 && cp <=
|
|
81
|
-
cp === 0x2329 ||
|
|
82
|
-
|
|
83
|
-
(cp >=
|
|
84
|
-
(cp >=
|
|
85
|
-
(cp >=
|
|
86
|
-
(cp >=
|
|
87
|
-
(cp >=
|
|
88
|
-
(cp >=
|
|
89
|
-
(cp >=
|
|
90
|
-
(cp >=
|
|
91
|
-
(cp >=
|
|
92
|
-
(cp >=
|
|
93
|
-
(cp >=
|
|
84
|
+
if ((cp >= 0x1100 && cp <= 0x115f) || // Hangul Jamo
|
|
85
|
+
cp === 0x2329 ||
|
|
86
|
+
cp === 0x232a ||
|
|
87
|
+
(cp >= 0x2e80 && cp <= 0x303e) || // CJK Radicals / Punctuation
|
|
88
|
+
(cp >= 0x3041 && cp <= 0x33ff) || // Hiragana / Katakana / CJK Symbols
|
|
89
|
+
(cp >= 0x3400 && cp <= 0x4dbf) || // CJK Ext A
|
|
90
|
+
(cp >= 0x4e00 && cp <= 0x9fff) || // CJK Unified
|
|
91
|
+
(cp >= 0xa000 && cp <= 0xa4cf) || // Yi
|
|
92
|
+
(cp >= 0xac00 && cp <= 0xd7a3) || // Hangul Syllables
|
|
93
|
+
(cp >= 0xf900 && cp <= 0xfaff) || // CJK Compat Ideographs
|
|
94
|
+
(cp >= 0xfe30 && cp <= 0xfe4f) || // CJK Compat Forms
|
|
95
|
+
(cp >= 0xff00 && cp <= 0xff60) || // Fullwidth Forms
|
|
96
|
+
(cp >= 0xffe0 && cp <= 0xffe6) ||
|
|
97
|
+
(cp >= 0x20000 && cp <= 0x2fffd) || // CJK Ext B-F
|
|
98
|
+
(cp >= 0x30000 && cp <= 0x3fffd) // CJK Ext G-H
|
|
94
99
|
) {
|
|
95
100
|
return 2;
|
|
96
101
|
}
|
|
@@ -109,7 +114,8 @@ function padVisibleEnd(s, targetWidth) {
|
|
|
109
114
|
const w = visibleWidth(s);
|
|
110
115
|
return w >= targetWidth ? s : s + " ".repeat(targetWidth - w);
|
|
111
116
|
}
|
|
112
|
-
/** 渲染 TTY 对齐表格(多行,列宽按最长内容;ANSI 转义不计入列宽)。
|
|
117
|
+
/** 渲染 TTY 对齐表格(多行,列宽按最长内容;ANSI 转义不计入列宽)。
|
|
118
|
+
* 表头按 spec 用 bold + cyan 染色;ANSI 序列由 visibleWidth 剥离不影响列宽。 */
|
|
113
119
|
function renderAlignedTable(headers, rows) {
|
|
114
120
|
const colWidths = headers.map((h, i) => {
|
|
115
121
|
let w = visibleWidth(h);
|
|
@@ -121,9 +127,15 @@ function renderAlignedTable(headers, rows) {
|
|
|
121
127
|
return w;
|
|
122
128
|
});
|
|
123
129
|
const lines = [];
|
|
124
|
-
lines.push(headers
|
|
130
|
+
lines.push(headers
|
|
131
|
+
.map((h, i) => colors_1.c.header(padVisibleEnd(h, colWidths[i])))
|
|
132
|
+
.join(" ")
|
|
133
|
+
.trimEnd());
|
|
125
134
|
for (const row of rows) {
|
|
126
|
-
lines.push(row
|
|
135
|
+
lines.push(row
|
|
136
|
+
.map((cell, i) => padVisibleEnd(cell || "", colWidths[i]))
|
|
137
|
+
.join(" ")
|
|
138
|
+
.trimEnd());
|
|
127
139
|
}
|
|
128
140
|
return lines.join("\n");
|
|
129
141
|
}
|
|
@@ -136,7 +148,7 @@ function renderTsv(headers, rows) {
|
|
|
136
148
|
}
|
|
137
149
|
return lines.join("\n");
|
|
138
150
|
}
|
|
139
|
-
/** 渲染 key-value 多行(用于 stat 等单条详情)。key
|
|
151
|
+
/** 渲染 key-value 多行(用于 stat 等单条详情)。key 右对齐 + bold cyan 染色。 */
|
|
140
152
|
function renderKeyValue(pairs, isTty) {
|
|
141
153
|
if (pairs.length === 0)
|
|
142
154
|
return "";
|
|
@@ -144,9 +156,7 @@ function renderKeyValue(pairs, isTty) {
|
|
|
144
156
|
return pairs.map(([k, v]) => `${k}\t${v}`).join("\n");
|
|
145
157
|
}
|
|
146
158
|
const keyWidth = Math.max(...pairs.map(([k]) => k.length));
|
|
147
|
-
return pairs
|
|
148
|
-
.map(([k, v]) => `${k.padStart(keyWidth)}: ${v}`)
|
|
149
|
-
.join("\n");
|
|
159
|
+
return pairs.map(([k, v]) => `${colors_1.c.header(k.padStart(keyWidth))}: ${v}`).join("\n");
|
|
150
160
|
}
|
|
151
161
|
/** 通用 isTTY 判定(stdout 是否交互终端)。Node 运行时 isTTY 为 true 或 undefined;TS 类型上 tty.WriteStream 定义为固定 true,绕开做运行时判断。 */
|
|
152
162
|
function isStdoutTty() {
|
|
@@ -162,11 +172,16 @@ function parseDuration(input) {
|
|
|
162
172
|
const n = Number(m[1]);
|
|
163
173
|
const unit = m[2] || "s";
|
|
164
174
|
switch (unit) {
|
|
165
|
-
case "s":
|
|
166
|
-
|
|
167
|
-
case "
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
case "s":
|
|
176
|
+
return n;
|
|
177
|
+
case "m":
|
|
178
|
+
return n * 60;
|
|
179
|
+
case "h":
|
|
180
|
+
return n * 3600;
|
|
181
|
+
case "d":
|
|
182
|
+
return n * 86400;
|
|
183
|
+
default:
|
|
184
|
+
return n;
|
|
170
185
|
}
|
|
171
186
|
}
|
|
172
187
|
/** 解析 size 字符串 `1MB` / `500KB` / `1GB` → 字节。 */
|
|
@@ -178,10 +193,15 @@ function parseSize(input) {
|
|
|
178
193
|
const n = Number(m[1]);
|
|
179
194
|
const unit = (m[2] || "B").toUpperCase();
|
|
180
195
|
switch (unit) {
|
|
181
|
-
case "B":
|
|
182
|
-
|
|
183
|
-
case "
|
|
184
|
-
|
|
185
|
-
|
|
196
|
+
case "B":
|
|
197
|
+
return Math.round(n);
|
|
198
|
+
case "KB":
|
|
199
|
+
return Math.round(n * 1024);
|
|
200
|
+
case "MB":
|
|
201
|
+
return Math.round(n * 1024 * 1024);
|
|
202
|
+
case "GB":
|
|
203
|
+
return Math.round(n * 1024 * 1024 * 1024);
|
|
204
|
+
default:
|
|
205
|
+
return Math.round(n);
|
|
186
206
|
}
|
|
187
207
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/miaoda-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Miaoda 平台命令行工具,面向 Agent 调用",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@lark-apaas/http-client": "^0.1.5",
|
|
29
|
-
"commander": "^13.1.0"
|
|
29
|
+
"commander": "^13.1.0",
|
|
30
|
+
"picocolors": "^1.1.1"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/node": "^22.15.3",
|
|
@@ -34,7 +35,12 @@
|
|
|
34
35
|
"@typescript-eslint/parser": "^8.58.2",
|
|
35
36
|
"@vitest/coverage-v8": "^4.1.4",
|
|
36
37
|
"eslint": "^9.25.1",
|
|
38
|
+
"eslint-config-prettier": "^10.1.8",
|
|
39
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
40
|
+
"eslint-plugin-boundaries": "^6.0.2",
|
|
41
|
+
"eslint-plugin-import": "^2.32.0",
|
|
37
42
|
"husky": "^9.1.7",
|
|
43
|
+
"prettier": "^3.8.3",
|
|
38
44
|
"tsc-alias": "^1.8.11",
|
|
39
45
|
"tsx": "^4.19.4",
|
|
40
46
|
"typescript": "^5.8.3",
|
|
@@ -45,6 +51,8 @@
|
|
|
45
51
|
"build": "bash scripts/build.sh",
|
|
46
52
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
47
53
|
"lint": "eslint src/ --max-warnings 0",
|
|
54
|
+
"format": "prettier --write src/",
|
|
55
|
+
"format:check": "prettier --check src/",
|
|
48
56
|
"test": "vitest run",
|
|
49
57
|
"test:watch": "vitest",
|
|
50
58
|
"test:integration": "vitest run --config vitest.integration.config.ts",
|