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 = ( path: string, init?: ApiRequestInit, ) => Promise; export function runDown( project: string, full = false, request: DownApiRequest = apiRequest, ): Promise { return request( `/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(); }, });