Refactor(ci_command_handling): Move to the event handlers

This commit is contained in:
Benedikt Peetz 2023-07-17 00:17:53 +02:00
parent 49818e0bfe
commit 866ec7c277
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,11 @@
use anyhow::Result;
use cli_log::info;
use crate::app::{events::event_types::EventStatus, App};
pub async fn handle(app: &mut App<'_>, output: &String) -> Result<EventStatus> {
info!("Recieved command output: `{}`", output);
app.ui.set_command_output(output);
Ok(EventStatus::Ok)
}

View File

@ -0,0 +1,22 @@
use anyhow::{Context, Result};
use cli_log::info;
use crate::app::{App, events::event_types::{EventStatus, Event}};
pub async fn handle(app: &mut App<'_>, command: &str) -> Result<EventStatus> {
info!("Recieved ci command: `{command}`; executing..");
// TODO: Should the ci support more than strings?
let output = app.lua.context(|context| -> Result<String> {
let output = context
.load(&command)
.eval::<String>()
.with_context(|| format!("Failed to execute: `{command}`"))?;
info!("Function evaluated to: `{output}`");
Ok(output)
})?;
app.transmitter.send(Event::CiOutput(output));
Ok(EventStatus::Ok)
}