@lark-apaas/miaoda-cli 0.1.2 → 0.1.3-alpha.09899c4
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/README.md +8 -7
- package/dist/api/app/api.js +25 -0
- package/dist/api/app/index.js +15 -0
- package/dist/api/app/schemas.js +79 -0
- package/dist/api/app/types.js +58 -0
- package/dist/api/db/api.js +390 -55
- package/dist/api/db/client.js +65 -25
- package/dist/api/db/index.js +12 -1
- package/dist/api/db/parsers.js +20 -20
- package/dist/api/db/sql-keywords.js +87 -87
- package/dist/api/deploy/api.js +60 -0
- package/dist/api/deploy/index.js +16 -0
- package/dist/api/deploy/schemas.js +105 -0
- package/dist/api/deploy/types.js +22 -0
- package/dist/api/file/api.js +89 -87
- package/dist/api/file/client.js +62 -22
- package/dist/api/file/detect.js +3 -3
- package/dist/api/file/index.js +2 -1
- package/dist/api/file/parsers.js +18 -7
- package/dist/api/index.js +7 -1
- package/dist/api/observability/api.js +52 -0
- package/dist/api/observability/index.js +16 -0
- package/dist/api/observability/schemas.js +60 -0
- package/dist/api/observability/types.js +27 -0
- package/dist/api/plugin/api.js +31 -31
- package/dist/cli/commands/app/index.js +62 -0
- package/dist/cli/commands/db/index.js +600 -59
- package/dist/cli/commands/deploy/index.js +155 -0
- package/dist/cli/commands/file/index.js +91 -63
- package/dist/cli/commands/index.js +10 -6
- package/dist/cli/commands/observability/index.js +240 -0
- package/dist/cli/commands/plugin/index.js +27 -27
- package/dist/cli/commands/shared.js +86 -10
- package/dist/cli/handlers/app/get.js +47 -0
- package/dist/cli/handlers/app/index.js +7 -0
- package/dist/cli/handlers/app/update.js +59 -0
- package/dist/cli/handlers/db/_operator.js +35 -0
- package/dist/cli/handlers/db/audit.js +383 -0
- package/dist/cli/handlers/db/changelog.js +160 -0
- package/dist/cli/handlers/db/data.js +34 -34
- package/dist/cli/handlers/db/index.js +17 -1
- package/dist/cli/handlers/db/migration.js +245 -0
- package/dist/cli/handlers/db/quota.js +68 -0
- package/dist/cli/handlers/db/recovery.js +387 -0
- package/dist/cli/handlers/db/schema.js +35 -36
- package/dist/cli/handlers/db/sql.js +70 -71
- package/dist/cli/handlers/deploy/deploy.js +84 -0
- package/dist/cli/handlers/deploy/error-log.js +60 -0
- package/dist/cli/handlers/deploy/format.js +39 -0
- package/dist/cli/handlers/deploy/get.js +71 -0
- package/dist/cli/handlers/deploy/helpers.js +41 -0
- package/dist/cli/handlers/deploy/history.js +70 -0
- package/dist/cli/handlers/deploy/index.js +14 -0
- package/dist/cli/handlers/deploy/polling.js +162 -0
- package/dist/cli/handlers/file/cp.js +31 -32
- package/dist/cli/handlers/file/index.js +3 -1
- package/dist/cli/handlers/file/ls.js +6 -7
- package/dist/cli/handlers/file/quota.js +66 -0
- package/dist/cli/handlers/file/rm.js +33 -32
- package/dist/cli/handlers/file/sign.js +4 -5
- package/dist/cli/handlers/file/stat.js +11 -11
- package/dist/cli/handlers/observability/analytics.js +212 -0
- package/dist/cli/handlers/observability/helpers.js +66 -0
- package/dist/cli/handlers/observability/index.js +12 -0
- package/dist/cli/handlers/observability/log.js +94 -0
- package/dist/cli/handlers/observability/metric.js +208 -0
- package/dist/cli/handlers/observability/trace.js +102 -0
- package/dist/cli/handlers/plugin/plugin-local.js +53 -53
- package/dist/cli/handlers/plugin/plugin.js +15 -15
- package/dist/cli/help.js +16 -16
- package/dist/main.js +13 -9
- package/dist/utils/args.js +8 -0
- package/dist/utils/colors.js +2 -2
- package/dist/utils/config.js +2 -2
- package/dist/utils/devops-error.js +28 -0
- package/dist/utils/error.js +2 -2
- package/dist/utils/git.js +29 -0
- package/dist/utils/http.js +119 -1
- package/dist/utils/index.js +15 -1
- package/dist/utils/output.js +373 -20
- package/dist/utils/poll.js +35 -0
- package/dist/utils/render.js +27 -27
- package/dist/utils/spinner.js +46 -0
- package/dist/utils/time.js +208 -0
- package/package.json +7 -5
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerDeployCommands = registerDeployCommands;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const shared_1 = require("../../../cli/commands/shared");
|
|
6
|
+
const index_1 = require("../../../cli/handlers/deploy/index");
|
|
7
|
+
const COMMON_TIME_HELP = `
|
|
8
|
+
时间格式:
|
|
9
|
+
- 相对时间:30m(30 分钟前)、1h、2d、1w
|
|
10
|
+
- 日期:2026-04-01(本地时区当日 00:00:00)
|
|
11
|
+
- 本地日期+时间:2026-04-01T10:00:00(按本地时区,T 分隔)
|
|
12
|
+
- 带时区 ISO:2026-04-01T10:00:00Z(UTC)或 2026-04-01T10:00:00+08:00(指定偏移)
|
|
13
|
+
备注:
|
|
14
|
+
1) 不带时区的形式与 pretty 输出闭环(同机器复制粘贴稳定);跨机器请带显式时区。
|
|
15
|
+
2) 必须用 T 分隔日期与时间,禁止空格——shell 会把不带引号的 'YYYY-MM-DD HH:mm:ss' 拆成两个参数。
|
|
16
|
+
`;
|
|
17
|
+
function registerDeployCommands(program) {
|
|
18
|
+
// PRD:`miaoda deploy` 自身即为触发发布;get / history / error-log 是子命令
|
|
19
|
+
const deployCmd = program
|
|
20
|
+
.command('deploy')
|
|
21
|
+
.description('触发发布;支持 --wait 阻塞到终态。子命令:get / history / error-log')
|
|
22
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
23
|
+
.addOption((0, shared_1.branchOption)().hideHelp())
|
|
24
|
+
.option('--wait', '阻塞直到流水线终态', false)
|
|
25
|
+
.option('--timeout <sec>', '--wait 最长等待秒数(默认 300)', parseTimeout, 300)
|
|
26
|
+
.addHelpText('after', `
|
|
27
|
+
不要用异步模式或后台模式调用 deploy(例如 &、nohup、后台 task、detached run,或任何会让命令提前返回的包装方式),否则调用可能提前结束,Agent 会误判发布已完成。
|
|
28
|
+
部署前置检查(Agent 必须执行)
|
|
29
|
+
miaoda deploy 跑的是当前分支的远端 HEAD——本地未 commit / 未 push 的代码不会进发布产物。
|
|
30
|
+
调用前先 \`git status\` + \`git rev-list --count @{u}..HEAD\` 确认;有未提交 / 未推送时:
|
|
31
|
+
- 是本次任务的产物 → 先 commit + push 再 deploy
|
|
32
|
+
- 不能确定意图 → 用 AskUser 跟用户确认(不要默默继续)
|
|
33
|
+
|
|
34
|
+
JSON 输出
|
|
35
|
+
不带 --wait:{"data": {"pipelineTaskID": "..."}}(pipelineTaskID 即 deploy-id)
|
|
36
|
+
带 --wait:data 额外包含 detail(pipeline 终态)
|
|
37
|
+
detail/status 字段为可读字符串;对应 *_code 字段保留 BAM 原始数字枚举。
|
|
38
|
+
|
|
39
|
+
状态确认(Agent 必须执行)
|
|
40
|
+
优先使用 --wait,但无论是否传 --wait,只要 deploy 调用后没有明确的 success / failed / canceled 终态,
|
|
41
|
+
都必须每 2s 轮询一次当前发布状态:拿到 pipelineTaskID 就执行 \`miaoda deploy get <pipelineTaskID> --json\`;
|
|
42
|
+
如果没有拿到 deploy-id 或输出为空,先执行 \`miaoda deploy history --limit 1 --json\` 找到对应发布记录并取得 ID,
|
|
43
|
+
再用这个 ID 每 2s 执行一次 \`miaoda deploy get <ID> --json\`,直到 status 进入终态。
|
|
44
|
+
|
|
45
|
+
示例
|
|
46
|
+
$ miaoda deploy
|
|
47
|
+
$ miaoda deploy --wait --timeout 600
|
|
48
|
+
$ miaoda deploy get 12345
|
|
49
|
+
$ miaoda deploy history --status failed
|
|
50
|
+
`);
|
|
51
|
+
deployCmd.action((0, shared_1.withHelp)(deployCmd, async (rawOpts) => {
|
|
52
|
+
(0, shared_1.rejectCliOverride)(deployCmd, 'appId', 'branch');
|
|
53
|
+
await (0, index_1.handleDeploy)({
|
|
54
|
+
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
55
|
+
branch: rawOpts.branch,
|
|
56
|
+
wait: rawOpts.wait,
|
|
57
|
+
timeout: rawOpts.timeout,
|
|
58
|
+
});
|
|
59
|
+
}));
|
|
60
|
+
registerDeployGet(deployCmd);
|
|
61
|
+
registerDeployHistory(deployCmd);
|
|
62
|
+
registerDeployErrorLog(deployCmd);
|
|
63
|
+
}
|
|
64
|
+
function registerDeployGet(parent) {
|
|
65
|
+
const cmd = parent
|
|
66
|
+
.command('get')
|
|
67
|
+
.description('查看指定发布单的详情')
|
|
68
|
+
.argument('<deploy-id>', '发布单 ID')
|
|
69
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
70
|
+
.addHelpText('after', `
|
|
71
|
+
JSON 输出
|
|
72
|
+
{"data": {"ID": ..., "status": ..., "creator": "...", "createdAt": ..., "updatedAt": ..., ...}, "next_cursor": null, "has_more": false}
|
|
73
|
+
ID 即 deploy-id(== pipelineTaskID)
|
|
74
|
+
data.status 为可读字符串;data.status_code 为 BAM 原始数字枚举。
|
|
75
|
+
|
|
76
|
+
示例
|
|
77
|
+
$ miaoda deploy get 12345
|
|
78
|
+
`);
|
|
79
|
+
cmd.action((0, shared_1.withHelp)(cmd, async (deployId, rawOpts) => {
|
|
80
|
+
(0, shared_1.rejectCliOverride)(cmd, 'appId');
|
|
81
|
+
await (0, index_1.handleDeployGet)({
|
|
82
|
+
deployId,
|
|
83
|
+
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
84
|
+
});
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
function registerDeployHistory(parent) {
|
|
88
|
+
const cmd = parent
|
|
89
|
+
.command('history')
|
|
90
|
+
.description('查询发布历史(按时间倒序,分页)')
|
|
91
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
92
|
+
.addOption(new commander_1.Option('--status <status>', '状态过滤(pipeline 节点状态,大小写不敏感)')
|
|
93
|
+
.choices(['todo', 'running', 'success', 'failed', 'canceled', 'hold_on'])
|
|
94
|
+
.argParser((0, shared_1.caseInsensitiveChoice)(['todo', 'running', 'success', 'failed', 'canceled', 'hold_on'])))
|
|
95
|
+
.option('--since <time>', '起始时间')
|
|
96
|
+
.option('--until <time>', '截止时间')
|
|
97
|
+
.option('--limit <n>', '返回条数上限(1~100)', parseLimit, 50)
|
|
98
|
+
.option('--cursor <token>', '下一页游标')
|
|
99
|
+
.addHelpText('after', `${COMMON_TIME_HELP}
|
|
100
|
+
JSON 输出
|
|
101
|
+
{"data": [...], "next_cursor": "...", "has_more": true|false}
|
|
102
|
+
data[].status 为可读字符串;data[].status_code 为 BAM 原始数字枚举。
|
|
103
|
+
|
|
104
|
+
示例
|
|
105
|
+
$ miaoda deploy history --status failed
|
|
106
|
+
$ miaoda deploy history --since 7d
|
|
107
|
+
`);
|
|
108
|
+
cmd.action((0, shared_1.withHelp)(cmd, async (rawOpts) => {
|
|
109
|
+
(0, shared_1.validateTimeOptions)(rawOpts, 'since', 'until');
|
|
110
|
+
(0, shared_1.rejectCliOverride)(cmd, 'appId');
|
|
111
|
+
await (0, index_1.handleDeployHistory)({
|
|
112
|
+
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
113
|
+
status: rawOpts.status,
|
|
114
|
+
since: rawOpts.since,
|
|
115
|
+
until: rawOpts.until,
|
|
116
|
+
limit: rawOpts.limit,
|
|
117
|
+
cursor: rawOpts.cursor,
|
|
118
|
+
});
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
function registerDeployErrorLog(parent) {
|
|
122
|
+
const cmd = parent
|
|
123
|
+
.command('error-log')
|
|
124
|
+
.description('查询指定发布的错误日志')
|
|
125
|
+
.argument('<deploy-id>', '发布单 ID')
|
|
126
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
127
|
+
.addHelpText('after', `
|
|
128
|
+
JSON 输出
|
|
129
|
+
{"data": [{"jobID": ..., "componentName": ..., "errorMsg": ...}], "next_cursor": null, "has_more": false}
|
|
130
|
+
|
|
131
|
+
示例
|
|
132
|
+
$ miaoda deploy error-log 12345 --json
|
|
133
|
+
`);
|
|
134
|
+
cmd.action((0, shared_1.withHelp)(cmd, async (deployId, rawOpts) => {
|
|
135
|
+
(0, shared_1.rejectCliOverride)(cmd, 'appId');
|
|
136
|
+
await (0, index_1.handleDeployErrorLog)({
|
|
137
|
+
deployId,
|
|
138
|
+
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
139
|
+
});
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
function parseLimit(value) {
|
|
143
|
+
const n = Number(value);
|
|
144
|
+
if (!Number.isFinite(n)) {
|
|
145
|
+
throw new Error(`--limit 必须是数字,收到 '${value}'`);
|
|
146
|
+
}
|
|
147
|
+
return n;
|
|
148
|
+
}
|
|
149
|
+
function parseTimeout(value) {
|
|
150
|
+
const n = Number(value);
|
|
151
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
152
|
+
throw new Error(`--timeout 必须是正数,收到 '${value}'`);
|
|
153
|
+
}
|
|
154
|
+
return n;
|
|
155
|
+
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.registerFileCommands = registerFileCommands;
|
|
4
4
|
const index_1 = require("../../../cli/handlers/file/index");
|
|
5
5
|
const error_1 = require("../../../utils/error");
|
|
6
|
+
const shared_1 = require("../../../cli/commands/shared");
|
|
6
7
|
/**
|
|
7
8
|
* commander option 校验器:把 --limit <n> 解析成正整数(≥1)。
|
|
8
9
|
* 默认值(如 "50")会先经过这里被规范化成 number。
|
|
@@ -12,40 +13,40 @@ const error_1 = require("../../../utils/error");
|
|
|
12
13
|
function parsePositiveInt(raw) {
|
|
13
14
|
const n = Number(raw);
|
|
14
15
|
if (!Number.isInteger(n) || n < 1) {
|
|
15
|
-
throw new error_1.AppError(
|
|
16
|
+
throw new error_1.AppError('ARGS_INVALID', `--limit must be a positive integer (got '${raw}')`);
|
|
16
17
|
}
|
|
17
18
|
return n;
|
|
18
19
|
}
|
|
19
20
|
function registerFileCommands(program) {
|
|
20
21
|
const fileCmd = program
|
|
21
|
-
.command(
|
|
22
|
-
.description(
|
|
23
|
-
|
|
24
|
-
.usage(
|
|
22
|
+
.command('file')
|
|
23
|
+
.description('应用文件存储(TOS)的命令行操作集合。操作对象是 UGC 资源(用户上传的文件、应用运行时\n' +
|
|
24
|
+
'生成的报表 / 导出文件等),不涉及代码仓库里的本地文件。')
|
|
25
|
+
.usage('<command> [flags]');
|
|
25
26
|
fileCmd.action(() => {
|
|
26
27
|
fileCmd.outputHelp();
|
|
27
28
|
});
|
|
28
29
|
fileCmd
|
|
29
|
-
.command(
|
|
30
|
-
.summary(
|
|
31
|
-
.description(
|
|
32
|
-
|
|
33
|
-
.usage(
|
|
34
|
-
.argument(
|
|
35
|
-
.option(
|
|
36
|
-
.option(
|
|
37
|
-
.option(
|
|
38
|
-
.option(
|
|
39
|
-
.option(
|
|
40
|
-
.option(
|
|
41
|
-
.option(
|
|
42
|
-
.option(
|
|
43
|
-
.option(
|
|
44
|
-
.option(
|
|
30
|
+
.command('ls')
|
|
31
|
+
.summary('列出 / 筛选文件')
|
|
32
|
+
.description('列出当前应用存储里的文件,支持按文件名、大小、上传时间筛选,以及游标分页。\n' +
|
|
33
|
+
'默认 pretty 输出省略 download_url(列宽限制),需获取请用 --json。')
|
|
34
|
+
.usage('[query] [flags]')
|
|
35
|
+
.argument('[query]', '筛选值:以 / 开头视为路径精确匹配,否则按文件名精确匹配')
|
|
36
|
+
.option('--path <path>', '按路径精确匹配')
|
|
37
|
+
.option('--name <name>', '按文件名精确匹配')
|
|
38
|
+
.option('--type <mime>', '按 MIME 类型筛选(如 image/png)')
|
|
39
|
+
.option('--size-gt <size>', '文件大小下限(支持 B / KB / MB / GB)')
|
|
40
|
+
.option('--size-lt <size>', '文件大小上限(支持 B / KB / MB / GB)')
|
|
41
|
+
.option('--uploaded-since <time>', '上传时间下限(晚于该时间)')
|
|
42
|
+
.option('--uploaded-until <time>', '上传时间上限(早于该时间)')
|
|
43
|
+
.option('--limit <n>', '单次返回上限(正整数,默认 50)', parsePositiveInt, 50)
|
|
44
|
+
.option('--cursor <token>', '分页游标,从上次响应的 next_cursor 取值')
|
|
45
|
+
.option('--all', '自动翻页返回全部结果')
|
|
45
46
|
.action(async (query, opts) => {
|
|
46
|
-
await (0, index_1.handleFileLs)({ ...opts, query });
|
|
47
|
+
await (0, index_1.handleFileLs)({ ...opts, appId: (0, shared_1.resolveAppId)({}), query });
|
|
47
48
|
})
|
|
48
|
-
.addHelpText(
|
|
49
|
+
.addHelpText('after', `
|
|
49
50
|
Examples:
|
|
50
51
|
$ miaoda file ls
|
|
51
52
|
file_name path size type uploaded_at
|
|
@@ -61,16 +62,16 @@ Examples:
|
|
|
61
62
|
...
|
|
62
63
|
`);
|
|
63
64
|
fileCmd
|
|
64
|
-
.command(
|
|
65
|
-
.summary(
|
|
66
|
-
.description(
|
|
67
|
-
|
|
68
|
-
.usage(
|
|
69
|
-
.argument(
|
|
65
|
+
.command('stat')
|
|
66
|
+
.summary('查看单文件元数据')
|
|
67
|
+
.description('查看单文件完整元数据,含 download_url(应用内消费)。\n' +
|
|
68
|
+
'需要公网可访问的临时链接请用 `file sign` 生成 signed_url。')
|
|
69
|
+
.usage('<file> [flags]')
|
|
70
|
+
.argument('<file>', '文件的路径或文件名(自动识别)')
|
|
70
71
|
.action(async (file, opts) => {
|
|
71
|
-
await (0, index_1.handleFileStat)(file, opts);
|
|
72
|
+
await (0, index_1.handleFileStat)(file, { ...opts, appId: (0, shared_1.resolveAppId)({}) });
|
|
72
73
|
})
|
|
73
|
-
.addHelpText(
|
|
74
|
+
.addHelpText('after', `
|
|
74
75
|
Notes:
|
|
75
76
|
- <file> 可传 path(推荐,全局唯一)或 file_name。
|
|
76
77
|
- file_name 重名时报 AMBIGUOUS_FILE_NAME,需先 \`ls --name\` 拿到 path 再调用。
|
|
@@ -91,19 +92,19 @@ Examples:
|
|
|
91
92
|
hint: Use path instead. Run \`miaoda file ls --name logo.png\` to see candidates.
|
|
92
93
|
`);
|
|
93
94
|
fileCmd
|
|
94
|
-
.command(
|
|
95
|
-
.summary(
|
|
96
|
-
.description(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.usage(
|
|
100
|
-
.argument(
|
|
101
|
-
.argument(
|
|
102
|
-
.option(
|
|
95
|
+
.command('cp')
|
|
96
|
+
.summary('上传或下载文件(方向由路径前缀自动判断)')
|
|
97
|
+
.description('上传或下载文件,方向由 src/dst 路径前缀自动判断:\n' +
|
|
98
|
+
' / 开头 → 远程 TOS 路径\n' +
|
|
99
|
+
' ./、~/、裸文件名 → 本地路径')
|
|
100
|
+
.usage('<src> <dst> [flags]')
|
|
101
|
+
.argument('<src>', '源:本地文件路径或远程文件路径 / 文件名')
|
|
102
|
+
.argument('<dst>', '目标:本地路径或远程路径')
|
|
103
|
+
.option('--rename <name>', '上传后在远端使用的新文件名')
|
|
103
104
|
.action(async (src, dst, opts) => {
|
|
104
|
-
await (0, index_1.handleFileCp)(src, dst, opts);
|
|
105
|
+
await (0, index_1.handleFileCp)(src, dst, { ...opts, appId: (0, shared_1.resolveAppId)({}) });
|
|
105
106
|
})
|
|
106
|
-
.addHelpText(
|
|
107
|
+
.addHelpText('after', `
|
|
107
108
|
Notes:
|
|
108
109
|
- 单文件上限 100 MB,超过请拆分或用 web console 上传。
|
|
109
110
|
- 同目录下允许同 file_name 并存(每次上传生成新的 path),不会因重名失败。
|
|
@@ -138,18 +139,18 @@ Examples:
|
|
|
138
139
|
hint: Split the file, or use the web console for large uploads.
|
|
139
140
|
`);
|
|
140
141
|
fileCmd
|
|
141
|
-
.command(
|
|
142
|
-
.summary(
|
|
143
|
-
.description(
|
|
144
|
-
|
|
145
|
-
.usage(
|
|
146
|
-
.argument(
|
|
147
|
-
.option(
|
|
148
|
-
.option(
|
|
142
|
+
.command('rm')
|
|
143
|
+
.summary('删除一个或多个文件')
|
|
144
|
+
.description('删除一个或多个文件。<file> 可传 path(推荐)或 file_name,可混用。\n' +
|
|
145
|
+
'操作不可撤销(不进回收站),TTY 下默认会要求二次确认。')
|
|
146
|
+
.usage('[paths...] [flags]')
|
|
147
|
+
.argument('[paths...]', '要删除的文件,每项可填路径或文件名(自动识别)')
|
|
148
|
+
.option('-n, --name <name>', '按文件名删除(可重复指定)', (value, prev) => [...(prev ?? []), value])
|
|
149
|
+
.option('-y, --yes', '跳过交互确认;非交互场景必加')
|
|
149
150
|
.action(async (paths, opts) => {
|
|
150
|
-
await (0, index_1.handleFileRm)(paths, opts);
|
|
151
|
+
await (0, index_1.handleFileRm)(paths, { ...opts, appId: (0, shared_1.resolveAppId)({}) });
|
|
151
152
|
})
|
|
152
|
-
.addHelpText(
|
|
153
|
+
.addHelpText('after', `
|
|
153
154
|
Notes:
|
|
154
155
|
- 删除不可撤销,没有回收站。
|
|
155
156
|
- 批量场景下失败项不影响其他项;全部成功退出码 0,任意一项失败退出码 1。
|
|
@@ -158,7 +159,7 @@ Notes:
|
|
|
158
159
|
Examples:
|
|
159
160
|
# 单文件删除(TTY 下需确认)
|
|
160
161
|
$ miaoda file rm /images/brand/1858537546760216.png
|
|
161
|
-
?
|
|
162
|
+
? Are you sure you want to permanently delete '/images/brand/1858537546760216.png'? (y/N) y
|
|
162
163
|
✓ Deleted /images/brand/1858537546760216.png
|
|
163
164
|
|
|
164
165
|
# 批量删除(混用 path 与 file_name)
|
|
@@ -181,18 +182,18 @@ Examples:
|
|
|
181
182
|
hint: Use path instead. Run \`miaoda file ls --name logo.png\` to see candidates.
|
|
182
183
|
`);
|
|
183
184
|
fileCmd
|
|
184
|
-
.command(
|
|
185
|
-
.summary(
|
|
186
|
-
.description(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
.usage(
|
|
190
|
-
.argument(
|
|
191
|
-
.option(
|
|
185
|
+
.command('sign')
|
|
186
|
+
.summary('生成公网可访问的临时下载链接')
|
|
187
|
+
.description('生成 signed_url——公网可直接访问的临时下载链接,带过期时间。\n' +
|
|
188
|
+
'仅在需要浏览器打开 / 公网分享时使用;应用代码内引用文件请用 download_url\n' +
|
|
189
|
+
'(来自 cp 或 stat),无需 sign。')
|
|
190
|
+
.usage('<file> [flags]')
|
|
191
|
+
.argument('<file>', '文件的路径或文件名')
|
|
192
|
+
.option('--expires <duration>', '链接有效期,支持 30m / 24h / 7d 等单位(默认 1d,最长 30d)')
|
|
192
193
|
.action(async (file, opts) => {
|
|
193
|
-
await (0, index_1.handleFileSign)(file, opts);
|
|
194
|
+
await (0, index_1.handleFileSign)(file, { ...opts, appId: (0, shared_1.resolveAppId)({}) });
|
|
194
195
|
})
|
|
195
|
-
.addHelpText(
|
|
196
|
+
.addHelpText('after', `
|
|
196
197
|
Notes:
|
|
197
198
|
- <file> 可传 path(推荐)或 file_name;重名报 AMBIGUOUS_FILE_NAME。
|
|
198
199
|
- signed_url 会过期,不要持久化到数据库。永久引用请用 download_url。
|
|
@@ -208,5 +209,32 @@ Examples:
|
|
|
208
209
|
$ miaoda file sign /images/brand/1858537546760216.png --expires 60d
|
|
209
210
|
Error: Expires duration '60d' exceeds the maximum of 30d
|
|
210
211
|
hint: Maximum allowed value is 30d. Use \`--expires 30d\` for the longest link.
|
|
212
|
+
`);
|
|
213
|
+
fileCmd
|
|
214
|
+
.command('quota')
|
|
215
|
+
.summary('查看文件存储的用量与配额')
|
|
216
|
+
.description('查看文件存储的用量与配额。')
|
|
217
|
+
.usage('[flags]')
|
|
218
|
+
.action(async function () {
|
|
219
|
+
await (0, index_1.handleFileQuota)(this.optsWithGlobals());
|
|
220
|
+
})
|
|
221
|
+
.addHelpText('after', `
|
|
222
|
+
Examples:
|
|
223
|
+
$ miaoda file quota
|
|
224
|
+
Storage: 150 MB / 1 GB (15%)
|
|
225
|
+
Files: 42
|
|
226
|
+
|
|
227
|
+
# --json
|
|
228
|
+
$ miaoda file quota --json
|
|
229
|
+
{
|
|
230
|
+
"data": {
|
|
231
|
+
"storage_used_bytes": 157286400,
|
|
232
|
+
"storage_quota_bytes": 1073741824,
|
|
233
|
+
"usage_percent": 15,
|
|
234
|
+
"files": 42
|
|
235
|
+
},
|
|
236
|
+
"next_cursor": null,
|
|
237
|
+
"has_more": false
|
|
238
|
+
}
|
|
211
239
|
`);
|
|
212
240
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerCommands = registerCommands;
|
|
4
|
-
const index_1 = require("../../cli/commands/
|
|
5
|
-
const index_2 = require("../../cli/commands/
|
|
6
|
-
const index_3 = require("../../cli/commands/
|
|
4
|
+
const index_1 = require("../../cli/commands/file/index");
|
|
5
|
+
const index_2 = require("../../cli/commands/db/index");
|
|
6
|
+
const index_3 = require("../../cli/commands/observability/index");
|
|
7
|
+
const index_4 = require("../../cli/commands/app/index");
|
|
8
|
+
const index_5 = require("../../cli/commands/deploy/index");
|
|
7
9
|
function registerCommands(program) {
|
|
8
|
-
(0, index_1.
|
|
9
|
-
(0, index_2.
|
|
10
|
-
(0, index_3.
|
|
10
|
+
(0, index_1.registerFileCommands)(program);
|
|
11
|
+
(0, index_2.registerDbCommands)(program);
|
|
12
|
+
(0, index_3.registerObservabilityCommands)(program);
|
|
13
|
+
(0, index_4.registerAppCommands)(program);
|
|
14
|
+
(0, index_5.registerDeployCommands)(program);
|
|
11
15
|
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerObservabilityCommands = registerObservabilityCommands;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const shared_1 = require("../../../cli/commands/shared");
|
|
6
|
+
const index_1 = require("../../../cli/handlers/observability/index");
|
|
7
|
+
const COMMON_TIME_HELP = `
|
|
8
|
+
时间格式:
|
|
9
|
+
- 相对时间:30m(30 分钟前)、1h、2d、1w
|
|
10
|
+
- 日期:2026-04-01(本地时区当日 00:00:00)
|
|
11
|
+
- 本地日期+时间:2026-04-01T10:00:00(按本地时区,T 分隔)
|
|
12
|
+
- 带时区 ISO:2026-04-01T10:00:00Z(UTC)或 2026-04-01T10:00:00+08:00(指定偏移)
|
|
13
|
+
备注:
|
|
14
|
+
1) 不带时区的形式与 pretty 输出闭环(同机器复制粘贴稳定);跨机器请带显式时区。
|
|
15
|
+
2) 必须用 T 分隔日期与时间,禁止空格——shell 会把不带引号的 'YYYY-MM-DD HH:mm:ss' 拆成两个参数。
|
|
16
|
+
`;
|
|
17
|
+
function registerObservabilityCommands(program) {
|
|
18
|
+
const obCmd = program
|
|
19
|
+
.command('observability')
|
|
20
|
+
.description('可观测性:查询线上日志、链路、监控指标、运营指标');
|
|
21
|
+
obCmd.action(() => {
|
|
22
|
+
obCmd.outputHelp();
|
|
23
|
+
});
|
|
24
|
+
obCmd.addHelpText('after', `
|
|
25
|
+
作用范围
|
|
26
|
+
仅供 Agent 在妙搭沙箱内调用,查询当前应用的线上观测数据。所有命令为只读。
|
|
27
|
+
应用上下文:--app-id <id> 或环境变量 MIAODA_APP_ID。
|
|
28
|
+
|
|
29
|
+
应用环境
|
|
30
|
+
目前只支持线上环境。
|
|
31
|
+
`);
|
|
32
|
+
registerLog(obCmd);
|
|
33
|
+
registerTrace(obCmd);
|
|
34
|
+
registerMetric(obCmd);
|
|
35
|
+
registerAnalytics(obCmd);
|
|
36
|
+
}
|
|
37
|
+
// ── log ──
|
|
38
|
+
function registerLog(parent) {
|
|
39
|
+
const cmd = parent
|
|
40
|
+
.command('log')
|
|
41
|
+
.description('查询线上运行日志(按时间倒序,分页)')
|
|
42
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
43
|
+
.addOption(new commander_1.Option('--level <level>', '日志级别(大小写不敏感)')
|
|
44
|
+
.choices(['DEBUG', 'INFO', 'WARN', 'ERROR'])
|
|
45
|
+
.argParser((0, shared_1.caseInsensitiveChoice)(['DEBUG', 'INFO', 'WARN', 'ERROR'])))
|
|
46
|
+
.option('--since <time>', '开始时间')
|
|
47
|
+
.option('--until <time>', '截止时间')
|
|
48
|
+
.option('--log-id <id>', '按请求 logid 过滤(attributes.ob_data_id)')
|
|
49
|
+
.option('--trace-id <id>', '按 trace ID 过滤')
|
|
50
|
+
.option('--grep <pattern>', '按关键字模糊搜索 body')
|
|
51
|
+
.option('--module <name>', '按模块名过滤')
|
|
52
|
+
.option('--user-id <user-id>', '按触发用户 ID 过滤')
|
|
53
|
+
.option('--page <path>', '按页面路径过滤')
|
|
54
|
+
.option('--api <path>', '按接口路径过滤')
|
|
55
|
+
.option('--min-duration <ms>', '最小耗时过滤(毫秒)')
|
|
56
|
+
.option('--max-duration <ms>', '最大耗时过滤(毫秒)')
|
|
57
|
+
.option('--limit <n>', '返回条数上限(1~100)', parseLimit, 50)
|
|
58
|
+
.option('--cursor <token>', '下一页游标,从上一次返回的 next_cursor 取值')
|
|
59
|
+
.addHelpText('after', `${COMMON_TIME_HELP}
|
|
60
|
+
JSON 输出
|
|
61
|
+
{"data": [...], "next_cursor": "...", "has_more": true|false}
|
|
62
|
+
|
|
63
|
+
示例
|
|
64
|
+
$ miaoda observability log --since 1h --level error --json
|
|
65
|
+
$ miaoda observability log --log-id log_abc123 --json
|
|
66
|
+
$ miaoda observability log --trace-id 140ebb5ac9b... --json
|
|
67
|
+
$ miaoda observability log --api /api/orders --min-duration 200 --json
|
|
68
|
+
`);
|
|
69
|
+
cmd.action((0, shared_1.withHelp)(cmd, async (rawOpts) => {
|
|
70
|
+
(0, shared_1.validateTimeOptions)(rawOpts, 'since', 'until');
|
|
71
|
+
(0, shared_1.rejectCliOverride)(cmd, 'appId');
|
|
72
|
+
await (0, index_1.handleObservabilityLog)({
|
|
73
|
+
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
74
|
+
level: rawOpts.level,
|
|
75
|
+
since: rawOpts.since,
|
|
76
|
+
until: rawOpts.until,
|
|
77
|
+
logId: rawOpts.logId,
|
|
78
|
+
traceId: rawOpts.traceId,
|
|
79
|
+
grep: rawOpts.grep,
|
|
80
|
+
module: rawOpts.module,
|
|
81
|
+
userId: rawOpts.userId,
|
|
82
|
+
page: rawOpts.page,
|
|
83
|
+
api: rawOpts.api,
|
|
84
|
+
minDuration: rawOpts.minDuration,
|
|
85
|
+
maxDuration: rawOpts.maxDuration,
|
|
86
|
+
limit: rawOpts.limit,
|
|
87
|
+
cursor: rawOpts.cursor,
|
|
88
|
+
});
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
// ── trace ──
|
|
92
|
+
function registerTrace(parent) {
|
|
93
|
+
const traceCmd = parent.command('trace').description('链路追踪:列表 / 详情');
|
|
94
|
+
traceCmd.action(() => {
|
|
95
|
+
traceCmd.outputHelp();
|
|
96
|
+
});
|
|
97
|
+
const listCmd = traceCmd
|
|
98
|
+
.command('list')
|
|
99
|
+
.description('查询线上链路列表(按链路时间倒序,分页)')
|
|
100
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
101
|
+
.option('--since <time>', '开始时间')
|
|
102
|
+
.option('--until <time>', '截止时间')
|
|
103
|
+
.option('--trace-id <id>', '按 trace ID 过滤')
|
|
104
|
+
.option('--root-span <span-name>', '按入口节点关键词过滤')
|
|
105
|
+
.option('--user-id <user-id>', '按触发用户 ID 过滤')
|
|
106
|
+
.option('--limit <n>', '返回条数上限(1~100)', parseLimit, 50)
|
|
107
|
+
.option('--cursor <token>', '下一页游标')
|
|
108
|
+
.addHelpText('after', `${COMMON_TIME_HELP}
|
|
109
|
+
JSON 输出
|
|
110
|
+
{"data": [...], "next_cursor": "...", "has_more": true|false}
|
|
111
|
+
|
|
112
|
+
示例
|
|
113
|
+
$ miaoda observability trace list --since 1h --json
|
|
114
|
+
$ miaoda observability trace list --root-span api-gateway --limit 20 --json
|
|
115
|
+
`);
|
|
116
|
+
listCmd.action((0, shared_1.withHelp)(listCmd, async (rawOpts) => {
|
|
117
|
+
(0, shared_1.validateTimeOptions)(rawOpts, 'since', 'until');
|
|
118
|
+
(0, shared_1.rejectCliOverride)(listCmd, 'appId');
|
|
119
|
+
await (0, index_1.handleObservabilityTraceList)({
|
|
120
|
+
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
121
|
+
since: rawOpts.since,
|
|
122
|
+
until: rawOpts.until,
|
|
123
|
+
traceId: rawOpts.traceId,
|
|
124
|
+
rootSpan: rawOpts.rootSpan,
|
|
125
|
+
userId: rawOpts.userId,
|
|
126
|
+
limit: rawOpts.limit,
|
|
127
|
+
cursor: rawOpts.cursor,
|
|
128
|
+
});
|
|
129
|
+
}));
|
|
130
|
+
const getCmd = traceCmd
|
|
131
|
+
.command('get')
|
|
132
|
+
.description('查询指定链路的完整详情')
|
|
133
|
+
.argument('<trace-id>', '链路 ID')
|
|
134
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
135
|
+
.option('--with-log-severity-count', '返回每个 Span 各日志级别的数量', false)
|
|
136
|
+
.addHelpText('after', `
|
|
137
|
+
JSON 输出
|
|
138
|
+
{"data": {"spans": [...], "isBreak": false}}
|
|
139
|
+
|
|
140
|
+
示例
|
|
141
|
+
$ miaoda observability trace get 140ebb5ac9b55ed50d6ed1090cad4d --json
|
|
142
|
+
|
|
143
|
+
# 报错:链路不存在
|
|
144
|
+
$ miaoda observability trace get not-exist
|
|
145
|
+
Error: Failed to get trace: 500 ...
|
|
146
|
+
hint: 检查 trace-id 是否正确,或链路已超出保留时长
|
|
147
|
+
`);
|
|
148
|
+
getCmd.action((0, shared_1.withHelp)(getCmd, async (traceId, rawOpts) => {
|
|
149
|
+
(0, shared_1.rejectCliOverride)(getCmd, 'appId');
|
|
150
|
+
await (0, index_1.handleObservabilityTraceGet)({
|
|
151
|
+
traceId,
|
|
152
|
+
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
153
|
+
withLogSeverityCount: rawOpts.withLogSeverityCount,
|
|
154
|
+
});
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
// ── metric ──
|
|
158
|
+
function registerMetric(parent) {
|
|
159
|
+
const cmd = parent
|
|
160
|
+
.command('metric')
|
|
161
|
+
.description('查询监控指标:requests / latency / cpu / memory')
|
|
162
|
+
.argument('<metric-name>', '指标名:requests | latency | cpu | memory')
|
|
163
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
164
|
+
.option('--page <path>', '按页面路径过滤(仅对 requests/latency 生效)')
|
|
165
|
+
.option('--api <path>', '按接口路径过滤(仅对 requests/latency 生效)')
|
|
166
|
+
.option('--series <name>', '过滤图表中的某条线:latency 取 p50/p99;requests 取 total/error;缺省返回所有相关线')
|
|
167
|
+
.option('--since <time>', '开始时间')
|
|
168
|
+
.option('--until <time>', '截止时间')
|
|
169
|
+
.addOption(new commander_1.Option('--down-sample <duration>', '降采样粒度(1m=1分钟 / 1h=1小时 / 1d=1天,大小写不敏感)')
|
|
170
|
+
.choices(['1m', '1h', '1d'])
|
|
171
|
+
.argParser((0, shared_1.caseInsensitiveChoice)(['1m', '1h', '1d']))
|
|
172
|
+
.default('1m'))
|
|
173
|
+
.addHelpText('after', `${COMMON_TIME_HELP}
|
|
174
|
+
JSON 输出
|
|
175
|
+
{"data": [{"metricName": "...", "dimensions": {...}, "dataPoints": [...]}], "next_cursor": null, "has_more": false}
|
|
176
|
+
|
|
177
|
+
示例
|
|
178
|
+
$ miaoda observability metric latency --since 1h --json
|
|
179
|
+
$ miaoda observability metric latency --since 1h --series p99 --json
|
|
180
|
+
$ miaoda observability metric requests --api /api/users --json
|
|
181
|
+
$ miaoda observability metric cpu --since 1d --down-sample 1d --json
|
|
182
|
+
`);
|
|
183
|
+
cmd.action((0, shared_1.withHelp)(cmd, async (metricName, rawOpts) => {
|
|
184
|
+
(0, shared_1.validateTimeOptions)(rawOpts, 'since', 'until');
|
|
185
|
+
(0, shared_1.rejectCliOverride)(cmd, 'appId');
|
|
186
|
+
await (0, index_1.handleObservabilityMetric)({
|
|
187
|
+
metricName,
|
|
188
|
+
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
189
|
+
page: rawOpts.page,
|
|
190
|
+
api: rawOpts.api,
|
|
191
|
+
series: rawOpts.series,
|
|
192
|
+
since: rawOpts.since,
|
|
193
|
+
until: rawOpts.until,
|
|
194
|
+
downSample: rawOpts.downSample,
|
|
195
|
+
});
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
// ── analytics ──
|
|
199
|
+
function registerAnalytics(parent) {
|
|
200
|
+
const cmd = parent
|
|
201
|
+
.command('analytics')
|
|
202
|
+
.description('查询运营指标:users(用户数)/ page-view(页面访问)')
|
|
203
|
+
.argument('<analytics-name>', '指标名:users | page-view')
|
|
204
|
+
.addOption((0, shared_1.appIdOption)().hideHelp())
|
|
205
|
+
.option('--page <path>', '按页面路径过滤(仅对 page-view 生效)')
|
|
206
|
+
.option('--series <name>', '过滤图表中的某条线:users 取 active/new/total(兼容 active-users/new-users/total-users);page-view 取 all/desktop/mobile(兼容 all-view/desktop-view/mobile-view)')
|
|
207
|
+
.option('--since <time>', '开始时间')
|
|
208
|
+
.option('--until <time>', '截止时间')
|
|
209
|
+
.option('--granularity <duration>', '时间粒度:day | week | month', 'day')
|
|
210
|
+
.addHelpText('after', `${COMMON_TIME_HELP}
|
|
211
|
+
JSON 输出
|
|
212
|
+
{"data": [{"metricType": "...", "points": [{"timestampNs": "...", "value": ..., "dimensions": {...}}]}], "next_cursor": null, "has_more": false}
|
|
213
|
+
|
|
214
|
+
示例
|
|
215
|
+
$ miaoda observability analytics users --json # 同时返回 active/new/total 三条线
|
|
216
|
+
$ miaoda observability analytics users --series new --since 7d --json
|
|
217
|
+
$ miaoda observability analytics page-view --granularity week --json
|
|
218
|
+
`);
|
|
219
|
+
cmd.action((0, shared_1.withHelp)(cmd, async (analyticsName, rawOpts) => {
|
|
220
|
+
(0, shared_1.validateTimeOptions)(rawOpts, 'since', 'until');
|
|
221
|
+
(0, shared_1.rejectCliOverride)(cmd, 'appId');
|
|
222
|
+
await (0, index_1.handleObservabilityAnalytics)({
|
|
223
|
+
analyticsName,
|
|
224
|
+
appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
|
|
225
|
+
env: rawOpts.env,
|
|
226
|
+
page: rawOpts.page,
|
|
227
|
+
series: rawOpts.series,
|
|
228
|
+
since: rawOpts.since,
|
|
229
|
+
until: rawOpts.until,
|
|
230
|
+
granularity: rawOpts.granularity,
|
|
231
|
+
});
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
function parseLimit(value) {
|
|
235
|
+
const n = Number(value);
|
|
236
|
+
if (!Number.isFinite(n)) {
|
|
237
|
+
throw new Error(`--limit 必须是数字,收到 '${value}'`);
|
|
238
|
+
}
|
|
239
|
+
return n;
|
|
240
|
+
}
|