From c42b6fca97502bd3f590f78324cfc9437e5ce20d Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Tue, 23 Apr 2024 20:50:27 +0200 Subject: [PATCH] add log folder config --- Cargo.toml | 2 +- src/lib.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index beb3fd2..8e085d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "twba-backup-config" -version = "0.1.4" +version = "0.1.5" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/lib.rs b/src/lib.rs index 6419fce..d2681f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ use prelude::*; use serde::{Deserialize, Serialize}; +use std::path::{Path, PathBuf}; pub mod prelude { pub use super::Conf; pub use confique::Config; @@ -10,6 +11,9 @@ pub struct Conf { /// The Database Connection URL #[config(default = "sqlite://data.db?mode=rwc")] pub db_url: String, + /// The folder where all the logs will be stored. + #[config(default = "/var/tmp/twba/logs/")] + pub log_folder: String, #[config(nested)] pub twitch: Twitch, @@ -29,6 +33,16 @@ pub struct Conf { pub maximum_downloaded_videos: Option, } +impl Conf { + pub fn log_path(&self) -> PathBuf { + #[cfg(feature = "home")] + let path = &shellexpand::tilde(&self.log_folder).into_owned(); + + #[cfg(not(feature = "home"))] + let path = &self.log_folder; + PathBuf::from(path) + } +} #[derive(Debug, Serialize, Deserialize, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Config)] pub struct Google { /// The path for the auth code file.