summaryrefslogtreecommitdiffstats
path: root/src/config.rs
blob: 08fa002893ba449f78f3d235bab85fd73285037b (plain) (blame)
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
use crate::prelude::*;

#[derive(serde::Deserialize, Default, Debug)]
pub struct Config {
    aliases:
        std::collections::HashMap<std::path::PathBuf, crate::parse::ast::Exe>,
}

impl Config {
    pub fn load() -> Result<Self> {
        let file = crate::dirs::config_file();
        if std::fs::metadata(&file).is_ok() {
            Ok(toml::from_slice(&std::fs::read(&file)?)?)
        } else {
            Ok(Self::default())
        }
    }

    pub fn alias_for(
        &self,
        path: &std::path::Path,
    ) -> Option<&crate::parse::ast::Exe> {
        self.aliases.get(path)
    }
}