53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
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 RestartApiRequest = <T>(
|
|
path: string,
|
|
init?: ApiRequestInit,
|
|
) => Promise<T>;
|
|
|
|
export function runRestart(
|
|
project: string,
|
|
name?: string,
|
|
request: RestartApiRequest = apiRequest,
|
|
): Promise<LifecycleResponse> {
|
|
return request<LifecycleResponse>(
|
|
`/workspaces/${encodeURIComponent(project)}/lifecycle`,
|
|
{
|
|
method: "POST",
|
|
json: { action: "restart", ...(name && { services: [name] }) },
|
|
},
|
|
);
|
|
}
|
|
|
|
export const restart = defineCommand({
|
|
meta: {
|
|
name: "restart",
|
|
description: "Roll out a restart for managed deployments",
|
|
},
|
|
args: {
|
|
deployment: {
|
|
type: "positional",
|
|
description: "Deployment name to restart (defaults to all managed)",
|
|
required: false,
|
|
},
|
|
},
|
|
async run({ args }) {
|
|
await new Listr([
|
|
{
|
|
title: "Restart deployments",
|
|
task: async (_ctx, task) => {
|
|
const { deployments } = await runRestart(
|
|
ctx().project,
|
|
args.deployment,
|
|
);
|
|
task.output = `${deployments.length} deployments queued`;
|
|
},
|
|
},
|
|
]).run();
|
|
},
|
|
});
|