feat: v2
This commit is contained in:
+21
-12
@@ -1,10 +1,24 @@
|
||||
import { defineCommand } from "citty";
|
||||
import {
|
||||
buildNamespaceGraphs,
|
||||
fetchNamespaceObjects,
|
||||
renderNamespaceGraphs,
|
||||
} from "../lib/graph";
|
||||
import { getProject } from "../lib/shared";
|
||||
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: {
|
||||
@@ -20,11 +34,6 @@ export const ps = defineCommand({
|
||||
},
|
||||
},
|
||||
async run({ args: { all } }) {
|
||||
const objects = await fetchNamespaceObjects(getProject());
|
||||
console.log(
|
||||
renderNamespaceGraphs(
|
||||
buildNamespaceGraphs(objects, { includeIdle: all }),
|
||||
),
|
||||
);
|
||||
console.log(await runPs(ctx().project, all));
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user