whiteout/
lib.rs

1pub mod config;
2pub mod parser;
3pub mod storage;
4pub mod transform;
5
6use anyhow::Result;
7use std::path::Path;
8
9#[derive(Debug, Clone)]
10pub struct Whiteout {
11    config: config::Config,
12    storage: storage::LocalStorage,
13}
14
15impl Whiteout {
16    pub fn new(project_root: impl AsRef<Path>) -> Result<Self> {
17        let project_root = project_root.as_ref();
18        let config = config::Config::load_or_default(project_root)?;
19        let storage = storage::LocalStorage::new(project_root)?;
20        
21        Ok(Self { config, storage })
22    }
23
24    pub fn init(project_root: impl AsRef<Path>) -> Result<Self> {
25        let project_root = project_root.as_ref();
26        config::Config::init(project_root)?;
27        storage::LocalStorage::init(project_root)?;
28        
29        Self::new(project_root)
30    }
31
32    pub fn clean(&self, content: &str, file_path: &Path) -> Result<String> {
33        transform::clean(content, file_path, &self.storage, &self.config)
34    }
35
36    pub fn smudge(&self, content: &str, file_path: &Path) -> Result<String> {
37        transform::smudge(content, file_path, &self.storage, &self.config)
38    }
39}