diff --git a/main.ts b/main.ts index a1adc88..e6b3ced 100755 --- a/main.ts +++ b/main.ts @@ -4,6 +4,7 @@ import { Command } from "@cliffy/command"; import { createBridgeNetworkIfNeeded } from "./src/network.ts"; import inspect from "./src/subcommands/inspect.ts"; import ps from "./src/subcommands/ps.ts"; +import rm from "./src/subcommands/rm.ts"; import start from "./src/subcommands/start.ts"; import stop from "./src/subcommands/stop.ts"; import { @@ -88,6 +89,10 @@ if (import.meta.main) { "Inspect a VM", "openbsd-up inspect my-vm", ) + .example( + "Remove a VM", + "openbsd-up rm my-vm", + ) .action(async (options: Options, input?: string) => { const resolvedInput = handleInput(input); let isoPath: string | null = resolvedInput; @@ -133,5 +138,10 @@ if (import.meta.main) { .action(async (_options: unknown, vmName: string) => { await inspect(vmName); }) + .command("rm", "Remove a virtual machine") + .arguments("") + .action(async (_options: unknown, vmName: string) => { + await rm(vmName); + }) .parse(Deno.args); } diff --git a/src/subcommands/rm.ts b/src/subcommands/rm.ts new file mode 100644 index 0000000..c03fc72 --- /dev/null +++ b/src/subcommands/rm.ts @@ -0,0 +1,14 @@ +import { getInstanceState, removeInstanceState } from "../state.ts"; + +export default async function (name: string) { + const vm = await getInstanceState(name); + if (!vm) { + console.error( + `Virtual machine with name or ID ${name} not found.`, + ); + Deno.exit(1); + } + + console.log(`Removing virtual machine ${vm.name} (ID: ${vm.id})...`); + await removeInstanceState(name); +}