- 彻底移除旧内部狭隘命名与垫片包袱,一步到位全仓整体重命名: * session-client.ts ➔ hose-web-session-client.ts (合思 Web 主站会话客户端) * script-engine-client.ts ➔ piper-workflow-client.ts (Piper 工作流引擎客户端) * unity-client.ts ➔ unity-easo-client.ts (Unity / EASO 运营中台与动态集群客户端) * sso-client.ts ➔ sso-auth-client.ts (SSO 与扫码鉴权客户端) - 新增 hose-docs-client.ts 纳为第 7 大通信底座客户端,收口 docs.ekuaibao.com 文档站点通信 - 端正 Piper 工作流引擎定位,完整覆盖工作流创建、保存、发布、108 类节点编排与 Job 流转 - 彻底整体替换全仓 import 引用与测试套件,新增 clients-semantics.test.ts 自动化校验 - 全量自动化测试 150 files 1155 tests 全部通过,类型检查零错误
36 lines
3.0 KiB
TypeScript
36 lines
3.0 KiB
TypeScript
import { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
|
import { printJson, printTable } from "../printer.js";
|
|
import { numberOption, stringOption } from "../parser.js";
|
|
import { createSessionClient } from "../../core/http/hose-web-session-client.js";
|
|
import { searchDimensions, resolveDimension } from "../../domains/dimension/tools.js";
|
|
|
|
export async function handleDimensionCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
|
const corp = runtime.selectedCorp;
|
|
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。");
|
|
const client = await createSessionClient(corp);
|
|
const corpId = corp.corpId || corp.id;
|
|
const action = parsed.action?.toLowerCase() || "list";
|
|
if (["list", "search", "catalogs", undefined].includes(action)) {
|
|
const keyword = stringOption(parsed.options, ["keyword", "q", "query"]) || parsed.args[0];
|
|
const dimensions = await searchDimensions(client, corpId, { name: keyword });
|
|
if (runtime.jsonMode) return { stdout: printJson({ corpId, corpName: corp.name, count: dimensions.length, dimensions }, runtime.outputOptions), stderr: "", exitCode: 0 };
|
|
const rows = dimensions.map((item, index) => [index + 1, item.name, item.code || "-", item.id, item.type || "-", item.active ? "启用" : "停用"]);
|
|
return { stdout: `====== 企业档案维度目录 (企业: ${corp.name} | 共 ${dimensions.length} 个) ======\n${rows.length ? printTable(["#", "名称", "编码", "ID", "类型", "状态"], rows) : "暂无匹配档案维度"}\n`, stderr: "", exitCode: 0 };
|
|
}
|
|
if (["items", "get", "show"].includes(action)) {
|
|
const target = parsed.args[0] || stringOption(parsed.options, ["dimension", "id", "code", "name"]);
|
|
if (!target) throw new Error("请提供档案维度 ID、编码或名称: hose-use dimension items <维度>");
|
|
const result = await resolveDimension(client, corpId, target);
|
|
if (!result) {
|
|
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
|
|
return { stdout: "", stderr: `[NOT FOUND] 未找到档案维度: ${target}\n`, exitCode: 1 };
|
|
}
|
|
const count = numberOption(parsed.options, ["count", "limit", "n"], 100) || 100;
|
|
const items = count >= result.items.length ? result.items : result.items.slice(0, count);
|
|
if (runtime.jsonMode) return { stdout: printJson({ corpId, corpName: corp.name, dimension: result.dimension, count: items.length, items }, runtime.outputOptions), stderr: "", exitCode: 0 };
|
|
const rows = items.map((item, index) => [index + 1, item.name, item.code || "-", item.id, item.parentId || "-", item.fullPath || "-"]);
|
|
return { stdout: `====== 档案项 (维度: ${result.dimension.name} | 共 ${items.length} 条) ======\n${rows.length ? printTable(["#", "名称", "编码", "ID", "上级 ID", "全路径"], rows) : "暂无档案项"}\n`, stderr: "", exitCode: 0 };
|
|
}
|
|
throw new Error(`未知 dimension 子命令: ${action}。支持: list, items <维度 ID|编码|名称>`);
|
|
}
|