From af0ddab54a5cf259dbbd0017fa980423aaf1fb16 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Wed, 1 Oct 2025 09:59:12 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(cli):=20implement=20list=20sub?= =?UTF-8?q?command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add `list` subcommand using clap - integrate google_gmail1 crate for Gmail API interaction - add credential loading and authentication flow --- src/main.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index b679ef3..75e5510 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,11 @@ use clap::{Parser, Subcommand}; +mod list_cli; + +use cull_gmail::Credential; +use google_gmail1::{Gmail, yup_oauth2::ApplicationSecret}; +use list_cli::ListCli; + #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] struct Cli { @@ -13,16 +19,17 @@ struct Cli { enum Commands { /// List messages #[clap(name = "list")] - List, + List(ListCli), } -fn main() { +#[tokio::main] +async fn main() { let args = Cli::parse(); let mut logging = get_logging(args.logging.log_level_filter()); logging.init(); - run(args); + run(args).await; // match run(args) { // Ok(_) => {} // Err(e) => { @@ -38,10 +45,17 @@ fn main() { // } } -fn run(args: Cli) { +async fn run(args: Cli) { + let secret: ApplicationSecret = Credential::load_json_file("credential.json").into(); + + let auth = cull_gmail::get_auth(secret).await; + let client = cull_gmail::get_client(); + + let hub = Gmail::new(client, auth); + if let Some(cmds) = args.command { match cmds { - Commands::List => todo!(), + Commands::List(list_cli) => list_cli.run(hub).await, } } // Ok(())