use super::rules::Rule; use crate::error::{PakkerError, Result}; pub trait ExportProfile { fn name(&self) -> &str; fn rules(&self) -> Vec>; } /// Implements [`ExportProfile`] for a unit struct with a static name and rule /// list. /// /// Each rule entry is an expression evaluated as /// `Box::new(super::rules::)`, supporting both bare unit struct names and /// constructor calls with arguments. /// /// # Example /// /// ```ignore /// export_profile! { /// MyProfile => "my-profile" { /// SomeRule, /// AnotherRule::new("arg"), /// } /// } /// ``` macro_rules! export_profile { ($struct:ident => $name:literal { $($rule:expr),* $(,)? }) => { pub struct $struct; impl ExportProfile for $struct { fn name(&self) -> &'static str { $name } fn rules(&self) -> Vec> { use super::rules::*; vec![ $(Box::new($rule)),* ] } } }; } export_profile! { CurseForgeProfile => "curseforge" { CopyProjectFilesRule, FilterByPlatformRule, MissingProjectsAsOverridesRule::new("curseforge"), CopyOverridesRule, CopyClientOverridesRule, FilterServerOnlyRule, GenerateManifestRule::curseforge(), FilterNonRedistributableRule, TextReplacementRule } } export_profile! { ModrinthProfile => "modrinth" { CopyProjectFilesRule, FilterByPlatformRule, MissingProjectsAsOverridesRule::new("modrinth"), CopyOverridesRule, CopyClientOverridesRule, FilterServerOnlyRule, GenerateManifestRule::modrinth(), TextReplacementRule } } export_profile! { ServerPackProfile => "serverpack" { CopyProjectFilesRule, CopyServerOverridesRule, FilterClientOnlyRule, TextReplacementRule } } pub fn create_profile(name: &str) -> Result> { match name { "curseforge" => Ok(Box::new(CurseForgeProfile)), "modrinth" => Ok(Box::new(ModrinthProfile)), "serverpack" => Ok(Box::new(ServerPackProfile)), _ => Err(PakkerError::InvalidExportProfile(name.to_string())), } }