68 lines
2.7 KiB
TypeScript
68 lines
2.7 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import type { CorpConfig } from "../../core/config/types.js";
|
|
import type { createSealClient } from "../../core/http/factory.js";
|
|
import { runTool } from "../helpers.js";
|
|
import { jsonObject, stringOption } from "../parser.js";
|
|
import { outputOptions } from "../printer.js";
|
|
import type { ParsedArgs } from "../types.js";
|
|
|
|
export async function handleDeployCommand(
|
|
systemOrAction: string | undefined,
|
|
actionOrTarget: string | undefined,
|
|
maybeTarget: string | undefined,
|
|
client: Awaited<ReturnType<typeof createSealClient>>,
|
|
corp: CorpConfig,
|
|
args: ParsedArgs
|
|
) {
|
|
const isHosecloud = systemOrAction === "hosecloud" || !systemOrAction;
|
|
const action = systemOrAction === "hosecloud" ? actionOrTarget : systemOrAction;
|
|
const target = systemOrAction === "hosecloud" ? maybeTarget : actionOrTarget;
|
|
|
|
if (!isHosecloud && systemOrAction !== "hosecloud") {
|
|
throw new Error(`Unknown deploy target: ${systemOrAction ?? ""}. Currently supported: hosecloud`);
|
|
}
|
|
|
|
if (action === "requirements") {
|
|
await runTool("seal_deploy_hosecloud_requirements", client, corp, {}, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "list") {
|
|
await runTool("seal_deploy_hosecloud_list", client, corp, {}, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "get") {
|
|
const signKey = target ?? stringOption(args.options.signKey) ?? stringOption(args.options["sign-key"]);
|
|
if (!signKey) throw new Error("Usage: seal-use deploy hosecloud get <sign-key>");
|
|
await runTool("seal_deploy_hosecloud_get", client, corp, { signKey }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "status") {
|
|
await runTool("seal_deploy_hosecloud_status", client, corp, {}, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "configure") {
|
|
const rawInput = stringOption(args.options.input);
|
|
const payload = rawInput
|
|
? JSON.parse(readFileSync(rawInput, "utf8"))
|
|
: jsonObject(args.json);
|
|
if (!payload || Object.keys(payload).length === 0) {
|
|
throw new Error("Usage: seal-use deploy hosecloud configure --json '{...}' or --input <file>");
|
|
}
|
|
await runTool("seal_deploy_hosecloud_configure", client, corp, payload, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "sync") {
|
|
const signKey = target ?? stringOption(args.options.signKey) ?? stringOption(args.options["sign-key"]);
|
|
if (!signKey) throw new Error("Usage: seal-use deploy hosecloud sync <sign-key>");
|
|
await runTool("seal_deploy_hosecloud_sync", client, corp, { signKey }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
throw new Error(`Unknown deploy hosecloud action: ${action ?? ""}. Available: requirements, list, get, status, configure, sync.`);
|
|
}
|