aboutsummaryrefslogtreecommitdiff
path: root/deno/tools
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-12-22 17:08:15 +0800
committerYuqian Yang <crupest@crupest.life>2025-12-22 17:08:15 +0800
commitf61c9dd3cab85fbde4ab44bad33a9394be6fcab0 (patch)
treea4e28de0c18e3fa5b925bb2138d902897763a1dc /deno/tools
parent3bc7415d0e57382e76fa863d1f9598f46d34656a (diff)
downloadcrupest-f61c9dd3cab85fbde4ab44bad33a9394be6fcab0.tar.gz
crupest-f61c9dd3cab85fbde4ab44bad33a9394be6fcab0.tar.bz2
crupest-f61c9dd3cab85fbde4ab44bad33a9394be6fcab0.zip
tools: add run vm command.
Diffstat (limited to 'deno/tools')
-rw-r--r--deno/tools/deno.json1
-rw-r--r--deno/tools/vm.ts48
2 files changed, 48 insertions, 1 deletions
diff --git a/deno/tools/deno.json b/deno/tools/deno.json
index 355046a..b3405aa 100644
--- a/deno/tools/deno.json
+++ b/deno/tools/deno.json
@@ -1,6 +1,7 @@
{
"version": "0.1.0",
"tasks": {
+ "compile": "deno compile -o out/crupest-tools -A main.ts"
},
"imports": {
"mustache": "npm:mustache@^4.2.0"
diff --git a/deno/tools/vm.ts b/deno/tools/vm.ts
index b54c0d4..a7ee98e 100644
--- a/deno/tools/vm.ts
+++ b/deno/tools/vm.ts
@@ -215,11 +215,57 @@ const gen = defineYargsModule({
},
});
+function runVm(name: string) {
+ const vm = resolveVmSetup(name, MY_VMS);
+ if (vm == null) {
+ console.error(`No vm called ${name} is found.`);
+ Deno.exit(-1);
+ }
+ const preCommands = createPreCommands(vm);
+ const cli = createQemuArgs(vm);
+ const commands = [...preCommands, cli];
+ const processes = commands.map((command) => {
+ console.log("Run command:", command.join(" "));
+ return new Deno.Command(command[0], {
+ args: command.slice(1),
+ stdin: "null",
+ stdout: "inherit",
+ stderr: "inherit",
+ }).spawn();
+ });
+ Deno.addSignalListener("SIGINT", () => {
+ processes.forEach((process) => process.kill("SIGINT"));
+ });
+ Deno.addSignalListener("SIGTERM", () => {
+ processes.forEach((process) => process.kill("SIGTERM"));
+ });
+}
+
+export const run = defineYargsModule({
+ command: "run <name>",
+ describe: "run the vm",
+ builder: (builder) => {
+ return builder
+ .positional("name", {
+ describe: "name of the vm to run",
+ type: "string",
+ })
+ .demandOption("name")
+ .strict();
+ },
+ handler: (argv) => {
+ runVm(argv.name);
+ },
+});
+
export default defineYargsModule({
command: "vm",
describe: "Manage (qemu) virtual machines.",
builder: (builder) => {
- return builder.command(gen).demandCommand(1, DEMAND_COMMAND_MESSAGE);
+ return builder.command(gen).command(run).demandCommand(
+ 1,
+ DEMAND_COMMAND_MESSAGE,
+ );
},
handler: () => {},
});