support_kit/boilerplate/
boilerplate_control.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::path::PathBuf;

use crate::Configuration;

use super::{BoilerplateContext, BoilerplatePreset, BoilerplateTemplate};

#[derive(Debug, Clone, bon::Builder)]
pub struct BoilerplateControl {
    #[builder(into)]
    pub context: BoilerplateContext,
    #[builder(into, default)]
    pub base_path: PathBuf,
}

impl BoilerplateControl {
    pub fn write(&self, preset: BoilerplatePreset) -> crate::Result<()> {
        Ok(self.template(preset).write(&self.context)?)
    }

    pub fn template(&self, preset: BoilerplatePreset) -> BoilerplateTemplate {
        preset.init(&self.base_path)
    }
}

impl From<Configuration> for BoilerplateControl {
    fn from(config: Configuration) -> Self {
        Self::builder()
            .context(config)
            .base_path(PathBuf::from(std::env::current_dir().unwrap()))
            .build()
    }
}