use std::path::Path;
use anyhow::{Context, Result};
pub async fn execute(output: &str) -> Result<()> {
if !Path::new("clankeRS.toml").exists() {
anyhow::bail!(
"no clankeRS.toml in the current directory — run `clankers record` inside a \
clankeRS project. (You can also set [logging] record_mcap = true in \
clankeRS.toml and use `clankers run`.)"
);
}
println!("clankeRS record → {output} (Ctrl-C to stop)");
let mut child = tokio::process::Command::new("cargo")
.args(["run", "--release"])
.env("CLANKERS_RECORD_MCAP", "1")
.env("CLANKERS_RECORD_OUTPUT", output)
.spawn()
.context("failed to run cargo run")?;
let status = tokio::select! {
s = child.wait() => Some(s.context("wait for node")?),
_ = tokio::signal::ctrl_c() => {
let _ = child.wait().await;
None
}
};
if let Some(status) = status {
if !status.success() {
anyhow::bail!("node exited with {status}");
}
}
println!("clankeRS record finished → {output}");
Ok(())
}