From 8788f78f811d74f7d98c3a13fdc1dcf6f7e743f7 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 28 Jan 2024 21:06:16 +0100 Subject: [PATCH] feat: with cuddle x render Signed-off-by: kjuulh --- crates/cuddle-ci/src/cuddle_x.rs | 42 ++++++++++++++++++++++++++++++++ crates/cuddle-ci/src/lib.rs | 1 + 2 files changed, 43 insertions(+) create mode 100644 crates/cuddle-ci/src/cuddle_x.rs diff --git a/crates/cuddle-ci/src/cuddle_x.rs b/crates/cuddle-ci/src/cuddle_x.rs new file mode 100644 index 0000000..fd466f3 --- /dev/null +++ b/crates/cuddle-ci/src/cuddle_x.rs @@ -0,0 +1,42 @@ +pub struct CuddleX { + command: String, + args: Vec, +} + +impl CuddleX { + pub fn command(command: impl Into) -> Self { + Self { + command: command.into(), + args: Vec::new(), + } + } + pub fn arg(&mut self, arg: impl Into) -> &mut Self { + self.args.push(arg.into()); + + self + } + + pub async fn run(&mut self) -> eyre::Result<(String, String, i32)> { + let mut cmd = tokio::process::Command::new("cuddle"); + + let cmd = cmd.arg("x").arg(&self.command).args(&self.args); + + let output = cmd.output().await?; + + 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; + + pub async fn render() -> eyre::Result<()> { + CuddleX::command("render").run().await?; + + Ok(()) + } +} diff --git a/crates/cuddle-ci/src/lib.rs b/crates/cuddle-ci/src/lib.rs index 46c2eca..daec4e0 100644 --- a/crates/cuddle-ci/src/lib.rs +++ b/crates/cuddle-ci/src/lib.rs @@ -9,4 +9,5 @@ pub mod rust_service; pub mod cuddle_file; pub mod cuddle_please; pub mod cuddle_releaser; +pub mod cuddle_x; pub mod dagger_middleware;