diff options
Diffstat (limited to 'deno/tools')
| -rw-r--r-- | deno/tools/deno.json | 1 | ||||
| -rw-r--r-- | deno/tools/vm.ts | 48 |
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: () => {}, }); |
