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:
gitea committed 2026-11-02 17:56:01 +08:00
1 parent d07336a1b0
commit a0cb09b500
6 files changed
+230 -19

No files matched your search

+86 -4
View File
@@ -3,6 +3,72 @@ import { usageError } from "./errors.js";
export type { HelpTopic } from "./command-metadata.js";
export const HELP_REGISTRY = COMMAND_METADATA;
interface SubActionHelp {
summary: string;
usage: string;
options: string[];
}
const SUB_ACTION_HELP: Record<string, SubActionHelp> = {
"workflow:node:add": {
summary: "向工作流声明式追加任务节点",
usage: "hose-use workflow node add <pipelineId> --type=<类型> [选项]",
options: [
"--type=<type> 节点类型 (如 task-dynamic-delay / code-js2 / http / stop / every)",
"--sleep-time=<秒数> 延迟等待秒数 (针对 task-dynamic-delay,如 5)",
"--set='key=value' 自定义节点属性注入 (如 --set='sleepTime=5')",
"--after=<节点name> 插入在指定节点之后",
"--parent=<容器节点name> 插入指定容器节点内部 (如 every 循环)",
"--label=<标题> 节点类型标题",
"--display-name=<名称> 设计器节点标题(最多 20 字符)",
"--code-file=<脚本路径> 从本地文件导入代码 (推荐)",
"--code=<代码片段> 传入代码字符串 (仅限简短代码)",
"--dry-run 只预览追加变更,不实际写入",
"--yes 确认追加新节点",
],
},
"workflow:node:edit": {
summary: "定向修改工作流任务节点配置",
usage: "hose-use workflow node edit <pipelineId> <nodeNameOrIndex> [选项]",
options: [
"--sleep-time=<秒数> 更新延迟等待秒数 (针对 task-dynamic-delay,如 5)",
"--set='key=value' 定向修改节点自定义属性 (如 --set='sleepTime=5')",
"--display-name=<新名称> 更新设计器节点标题(displayName,最多 20 字符)",
"--code-file=<脚本路径> 从本地文件导入最新脚本 (推荐)",
"--code=<行内代码> 直接传入代码片段",
"--desc=<描述> 更新节点描述",
"--label=<类型标题> 更新节点类型标题",
"--dry-run 只预览变更",
"--yes 确认保存修改",
],
},
"workflow:test": {
summary: "端到端一键调试工作流(替代前端手工调测)",
usage: "hose-use workflow test <pipelineId> [选项]",
options: [
"--flow=<单号> 测试单据编号 (flowCode 或 flowId)",
"--body='{...}' 自定义测试请求体 (针对 Webhook 触发器)",
"--sample=<1|2|3> 直接选用服务器最近接收的数据样本发起测试",
"--timeout=<ms> 轮询超时时间 (毫秒,默认 15000)",
"--auto-publish 调试通过后是否自动发布测试快照 (默认 false)",
"--force, -f 生产环境安全放行 (正式企业 env: prod 调试必须加)",
"--dry-run 只预览测试配置,不发起调用",
"--yes/--confirm 确认执行真实调试",
],
},
"workflow:webhook": {
summary: "向工作流 Webhook 触发器发送测试数据 (别名: webhook-send)",
usage: "hose-use workflow webhook [send] <pipelineId> [选项]",
options: [
"--bill=<单号|单据ID> 抓取真实单据数据作为测试载荷发送",
"--body='{...}' 指定自定义 JSON 请求体",
"--file=<path.json> 从 JSON 文件读取请求体",
"--dry-run 仅预览目标 Webhook 地址与载荷,不实际发送",
"--yes 确认发送网络请求",
],
},
};
export function renderScopedHelp(target: string[]): string {
const resolved = resolveCommandMetadata(target[0]);
if (!resolved) throw usageError(`未找到命令域帮助: ${target.join(" ") || "<empty>"}。运行 hose-use --help 查看全部命令域。`);
@@ -10,10 +76,26 @@ export function renderScopedHelp(target: string[]): string {
const action = resolveCommandAction(area, target[1]);
if (action && !Object.hasOwn(topic.commands, action)) throw usageError(`未找到子命令帮助: ${area} ${target[1]}`);
const lines = [`${area} - ${topic.summary}`, "", `用法: ${topic.usage}`, "", "子命令:"];
if (action && topic.commands[action]) lines.push(` ${action.padEnd(14)} ${topic.commands[action]}`);
else for (const [name, description] of Object.entries(topic.commands)) lines.push(` ${name.padEnd(14)} ${description}`);
if (topic.options?.length) lines.push("", "常用选项:", ...topic.options.map((option) => ` ${option}`));
const subTarget = target[2]?.toLowerCase();
const subKey = subTarget ? `${area}:${action}:${subTarget}` : `${area}:${action}`;
const subHelp = SUB_ACTION_HELP[subKey] || SUB_ACTION_HELP[`${area}:${action}`];
const titlePrefix = subHelp ? `${area} ${action}${subTarget ? ` ${subTarget}` : ""}` : area;
const summaryText = subHelp?.summary || topic.summary;
const usageText = subHelp?.usage || topic.usage;
const commonOpts = subHelp?.options || topic.options;
const lines = [`${titlePrefix} - ${summaryText}`, "", `用法: ${usageText}`, "", "子命令:"];
if (subHelp) {
lines.push(` ${action}${subTarget ? ` ${subTarget}` : ""}`.padEnd(16) + ` ${subHelp.summary}`);
} else if (action && topic.commands[action]) {
lines.push(` ${action.padEnd(14)} ${topic.commands[action]}`);
} else {
for (const [name, description] of Object.entries(topic.commands)) lines.push(` ${name.padEnd(14)} ${description}`);
}
if (commonOpts?.length) lines.push("", "常用选项:", ...commonOpts.map((option) => ` ${option}`));
lines.push("", "支持选项:", ...Object.entries(commandFlags(area, action)).map(([key, kind]) => ` --${key}${kind === "value" ? "=<值>" : kind === "boolean-or-value" ? "[=<值>]" : ""}`));
lines.push("", "提示: 追加 --json 获取机器可解析结果;写操作先用 --dry-run,再用 --yes 或 --confirm 执行。", "更多: hose-use --help");
return lines.join("\n");