diff --git a/src/list_cli.rs b/src/list_cli.rs index d46dca1..11c3e4a 100644 --- a/src/list_cli.rs +++ b/src/list_cli.rs @@ -1,5 +1,5 @@ use clap::Parser; -use cull_gmail::{Error, List}; +use cull_gmail::{Error, Labels, List}; /// Command line options for the list subcommand #[derive(Debug, Parser)] @@ -10,13 +10,28 @@ pub struct ListCli { /// Maximum number of pages (0=all) #[arg(short, long, default_value = "1")] pages: u32, + /// Labels to filter the message list + #[arg(short, long)] + labels: Vec, } impl ListCli { pub(crate) async fn run(&self, credential_file: &str) -> Result<(), Error> { - log::debug!("Max results: `{}`", self.max_results); + let mut labels = Labels::new(credential_file).await?; + labels.get_labels().await?; + log::trace!("labels found and setup {labels:#?}"); let mut list = List::new(credential_file).await?; + log::debug!("labels from command line: {:?}", self.labels); + + for label in &self.labels { + if let Some(l) = labels.get_label_id(label) { + log::trace!("adding `{l}` id to labels"); + list.add_label(&l); + } + } + + log::trace!("Max results: `{}`", self.max_results); list.set_max_results(self.max_results); log::debug!("List max results set to {}", list.max_results());