mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
minor cleanups
This commit is contained in:
parent
1acf6e4d35
commit
2feefb3ca3
@ -1,13 +1,8 @@
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! info {
|
macro_rules! info {
|
||||||
($writer:expr, $($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
use crate::macros::_info_helper;
|
$crate::macros::_info_helper();
|
||||||
_info_helper();
|
println!($($arg)*);
|
||||||
println!($writer, $($arg)*);
|
|
||||||
};
|
|
||||||
($writer:expr) => {
|
|
||||||
_info_helper();
|
|
||||||
println!($writer);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,23 +1,11 @@
|
|||||||
/// Util function to skip the two leading long flag hyphens.
|
/// Util function to skip the two leading long flag hyphens.
|
||||||
pub fn trim_double_hyphen(flag_text: &str) -> &str {
|
pub fn trim_double_hyphen(flag_text: &str) -> &str {
|
||||||
let mut chars = flag_text.chars();
|
flag_text.get(2..).unwrap_or_default()
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::trim_double_hyphen;
|
use super::trim_double_hyphen;
|
||||||
use super::trim_single_hyphen;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn _trim_double_hyphen() {
|
fn _trim_double_hyphen() {
|
||||||
@ -25,9 +13,4 @@ mod tests {
|
|||||||
assert_eq!(trim_double_hyphen("--verbose"), "verbose");
|
assert_eq!(trim_double_hyphen("--verbose"), "verbose");
|
||||||
assert_eq!(trim_double_hyphen("--help"), "help");
|
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ use crate::{dialogs::Confirmation, info, oof};
|
|||||||
pub fn dir_is_empty(dir_path: &Path) -> bool {
|
pub fn dir_is_empty(dir_path: &Path) -> bool {
|
||||||
let is_empty = |mut rd: ReadDir| rd.next().is_none();
|
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<()> {
|
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);
|
Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")).ask(Some(&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))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_utf(os_str: impl AsRef<OsStr>) -> String {
|
pub fn to_utf(os_str: impl AsRef<OsStr>) -> String {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user