pub mod engine;
pub mod hypervisor;
pub mod server;
use std::path::{Path, PathBuf};
use isothrum_runner::{Event, RunName, Runner, RunnerConfig};
use crate::Context;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Progress<S, F, E> {
Running(S),
Passed(S, F),
Failed(S, E),
Skipped(S, F),
}
const PROMPT_LIMIT: std::time::Duration = std::time::Duration::from_secs(300);
struct Steps<'a, S, F, E>(&'a (dyn Fn(Progress<S, F, E>) + Send + Sync));
impl<S: Copy, F, E: Clone> Steps<'_, S, F, E> {
async fn run(&self, step: S, work: impl Future<Output = Result<F, E>>) -> Result<(), E> {
(self.0)(Progress::Running(step));
match work.await {
Ok(found) => {
(self.0)(Progress::Passed(step, found));
Ok(())
}
Err(why) => {
(self.0)(Progress::Failed(step, why.clone()));
Err(why)
}
}
}
}
fn throwaway(cx: &Context, dir: &Path, file: &str, text: &str) -> Result<(Runner, PathBuf), String> {
let project = dir.join("project");
let written = std::fs::create_dir_all(&project).and_then(|()| std::fs::write(project.join(file), text));
written.map_err(|e| format!("{} couldn't be written: {e}", project.display()))?;
let mut config = RunnerConfig::new(dir.join("home"));
config.processes = std::sync::Arc::clone(&cx.runner);
let runner = Runner::new(config).map_err(|e| e.to_string())?;
Ok((runner, project))
}
fn open<'a>(runner: &'a Runner, project: &Path, name: &str) -> Result<isothrum_runner::Running<'a>, String> {
let name = RunName::new(name).map_err(|e| e.to_string())?;
runner.open(project, Some(name)).map_err(|e| e.to_string())
}
fn quiet(_: &Event) {}