2022-04-19 19:10:36 +00:00
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
use crate::option_return;
|
|
|
|
|
|
|
|
use super::types::Config;
|
|
|
|
|
|
|
|
impl Config {
|
2022-06-07 20:36:26 +00:00
|
|
|
/// Parse configuration file
|
2022-04-19 19:10:36 +00:00
|
|
|
pub fn parse() -> Result<Config> {
|
|
|
|
// configuration file path
|
2022-04-19 19:18:45 +00:00
|
|
|
let config_dir = option_return!(dirs::config_dir(), "get config dir")?;
|
2022-04-19 19:10:36 +00:00
|
|
|
let config_path = format!("{}/homedisk/config.toml", config_dir.to_string_lossy());
|
|
|
|
|
2022-06-07 20:36:26 +00:00
|
|
|
// read file
|
2022-04-19 19:10:36 +00:00
|
|
|
let config = fs::read_to_string(config_path)?;
|
2022-06-07 20:36:26 +00:00
|
|
|
|
|
|
|
// parse config and return it
|
2022-04-19 19:10:36 +00:00
|
|
|
Ok(toml::from_str(&config)?)
|
|
|
|
}
|
|
|
|
}
|