From 4390fe4c2d89b8c1b17fe01f31da8ed2c8b80f6e Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Tue, 7 Oct 2025 15:51:26 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(cli):=20load=20configuration?= =?UTF-8?q?=20for=20message=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - load config file instead of hardcoding credential path - create default config if not exist --- src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 60158e1..be17f2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ mod message_cli; mod trash_cli; use config_cli::ConfigCli; -use cull_gmail::Error; +use cull_gmail::{Config, Error}; use label_cli::LabelCli; use message_cli::MessageCli; use std::error::Error as stdError; @@ -62,9 +62,10 @@ async fn main() { } async fn run(args: Cli) -> Result<(), Error> { + let config = get_config()?; if let Some(cmds) = args.command { match cmds { - Commands::Message(list_cli) => list_cli.run("credential.json").await?, + Commands::Message(list_cli) => list_cli.run(config.credential_file()).await?, Commands::Labels(label_cli) => label_cli.run("credential.json").await?, Commands::Trash(trash_cli) => trash_cli.run("credential.json").await?, Commands::Config(config_cli) => config_cli.run(), @@ -89,3 +90,15 @@ fn get_logging(level: log::LevelFilter) -> env_logger::Builder { builder } + +fn get_config() -> Result { + match Config::load() { + Ok(c) => Ok(c), + Err(_) => { + log::warn!("Configuration not found, creating default config."); + let config = Config::new(); + config.save()?; + Ok(config) + } + } +}