import { defineCommand } from "citty"; import { Listr } from "listr2"; import { apiRequest, type ApiRequestInit } from "../lib/api"; import { ctx } from "../lib/context"; type LifecycleResponse = { deployments: string[] }; export type StopApiRequest = ( path: string, init?: ApiRequestInit, ) => Promise; export function runStop( project: string, request: StopApiRequest = apiRequest, ): Promise { return request( `/workspaces/${encodeURIComponent(project)}/lifecycle`, { method: "POST", json: { action: "stop" } }, ); } export const stop = defineCommand({ meta: { name: "stop", description: "Scale managed deployments to zero", }, async run() { await new Listr([ { title: "Scale deployments", task: async (_ctx, task) => { const { deployments } = await runStop(ctx().project); task.output = `${deployments.length} deployments queued`; }, }, ]).run(); }, });