40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { defineCommand } from "citty";
|
|
import { apiRequest, type ApiRequestInit } from "../lib/api";
|
|
import { renderNamespaceGraphs, type NamespaceGraph } from "../lib/graph";
|
|
import { ctx } from "../lib/context";
|
|
|
|
export type PsApiRequest = <T>(
|
|
path: string,
|
|
init?: ApiRequestInit,
|
|
) => Promise<T>;
|
|
|
|
export async function runPs(
|
|
project: string,
|
|
includeIdle = false,
|
|
request: PsApiRequest = apiRequest,
|
|
): Promise<string> {
|
|
const query = includeIdle ? "?includeIdle=true" : "";
|
|
const graphs = await request<NamespaceGraph[]>(
|
|
`/workspaces/${encodeURIComponent(project)}/status${query}`,
|
|
);
|
|
return renderNamespaceGraphs(graphs);
|
|
}
|
|
|
|
export const ps = defineCommand({
|
|
meta: {
|
|
name: "ps",
|
|
description: "List deployments",
|
|
},
|
|
args: {
|
|
all: {
|
|
type: "boolean",
|
|
alias: "a",
|
|
description:
|
|
"Show all stopped deployments (including those created by the run command)",
|
|
},
|
|
},
|
|
async run({ args: { all } }) {
|
|
console.log(await runPs(ctx().project, all));
|
|
},
|
|
});
|