A convenient CLI tool to quickly spin up DragonflyBSD virtual machines using QEMU with sensible defaults.
1import { Table } from "@cliffy/table";
2import dayjs from "dayjs";
3import relativeTime from "dayjs/plugin/relativeTime.js";
4import utc from "dayjs/plugin/utc.js";
5import { Effect, pipe } from "effect";
6import type { Image } from "../db.ts";
7import { type DbError, listImages } from "../images.ts";
8import { humanFileSize } from "../utils.ts";
9
10dayjs.extend(relativeTime);
11dayjs.extend(utc);
12
13const createTable = () =>
14 Effect.succeed(
15 new Table(
16 ["REPOSITORY", "TAG", "IMAGE ID", "CREATED", "SIZE"],
17 ),
18 );
19
20const populateTable = (table: Table, images: Image[]) =>
21 Effect.gen(function* () {
22 for (const image of images) {
23 table.push([
24 image.repository,
25 image.tag,
26 image.id,
27 dayjs.utc(image.createdAt).local().fromNow(),
28 yield* humanFileSize(image.size),
29 ]);
30 }
31 return table;
32 });
33
34const displayTable = (table: Table) =>
35 Effect.sync(() => {
36 console.log(table.padding(2).toString());
37 });
38
39const handleError = (error: DbError | Error) =>
40 Effect.sync(() => {
41 console.error(`Failed to fetch virtual machines: ${error}`);
42 Deno.exit(1);
43 });
44
45const lsEffect = () =>
46 pipe(
47 Effect.all([listImages(), createTable()]),
48 Effect.flatMap(([images, table]) => populateTable(table, images)),
49 Effect.flatMap(displayTable),
50 Effect.catchAll(handleError),
51 );
52
53export default async function () {
54 await Effect.runPromise(lsEffect());
55}