feat(config): 实现有状态与无状态 (stateful/stateless) 运行模式无缝切换与企业解析
This commit is contained in:
1 parent
e7aa8a86cc
commit
189415cdac
6 files changed
+293
-16
No files matched your search
+30
-8
@@ -1,23 +1,45 @@
|
||||
import readline from "readline";
|
||||
import { loadCorpConfigs } from "../core/config/loader.js";
|
||||
import { CorpContext } from "../core/config/manager.js";
|
||||
import { loadCorpConfigs, loadGlobalConfig } from "../core/config/loader.js";
|
||||
import { CorpContext, resolveCorpConfig } from "../core/config/manager.js";
|
||||
import { CorpConfig } from "../core/config/types.js";
|
||||
import { createEkbClient } from "../core/auth/ekb.js";
|
||||
import { getEasoClient } from "../core/auth/easo.js";
|
||||
import { CliRuntime } from "./types.js";
|
||||
|
||||
export function initCorpRuntime(corpIdOption?: string, jsonMode: boolean = false): CliRuntime {
|
||||
export function initCorpRuntime(
|
||||
options: {
|
||||
corpId?: string;
|
||||
stateless?: boolean;
|
||||
stateful?: boolean;
|
||||
jsonMode?: boolean;
|
||||
} = {}
|
||||
): CliRuntime {
|
||||
const corps = loadCorpConfigs();
|
||||
const corpContext = new CorpContext(corps);
|
||||
const globalConfig = loadGlobalConfig();
|
||||
|
||||
if (corpIdOption) {
|
||||
corpContext.switchCorp(corpIdOption);
|
||||
// 命令行参数 --stateless / --stateful 具有最高优先级
|
||||
const isStateful = options.stateless
|
||||
? false
|
||||
: options.stateful
|
||||
? true
|
||||
: globalConfig.stateful;
|
||||
|
||||
const corpContext = new CorpContext(corps, {
|
||||
stateful: isStateful,
|
||||
defaultCorpId: globalConfig.defaultCorpId,
|
||||
});
|
||||
|
||||
let selectedCorp: CorpConfig | null = null;
|
||||
try {
|
||||
selectedCorp = corpContext.resolve(options.corpId);
|
||||
} catch {
|
||||
selectedCorp = null;
|
||||
}
|
||||
|
||||
return {
|
||||
corpContext,
|
||||
selectedCorp: corpContext.getCurrent(),
|
||||
jsonMode,
|
||||
selectedCorp,
|
||||
jsonMode: options.jsonMode ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user