feat: v2
This commit is contained in:
+20
-18
@@ -1,11 +1,23 @@
|
||||
import { defineCommand } from "citty";
|
||||
import { Listr } from "listr2";
|
||||
import { assertManagedNamespace } from "../lib/apply";
|
||||
import {
|
||||
getProject,
|
||||
listManagedDeployments,
|
||||
scaleDeployment,
|
||||
} from "../lib/shared";
|
||||
import { apiRequest, type ApiRequestInit } from "../lib/api";
|
||||
import { ctx } from "../lib/context";
|
||||
|
||||
type LifecycleResponse = { deployments: string[] };
|
||||
export type StopApiRequest = <T>(
|
||||
path: string,
|
||||
init?: ApiRequestInit,
|
||||
) => Promise<T>;
|
||||
|
||||
export function runStop(
|
||||
project: string,
|
||||
request: StopApiRequest = apiRequest,
|
||||
): Promise<LifecycleResponse> {
|
||||
return request<LifecycleResponse>(
|
||||
`/workspaces/${encodeURIComponent(project)}/lifecycle`,
|
||||
{ method: "POST", json: { action: "stop" } },
|
||||
);
|
||||
}
|
||||
|
||||
export const stop = defineCommand({
|
||||
meta: {
|
||||
@@ -13,22 +25,12 @@ export const stop = defineCommand({
|
||||
description: "Scale managed deployments to zero",
|
||||
},
|
||||
async run() {
|
||||
await assertManagedNamespace(getProject());
|
||||
const deployments = await listManagedDeployments();
|
||||
if (deployments.length === 0) return;
|
||||
|
||||
await new Listr([
|
||||
{
|
||||
title: "Scale deployments",
|
||||
task: (_ctx, task) => {
|
||||
task: async (_ctx, task) => {
|
||||
const { deployments } = await runStop(ctx().project);
|
||||
task.output = `${deployments.length} deployments queued`;
|
||||
return task.newListr(
|
||||
deployments.map((deployment) => ({
|
||||
title: `Deployment ${deployment.metadata?.name}`,
|
||||
task: () => scaleDeployment(deployment.metadata!.name!, 0),
|
||||
})),
|
||||
{ concurrent: false, exitOnError: true },
|
||||
);
|
||||
},
|
||||
},
|
||||
]).run();
|
||||
|
||||
Reference in New Issue
Block a user