Skip to content

Commit

Permalink
Automatic WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pwalski committed Dec 24, 2023
1 parent 04b43ad commit b18055b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ async fn main() -> anyhow::Result<()> {

match cli.runtime.to_lowercase().as_str() {
"dummy" => run::<process::dummy::Dummy>(cli).await,
"automatic" => run::<process::automatic::Automatic>(cli).await,
_ => {
let err = anyhow::format_err!("Unsupported framework {}", cli.runtime);
log::error!("{}", err);
Expand Down
1 change: 1 addition & 0 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::task::Poll;
use tokio::process::*;

pub mod dummy;
pub mod automatic;
pub mod win;

#[derive(Default, Clone)]
Expand Down
33 changes: 33 additions & 0 deletions src/process/automatic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::{path::Path, process::Stdio};

use tokio::process::Command;

use super::{AiFramework, RuntimeArgs};

#[derive(Clone)]
pub struct Automatic {

}

static _STARTUP_SCRIPT: &str = "automatic/run.bat";

impl AiFramework for Automatic {
fn parse_args(args: &[String]) -> anyhow::Result<super::RuntimeArgs> {
RuntimeArgs::new(&_STARTUP_SCRIPT.into(), args)
}

fn start(args: &super::RuntimeArgs) -> anyhow::Result<tokio::process::Child> {
log::info!("Start cmd");
let exe = super::find_exe(_STARTUP_SCRIPT)?;
let mut cmd = Command::new(&exe);
let work_dir = exe.parent().unwrap();
cmd.stdout(Stdio::piped())
.stdin(Stdio::null())
.current_dir(work_dir);
Ok(cmd.kill_on_drop(true).spawn()?)
}

fn run<ReportFn: Fn(super::Usage) + 'static>(stdout: tokio::process::ChildStdout, report_fn: ReportFn) {
log::info!("Run cmd");
}
}

0 comments on commit b18055b

Please sign in to comment.