A simple command-line tool to start NetBSD virtual machines using QEMU with sensible defaults.
at main 43 lines 1.1 kB view raw
1import { Data, Effect, pipe } from "effect"; 2import type { VirtualMachine } from "../db.ts"; 3import { getInstanceState } from "../state.ts"; 4 5class VmNotFoundError extends Data.TaggedError("VmNotFoundError")<{ 6 name: string; 7}> {} 8 9const findVm = (name: string) => 10 pipe( 11 getInstanceState(name), 12 Effect.flatMap((vm) => 13 vm ? Effect.succeed(vm) : Effect.fail(new VmNotFoundError({ name })) 14 ), 15 ); 16 17const displayVm = (vm: VirtualMachine) => 18 Effect.sync(() => { 19 console.log(vm); 20 }); 21 22const handleError = (error: VmNotFoundError | Error) => 23 Effect.sync(() => { 24 if (error instanceof VmNotFoundError) { 25 console.error( 26 `Virtual machine with name or ID ${error.name} not found.`, 27 ); 28 } else { 29 console.error(`An error occurred: ${error}`); 30 } 31 Deno.exit(1); 32 }); 33 34const inspectEffect = (name: string) => 35 pipe( 36 findVm(name), 37 Effect.flatMap(displayVm), 38 Effect.catchAll(handleError), 39 ); 40 41export default async function (name: string) { 42 await Effect.runPromise(inspectEffect(name)); 43}