tangled
alpha
login
or
join now
tsiry-sandratraina.com
/
openbsd-up
1
fork
atom
A simple CLI tool to spin up OpenBSD virtual machines using QEMU with minimal fuss.
1
fork
atom
overview
issues
pulls
pipelines
Add 'rm' command to remove a virtual machine
tsiry-sandratraina.com
4 months ago
2dd82e66
52cc0cdd
+24
2 changed files
expand all
collapse all
unified
split
main.ts
src
subcommands
rm.ts
+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
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
"openbsd-up inspect my-vm",
90
91
)
92
92
+
.example(
93
93
+
"Remove a VM",
94
94
+
"openbsd-up rm my-vm",
95
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
140
+
})
141
141
+
.command("rm", "Remove a virtual machine")
142
142
+
.arguments("<vm-name:string>")
143
143
+
.action(async (_options: unknown, vmName: string) => {
144
144
+
await rm(vmName);
135
145
})
136
146
.parse(Deno.args);
137
147
}
+14
src/subcommands/rm.ts
···
1
1
+
import { getInstanceState, removeInstanceState } from "../state.ts";
2
2
+
3
3
+
export default async function (name: string) {
4
4
+
const vm = await getInstanceState(name);
5
5
+
if (!vm) {
6
6
+
console.error(
7
7
+
`Virtual machine with name or ID ${name} not found.`,
8
8
+
);
9
9
+
Deno.exit(1);
10
10
+
}
11
11
+
12
12
+
console.log(`Removing virtual machine ${vm.name} (ID: ${vm.id})...`);
13
13
+
await removeInstanceState(name);
14
14
+
}