Assemble path with home dir

This commit is contained in:
Stefan Schlott 2022-09-21 08:59:50 +02:00
parent bd7d9ad4eb
commit 92dcbc49fc

View file

@ -9,10 +9,12 @@ use elefren::prelude::*;
use elefren::helpers::toml; // requires `features = ["toml"]`
fn main() -> Result<(), Box<dyn Error>> {
let home = env::var("HOME").unwrap();
let home_config_filename = format!("{}/.mastodon-data.toml", home);
let config_filename = if Path::new("mastodon-data.toml").exists() {
"mastodon-data.toml"
} else {
"~/.mastodon-data.toml"
home_config_filename.as_str()
};
let mastodon = if let Ok(data) = toml::from_file(config_filename) {
Mastodon::from(data)