kratactl: rework to separate commands

This commit is contained in:
Alex Zenla
2024-03-15 15:59:18 +00:00
parent 31a43f9108
commit d66b6f80b9
10 changed files with 363 additions and 251 deletions

View File

@ -0,0 +1,28 @@
use anyhow::Result;
use clap::Parser;
use krata::control::watch_events_reply::Event;
use crate::{cli::pretty::guest_status_text, events::EventStream};
#[derive(Parser)]
pub struct WatchCommand {}
impl WatchCommand {
pub async fn run(self, events: EventStream) -> Result<()> {
let mut stream = events.subscribe();
loop {
let event = stream.recv().await?;
match event {
Event::GuestChanged(changed) => {
if let Some(guest) = changed.guest {
println!(
"event=guest.changed guest={} status={}",
guest.id,
guest_status_text(guest.state.unwrap_or_default().status())
);
}
}
}
}
}
}