feat: unify CLI dry-run and write confirmation

This commit is contained in:
gitea committed 2026-09-11 16:53:14 +08:00
1 parent 639aaa9271
commit 45eb83a609
19 files changed
+506 -71

No files matched your search

+30
View File
@@ -2,6 +2,7 @@ import { ApprovalRepository, parseRuleBody } from "../../domains/approval/index.
import { booleanOption, stringOption } from "../parser.js";
import { printJson, printTable } from "../printer.js";
import { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../mutation.js";
export async function handleRuleCommand(
parsed: CliParsedArgs,
@@ -205,6 +206,22 @@ export async function handleRuleCommand(
if (!scope) throw new Error("缺少适用场景/索引参数:请输入索引名称或使用 --scope 指定");
if (!body) throw new Error("缺少规约正文参数:请输入正文或使用 --body 指定,须包含 [动作句式]{硬性|弹性|建议|特殊}");
// 先做纯函数校验,让调用方在确认前就能修正格式错误。
parseRuleBody(body);
requireMutationConfirmation(
parsed,
runtime,
"新增审批规则",
`hose-use rule add --scope=${scope} --body='${body}' --yes`
);
if (isDryRun(parsed, runtime)) {
return mutationPreview(parsed, runtime, "新增审批规则", scope, {
scope,
body,
status: "active",
});
}
const rule = repo.createRule({
scope,
@@ -240,6 +257,19 @@ export async function handleRuleCommand(
ruleId = found.id;
}
requireMutationConfirmation(
parsed,
runtime,
"删除审批规则",
`hose-use rule delete ${ruleId} --yes`
);
if (isDryRun(parsed, runtime)) {
return mutationPreview(parsed, runtime, "删除审批规则", ruleId, {
id: ruleId,
irreversible: true,
});
}
const deleted = repo.deleteRule(ruleId);
if (runtime.jsonMode) {
return {