feat(cli): add corps search command and intuitive aliases

- Implement hose-use corps search <keyword> with case-insensitive fuzzy matching across id, name, corpId, staffId, staffName, and accountId
- Format terminal table output with matched cell brackets, hit labels, active corp markers, and friendly no-match fallback
- Support --json structured output conforming to CliResult specification
- Add intuitive aliases for frequently guessed commands: auth list -> auth accounts, corps find -> corps search, config show -> config paths
- Enhance CorpSummary and CorpContext with corpId, staffName, and getAllCorps
- Add comprehensive unit tests in corps.test.ts, auth.test.ts, and config.test.ts
This commit is contained in:
gitea committed 2026-09-09 14:42:58 +08:00
1 parent 8efce4342a
commit 1cd8901f7a
10 files changed
+630 -11

No files matched your search

+18 -7
View File
@@ -15,17 +15,19 @@ export async function handleConfigCommand(
parsed: CliParsedArgs,
runtime: CliRuntime
): Promise<CliResult> {
const action = parsed.action || "show";
const action = parsed.action || "paths";
switch (action) {
case "show":
case "get":
case "list":
return handleShow(parsed, runtime);
case "paths":
case "path":
case "dirs":
case "show":
case "list":
return handlePaths(parsed, runtime);
case "get":
case "status":
case "info":
return handleShow(parsed, runtime);
case "mode":
return handleMode(parsed, runtime);
case "test-dir":
@@ -36,7 +38,7 @@ export async function handleConfigCommand(
default:
return {
stdout: "",
stderr: `未知 config 子命令: ${action}。支持: show, paths, mode <stateful|stateless>, test-dir <path|--clear>, set <key> <val>\n`,
stderr: `未知 config 子命令: ${action}。支持: paths, show, get, mode <stateful|stateless>, test-dir <path|--clear>, set <key> <val>\n`,
exitCode: 1,
};
}
@@ -227,11 +229,17 @@ async function handlePaths(parsed: CliParsedArgs, runtime: CliRuntime): Promise<
const writableDir = resolveWritableEnterprisesDir();
const configFile = resolveGlobalConfigFile();
const candidates = getEnterprisesDirCandidates();
const globalConfig = loadGlobalConfig();
const currentCorp = runtime.selectedCorp;
const data = {
configFile,
writableDir,
existingDirs,
mode: globalConfig.stateful ? "stateful" : "stateless",
stateful: globalConfig.stateful,
defaultCorpId: globalConfig.defaultCorpId || null,
activeCorp: currentCorp ? { id: currentCorp.id, name: currentCorp.name } : null,
env: {
HOSE_ENTERPRISES_DIR: envDir || null,
HOSE_USER_ENTERPRISES_DIR: envUserDir || null,
@@ -241,13 +249,16 @@ async function handlePaths(parsed: CliParsedArgs, runtime: CliRuntime): Promise<
};
if (runtime.jsonMode) {
return { stdout: printJson(data), stderr: "", exitCode: 0 };
return { stdout: printJson(data, runtime.outputOptions), stderr: "", exitCode: 0 };
}
const output = printKeyValue({
"当前生效配置文件": configFile,
"凭证保存写入目录": writableDir,
"已发现企业目录": existingDirs.length ? existingDirs.join("\n ") : "无 (未发现任何有效企业目录)",
"运行模式 (Mode)": globalConfig.stateful ? "有状态模式 (Stateful - 自动记忆默认企业)" : "无状态模式 (Stateless - 每次需显式传 --corp)",
"默认工作企业": globalConfig.defaultCorpId || "未设置 (使用首个可用企业)",
"当前解析企业": currentCorp ? `${currentCorp.name} (${currentCorp.id})` : "无",
"环境变量指定目录": envDir || "未设置 (HOSE_ENTERPRISES_DIR)",
"全部目录候选链": candidates.join("\n "),
});