Files
kuber/command/down.ts
T
2026-09-03 11:28:30 +07:00

52 lines
1.2 KiB
TypeScript

import { defineCommand } from "citty";
import { Listr } from "listr2";
import { apiRequest, type ApiRequestInit } from "../lib/api";
import { ctx } from "../lib/context";
export type DownResult = {
full: boolean;
retained: Array<{ kind: string; name: string }>;
delete: Array<{ kind: string; name: string }>;
};
export type DownApiRequest = <T>(
path: string,
init?: ApiRequestInit,
) => Promise<T>;
export function runDown(
project: string,
full = false,
request: DownApiRequest = apiRequest,
): Promise<DownResult> {
return request<DownResult>(
`/workspaces/${encodeURIComponent(project)}/down`,
{ method: "POST", json: { full } },
);
}
export const down = defineCommand({
meta: {
name: "down",
description: "Delete managed resources except ingress and PVCs",
},
args: {
full: {
type: "boolean",
alias: "f",
description: "Also delete ingress, PVCs, and the namespace",
},
},
async run({ args }) {
const { project } = ctx();
await new Listr([
{
title: "Delete resources",
task: async (_ctx, task) => {
const result = await runDown(project, args.full);
task.output = `${result.delete.length} resources queued`;
},
},
]).run();
},
});