diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-12-22 17:08:15 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-12-22 17:08:15 +0800 |
| commit | f61c9dd3cab85fbde4ab44bad33a9394be6fcab0 (patch) | |
| tree | a4e28de0c18e3fa5b925bb2138d902897763a1dc /deno/tools/vm.ts | |
| parent | 3bc7415d0e57382e76fa863d1f9598f46d34656a (diff) | |
| download | crupest-f61c9dd3cab85fbde4ab44bad33a9394be6fcab0.tar.gz crupest-f61c9dd3cab85fbde4ab44bad33a9394be6fcab0.tar.bz2 crupest-f61c9dd3cab85fbde4ab44bad33a9394be6fcab0.zip | |
tools: add run vm command.
Diffstat (limited to 'deno/tools/vm.ts')
| -rw-r--r-- | deno/tools/vm.ts | 48 |
1 files changed, 47 insertions, 1 deletions
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: () => {}, }); |
