import { Client } from "npm:ssh2"; import { Select } from "https://deno.land/x/cliffy@v1.0.0-rc.4/prompt/select.ts"; import { tty } from "https://deno.land/x/cliffy@v1.0.0-rc.4/ansi/tty.ts"; import { colors } from "https://deno.land/x/cliffy@v1.0.0-rc.4/ansi/colors.ts"; const instances = ( await import("./instances.json", { with: { type: "json" }, }) ).default; const actions = ( await import("./actions.json", { with: { type: "json" }, }) ).default; const baseConfig = { host: "gate.hidora.com", port: 3022, privateKey: Deno.readTextFileSync("/home/tim/.ssh/id_rsa"), }; const selectedConfig = await Select.prompt<(typeof instances)[number]>({ message: "🚀 Instance", options: instances.map(c => ({ name: c.name, value: c })), }); const selectedAction = await Select.prompt<(typeof actions)[number]>({ message: "⚡️ Action", options: actions.map(c => ({ name: c.name, value: c })), }); const secondaryText = colors.gray; const client = new Client().connect({ ...selectedConfig, ...baseConfig }); console.log(`✨ Connecting to ${selectedConfig.name}...`); client.on("ready", () => { tty.eraseScreen(); console.log(secondaryText(`✅ Connected to ${selectedConfig.name}`)); console.log(secondaryText(`$ ${selectedAction.cmd}`)); client.exec(selectedAction.cmd, (err: Error, stream: any) => { if (err) throw err; stream .on("close", () => { client.end(); }) .on("data", (data: string) => { console.log("STDOUT" + data); }) .stderr.on("data", (data: string) => { console.log("STDERR" + data); }); }); });