Files
hose-use/src/cli/commands/corps/whoami.ts
T
gitea a797196caa feat(cli): show acting staff identity per enterprise
- hose-use whoami: 逐企业一行显示执行身份(姓名 + 工号 + 来源)
- corps ls: 新增「员工姓名」列
- context/status 保持全局诊断
2026-10-23 17:54:16 +08:00

61 lines
1.8 KiB
TypeScript

import { formatSourceLabel } from "../../printer.js";
import { printJson, printTable } from "../../printer.js";
import type { CliResult, CliRuntime } from "../../types.js";
/**
* `hose-use whoami` — 按企业逐行显示当前执行身份(员工姓名 + 工号)。
*
* 只读本地配置,不发网络请求;写操作前可快速核对“我会以谁的身份执行”。
*/
export async function handleWhoami(_parsed: unknown, runtime: CliRuntime): Promise<CliResult> {
const corps = runtime.corpContext.listCorps();
if (runtime.jsonMode) {
return {
stdout: printJson(
{
activeCorpId: runtime.selectedCorp?.id,
corporations: corps.map((corp: any) => ({
id: corp.id,
name: corp.name,
env: corp.env,
staffId: corp.staffId,
staffName: corp.staffName || null,
source: corp.source,
current: Boolean(corp.current),
})),
},
runtime.outputOptions
),
stderr: "",
exitCode: 0,
};
}
if (corps.length === 0) {
return { stdout: "未配置任何企业,请先运行 hose-use auth login\n", stderr: "", exitCode: 0 };
}
const rows = corps.map((corp: any, index: number) => [
corp.current ? `* ${index + 1}` : ` ${index + 1}`,
corp.name,
corp.id,
corp.staffName || "-",
corp.staffId || "-",
formatSourceLabel(corp.source, corp.hasOpenApi),
]);
const table = printTable(
["#", "企业名称", "企业 ID", "执行身份", "员工工号", "来源"],
rows
);
return {
stdout:
`====== 当前执行身份(共 ${corps.length} 家企业)======\n${table}\n` +
`\n提示: 标记 * 为当前激活企业;写操作前请核对「执行身份」是否为你本人。\n`,
stderr: "",
exitCode: 0,
};
}