Files
hose-use/src/cli/commands/bill/index.ts
T

111 lines
2.7 KiB
TypeScript

import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
import { createBillActionContext } from "./context.js";
import { handleApprove, handleReject, handleTransfer, handleAddNode, handleComment } from "./approve.js";
import { handleList, handleGet, handleTrace } from "./search.js";
import { handleFlow, handleRisk, handleBudget } from "./flow.js";
import { handleRefs, handleRelations, handleAttachments, handleDownload } from "./related.js";
import { handleSchema, handleLink, handleSpec } from "./meta.js";
export async function handleBillCommand(
parsed: CliParsedArgs,
runtime: CliRuntime
): Promise<CliResult> {
const corp = runtime.selectedCorp;
if (!corp) {
throw new Error(
"未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。"
);
}
const ctx = createBillActionContext(parsed, runtime);
const action = ctx.action;
switch (action) {
case "approve":
case "agree":
return handleApprove(ctx);
case "reject":
case "deny":
return handleReject(ctx);
case "transfer":
case "shift":
return handleTransfer(ctx);
case "add-node":
case "addnode":
case "countersign":
case "counter-sign":
return handleAddNode(ctx);
case "comment":
case "remark":
return handleComment(ctx);
case "list":
case "search":
case undefined:
return handleList(ctx);
case "get":
case "show":
case "find":
return handleGet(ctx);
case "trace":
case "inspect":
case "diagnose":
return handleTrace(ctx);
case "schema":
case "schemas":
case "entities":
return handleSchema(ctx);
case "flow":
case "records":
case "timeline":
return handleFlow(ctx);
case "risk":
case "review":
case "warnings":
return handleRisk(ctx);
case "budget":
case "budgets":
return handleBudget(ctx);
case "refs":
case "references":
case "resolve":
return handleRefs(ctx);
case "relations":
case "relation":
case "links":
return handleRelations(ctx);
case "attachments":
case "attachment":
case "files":
return handleAttachments(ctx);
case "download":
case "file-download":
return handleDownload(ctx);
case "link":
case "url":
return handleLink(ctx);
case "spec":
case "specification":
return handleSpec(ctx);
default:
throw new Error(`未知 bill 子命令: ${action}。支持: list, get <单号> [--risk], trace <单号|ID>, spec <specificationId>, refs <单号>, relations <单号>, attachments <单号>, download <单号>, flow <单号>, risk <单号>, budget <单号>, schema, link <单号>`);
}
}