2024-01-28 21:06:16 +01:00
|
|
|
pub struct CuddleX {
|
|
|
|
command: String,
|
|
|
|
args: Vec<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CuddleX {
|
|
|
|
pub fn command(command: impl Into<String>) -> Self {
|
|
|
|
Self {
|
|
|
|
command: command.into(),
|
|
|
|
args: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub fn arg(&mut self, arg: impl Into<String>) -> &mut Self {
|
|
|
|
self.args.push(arg.into());
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn run(&mut self) -> eyre::Result<(String, String, i32)> {
|
2024-01-31 20:37:45 +01:00
|
|
|
let mut cmd = tokio::process::Command::new("cuddle");
|
2024-01-28 21:06:16 +01:00
|
|
|
|
2024-01-31 20:34:46 +01:00
|
|
|
let cmd = cmd.arg("x").arg(&self.command).args(&self.args);
|
2024-01-28 21:06:16 +01:00
|
|
|
|
2024-01-31 20:37:45 +01:00
|
|
|
let process = cmd.spawn()?;
|
|
|
|
|
|
|
|
let output = process.wait_with_output().await?;
|
2024-01-28 21:06:16 +01:00
|
|
|
|
|
|
|
Ok((
|
|
|
|
std::str::from_utf8(&output.stdout)?.to_string(),
|
|
|
|
std::str::from_utf8(&output.stderr)?.to_string(),
|
|
|
|
output.status.code().unwrap_or(0),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod well_known {
|
|
|
|
use super::CuddleX;
|
|
|
|
|
2024-02-03 19:02:03 +01:00
|
|
|
pub async fn render(args: impl IntoIterator<Item = impl Into<String>>) -> eyre::Result<()> {
|
2024-01-31 20:11:36 +01:00
|
|
|
tracing::info!("running render");
|
2024-02-03 19:02:03 +01:00
|
|
|
|
|
|
|
let mut cmd = CuddleX::command("render");
|
|
|
|
|
|
|
|
for arg in args.into_iter() {
|
|
|
|
let arg = arg.into();
|
|
|
|
|
|
|
|
cmd.arg(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
let (stdout, stderr, status) = cmd.run().await?;
|
2024-01-28 21:49:52 +01:00
|
|
|
|
|
|
|
for line in stdout.lines() {
|
|
|
|
tracing::trace!("render: {}", line);
|
|
|
|
}
|
|
|
|
|
|
|
|
for line in stderr.lines() {
|
|
|
|
tracing::trace!("render: {}", line);
|
|
|
|
}
|
2024-01-28 21:06:16 +01:00
|
|
|
|
2024-01-31 20:26:32 +01:00
|
|
|
if status != 0 {
|
|
|
|
tracing::warn!("finished render with non-zero exit code: {}", status);
|
|
|
|
}
|
|
|
|
|
2024-01-31 20:11:36 +01:00
|
|
|
tracing::info!("finished running render");
|
|
|
|
|
2024-01-28 21:06:16 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|