mirror of
https://github.com/MedzikUser/HomeDisk.git
synced 2024-08-14 21:46:53 +00:00
chore(config): parse config from current work directory
This commit is contained in:
parent
4e9ecc007c
commit
b5ff8dd32c
3 changed files with 5 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
//!
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue