A convenient CLI tool to quickly spin up DragonflyBSD virtual machines using QEMU with sensible defaults.
at main 47 lines 1.3 kB view raw
1import { Data, Effect, pipe } from "effect"; 2import type { Image, VirtualMachine, Volume } from "../db.ts"; 3import { getImage } from "../images.ts"; 4import { getInstanceState } from "../state.ts"; 5import { getVolume } from "../volumes.ts"; 6 7class ItemNotFoundError extends Data.TaggedError("ItemNotFoundError")<{ 8 name: string; 9}> {} 10 11const find = (name: string) => 12 pipe( 13 Effect.all([getInstanceState(name), getImage(name), getVolume(name)]), 14 Effect.flatMap(([vm, image, volume]) => 15 vm || image || volume 16 ? Effect.succeed(vm || image || volume) 17 : Effect.fail(new ItemNotFoundError({ name })) 18 ), 19 ); 20 21const display = (vm: VirtualMachine | Image | Volume | undefined) => 22 Effect.sync(() => { 23 console.log(vm); 24 }); 25 26const handleError = (error: ItemNotFoundError | Error) => 27 Effect.sync(() => { 28 if (error instanceof ItemNotFoundError) { 29 console.error( 30 `Virtual machine with name or ID ${error.name} not found.`, 31 ); 32 } else { 33 console.error(`An error occurred: ${error}`); 34 } 35 Deno.exit(1); 36 }); 37 38const inspectEffect = (name: string) => 39 pipe( 40 find(name), 41 Effect.flatMap(display), 42 Effect.catchAll(handleError), 43 ); 44 45export default async function (name: string) { 46 await Effect.runPromise(inspectEffect(name)); 47}