chore(config): parse config from current work directory
This commit is contained in:
parent
4e9ecc007c
commit
b5ff8dd32c
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -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)?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue