chore(config): use config from current directory instead of system configuration directory
This commit is contained in:
parent
4e9ecc007c
commit
07a9eddede
|
@ -720,7 +720,6 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"axum",
|
"axum",
|
||||||
"crypto-utils",
|
"crypto-utils",
|
||||||
"dirs",
|
|
||||||
"hex",
|
"hex",
|
||||||
"serde",
|
"serde",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
|
|
@ -6,3 +6,8 @@ members = [
|
||||||
"types",
|
"types",
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
opt-level = 'z'
|
||||||
|
codegen-units = 1
|
||||||
|
|
|
@ -11,11 +11,9 @@ 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("Failed to parse configuration file");
|
||||||
let config = Config::parse().expect("parse config");
|
|
||||||
|
|
||||||
// open database connection
|
// open database connection
|
||||||
let db =
|
let db =
|
||||||
|
|
|
@ -4,7 +4,7 @@ version = "0.0.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
config = ["toml", "dirs"]
|
config = ["toml"]
|
||||||
database = ["crypto-utils", "hex", "sqlx"]
|
database = ["crypto-utils", "hex", "sqlx"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -14,7 +14,6 @@ anyhow = "1.0.62"
|
||||||
serde = { version = "1.0.144", features = ["derive"] }
|
serde = { version = "1.0.144", features = ["derive"] }
|
||||||
axum = { version = "0.5.15", optional = true }
|
axum = { version = "0.5.15", optional = true }
|
||||||
toml = { version = "0.5.9", optional = true }
|
toml = { version = "0.5.9", optional = true }
|
||||||
dirs = { version = "4.0.0", optional = true }
|
|
||||||
crypto-utils = { version = "0.4.0", features = ["sha"], optional = true }
|
crypto-utils = { version = "0.4.0", features = ["sha"], optional = true }
|
||||||
hex = { version = "0.4.3", optional = true }
|
hex = { version = "0.4.3", optional = true }
|
||||||
sqlx = { version = "0.6.1", features = ["sqlite"], optional = true }
|
sqlx = { version = "0.6.1", features = ["sqlite"], optional = true }
|
||||||
|
|
|
@ -46,15 +46,10 @@ impl Config {
|
||||||
/// let config = Config::parse().unwrap();
|
/// let config = Config::parse().unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn parse() -> anyhow::Result<Config> {
|
pub fn parse() -> anyhow::Result<Config> {
|
||||||
// get path to the user's config directory
|
let config = 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 serialized = toml::from_str(&config)?;
|
||||||
let config = fs::read_to_string(config_path)?;
|
|
||||||
|
|
||||||
// parse config and return it
|
Ok(serialized)
|
||||||
Ok(toml::from_str(&config)?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue