A simple, powerful CLI tool to spin up OpenIndiana virtual machines with QEMU

Add 'rm' command to remove a virtual machine

Changed files
+24
src
subcommands
+10
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 { ··· 88 89 "Inspect a VM", 89 90 "openindiana-up inspect my-vm", 90 91 ) 92 + .example( 93 + "Remove a VM", 94 + "openindiana-up rm my-vm", 95 + ) 91 96 .action(async (options: Options, input?: string) => { 92 97 const resolvedInput = handleInput(input); 93 98 let isoPath: string | null = resolvedInput; ··· 132 137 .arguments("<vm-name:string>") 133 138 .action(async (_options: unknown, vmName: string) => { 134 139 await inspect(vmName); 140 + }) 141 + .command("rm", "Remove a virtual machine") 142 + .arguments("<vm-name:string>") 143 + .action(async (_options: unknown, vmName: string) => { 144 + await rm(vmName); 135 145 }) 136 146 .parse(Deno.args); 137 147 }
+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 + }