feat(labels): add show option to display labels

- add option to show labels when creating a new label
- only display labels if show is true
This commit is contained in:
Jeremiah Russell
2025-10-03 17:36:35 +01:00
committed by Jeremiah Russell
parent 8518242302
commit bdf6f56f50

View File

@@ -34,7 +34,7 @@ impl std::fmt::Debug for Labels {
impl Labels { impl Labels {
/// Create a new List struct and add the Gmail api connection. /// Create a new List struct and add the Gmail api connection.
pub async fn new(credential: &str) -> Result<Self, Error> { pub async fn new(credential: &str, show: bool) -> Result<Self, Error> {
let (config_dir, secret) = { let (config_dir, secret) = {
let config_dir = crate::utils::assure_config_dir_exists("~/.cull-gmail")?; let config_dir = crate::utils::assure_config_dir_exists("~/.cull-gmail")?;
@@ -67,12 +67,14 @@ impl Labels {
let call = hub.users().labels_list("me"); let call = hub.users().labels_list("me");
let (_response, list) = call.doit().await.map_err(Box::new)?; let (_response, list) = call.doit().await.map_err(Box::new)?;
if let Some(labels) = &list.labels { if show {
for label in labels { if let Some(labels) = &list.labels {
if let Some(name) = &label.name { for label in labels {
log::info!("{name}"); if let Some(name) = &label.name {
} else { log::info!("{name}");
log::warn!("No name for label {:?}", label.id); } else {
log::warn!("No name for label {:?}", label.id);
}
} }
} }
} }