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] #[tokio::main]
async fn main() { async fn main() {
// initialize logger
logger::init(); logger::init();
// parse config
let config = Config::parse().expect("parse config"); let config = Config::parse().expect("parse config");
// open database connection // open database connection

View File

@ -1,6 +1,6 @@
//! # Configuration file //! # 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 //! ## Example config
//! //!

View File

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