Files
hose-use/src/cli/commands/corps/shared.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

31 lines
940 B
TypeScript

import type { CorpConfig } from "../../../core/config/types.js";
import type { CliRuntime } from "../../types.js";
export function isHttpUrl(val?: string): boolean {
return Boolean(val && /^https?:\/\//i.test(val.trim()));
}
export function resolveTargetCorpByArgOrContext(
targetArg: string | undefined,
runtime: CliRuntime
): CorpConfig | null {
if (targetArg && !isHttpUrl(targetArg)) {
try {
return runtime.corpContext.resolve(targetArg);
} catch {
const allCorps = typeof runtime.corpContext.getAllCorps === "function"
? runtime.corpContext.getAllCorps()
: [];
const kw = targetArg.trim().toLowerCase();
const matched = allCorps.find(
(c) =>
c.id.toLowerCase() === kw ||
(c.corpId && c.corpId.toLowerCase() === kw) ||
c.name.toLowerCase().includes(kw)
);
if (matched) return matched;
}
}
return runtime.selectedCorp;
}