From f10059db026cdda3def757ee6a430b122e59bd83 Mon Sep 17 00:00:00 2001 From: John Shin Date: Tue, 30 May 2023 13:40:41 -0700 Subject: [PATCH] shred: refactor get_size --- src/uu/shred/src/shred.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 1ceffe995..47c3ff6ec 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -320,16 +320,16 @@ pub fn uu_app() -> Command { } fn get_size(size_str_opt: Option) -> Option { - match size_str_opt { - Some(size) => match parse_size(size.as_str()) { - Ok(res) => Some(res), - Err(_) => { + size_str_opt + .as_ref() + .and_then(|size| parse_size(size.as_str()).ok()) + .or_else(|| { + if let Some(size) = size_str_opt { show_error!("invalid file size: {}", size.quote()); - std::process::exit(1) + std::process::exit(1); } - }, - None => None, - } + None + }) } fn pass_name(pass_type: &PassType) -> String {