chore(config): parse config from current work directory

This commit is contained in:
MedzikUser 2022-08-29 12:54:32 +02:00
parent 4e9ecc007c
commit b5ff8dd32c
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
3 changed files with 5 additions and 12 deletions

View File

@ -11,10 +11,8 @@ pub const DATABASE_FILE: &str = "homedisk.db";
#[tokio::main]
async fn main() {
// initialize logger
logger::init();
// parse config
let config = Config::parse().expect("parse config");
// open database connection

View File

@ -1,6 +1,6 @@
//! # Configuration file
//!
//! Path to a config file is `config.toml` in the system configuration directory (`~/.config/homedisk/config.toml`).
//! Path to a config file is `config.toml` in the work directory.
//!
//! ## Example config
//!

View File

@ -45,16 +45,11 @@ impl Config {
///
/// let config = Config::parse().unwrap();
/// ```
pub fn parse() -> anyhow::Result<Config> {
// get path to the user's config directory
let sys_config_dir = dirs::config_dir().unwrap();
// path to the homedisk config file
let config_path = format!("{}/homedisk/config.toml", sys_config_dir.to_string_lossy());
pub fn parse() -> anyhow::Result<Self> {
let config_str = fs::read_to_string("config.toml")?;
// read file content to string
let config = fs::read_to_string(config_path)?;
let config = toml::from_str(&config_str)?;
// parse config and return it
Ok(toml::from_str(&config)?)
Ok(config)
}
}