Refactor(ci_command_handling): Move to the event handlers
This commit is contained in:
parent
49818e0bfe
commit
866ec7c277
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
Reference in New Issue