From 8376ba45126292ad414a35be7299cab96b620d29 Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Wed, 2 Aug 2023 16:17:18 +0200 Subject: [PATCH] fix: fixed the `--debug` argument not being used --- src/main.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7573465..24362d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,15 @@ const SESSION_ENV_KEY: &str = "BW_SESSION"; /// Environment variable referencing the name of the field containing the SSH key passphrase (if any). const BW_FIELD_KEY_PASSPHRASE: &str = "BW_KEY_PASSPHRASE"; +/// A macro to print when the debug CLI arg is enabled. +macro_rules! debug_println { + ($debug:expr, $($arg:tt)*) => { + if $debug { + println!($($arg)*); + } + } +} + fn main() -> Result<()> { // This environment variable only set when calling ssh-agent, so return the passphrase to authenticate and then quit. let unlock_passphrase = env::var(BW_FIELD_KEY_PASSPHRASE); @@ -27,9 +36,13 @@ fn main() -> Result<()> { let session_token: String = check_session_token(&args)?; if !session_token.is_empty() { let folders = bwutil::exec_folder_search(&session_token, &args.folder)?; + debug_println!(args.debug, "Found {} folder(s) named `{}`", folders.len(), args.folder); + // Retrieve items from each folder since there may be multiple folders with the same name. for folder in folders { let folder_items = bwutil::exec_list_folder_items(&session_token, &folder.id)?; + debug_println!(args.debug, "Found {} item(s) in folder `{}` id({})", folder_items.len(), folder.name, folder.id); + for item in folder_items { // In order for this to be considered a valid SSH key item, this item needs to have the following fields: // - private - (required) this is the filename of the attachment containing the SSH key. @@ -52,7 +65,7 @@ fn main() -> Result<()> { if let Some(attachments) = &item.attachments { for attachment in attachments { if attachment.file_name.eq(&key_filename) { - //println!("{:#?}", item); + debug_println!(args.debug, "Item `{}` id({}) meets all requirements. Adding to `ssh-agent`", item.name, item.id); let _key = register_key(&item.id, &attachment.id, &key_passphrase, &session_token)?; } } -- libgit2 1.7.2