feat: add macros for `warn_println` and `info_println`
Diff
src/main.rs | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
@@ -1,4 +1,5 @@
use std::{env, process::{Command, Stdio}};
use std::{env, process::{Command, Stdio}, ffi::OsString};
use std::str::FromStr;
use gumdrop::Options;
use anyhow::{Result, Context};
use colored::*;
@@ -23,6 +24,18 @@ macro_rules! debug_println {
}
}
macro_rules! warn_println {
($($arg:tt)*) => {
println!("{}",format!($($arg)*).yellow());
}
}
macro_rules! info_println {
($($arg:tt)*) => {
println!("{}",format!($($arg)*).green());
}
}
fn main() -> Result<()> {
let unlock_passphrase = env::var(BW_FIELD_KEY_PASSPHRASE);
@@ -49,6 +62,8 @@ fn main() -> Result<()> {
for folder in folders {
let folder_items = bwutil::exec_list_folder_items(&session_token, &folder.id)?;
debug_println!("Found {} item(s) in folder `{}` id({}) with at least one custom field and attachment", folder_items.len().to_string().cyan(), folder.name.cyan(), folder.id.cyan());
for item in folder_items {
@@ -90,7 +105,7 @@ fn main() -> Result<()> {
fn check_session_token(args: &util::Cli) -> Result<String> {
println!("Getting Bitwarden session...");
info_println!("Getting Bitwarden session...");
let mut session_token: String = String::new();
if args.session.trim().is_empty() {
@@ -98,18 +113,18 @@ fn check_session_token(args: &util::Cli) -> Result<String> {
let env_key = env::var(SESSION_ENV_KEY);
match env_key {
Ok(key) => {
println!("{} is set. Reusing existing session.", SESSION_ENV_KEY);
info_println!("{} is set. Reusing existing session.", SESSION_ENV_KEY);
session_token.push_str(&key);
},
Err(_) => {
println!("{} is not set. Attempting to login.", SESSION_ENV_KEY);
warn_println!("{} is not set. Attempting to login.", SESSION_ENV_KEY);
let token: &String = &bwutil::get_session_token()?;
if !token.is_empty() {
println!("Successfully unlocked. To re-use this session, run:");
println!("export {}=\"{}\"", SESSION_ENV_KEY, token);
info_println!("Successfully unlocked. To re-use this session, run:");
info_println!("export {}=\"{}\"", SESSION_ENV_KEY, token);
}
session_token.push_str(token)
}