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 = ( path: string, init?: ApiRequestInit, ) => Promise; export async function runPs( project: string, includeIdle = false, request: PsApiRequest = apiRequest, ): Promise { const query = includeIdle ? "?includeIdle=true" : ""; const graphs = await request( `/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)); }, });