diff --git a/src/stage4/src/executor.rs b/src/stage4/src/executor.rs index 2c01482..a1af9ec 100644 --- a/src/stage4/src/executor.rs +++ b/src/stage4/src/executor.rs @@ -13,7 +13,7 @@ use semver::{Version, VersionReq}; use serde::{Deserialize, Serialize}; use which::which_in; use crate::bloody_indiana_jones::BloodyIndianaJones; - +use crate::executors::caddy::Caddy; use crate::executors::custom_command::CustomCommand; use crate::executors::deno::Deno; use crate::executors::go::Go; @@ -151,6 +151,7 @@ impl dyn Executor { "run" => Some(Box::new(CustomCommand { executor_cmd })), "deno" => Some(Box::new(Deno { executor_cmd })), "go" => Some(Box::new(Go { executor_cmd })), + "caddy" => Some(Box::new(Caddy { executor_cmd })), _ => None, } } diff --git a/src/stage4/src/executors/caddy.rs b/src/stage4/src/executors/caddy.rs new file mode 100644 index 0000000..b1316a9 --- /dev/null +++ b/src/stage4/src/executors/caddy.rs @@ -0,0 +1,73 @@ +use std::collections::HashSet; +use std::future::Future; +use std::pin::Pin; + +use crate::executor::{AppInput, Download, Executor, ExecutorCmd, GgVersion}; +use crate::target::{Arch, Os, Variant}; +use crate::target::Os::Windows; + +pub struct Caddy { + pub executor_cmd: ExecutorCmd, +} + +impl Executor for Caddy { + fn get_executor_cmd(&self) -> &ExecutorCmd { + &self.executor_cmd + } + + fn get_download_urls<'a>(&self, _input: &'a AppInput) -> Pin> + 'a>> { + Box::pin(async move { + let mut downloads: Vec = vec!(); + let octocrab = octocrab::Octocrab::builder().build().unwrap(); + let mut page: u32 = 1; + loop { + let releases = octocrab.repos("caddyserver", "caddy") + .releases().list().page(page).per_page(100).send().await.unwrap(); + for release in releases.items { + for asset in release.assets { + let os = if asset.name.contains("windows") { + Some(Windows) + } else if asset.name.contains("linux") { + Some(Os::Linux) + } else if asset.name.contains("apple") { + Some(Os::Mac) + } else { + None + }; + let arch = if asset.name.contains("amd64") { + Some(Arch::X86_64) + } else { + None + }; + if os.is_some() && arch.is_some() { + downloads.push(Download { + download_url: asset.browser_download_url.to_string(), + version: GgVersion::new(release.tag_name.as_str()), + os, + arch, + tags: HashSet::new(), + variant: Some(Variant::Any), + }); + } + } + } + if releases.next == None { + break; + } + page += 1; + } + downloads + }) + } + + fn get_bins(&self, input: &AppInput) -> Vec { + vec!(match &input.target.os { + Windows => "caddy.exe", + _ => "caddy" + }.to_string()) + } + + fn get_name(&self) -> &str { + "caddy" + } +} diff --git a/src/stage4/src/executors/mod.rs b/src/stage4/src/executors/mod.rs index 2e034c3..32dc094 100644 --- a/src/stage4/src/executors/mod.rs +++ b/src/stage4/src/executors/mod.rs @@ -8,3 +8,4 @@ pub mod node; pub mod deno; pub mod gradle_properties; pub mod go; +pub mod caddy;