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; }