From 2fa7cd21ab7f41a0094ee22432a239a2ba671d00 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Wed, 15 Oct 2025 14:26:21 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(rules):=20remove?= =?UTF-8?q?=20credentials=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remove unused credentials configuration - remove credentials file setting/getting logic - rename config file to rules.toml --- src/cli/main.rs | 9 +++++++++ src/rules.rs | 29 +++-------------------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/cli/main.rs b/src/cli/main.rs index e4b95ab..dd1be33 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -84,6 +84,15 @@ fn get_logging(level: log::LevelFilter) -> env_logger::Builder { } fn get_config() -> Result { + // let settings = Config::builder() + // // Add in `./Settings.toml` + // .add_source(config::File::with_name("examples/simple/Settings")) + // // Add in settings from the environment (with a prefix of APP) + // // Eg.. `APP_DEBUG=1 ./target/app` would set the `debug` key + // .add_source(config::Environment::with_prefix("APP")) + // .build() + // .unwrap(); + match Rules::load() { Ok(c) => Ok(c), Err(_) => { diff --git a/src/rules.rs b/src/rules.rs index 7b33e27..79f68dc 100644 --- a/src/rules.rs +++ b/src/rules.rs @@ -16,7 +16,6 @@ use crate::{EolAction, Error, MessageAge, Result, Retention}; /// Configuration file for the program #[derive(Debug, Serialize, Deserialize)] pub struct Rules { - credentials: Option, rules: BTreeMap, } @@ -24,10 +23,7 @@ impl Default for Rules { fn default() -> Self { let rules = BTreeMap::new(); - let mut cfg = Self { - credentials: Some("credential.json".to_string()), - rules, - }; + let mut cfg = Self { rules }; cfg.add_rule(Retention::new(MessageAge::Years(1), true), None, false) .add_rule(Retention::new(MessageAge::Weeks(1), true), None, false) @@ -44,12 +40,6 @@ impl Rules { Rules::default() } - /// Set a name for the credentials file - pub fn set_credentials(&mut self, file_name: &str) -> &mut Self { - self.credentials = Some(file_name.to_string()); - self - } - /// Get the contents of an existing rule pub fn get_rule(&self, id: usize) -> Option { self.rules.get(&id.to_string()).cloned() @@ -189,9 +179,7 @@ impl Rules { /// Save the current configuration to the file pub fn save(&self) -> Result<()> { let home_dir = env::home_dir().unwrap(); - let path = PathBuf::new() - .join(home_dir) - .join(".cull-gmail/cull-gmail.toml"); + let path = PathBuf::new().join(home_dir).join(".cull-gmail/rules.toml"); let res = toml::to_string(self); log::trace!("toml conversion result: {res:#?}"); @@ -207,9 +195,7 @@ impl Rules { /// Load the current configuration pub fn load() -> Result { let home_dir = env::home_dir().unwrap(); - let path = PathBuf::new() - .join(home_dir) - .join(".cull-gmail/cull-gmail.toml"); + let path = PathBuf::new().join(home_dir).join(".cull-gmail/rules.toml"); log::trace!("Loading config from {}", path.display()); let input = read_to_string(path)?; @@ -217,15 +203,6 @@ impl Rules { Ok(config) } - /// Return the credential file name - pub fn credential_file(&self) -> &str { - if let Some(file) = &self.credentials { - file - } else { - "" - } - } - /// List the end of life rules set in the configuration pub fn list_rules(&self) -> Result<()> { for rule in self.rules.values() {