import type { Command } from "commander" import * as vm from "../vm.ts" import { spinner } from "../spinner.ts" export function register(program: Command) { const vmCmd = program.command("vm").description("Manage the sandlot VM") vmCmd .command("create") .description("Create and provision the VM") .action(async () => { const spin = spinner("Creating VM") try { await vm.create((msg) => { spin.text = msg }) spin.succeed("VM created") } catch (err) { spin.fail(String((err as Error).message ?? err)) process.exit(1) } }) vmCmd .command("start") .description("Start the VM") .action(async () => { try { await vm.start() console.log("✔ VM started") } catch (err) { console.error(`✖ ${(err as Error).message ?? err}`) process.exit(1) } }) vmCmd .command("shell") .description("Open a shell in the VM") .action(async () => { await vm.ensure() await vm.shell() }) vmCmd .command("status") .description("Show VM status") .action(async () => { const s = await vm.status() console.log(s) }) vmCmd .command("info") .description("Show VM system info (via neofetch)") .action(async () => { await vm.ensure() await vm.neofetch() }) vmCmd .command("stop") .description("Stop the VM") .action(async () => { const spin = spinner("Stopping VM") try { await vm.stop() spin.succeed("VM stopped") } catch (err) { spin.fail(String((err as Error).message ?? err)) process.exit(1) } }) vmCmd .command("destroy") .description("Stop and delete the VM") .action(async () => { const spin = spinner("Destroying VM") try { await vm.destroy() spin.succeed("VM destroyed") } catch (err) { spin.fail(String((err as Error).message ?? err)) process.exit(1) } }) vmCmd .command("uncache") .description("Clear the package cache (next create will re-download)") .action(async () => { const had = await vm.clearCache() console.log(had ? "✔ Package cache cleared" : "No cache to clear") }) }