A simple, zero-configuration script to quickly boot FreeBSD ISO images using QEMU

Add 'rm' command to remove virtual machines

+20
+6
main.ts
··· 4 4 import { createBridgeNetworkIfNeeded } from "./src/network.ts"; 5 5 import inspect from "./src/subcommands/inspect.ts"; 6 6 import ps from "./src/subcommands/ps.ts"; 7 + import rm from "./src/subcommands/rm.ts"; 7 8 import start from "./src/subcommands/start.ts"; 8 9 import stop from "./src/subcommands/stop.ts"; 9 10 import { ··· 132 133 .arguments("<vm-name:string>") 133 134 .action(async (_options: unknown, vmName: string) => { 134 135 await inspect(vmName); 136 + }) 137 + .command("rm", "Remove a virtual machine") 138 + .arguments("<vm-name:string>") 139 + .action(async (_options: unknown, vmName: string) => { 140 + await rm(vmName); 135 141 }) 136 142 .parse(Deno.args); 137 143 }
+14
src/subcommands/rm.ts
··· 1 + import { getInstanceState, removeInstanceState } from "../state.ts"; 2 + 3 + export default async function (name: string) { 4 + const vm = await getInstanceState(name); 5 + if (!vm) { 6 + console.error( 7 + `Virtual machine with name or ID ${name} not found.`, 8 + ); 9 + Deno.exit(1); 10 + } 11 + 12 + console.log(`Removing virtual machine ${vm.name} (ID: ${vm.id})...`); 13 + await removeInstanceState(name); 14 + }