57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import {
|
|
getEnterprisesDirCandidates,
|
|
loadCorpConfigs,
|
|
loadGlobalConfig,
|
|
resolveGlobalConfigFile,
|
|
saveGlobalConfig
|
|
} from "../../core/config/loader.js";
|
|
import { resolveCorpConfig } from "../../core/config/manager.js";
|
|
import { globalConfigSummary } from "../helpers.js";
|
|
import { parseStateMode, stringOption } from "../parser.js";
|
|
import { printJson } from "../printer.js";
|
|
import type { ParsedArgs } from "../types.js";
|
|
|
|
export function handleConfigCommand(action: string | undefined, maybeName: string | undefined, args: ParsedArgs) {
|
|
if (action === "paths") {
|
|
printJson({
|
|
candidates: getEnterprisesDirCandidates(),
|
|
globalConfigFile: resolveGlobalConfigFile()
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (action === "get" || action === "status") {
|
|
printJson(globalConfigSummary());
|
|
return;
|
|
}
|
|
|
|
if (action === "mode") {
|
|
const mode = maybeName ?? stringOption(args.options.mode);
|
|
if (!mode) {
|
|
printJson(globalConfigSummary());
|
|
return;
|
|
}
|
|
|
|
const stateful = parseStateMode(mode);
|
|
const requestedCorpId = stringOption(args.options.corp);
|
|
const previousConfig = loadGlobalConfig();
|
|
const defaultCorpId = stateful
|
|
? requestedCorpId
|
|
? resolveCorpConfig(
|
|
loadCorpConfigs(),
|
|
{ stateful: true, corpId: requestedCorpId },
|
|
getEnterprisesDirCandidates()
|
|
).id
|
|
: previousConfig.defaultCorpId
|
|
: undefined;
|
|
const config = saveGlobalConfig({
|
|
stateful,
|
|
...(defaultCorpId ? { defaultCorpId } : {})
|
|
});
|
|
printJson(globalConfigSummary(config));
|
|
return;
|
|
}
|
|
|
|
throw new Error(`Unknown config command: ${action ?? ""}. Run 'seal-use help' for available commands.`);
|
|
}
|