From 420ca81f51e42cc63c9f39be4db6f5bd0df8fed8 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Wed, 1 Oct 2025 10:04:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(cli):=20add=20list=20subcomman?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implement list subcommand to display Gmail messages - Use google_gmail1 crate to interact with Gmail API --- src/list_cli.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/list_cli.rs diff --git a/src/list_cli.rs b/src/list_cli.rs new file mode 100644 index 0000000..6e7b3f7 --- /dev/null +++ b/src/list_cli.rs @@ -0,0 +1,32 @@ +use clap::Parser; +use google_gmail1::{ + Error, Gmail, hyper_rustls::HttpsConnector, hyper_util::client::legacy::connect::HttpConnector, +}; + +/// Command line options for the list subcommand +#[derive(Debug, Parser)] +pub struct ListCli {} + +impl ListCli { + pub(crate) async fn run(&self, hub: Gmail>) { + let result = hub.users().messages_list("me").doit().await; + + match result { + Err(e) => match e { + // The Error enum provides details about what exactly happened. + // You can also just use its `Debug`, `Display` or `Error` traits + Error::HttpError(_) + | Error::Io(_) + | Error::MissingAPIKey + | Error::MissingToken(_) + | Error::Cancelled + | Error::UploadSizeLimitExceeded(_, _) + | Error::Failure(_) + | Error::BadRequest(_) + | Error::FieldClash(_) + | Error::JsonDecodeError(_, _) => println!("{e}"), + }, + Ok(res) => println!("Success: {res:?}"), + } + } +}