From 2feefb3ca35b210e41c3f132210ce01cfebc38e6 Mon Sep 17 00:00:00 2001 From: figsoda Date: Sun, 17 Oct 2021 17:54:40 -0400 Subject: [PATCH] minor cleanups --- src/macros.rs | 11 +++-------- src/oof/util.rs | 19 +------------------ src/utils.rs | 9 ++------- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 14996e3..76877fa 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,13 +1,8 @@ #[macro_export] macro_rules! info { - ($writer:expr, $($arg:tt)*) => { - use crate::macros::_info_helper; - _info_helper(); - println!($writer, $($arg)*); - }; - ($writer:expr) => { - _info_helper(); - println!($writer); + ($($arg:tt)*) => { + $crate::macros::_info_helper(); + println!($($arg)*); }; } diff --git a/src/oof/util.rs b/src/oof/util.rs index 5479818..0e75350 100644 --- a/src/oof/util.rs +++ b/src/oof/util.rs @@ -1,23 +1,11 @@ /// Util function to skip the two leading long flag hyphens. pub fn trim_double_hyphen(flag_text: &str) -> &str { - let mut chars = flag_text.chars(); - chars.nth(1); // Skipping 2 chars - chars.as_str() -} - -// Currently unused -/// Util function to skip the single leading short flag hyphen. -pub fn trim_single_hyphen(flag_text: &str) -> &str { - let mut chars = flag_text.chars(); - - chars.next(); // Skipping 1 char - chars.as_str() + flag_text.get(2..).unwrap_or_default() } #[cfg(test)] mod tests { use super::trim_double_hyphen; - use super::trim_single_hyphen; #[test] fn _trim_double_hyphen() { @@ -25,9 +13,4 @@ mod tests { assert_eq!(trim_double_hyphen("--verbose"), "verbose"); assert_eq!(trim_double_hyphen("--help"), "help"); } - - fn _trim_single_hyphen() { - assert_eq!(trim_single_hyphen("-vv"), "vv"); - assert_eq!(trim_single_hyphen("-h"), "h"); - } } diff --git a/src/utils.rs b/src/utils.rs index a372051..71e0337 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -11,7 +11,7 @@ use crate::{dialogs::Confirmation, info, oof}; pub fn dir_is_empty(dir_path: &Path) -> bool { let is_empty = |mut rd: ReadDir| rd.next().is_none(); - dir_path.read_dir().ok().map(is_empty).unwrap_or_default() + dir_path.read_dir().map(is_empty).unwrap_or_default() } pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> { @@ -45,12 +45,7 @@ pub fn user_wants_to_overwrite(path: &Path, flags: &oof::Flags) -> crate::Result _ => {} } - let file_path_str = to_utf(path); - - const OVERWRITE_CONFIRMATION_QUESTION: Confirmation = - Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")); - - OVERWRITE_CONFIRMATION_QUESTION.ask(Some(&file_path_str)) + Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")).ask(Some(&to_utf(path))) } pub fn to_utf(os_str: impl AsRef) -> String {