feat(cli): 增强工作流子命令专属帮助与参数体验
- 注册 workflow webhook 子命令与别名 (webhook-send, webhooks) - 为 workflow node add 和 node edit 增加 --sleep-time 参数支持与针对性错误提示 - 为 workflow test 增加单号与流程ID输入颠倒时的自纠错能力与 Webhook 引导提示 - 在 help.ts 中增加 node add/edit、test 与 webhook 的多层级精准帮助 - 保持黑盒 CLI 使用体验,杜绝阅读源码定位工作流操作参数
This commit is contained in:
1 parent
d07336a1b0
commit
a0cb09b500
6 files changed
+230
-19
No files matched your search
@@ -18,7 +18,20 @@ export async function handleWorkflowTest(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipeline-id", "pipelineId"]);
|
||||
let pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipeline-id", "pipelineId"]);
|
||||
let flowCodeOrId = stringOption(parsed.options, ["flow", "record", "code", "flow-code", "flowCode", "bill", "entity", "id"]);
|
||||
|
||||
// 智能参数纠错:如果首参数疑似单号/台账记录(非纯数字长ID),且第二个位置参数为工作流ID(16~20位纯数字)
|
||||
if (
|
||||
parsed.args[0] &&
|
||||
parsed.args[1] &&
|
||||
/^\d{16,20}$/.test(parsed.args[1]) &&
|
||||
!/^\d{16,20}$/.test(parsed.args[0])
|
||||
) {
|
||||
flowCodeOrId = parsed.args[0];
|
||||
pipelineId = parsed.args[1];
|
||||
}
|
||||
|
||||
if (!pipelineId) {
|
||||
return {
|
||||
stdout: "",
|
||||
@@ -44,7 +57,6 @@ export async function handleWorkflowTest(
|
||||
};
|
||||
}
|
||||
|
||||
const flowCodeOrId = stringOption(parsed.options, ["flow", "record", "code", "flow-code", "flowCode", "bill", "entity", "id"]);
|
||||
const autoPublish = booleanOption(parsed.options, ["auto-publish", "autoPublish", "publish"]);
|
||||
const timeoutMs = numberOption(parsed.options, ["timeout", "timeout-ms", "timeoutMs"]) ?? 15000;
|
||||
const rawBody = stringOption(parsed.options, ["body", "data", "payload"]);
|
||||
@@ -245,13 +257,16 @@ export async function handleWorkflowTest(
|
||||
...(sampleLines.length > 0
|
||||
? [` --sample=<1|2|3> 直接选用上述服务器最近接收的数据样本发起测试`]
|
||||
: []),
|
||||
` --flow=<单号> 提取指定单据的编码与数据作为 Webhook Payload 发起测试`,
|
||||
` --body='{"key": "value"}' 直接传入自定义 JSON 请求体`,
|
||||
` --file=<payload.json> 从本地 JSON 文件读取请求体`,
|
||||
` --empty 使用空对象 {} 直接发起测试`,
|
||||
"",
|
||||
`示例: hose-use workflow test ${pipelineId} ${
|
||||
sampleLines.length > 0 ? "--sample=1" : `--body='{"code": "TEST-001"}'`
|
||||
`示例:`,
|
||||
` hose-use workflow test ${pipelineId} ${
|
||||
sampleLines.length > 0 ? "--sample=1" : `--flow=B26000148`
|
||||
}`,
|
||||
` hose-use workflow webhook send ${pipelineId} --bill=B26000148 --yes`,
|
||||
].join("\n") + "\n",
|
||||
stderr: "",
|
||||
exitCode: 1,
|
||||
@@ -357,9 +372,13 @@ export async function handleWorkflowTest(
|
||||
].join("\n");
|
||||
return { stdout: `${out}\n`, stderr: "", exitCode: 1 };
|
||||
} catch (err: any) {
|
||||
const errMsg = err.message || String(err);
|
||||
const notFoundHint = errMsg.includes("expected 1 result. got 0")
|
||||
? `\n💡 提示: 云端未查询到工作流 [${pipelineId}] 的调试数据源,请检查工作流 ID 是否有效,或工作流类型是否需要 --flow / --body 等参数。`
|
||||
: "";
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `未指定测试单号 (--flow=<单号>),且拉取候选单据失败: ${err.message || String(err)}\n`,
|
||||
stderr: `未指定测试单号 (--flow=<单号>),且拉取候选单据失败: ${errMsg}${notFoundHint}\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
@@ -489,6 +508,13 @@ export async function handleWorkflowTest(
|
||||
outLines.push(...formatCodeNodeSummariesCard(codeSummaries, report.jobId));
|
||||
}
|
||||
|
||||
if (category === "WEBHOOK" && report.outcome !== "completed") {
|
||||
outLines.push("");
|
||||
outLines.push("💡 [Webhook 流程调试提示]");
|
||||
outLines.push(" 工作流首节点为 Webhook 触发器。若需向合思云端发起真实的 Webhook 事件调度流转,可直接运行:");
|
||||
outLines.push(` hose-use workflow webhook send ${pipelineId}${flowCodeOrId ? ` --bill=${flowCodeOrId}` : ""} --yes`);
|
||||
}
|
||||
|
||||
return {
|
||||
stdout: `${outLines.join("\n")}\n`,
|
||||
stderr: "",
|
||||
|
||||
Reference in new issue
Block a user