Files
hose-use/src/cli/commands/corps/index.ts
T
gitea 52342a9b8e refactor(cli): split commands/corps.ts into directory form mirroring domains layout
Pilot for the command-directory form: 1077-line corps.ts becomes
corps/{index,shared,query,context,link,credentials,probe}.ts with
verbatim code moves. index.ts keeps the dispatch switch plus
re-exports so auth.ts and registry.ts consumers stay source-compatible.

No behavior change: tsc clean, 316 tests pass.
2026-10-04 14:06:25 +08:00

123 lines
4.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { stringOption } from "../../parser.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
import { handleList, handleSearch } from "./query.js";
import { handleSwitch, handleCurrent } from "./context.js";
import { handleGenerateCorpLink, handleAddLink } from "./link.js";
import { handleAddPersistent, handleExtractKeys, handleElevateCorp, handleSyncFromSeal } from "./credentials.js";
import { handleProbeHose, handleHoseStaffs } from "./probe.js";
import { isHttpUrl, resolveTargetCorpByArgOrContext } from "./shared.js";
// 供 auth.ts 等跨命令复用的 handler 与 helper 维持原有命名导出。
export { handleGenerateCorpLink } from "./link.js";
export { handleAddPersistent, handleExtractKeys, handleElevateCorp, handleSyncFromSeal } from "./credentials.js";
export { isHttpUrl, resolveTargetCorpByArgOrContext } from "./shared.js";
export async function handleCorpsCommand(
parsed: CliParsedArgs,
runtime: CliRuntime
): Promise<CliResult> {
const action = parsed.action || "list";
switch (action) {
case "list":
case "ls":
return handleList(parsed, runtime);
case "search":
case "find":
case "query":
case "filter":
return handleSearch(parsed, runtime);
case "switch":
case "use":
return handleSwitch(parsed, runtime);
case "current":
case "whoami":
case "status":
case "active":
return handleCurrent(parsed, runtime);
case "add-link":
case "import-link":
return handleAddLink(parsed, runtime);
case "link": {
const maybeUrl = parsed.args[0] || stringOption(parsed.options, ["url", "link"]);
if (isHttpUrl(maybeUrl)) {
return handleAddLink(parsed, runtime);
}
return handleGenerateCorpLink(parsed, runtime);
}
case "hose-link":
case "auth-link":
case "login-link":
return handleGenerateCorpLink(parsed, runtime);
case "add-persistent":
case "add-hose-persistent":
case "add-openapi":
case "add-hose":
return handleAddPersistent(parsed, runtime);
case "extract-keys":
case "extract-key":
case "hose-extract-keys":
case "extract-hose-keys":
return handleExtractKeys(parsed, runtime);
case "elevate":
case "elevate-hose":
return handleElevateCorp(parsed, runtime);
case "sync-seal":
case "sync-from-seal":
case "import-seal":
return handleSyncFromSeal(parsed, runtime);
case "probe-hose":
return handleProbeHose(parsed, runtime);
case "hose-staffs":
return handleHoseStaffs(parsed, runtime);
case "help":
return handleCorpsHelp();
default:
return {
stdout: "",
stderr: `未知 corps 子命令: ${action}。支持: list, search, switch, current, link, add-link, add-persistent, extract-keys, elevate, sync-seal\n`,
exitCode: 1,
};
}
}
export function printCorpsHelp(): string {
return `
用法:
hose-use corps <子命令> [参数] [选项]
子命令:
list 列出本地已保存的所有企业配置 (别名: ls)
search <关键词> 根据关键词模糊搜索企业(支持 id, name, corpId, staffId, staffName, accountId,别名: find)
switch <企业ID> 切换当前激活的工作企业 (别名: use)
current 查看当前激活的企业配置与凭证详情
link [企业ID|名称] 生成企业合思 Web 免密登录直达链接 (别名: hose-link)
add-link <URL> 从第三方协助/免密链接导入企业凭证(默认自动探测并持久化 OpenAPI 密钥)
add-persistent 通过 OpenAPI 密钥 (appKey + appSecurity) 持久化接入企业 (别名: add-hose-persistent)
extract-keys <URL> 从协助链接提取企业 OpenAPI 密钥(附加 --save 可直接持久化保存)
elevate [企业ID] 为已登录/已导入的企业提取并持久化保存 OpenAPI 密钥
sync-seal [关键词] 从本机 seal-use 配置目录同步企业级 OpenAPI 持久化密钥
选项:
--json, -j 以 JSON 格式输出
--help, -h 查看帮助信息
示例:
hose-use corps list
hose-use corps search 某企业
hose-use corps search 17718556446
hose-use corps switch ID01MCcOgJl1td
hose-use corps link 新转转集团
hose-use corps add-link "<url>" --elevate --yes
hose-use corps add-persistent --app-key=... --app-security=... --yes
`.trim();
}
function handleCorpsHelp(): CliResult {
return {
stdout: printCorpsHelp() + "\n",
stderr: "",
exitCode: 0,
};
}