Fully add a lua api #11

Merged
antifallobst merged 19 commits from commands into master 2023-07-21 18:57:04 +00:00
2 changed files with 33 additions and 0 deletions
Showing only changes of commit 866ec7c277 - Show all commits

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)
}