From 66b7c820d7103d3d4e6d6d0dd8884723807d89ba Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Thu, 16 Oct 2025 06:47:35 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(cli):=20use=20Cli?= =?UTF-8?q?entConfig=20struct=20for=20gmail=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - use ClientConfig struct instead of credential string - load config from file and env vars - simplify config loading and client creation --- src/cli/main.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cli/main.rs b/src/cli/main.rs index 8c38d6f..691270e 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -4,8 +4,7 @@ mod labels_cli; mod messages_cli; mod rules_cli; -use config::Config; -use cull_gmail::{GmailClient, Result}; +use cull_gmail::{ClientConfig, GmailClient, Result}; use std::{env, error::Error as stdError}; use labels_cli::LabelsCli; @@ -60,8 +59,7 @@ async fn main() { async fn run(args: Cli) -> Result<()> { let config = get_config()?; - let credential = config.get_string("credentials")?; - let mut client = GmailClient::new(&credential).await?; + let mut client = GmailClient::new_with_config(config).await?; match args.sub_command { SubCmds::Message(messages_cli) => messages_cli.run(&mut client).await, @@ -87,13 +85,14 @@ fn get_logging(level: log::LevelFilter) -> env_logger::Builder { builder } -fn get_config() -> Result { +fn get_config() -> Result { let home_dir = env::home_dir().unwrap(); let path = home_dir.join(".cull-gmail/rules.toml"); log::trace!("Loading config from {}", path.display()); - Ok(Config::builder() + let configurations = config::Config::builder() .set_default("credentials", "credential.json")? + .set_default("config_root", "h:.cull-gmail")? // Add in `./Settings.toml` .add_source(config::File::with_name( path.to_path_buf().to_str().unwrap(), @@ -101,5 +100,7 @@ fn get_config() -> Result { // 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()?) + .build()?; + + ClientConfig::new_from_configuration(configurations) }