export: introduce `export_profile to reduce boilerplate; cleanup
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I30469f47be8df27ee2a31f1acdcd68a16a6a6964
This commit is contained in:
parent
fc2d89892c
commit
255220b43c
1 changed files with 60 additions and 50 deletions
|
|
@ -6,65 +6,75 @@ pub trait ExportProfile {
|
||||||
fn rules(&self) -> Vec<Box<dyn Rule>>;
|
fn rules(&self) -> Vec<Box<dyn Rule>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CurseForgeProfile;
|
/// Implements [`ExportProfile`] for a unit struct with a static name and rule
|
||||||
pub struct ModrinthProfile;
|
/// list.
|
||||||
pub struct ServerPackProfile;
|
///
|
||||||
|
/// Each rule entry is an expression evaluated as
|
||||||
|
/// `Box::new(super::rules::<expr>)`, 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 CurseForgeProfile {
|
impl ExportProfile for $struct {
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
"curseforge"
|
$name
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rules(&self) -> Vec<Box<dyn Rule>> {
|
fn rules(&self) -> Vec<Box<dyn Rule>> {
|
||||||
vec![
|
use super::rules::*;
|
||||||
Box::new(super::rules::CopyProjectFilesRule),
|
vec![
|
||||||
Box::new(super::rules::FilterByPlatformRule),
|
$(Box::new($rule)),*
|
||||||
Box::new(super::rules::MissingProjectsAsOverridesRule::new(
|
]
|
||||||
"curseforge",
|
}
|
||||||
)),
|
}
|
||||||
Box::new(super::rules::CopyOverridesRule),
|
};
|
||||||
Box::new(super::rules::CopyClientOverridesRule),
|
}
|
||||||
Box::new(super::rules::FilterServerOnlyRule),
|
|
||||||
Box::new(super::rules::GenerateManifestRule::curseforge()),
|
export_profile! {
|
||||||
Box::new(super::rules::FilterNonRedistributableRule),
|
CurseForgeProfile => "curseforge" {
|
||||||
Box::new(super::rules::TextReplacementRule),
|
CopyProjectFilesRule,
|
||||||
]
|
FilterByPlatformRule,
|
||||||
|
MissingProjectsAsOverridesRule::new("curseforge"),
|
||||||
|
CopyOverridesRule,
|
||||||
|
CopyClientOverridesRule,
|
||||||
|
FilterServerOnlyRule,
|
||||||
|
GenerateManifestRule::curseforge(),
|
||||||
|
FilterNonRedistributableRule,
|
||||||
|
TextReplacementRule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExportProfile for ModrinthProfile {
|
export_profile! {
|
||||||
fn name(&self) -> &'static str {
|
ModrinthProfile => "modrinth" {
|
||||||
"modrinth"
|
CopyProjectFilesRule,
|
||||||
}
|
FilterByPlatformRule,
|
||||||
|
MissingProjectsAsOverridesRule::new("modrinth"),
|
||||||
fn rules(&self) -> Vec<Box<dyn Rule>> {
|
CopyOverridesRule,
|
||||||
vec![
|
CopyClientOverridesRule,
|
||||||
Box::new(super::rules::CopyProjectFilesRule),
|
FilterServerOnlyRule,
|
||||||
Box::new(super::rules::FilterByPlatformRule),
|
GenerateManifestRule::modrinth(),
|
||||||
Box::new(super::rules::MissingProjectsAsOverridesRule::new(
|
TextReplacementRule
|
||||||
"modrinth",
|
|
||||||
)),
|
|
||||||
Box::new(super::rules::CopyOverridesRule),
|
|
||||||
Box::new(super::rules::CopyClientOverridesRule),
|
|
||||||
Box::new(super::rules::FilterServerOnlyRule),
|
|
||||||
Box::new(super::rules::GenerateManifestRule::modrinth()),
|
|
||||||
Box::new(super::rules::TextReplacementRule),
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExportProfile for ServerPackProfile {
|
export_profile! {
|
||||||
fn name(&self) -> &'static str {
|
ServerPackProfile => "serverpack" {
|
||||||
"serverpack"
|
CopyProjectFilesRule,
|
||||||
}
|
CopyServerOverridesRule,
|
||||||
|
FilterClientOnlyRule,
|
||||||
fn rules(&self) -> Vec<Box<dyn Rule>> {
|
TextReplacementRule
|
||||||
vec![
|
|
||||||
Box::new(super::rules::CopyProjectFilesRule),
|
|
||||||
Box::new(super::rules::CopyServerOverridesRule),
|
|
||||||
Box::new(super::rules::FilterClientOnlyRule),
|
|
||||||
Box::new(super::rules::TextReplacementRule),
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue