72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import { fetchDesktopMenus } from "../../domains/menu/tools.js";
|
|
import { handleAppCommand } from "./app.js";
|
|
import { printJson, printTable } from "../printer.js";
|
|
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
|
|
|
export async function handleMenuCommand(
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime
|
|
): Promise<CliResult> {
|
|
if (!runtime.selectedCorp) {
|
|
return {
|
|
stdout: "",
|
|
stderr: "未选中企业,请先通过 hose-use corps switch 或 --corp 指定企业\n",
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
|
|
const action = parsed.action || "list";
|
|
|
|
switch (action) {
|
|
case "apps":
|
|
case "workbench":
|
|
return handleAppCommand(parsed, runtime);
|
|
|
|
case "list":
|
|
case "ls":
|
|
case "tree": {
|
|
const items = await fetchDesktopMenus(runtime.selectedCorp);
|
|
|
|
if (runtime.jsonMode) {
|
|
return {
|
|
stdout: printJson(
|
|
{
|
|
corpId: runtime.selectedCorp.credentials.corpId,
|
|
corpName: runtime.selectedCorp.name,
|
|
count: items.length,
|
|
menus: items,
|
|
},
|
|
runtime.outputOptions
|
|
),
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
const headers = ["#", "模块 ID", "导航名称", "模块标识 (appId)", "子菜单数", "默认路由"];
|
|
const rows = items.map((m, i) => [
|
|
i + 1,
|
|
m.id,
|
|
m.label,
|
|
m.appId || "-",
|
|
m.children?.length || 0,
|
|
m.href || "-",
|
|
]);
|
|
|
|
const title = `====== [${runtime.selectedCorp.name}] 桌面端主框架导航与模块列表 (共 ${items.length} 个一级导航) ======\n`;
|
|
return {
|
|
stdout: title + printTable(headers, rows) + "\n",
|
|
stderr: "",
|
|
exitCode: 0,
|
|
};
|
|
}
|
|
|
|
default:
|
|
return {
|
|
stdout: "",
|
|
stderr: `未知 menu 子命令: ${action}。支持: list, tree, apps\n用法: hose-use menu list\n`,
|
|
exitCode: 1,
|
|
};
|
|
}
|
|
}
|