2022-01-22 21:02:51 +00:00
|
|
|
use dirs::config_dir;
|
2022-01-22 21:14:26 +00:00
|
|
|
use serde_derive::Deserialize;
|
2022-01-22 21:02:51 +00:00
|
|
|
use std::fs::read_to_string;
|
2022-01-22 21:14:26 +00:00
|
|
|
use toml::from_str;
|
2022-01-22 21:02:51 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
pub struct Config {
|
2022-01-22 21:14:26 +00:00
|
|
|
pub imgur: ConfigImgur,
|
2022-01-22 21:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
pub struct ConfigImgur {
|
2022-01-22 21:14:26 +00:00
|
|
|
pub id: String,
|
2022-01-22 21:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn parse() -> Result<Config, String> {
|
|
|
|
let config_dir = config_dir().unwrap();
|
2022-01-24 18:33:44 +00:00
|
|
|
let file_dir: String = String::from(config_dir.to_string_lossy()) + "/imgurs/config.toml";
|
2022-01-22 21:02:51 +00:00
|
|
|
|
|
|
|
let toml_str = read_to_string(file_dir).map_err(|err| err.to_string())?;
|
|
|
|
|
|
|
|
let decode = from_str(&toml_str).map_err(|err| err.to_string())?;
|
|
|
|
|
|
|
|
Ok(decode)
|
|
|
|
}
|