mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
rm: return UResult from uumain() function
This commit is contained in:
parent
4ae838a8b2
commit
f6305e2a3e
2 changed files with 14 additions and 10 deletions
|
@ -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> {
|
||||
|
|
|
@ -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()
|
||||
));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue