archetect_core/actions/
rules.rs1use crate::actions::Action;
2use crate::config::{RuleConfig, VariableInfo};
3use crate::rules::RulesContext;
4use crate::vendor::tera::Context;
5use crate::{Archetect, ArchetectError, Archetype};
6use linked_hash_map::LinkedHashMap;
7use std::path::Path;
8
9#[derive(Debug, Serialize, Deserialize, Clone)]
10pub enum RuleType {
11 #[serde(rename = "destination")]
12 DestinationRules(DestinationOptions),
13 #[serde(rename = "source")]
14 SourceRules(LinkedHashMap<String, RuleConfig>),
15}
16
17#[derive(Debug, Serialize, Deserialize, Clone)]
18pub struct DestinationOptions {
19 overwrite: bool,
20}
21
22impl Action for RuleType {
23 fn execute<D: AsRef<Path>>(
24 &self,
25 _archetect: &mut Archetect,
26 _archetype: &Archetype,
27 _destination: D,
28 rules_context: &mut RulesContext,
29 _answers: &LinkedHashMap<String, VariableInfo>,
30 _context: &mut Context,
31 ) -> Result<(), ArchetectError> {
32 match self {
33 RuleType::SourceRules(rules) => {
34 rules_context.insert_path_rules(rules);
35 }
36 RuleType::DestinationRules(options) => {
37 rules_context.set_overwrite(options.overwrite);
38 }
39 }
40 Ok(())
41 }
42}