From 31761bd5fd244900c03f44e98e2d59323c20bfbe Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Thu, 9 Jun 2022 21:32:26 -0400 Subject: view: Open virt-viewer given a server and a UUID requires that `virt-viewer` is installed on the client machine. Closes #2 --- src/main.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main.rs b/src/main.rs index 83d572c..fbe2463 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::process::Command; + use clap::Parser; mod errors; use errors::CliError; @@ -41,6 +43,9 @@ enum Action { #[clap(long, short)] force: bool + }, + View { + uuid: String } } @@ -67,6 +72,9 @@ fn main() { Action::Reboot { uuid, force } => { reboot(root, client, uuid, force).unwrap(); } + Action::View { uuid } => { + view(root, uuid).unwrap(); + } }; } @@ -160,3 +168,16 @@ fn reboot(server: String, c: Client, u: String, f: bool) -> Result<(), CliError> Ok(()) } + +fn view(server: String, u: String) -> Result<(), CliError> { + let host = server.split(':').next().unwrap(); + let qemu_url = format!("qemu+ssh://{}/system", host); + + let output = Command::new("virt-viewer") + .arg("-c") + .arg(qemu_url) + .arg(u) + .output(); + + Ok(()) +} -- cgit v1.2.3