Alternative location for toot config

This commit is contained in:
Stefan Schlott 2022-09-21 08:26:05 +02:00
parent 7650f9facc
commit bd7d9ad4eb

View file

@ -2,13 +2,19 @@ extern crate elefren;
use std::env;
use std::io;
use std::path::Path;
use std::error::Error;
use elefren::prelude::*;
use elefren::helpers::toml; // requires `features = ["toml"]`
fn main() -> Result<(), Box<dyn Error>> {
let mastodon = if let Ok(data) = toml::from_file("mastodon-data.toml") {
let config_filename = if Path::new("mastodon-data.toml").exists() {
"mastodon-data.toml"
} else {
"~/.mastodon-data.toml"
};
let mastodon = if let Ok(data) = toml::from_file(config_filename) {
Mastodon::from(data)
} else {
register()?