diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index 202adff27..86a971085 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -18,6 +18,7 @@ use std::io::{stderr, stdin, BufRead, Write}; use std::ops::BitOr; use std::path::{Path, PathBuf}; use uucore::display::Quotable; +use uucore::error::{UResult, USimpleError, UUsageError}; use walkdir::{DirEntry, WalkDir}; #[derive(Eq, PartialEq, Clone, Copy)] @@ -75,7 +76,8 @@ fn get_long_usage() -> String { ) } -pub fn uumain(args: impl uucore::Args) -> i32 { +#[uucore_procs::gen_uumain] +pub fn uumain(args: impl uucore::Args) -> UResult<()> { let usage = usage(); let long_usage = get_long_usage(); @@ -94,9 +96,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { if files.is_empty() && !force { // Still check by hand and not use clap // Because "rm -f" is a thing - show_error!("missing an argument"); - show_error!("for help, try '{0} --help'", uucore::execution_phrase()); - return 1; + return Err(UUsageError::new(1, "missing operand")); } else { let options = Options { force, @@ -110,7 +110,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 { "none" => InteractiveMode::None, "once" => InteractiveMode::Once, "always" => InteractiveMode::Always, - val => crash!(1, "Invalid argument to interactive ({})", val), + val => { + return Err(USimpleError::new( + 1, + format!("Invalid argument to interactive ({})", val), + )) + } } } else { InteractiveMode::None @@ -129,16 +134,15 @@ pub fn uumain(args: impl uucore::Args) -> i32 { "Remove all arguments? " }; if !prompt(msg) { - return 0; + return Ok(()); } } if remove(files, options) { - return 1; + return Err(1.into()); } } - - 0 + Ok(()) } pub fn uu_app() -> App<'static, 'static> { diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index 740c30bdd..f846e064b 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -280,7 +280,7 @@ fn test_rm_force_no_operand() { fn test_rm_no_operand() { let ts = TestScenario::new(util_name!()); ts.ucmd().fails().stderr_is(&format!( - "{0}: missing an argument\n{0}: for help, try '{1} {0} --help'\n", + "{0}: missing operand\nTry '{1} {0} --help' for more information.\n", ts.util_name, ts.bin_path.to_string_lossy() ));