Moved fediverse config path to constant

This commit is contained in:
Emile 2021-06-25 20:48:23 +01:00
parent c96ff09128
commit d467fd261a
1 changed files with 5 additions and 2 deletions

View File

@ -6,6 +6,9 @@ use elefren::{
status_builder::Visibility, status_builder::Visibility,
Language, Mastodon, MastodonClient, Registration, StatusBuilder, Language, Mastodon, MastodonClient, Registration, StatusBuilder,
}; };
const FEDIVERSE_TOML_PATH: &str = "fediverse.toml";
pub trait Publisher { pub trait Publisher {
fn publish(&self, content: String) -> Option<Box<dyn Error>>; fn publish(&self, content: String) -> Option<Box<dyn Error>>;
} }
@ -16,7 +19,7 @@ pub struct FediversePublisher {
impl FediversePublisher { impl FediversePublisher {
pub fn new(fedi_url: String) -> Result<FediversePublisher, Box<dyn Error>> { pub fn new(fedi_url: String) -> Result<FediversePublisher, Box<dyn Error>> {
let fedi = if let Ok(data) = toml::from_file("fediverse.toml") { let fedi = if let Ok(data) = toml::from_file(FEDIVERSE_TOML_PATH.to_string()) {
Mastodon::from(data) Mastodon::from(data)
} else { } else {
register(fedi_url)? register(fedi_url)?
@ -56,7 +59,7 @@ fn register(fedi_url: String) -> Result<Mastodon, Box<dyn Error>> {
let fediverse = cli::authenticate(registration)?; let fediverse = cli::authenticate(registration)?;
// Save app data for using on the next run. // Save app data for using on the next run.
toml::to_file(&*fediverse, "fediverse.toml")?; toml::to_file(&*fediverse, FEDIVERSE_TOML_PATH.to_string())?;
Ok(fediverse) Ok(fediverse)
} }