···11+import { getInstanceState } from "../state.ts";
22+33+export default async function (name: string) {
44+ const vm = await getInstanceState(name);
55+ if (!vm) {
66+ console.error(
77+ `Virtual machine with name or ID ${name} not found.`,
88+ );
99+ Deno.exit(1);
1010+ }
1111+1212+ console.log(vm);
1313+}
+39
src/subcommands/ps.ts
···11+import { Table } from "@cliffy/table";
22+import dayjs from "dayjs";
33+import relativeTime from "dayjs/plugin/relativeTime.js";
44+import utc from "dayjs/plugin/utc.js";
55+import { ctx } from "../context.ts";
66+77+dayjs.extend(relativeTime);
88+dayjs.extend(utc);
99+1010+export default async function (all: boolean) {
1111+ const results = await ctx.db.selectFrom("virtual_machines")
1212+ .selectAll()
1313+ .where((eb) => {
1414+ if (all) {
1515+ return eb("id", "!=", "");
1616+ }
1717+ return eb("status", "=", "RUNNING");
1818+ })
1919+ .execute();
2020+2121+ const table: Table = new Table(
2222+ ["NAME", "VCPU", "MEMORY", "STATUS", "PID", "BRIDGE", "MAC", "CREATED"],
2323+ );
2424+2525+ for (const vm of results) {
2626+ table.push([
2727+ vm.name,
2828+ vm.cpus.toString(),
2929+ vm.memory,
3030+ vm.status,
3131+ vm.pid?.toString() ?? "-",
3232+ vm.bridge ?? "-",
3333+ vm.macAddress,
3434+ dayjs.utc(vm.createdAt).local().fromNow(),
3535+ ]);
3636+ }
3737+3838+ console.log(table.padding(2).toString());
3939+}