diff --git a/src/uu/arch/src/arch.rs b/src/uu/arch/src/arch.rs index 502e2d5a0..69049868d 100644 --- a/src/uu/arch/src/arch.rs +++ b/src/uu/arch/src/arch.rs @@ -16,7 +16,7 @@ static SUMMARY: &str = "Determine architecture name for current machine."; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - uu_app().get_matches_from(args); + uu_app().try_get_matches_from(args)?; let uts = PlatformInfo::new().map_err_context(|| "cannot get system name".to_string())?; println!("{}", uts.machine().trim()); diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index 4d0125330..88e2cae02 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -49,7 +49,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // // Argument parsing // - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; // too few arguments if !matches.contains_id(options::NAME) { diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index 181517fea..23b838d29 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -54,7 +54,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let after_help = get_long_usage(); - let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&after_help[..]) + .try_get_matches_from(args)?; let changes = matches.contains_id(options::CHANGES); let quiet = matches.contains_id(options::QUIET); diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 1e5f62d5f..b4926acd9 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -15,7 +15,7 @@ use std::ffi::CString; use std::io::Error; use std::path::Path; use std::process; -use uucore::error::{set_exit_code, UResult}; +use uucore::error::{set_exit_code, UClapError, UResult}; use uucore::libc::{self, chroot, setgid, setgroups, setuid}; use uucore::{entries, format_usage}; @@ -35,7 +35,7 @@ mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?; let default_shell: &'static str = "/bin/sh"; let default_option: &'static str = "-i"; diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 2d8c930fe..8008833ad 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -115,7 +115,7 @@ mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let files: Vec = match matches.get_many::(options::FILE) { Some(v) => v.clone().map(|v| v.to_owned()).collect(), diff --git a/src/uu/comm/src/comm.rs b/src/uu/comm/src/comm.rs index 5e08613cd..c14c692dc 100644 --- a/src/uu/comm/src/comm.rs +++ b/src/uu/comm/src/comm.rs @@ -134,7 +134,7 @@ fn open_file(name: &str) -> io::Result { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let filename1 = matches.value_of(options::FILE_1).unwrap(); let filename2 = matches.value_of(options::FILE_2).unwrap(); let mut f1 = open_file(filename1).map_err_context(|| filename1.to_string())?; diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index 143d2d2e8..d6f8bb4a6 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -715,7 +715,7 @@ mod tests { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; // get the file to split let file_name = matches.value_of(options::FILE).unwrap(); diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index a1883adc5..eec404666 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -401,7 +401,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); let delimiter_is_equal = args.contains(&"-d=".to_string()); // special case - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let complement = matches.contains_id(options::COMPLEMENT); diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index daed244e3..b1535a995 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -144,7 +144,7 @@ impl<'a> From<&'a str> for Rfc3339Format { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let format = if let Some(form) = matches.value_of(OPT_FORMAT) { if !form.starts_with('+') { diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 57a661b94..480dd915a 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -712,7 +712,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app() //.after_help(TODO: Add note about multiplier strings here.) - .get_matches_from(dashed_args); + .try_get_matches_from(dashed_args)?; match ( matches.contains_id(options::INFILE), diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 6abf93366..e07247200 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -431,7 +431,7 @@ impl fmt::Display for DfError { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; #[cfg(windows)] { diff --git a/src/uu/dircolors/src/dircolors.rs b/src/uu/dircolors/src/dircolors.rs index 3224f07e1..72b49f767 100644 --- a/src/uu/dircolors/src/dircolors.rs +++ b/src/uu/dircolors/src/dircolors.rs @@ -67,7 +67,7 @@ pub fn guess_syntax() -> OutputFmt { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().get_matches_from(&args); + let matches = uu_app().try_get_matches_from(&args)?; let files = matches .get_many::(options::FILE) diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 0a4b16832..2bfdbb2e9 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -32,7 +32,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let after_help = get_long_usage(); - let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&after_help[..]) + .try_get_matches_from(args)?; let separator = if matches.contains_id(options::ZERO) { "\0" diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 41a532ffd..dd7c78899 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -517,7 +517,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult> { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let summarize = matches.contains_id(options::SUMMARIZE); diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index 7590feb88..f8437a69b 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -26,7 +26,7 @@ use std::iter::Iterator; use std::os::unix::process::ExitStatusExt; use std::process; use uucore::display::Quotable; -use uucore::error::{UResult, USimpleError, UUsageError}; +use uucore::error::{UClapError, UResult, USimpleError, UUsageError}; use uucore::format_usage; #[cfg(unix)] use uucore::signals::signal_name_by_value; @@ -173,7 +173,7 @@ pub fn uu_app<'a>() -> Command<'a> { fn run_env(args: impl uucore::Args) -> UResult<()> { let app = uu_app(); - let matches = app.get_matches_from(args); + let matches = app.try_get_matches_from(args).with_exit_code(125)?; let ignore_env = matches.contains_id("ignore-environment"); let null = matches.contains_id("null"); diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 414138da6..4b72dcadf 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -271,7 +271,7 @@ fn expand_shortcuts(args: &[String]) -> Vec { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().get_matches_from(expand_shortcuts(&args)); + let matches = uu_app().try_get_matches_from(expand_shortcuts(&args))?; expand(&Options::new(&matches)?).map_err_context(|| "failed to write output".to_string()) } diff --git a/src/uu/factor/src/cli.rs b/src/uu/factor/src/cli.rs index 635f215d4..3c345ab48 100644 --- a/src/uu/factor/src/cli.rs +++ b/src/uu/factor/src/cli.rs @@ -47,7 +47,7 @@ fn print_factors_str( #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let stdout = stdout(); // We use a smaller buffer here to pass a gnu test. 4KiB appears to be the default pipe size for bash. let mut w = io::BufWriter::with_capacity(4 * 1024, stdout.lock()); diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index b830fd189..39c896497 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -67,7 +67,7 @@ pub struct FmtOptions { #[uucore::main] #[allow(clippy::cognitive_complexity)] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let mut files: Vec = matches .get_many::(ARG_FILES) diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index 6587d5eae..4e46fa5a1 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -34,7 +34,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); let (args, obs_width) = handle_obsolete(&args[..]); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let bytes = matches.contains_id(options::BYTES); let spaces = matches.contains_id(options::SPACES); diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index e1ddb7edc..f1377234d 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -70,7 +70,7 @@ fn infallible_gid2grp(gid: &u32) -> String { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let users: Vec = matches .get_many::(options::USERS) diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index d0556bacc..cf54a3f1c 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -284,7 +284,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { // causes "error: " to be printed twice (once from crash!() and once from clap). With // the current setup, the name of the utility is not printed, but I think this is at // least somewhat better from a user's perspective. - let matches = command.get_matches_from(args); + let matches = command.try_get_matches_from(args)?; let (name, algo, bits) = detect_algo(&binary_name, &matches); diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index faf2a552d..903a8a6cb 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -154,7 +154,7 @@ impl Mode { fn arg_iterate<'a>( mut args: impl uucore::Args + 'a, -) -> Result + 'a>, String> { +) -> UResult + 'a>> { // argv[0] is always present let first = args.next().unwrap(); if let Some(second) = args.next() { @@ -162,16 +162,22 @@ fn arg_iterate<'a>( match parse::parse_obsolete(s) { Some(Ok(iter)) => Ok(Box::new(vec![first].into_iter().chain(iter).chain(args))), Some(Err(e)) => match e { - parse::ParseError::Syntax => Err(format!("bad argument format: {}", s.quote())), - parse::ParseError::Overflow => Err(format!( - "invalid argument: {} Value too large for defined datatype", - s.quote() + parse::ParseError::Syntax => Err(USimpleError::new( + 1, + format!("bad argument format: {}", s.quote()), + )), + parse::ParseError::Overflow => Err(USimpleError::new( + 1, + format!( + "invalid argument: {} Value too large for defined datatype", + s.quote() + ), )), }, None => Ok(Box::new(vec![first, second].into_iter().chain(args))), } } else { - Err("bad argument encoding".to_owned()) + Err(USimpleError::new(1, "bad argument encoding".to_owned())) } } else { Ok(Box::new(vec![first].into_iter())) @@ -190,9 +196,7 @@ struct HeadOptions { impl HeadOptions { ///Construct options from matches - pub fn get_from(args: impl uucore::Args) -> Result { - let matches = uu_app().get_matches_from(arg_iterate(args)?); - + pub fn get_from(matches: &clap::ArgMatches) -> Result { let mut options = Self::default(); options.quiet = matches.contains_id(options::QUIET_NAME); @@ -200,7 +204,7 @@ impl HeadOptions { options.zeroed = matches.contains_id(options::ZERO_NAME); options.presume_input_pipe = matches.contains_id(options::PRESUME_INPUT_PIPE); - options.mode = Mode::from(&matches)?; + options.mode = Mode::from(matches)?; options.files = match matches.get_many::(options::FILES_NAME) { Some(v) => v.map(|s| s.to_owned()).collect(), @@ -514,7 +518,8 @@ fn uu_head(options: &HeadOptions) -> UResult<()> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let args = match HeadOptions::get_from(args) { + let matches = uu_app().try_get_matches_from(arg_iterate(args)?)?; + let args = match HeadOptions::get_from(&matches) { Ok(o) => o, Err(s) => { return Err(USimpleError::new(1, s)); @@ -531,8 +536,10 @@ mod tests { use super::*; fn options(args: &str) -> Result { let combined = "head ".to_owned() + args; - let args = combined.split_whitespace(); - HeadOptions::get_from(args.map(OsString::from)) + let args = combined.split_whitespace().map(OsString::from); + let matches = uu_app() + .get_matches_from(arg_iterate(args).map_err(|_| String::from("Arg iterate failed"))?); + HeadOptions::get_from(&matches) } #[test] fn test_args_modes() { @@ -579,7 +586,7 @@ mod tests { assert_eq!(opts.mode, Mode::FirstLines(10)); assert!(opts.files.is_empty()); } - fn arg_outputs(src: &str) -> Result { + fn arg_outputs(src: &str) -> Result { let split = src.split_whitespace().map(OsString::from); match arg_iterate(split) { Ok(args) => { @@ -588,7 +595,7 @@ mod tests { .collect::>(); Ok(vec.join(" ")) } - Err(e) => Err(e), + Err(_) => Err(()), } } #[test] diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index 404b08ffd..9c1157e18 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -61,7 +61,7 @@ mod wsa { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; #[cfg(windows)] let _handle = wsa::start().map_err_context(|| "failed to start Winsock".to_owned())?; diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 93be02bf0..6269166ef 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -128,7 +128,9 @@ struct State { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let after_help = get_description(); - let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&after_help[..]) + .try_get_matches_from(args)?; let users: Vec = matches .get_many::(options::ARG_USERS) diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 44ca4aafd..141e429d7 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -171,7 +171,7 @@ static ARG_FILES: &str = "files"; /// #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let paths: Vec = matches .get_many::(ARG_FILES) diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index 665baf16a..b8b0e169f 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -602,7 +602,7 @@ impl<'a> State<'a> { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let keys = parse_field_number_option(matches.value_of("j"))?; let key1 = parse_field_number_option(matches.value_of("1"))?; diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index abb72799d..5dc68f756 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -41,7 +41,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let mut args = args.collect_ignore(); let obs_signal = handle_obsolete(&mut args); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let mode = if matches.contains_id(options::TABLE) { Mode::Table diff --git a/src/uu/link/src/link.rs b/src/uu/link/src/link.rs index 041619938..ba754007f 100644 --- a/src/uu/link/src/link.rs +++ b/src/uu/link/src/link.rs @@ -22,7 +22,7 @@ pub mod options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let files: Vec<_> = matches .get_many::(options::FILES) diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 9530b7f9a..10900260b 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -136,7 +136,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { long_usage, backup_control::BACKUP_CONTROL_LONG_HELP )) - .get_matches_from(args); + .try_get_matches_from(args)?; /* the list of files */ diff --git a/src/uu/logname/src/logname.rs b/src/uu/logname/src/logname.rs index 112923296..94d690713 100644 --- a/src/uu/logname/src/logname.rs +++ b/src/uu/logname/src/logname.rs @@ -38,7 +38,7 @@ static ABOUT: &str = "Print user's login name"; pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let _ = uu_app().get_matches_from(args); + let _ = uu_app().try_get_matches_from(args)?; match get_userlogin() { Some(userlogin) => println!("{}", userlogin), diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 24261c485..3e3bd935d 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -96,7 +96,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // Linux-specific options, not implemented // opts.optflag("Z", "context", "set SELinux security context" + // " of each created directory to CTX"), - let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&after_help[..]) + .try_get_matches_from(args)?; let dirs = matches .get_many::(options::DIRS) diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index 1c70f52c6..a9f5736df 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -30,7 +30,7 @@ mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; if matches.contains_id(options::CONTEXT) { return Err(USimpleError::new(1, "--context is not implemented")); diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 551d1e90d..82b8219b7 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -86,7 +86,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // opts.optflag("Z", "", "set the SELinux security context to default type"); // opts.optopt("", "context", "like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX"); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let mode = get_mode(&matches).map_err(|e| USimpleError::new(1, e))?; diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 8d0dbe93d..17cc01f00 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -77,9 +77,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { backup_control::BACKUP_CONTROL_LONG_HELP ); let mut app = uu_app().after_help(&*help); - let matches = app - .try_get_matches_from_mut(args) - .unwrap_or_else(|e| e.exit()); + let matches = app.try_get_matches_from_mut(args)?; if !matches.contains_id(OPT_TARGET_DIRECTORY) && matches diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 7f36cb424..807a6a072 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -86,7 +86,7 @@ pub mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; // A mutable settings object, initialized with the defaults. let mut settings = Settings { diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 6b11ea920..ddc5b043c 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -21,7 +21,7 @@ use std::io::Error; use std::os::unix::prelude::*; use std::path::{Path, PathBuf}; use uucore::display::Quotable; -use uucore::error::{set_exit_code, UError, UResult}; +use uucore::error::{set_exit_code, UClapError, UError, UResult}; use uucore::format_usage; static ABOUT: &str = "Run COMMAND ignoring hangup signals."; @@ -88,7 +88,7 @@ impl Display for NohupError { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?; replace_fds()?; diff --git a/src/uu/nproc/src/nproc.rs b/src/uu/nproc/src/nproc.rs index dc75ab591..efa00dc98 100644 --- a/src/uu/nproc/src/nproc.rs +++ b/src/uu/nproc/src/nproc.rs @@ -32,7 +32,7 @@ const USAGE: &str = "{} [OPTIONS]..."; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let ignore = match matches.value_of(OPT_IGNORE) { Some(numstr) => match numstr.trim().parse() { diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 36eb295cc..db530a4ad 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -229,7 +229,7 @@ fn concat_format_arg_and_value(args: &[String]) -> Vec { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().get_matches_from(concat_format_arg_and_value(&args)); + let matches = uu_app().try_get_matches_from(concat_format_arg_and_value(&args))?; let options = parse_options(&matches).map_err(NumfmtError::IllegalArgument)?; diff --git a/src/uu/od/src/od.rs b/src/uu/od/src/od.rs index 3d99b8fa8..999693ccf 100644 --- a/src/uu/od/src/od.rs +++ b/src/uu/od/src/od.rs @@ -259,9 +259,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let clap_opts = uu_app(); - let clap_matches = clap_opts - .clone() // Clone to reuse clap_opts to print help - .get_matches_from(args.clone()); + let clap_matches = clap_opts.try_get_matches_from(&args)?; let od_options = OdOptions::new(&clap_matches, &args)?; diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index 70d615f04..655cb2f6f 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -54,7 +54,7 @@ fn read_until( #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let serial = matches.contains_id(options::SERIAL); let delimiters = matches.value_of(options::DELIMITER).unwrap(); diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index fb4d44494..1c0444ac7 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -41,7 +41,7 @@ const POSIX_NAME_MAX: usize = 14; pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; // set working mode let is_posix = matches.get_many::(options::POSIX).is_some(); diff --git a/src/uu/pinky/src/pinky.rs b/src/uu/pinky/src/pinky.rs index 039dd0a5e..18c8dd5b9 100644 --- a/src/uu/pinky/src/pinky.rs +++ b/src/uu/pinky/src/pinky.rs @@ -53,7 +53,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let after_help = get_long_usage(); - let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&after_help[..]) + .try_get_matches_from(args)?; let users: Vec = matches .get_many::(options::USER) diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index fc5820065..72238806c 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -724,8 +724,7 @@ mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - // let mut opts = Options::new(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let mut input_files: Vec = match &matches.get_many::(options::FILE) { Some(v) => v.clone().map(|v| v.to_owned()).collect(), diff --git a/src/uu/pwd/src/pwd.rs b/src/uu/pwd/src/pwd.rs index 21d3a6d43..272133589 100644 --- a/src/uu/pwd/src/pwd.rs +++ b/src/uu/pwd/src/pwd.rs @@ -124,7 +124,7 @@ fn logical_path() -> io::Result { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let cwd = if matches.contains_id(OPT_LOGICAL) { logical_path() } else { diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index ac72d055e..6236f552f 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -34,7 +34,7 @@ const ARG_FILES: &str = "files"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let mut no_trailing_delimiter = matches.contains_id(OPT_NO_NEWLINE); let use_zero = matches.contains_id(OPT_ZERO); diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index dd48bc47d..403727d4c 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -81,7 +81,9 @@ fn get_long_usage() -> String { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let long_usage = get_long_usage(); - let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&long_usage[..]) + .try_get_matches_from(args)?; let files: Vec = matches .get_many::(ARG_FILES) diff --git a/src/uu/rmdir/src/rmdir.rs b/src/uu/rmdir/src/rmdir.rs index c13503222..5a87290fe 100644 --- a/src/uu/rmdir/src/rmdir.rs +++ b/src/uu/rmdir/src/rmdir.rs @@ -33,7 +33,7 @@ static ARG_DIRS: &str = "dirs"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let opts = Opts { ignore: matches.contains_id(OPT_IGNORE_FAIL_NON_EMPTY), diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 99cc3e020..de6ae4204 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -59,7 +59,7 @@ type RangeFloat = (ExtendedBigDecimal, ExtendedBigDecimal, ExtendedBigDecimal); #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let numbers = matches .get_many::(ARG_NUMBERS) diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index 8fa525482..7ef7d3d3d 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -268,7 +268,7 @@ pub mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; if !matches.contains_id(options::FILE) { return Err(UUsageError::new(1, "missing file operand")); diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 50594cedb..ab761516f 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -58,7 +58,7 @@ mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let mode = if let Some(args) = matches.get_many::(options::ECHO) { Mode::Echo(args.map(String::from).collect()) diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 6652af5a0..186451592 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -53,7 +53,7 @@ const AFTER_HELP: &str = "\ #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; match Settings::from(&matches) { Ok(settings) => split(&settings), Err(e) if e.requires_usage() => Err(UUsageError::new(1, format!("{}", e))), diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 4502efab8..2daa36dae 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -985,7 +985,9 @@ for details about the options it supports. pub fn uumain(args: impl uucore::Args) -> UResult<()> { let long_usage = get_long_usage(); - let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&long_usage[..]) + .try_get_matches_from(args)?; let stater = Stater::new(&matches)?; let exit_status = stater.exec(); diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index a74091739..91e36db26 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -158,7 +158,7 @@ fn get_preload_env(tmp_dir: &mut TempDir) -> io::Result<(String, PathBuf)> { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let options = ProgramOptions::try_from(&matches).map_err(|e| UUsageError::new(125, e.0))?; diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 23c1c357c..a3799ce15 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -139,7 +139,7 @@ ioctl_write_ptr_bad!( pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let opts = Options::from(&matches)?; diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 1422e473b..825071aee 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -111,7 +111,7 @@ mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let files: Vec = match matches.get_many::(options::FILE) { Some(v) => v.clone().map(|v| v.to_owned()).collect(), diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 396131982..5bd21bb1b 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -162,7 +162,7 @@ mod platform { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let files: Vec = matches .get_many::(ARG_FILES) diff --git a/src/uu/tac/src/tac.rs b/src/uu/tac/src/tac.rs index 924e30cfe..608c1133f 100644 --- a/src/uu/tac/src/tac.rs +++ b/src/uu/tac/src/tac.rs @@ -38,7 +38,7 @@ mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let before = matches.contains_id(options::BEFORE); let regex = matches.contains_id(options::REGEX); diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index d8442f09b..29176ae5d 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -295,7 +295,7 @@ impl Settings { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(arg_iterate(args)?); + let matches = uu_app().try_get_matches_from(arg_iterate(args)?)?; let mut settings = Settings::from(&matches)?; // skip expensive call to fstat if PRESUME_INPUT_PIPE is selected diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index 4d8d7c1a0..29f91d8af 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -51,7 +51,7 @@ enum OutputErrorMode { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let options = Options { append: matches.contains_id(options::APPEND), diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index ed55780ef..ad3ae8339 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -19,7 +19,7 @@ use std::io::ErrorKind; use std::process::{self, Child, Stdio}; use std::time::Duration; use uucore::display::Quotable; -use uucore::error::{UResult, USimpleError, UUsageError}; +use uucore::error::{UClapError, UResult, USimpleError, UUsageError}; use uucore::format_usage; use uucore::process::ChildExt; use uucore::signals::{signal_by_name_or_value, signal_name_by_value}; @@ -108,9 +108,7 @@ impl Config { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let command = uu_app(); - - let matches = command.get_matches_from(args); + let matches = uu_app().try_get_matches_from(args).with_exit_code(125)?; let config = Config::from(&matches)?; timeout( diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index dff59a38c..90618bf77 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -69,7 +69,7 @@ fn dt_to_filename(tm: time::PrimitiveDateTime) -> FileTime { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let files = matches.get_many::(ARG_FILES).ok_or_else(|| { USimpleError::new( diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 61ada1ab7..b7f9b413d 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -44,7 +44,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let after_help = get_long_usage(); - let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&after_help[..]) + .try_get_matches_from(args)?; let delete_flag = matches.contains_id(options::DELETE); let complement_flag = matches.contains_id(options::COMPLEMENT); diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 4aa9aca83..691761841 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -27,7 +27,7 @@ mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let input = matches .value_of(options::FILE) diff --git a/src/uu/uname/src/uname.rs b/src/uu/uname/src/uname.rs index cd74ee094..af6c2e884 100644 --- a/src/uu/uname/src/uname.rs +++ b/src/uu/uname/src/uname.rs @@ -56,7 +56,7 @@ const HOST_OS: &str = "Redox"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let uname = PlatformInfo::new().map_err_context(|| "failed to create PlatformInfo".to_string())?; diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index e42bb11a3..13be2bff3 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -167,7 +167,7 @@ fn expand_shortcuts(args: &[String]) -> Vec { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_ignore(); - let matches = uu_app().get_matches_from(expand_shortcuts(&args)); + let matches = uu_app().try_get_matches_from(expand_shortcuts(&args))?; unexpand(&Options::new(&matches)?).map_err_context(String::new) } diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index dc3415a44..830b211e0 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -257,7 +257,9 @@ fn get_long_usage() -> String { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let long_usage = get_long_usage(); - let matches = uu_app().after_help(&long_usage[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&long_usage[..]) + .try_get_matches_from(args)?; let files: Vec = matches .get_many::(ARG_FILES) diff --git a/src/uu/unlink/src/unlink.rs b/src/uu/unlink/src/unlink.rs index 2e12ba4f1..213ef6dce 100644 --- a/src/uu/unlink/src/unlink.rs +++ b/src/uu/unlink/src/unlink.rs @@ -22,7 +22,7 @@ static OPT_PATH: &str = "FILE"; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let path: &Path = matches.get_one::(OPT_PATH).unwrap().as_ref(); diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index 441d1db9e..41c962fb2 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -36,7 +36,7 @@ extern "C" { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let (boot_time, user_count) = process_utmpx(); let uptime = get_uptime(boot_time); diff --git a/src/uu/users/src/users.rs b/src/uu/users/src/users.rs index a700a68a0..f8067bcc6 100644 --- a/src/uu/users/src/users.rs +++ b/src/uu/users/src/users.rs @@ -33,7 +33,9 @@ If FILE is not specified, use {}. /var/log/wtmp as FILE is common.", pub fn uumain(args: impl uucore::Args) -> UResult<()> { let after_help = get_long_usage(); - let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&after_help[..]) + .try_get_matches_from(args)?; let files: Vec<&Path> = matches .get_many::(ARG_FILES) diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index ef3b40c91..75e5c2d15 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -196,7 +196,7 @@ impl Display for WcError { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let inputs = inputs(&matches)?; diff --git a/src/uu/who/src/who.rs b/src/uu/who/src/who.rs index a679609e7..96c4f469f 100644 --- a/src/uu/who/src/who.rs +++ b/src/uu/who/src/who.rs @@ -60,7 +60,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let after_help = get_long_usage(); - let matches = uu_app().after_help(&after_help[..]).get_matches_from(args); + let matches = uu_app() + .after_help(&after_help[..]) + .try_get_matches_from(args)?; let files: Vec = matches .get_many::(options::FILE) diff --git a/src/uu/whoami/src/whoami.rs b/src/uu/whoami/src/whoami.rs index 770802764..4b67a3643 100644 --- a/src/uu/whoami/src/whoami.rs +++ b/src/uu/whoami/src/whoami.rs @@ -21,7 +21,7 @@ static ABOUT: &str = "Print the current username."; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - uu_app().get_matches_from(args); + uu_app().try_get_matches_from(args)?; let username = platform::get_username().map_err_context(|| "failed to get username".into())?; println_verbatim(&username).map_err_context(|| "failed to print username".into())?; Ok(()) diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index 791e72036..0dfa77195 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -26,7 +26,7 @@ const BUF_SIZE: usize = 16 * 1024; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = uu_app().get_matches_from(args); + let matches = uu_app().try_get_matches_from(args)?; let string = if let Some(values) = matches.get_many::("STRING") { let mut result = values.fold(String::new(), |res, s| res + s + " "); diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index 312f5f164..f1bc4912c 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -463,7 +463,7 @@ pub fn chown_base<'a>( .required(true) .min_values(1), ); - let matches = command.get_matches_from(args); + let matches = command.try_get_matches_from(args)?; let files: Vec = matches .get_many::(options::ARG_FILES) diff --git a/tests/by-util/test_arch.rs b/tests/by-util/test_arch.rs index 909e0ee80..2945a0937 100644 --- a/tests/by-util/test_arch.rs +++ b/tests/by-util/test_arch.rs @@ -12,3 +12,8 @@ fn test_arch_help() { .succeeds() .stdout_contains("architecture name"); } + +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} diff --git a/tests/by-util/test_basename.rs b/tests/by-util/test_basename.rs index 0e8d65657..f5bb5c96a 100644 --- a/tests/by-util/test_basename.rs +++ b/tests/by-util/test_basename.rs @@ -192,3 +192,8 @@ fn test_simple_format() { .code_is(1) .stderr_contains("extra operand 'c'"); } + +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} diff --git a/tests/by-util/test_chgrp.rs b/tests/by-util/test_chgrp.rs index 33ec2c6c9..d2be150cd 100644 --- a/tests/by-util/test_chgrp.rs +++ b/tests/by-util/test_chgrp.rs @@ -8,6 +8,11 @@ fn test_invalid_option() { new_ucmd!().arg("-w").arg("/").fails(); } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + static DIR: &str = "/dev"; // we should always get both arguments, regardless of whether --reference was used diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index ea296de1c..9eb576f34 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -561,6 +561,11 @@ fn test_no_operands() { .usage_error("missing operand"); } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_mode_after_dash_dash() { let (at, ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_chown.rs b/tests/by-util/test_chown.rs index ef3fc0d33..c51d5ba69 100644 --- a/tests/by-util/test_chown.rs +++ b/tests/by-util/test_chown.rs @@ -78,6 +78,11 @@ fn test_invalid_option() { new_ucmd!().arg("-w").arg("-q").arg("/").fails(); } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_chown_only_owner() { // test chown username file.txt diff --git a/tests/by-util/test_chroot.rs b/tests/by-util/test_chroot.rs index 6c9237ac3..93eb9fc6c 100644 --- a/tests/by-util/test_chroot.rs +++ b/tests/by-util/test_chroot.rs @@ -2,6 +2,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(125); +} + #[test] fn test_missing_operand() { let result = new_ucmd!().run(); diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 66bdba9e3..523715126 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -2,6 +2,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_single_file() { new_ucmd!() diff --git a/tests/by-util/test_comm.rs b/tests/by-util/test_comm.rs index de75839de..9fc175c7f 100644 --- a/tests/by-util/test_comm.rs +++ b/tests/by-util/test_comm.rs @@ -2,6 +2,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn ab_no_args() { new_ucmd!() diff --git a/tests/by-util/test_csplit.rs b/tests/by-util/test_csplit.rs index 7eeb584eb..d44b4aca5 100644 --- a/tests/by-util/test_csplit.rs +++ b/tests/by-util/test_csplit.rs @@ -7,6 +7,11 @@ fn generate(from: u32, to: u32) -> String { (from..to).fold(String::new(), |acc, v| format!("{}{}\n", acc, v)) } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_stdin() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index 457ba7096..bcdd9eaf0 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -39,6 +39,11 @@ static COMPLEX_SEQUENCE: &TestedSequence = &TestedSequence { sequence: "9-,6-7,-2,4", }; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_byte_sequence() { for param in ["-b", "--bytes", "--byt"] { diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index 81b176ce9..41fd54798 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -5,6 +5,11 @@ use crate::common::util::*; #[cfg(all(unix, not(target_os = "macos")))] use rust_users::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_date_email() { for param in ["--rfc-email", "--rfc-e", "-R"] { diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index 40a54d7d2..89699426c 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -75,6 +75,11 @@ fn build_ascii_block(n: usize) -> Vec { (0..=127).cycle().take(n).collect() } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + // Sanity Tests #[test] fn version() { diff --git a/tests/by-util/test_df.rs b/tests/by-util/test_df.rs index 76df27b58..78f353062 100644 --- a/tests/by-util/test_df.rs +++ b/tests/by-util/test_df.rs @@ -3,6 +3,11 @@ use std::collections::HashSet; use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_df_compatible_no_size_arg() { new_ucmd!().arg("-a").succeeds(); diff --git a/tests/by-util/test_dircolors.rs b/tests/by-util/test_dircolors.rs index 2a93cbfa9..7e9578020 100644 --- a/tests/by-util/test_dircolors.rs +++ b/tests/by-util/test_dircolors.rs @@ -4,6 +4,11 @@ use crate::common::util::*; extern crate dircolors; use self::dircolors::{guess_syntax, OutputFmt, StrUtils}; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_shell_syntax() { use std::env; diff --git a/tests/by-util/test_dirname.rs b/tests/by-util/test_dirname.rs index 026ac22bb..952f715e8 100644 --- a/tests/by-util/test_dirname.rs +++ b/tests/by-util/test_dirname.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_path_with_trailing_slashes() { new_ucmd!() diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index 4eea79d45..09bb36e05 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -41,6 +41,11 @@ fn _du_basics(s: &str) { assert_eq!(s, answer); } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_du_basics_subdir() { let ts = TestScenario::new(util_name!()); diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index 395e6d157..6e29cbf79 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -5,6 +5,11 @@ use std::env; use std::path::Path; use tempfile::tempdir; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(125); +} + #[test] fn test_env_help() { new_ucmd!() diff --git a/tests/by-util/test_expand.rs b/tests/by-util/test_expand.rs index 555671707..ac9eb1fad 100644 --- a/tests/by-util/test_expand.rs +++ b/tests/by-util/test_expand.rs @@ -2,6 +2,11 @@ use crate::common::util::*; use uucore::display::Quotable; // spell-checker:ignore (ToDO) taaaa tbbbb tcccc +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_with_tab() { new_ucmd!() diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index 7c1e540b6..3e576cd04 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -27,6 +27,11 @@ use self::sieve::Sieve; const NUM_PRIMES: usize = 10000; const NUM_TESTS: usize = 100; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_parallel() { use hex_literal::hex; diff --git a/tests/by-util/test_fmt.rs b/tests/by-util/test_fmt.rs index 0d6d9bb24..02d205466 100644 --- a/tests/by-util/test_fmt.rs +++ b/tests/by-util/test_fmt.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_fmt() { let result = new_ucmd!().arg("one-word-per-line.txt").run(); diff --git a/tests/by-util/test_fold.rs b/tests/by-util/test_fold.rs index 1acdadac1..049535422 100644 --- a/tests/by-util/test_fold.rs +++ b/tests/by-util/test_fold.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_default_80_column_wrap() { new_ucmd!() diff --git a/tests/by-util/test_groups.rs b/tests/by-util/test_groups.rs index 73837235f..1432e8c9c 100644 --- a/tests/by-util/test_groups.rs +++ b/tests/by-util/test_groups.rs @@ -9,6 +9,12 @@ use crate::common::util::*; const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31 +#[test] +#[cfg(unix)] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] #[cfg(unix)] fn test_groups() { diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index 06d039d59..5fdc6e648 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -116,3 +116,8 @@ fn test_check_sha1() { .stdout_is("testf: OK\n") .stderr_is(""); } + +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} diff --git a/tests/by-util/test_head.rs b/tests/by-util/test_head.rs index 20bec7589..cefb5c0ae 100644 --- a/tests/by-util/test_head.rs +++ b/tests/by-util/test_head.rs @@ -9,6 +9,11 @@ use crate::common::util::*; static INPUT: &str = "lorem_ipsum.txt"; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_stdin_default() { new_ucmd!() diff --git a/tests/by-util/test_hostname.rs b/tests/by-util/test_hostname.rs index 45acff1b5..474be8b3e 100644 --- a/tests/by-util/test_hostname.rs +++ b/tests/by-util/test_hostname.rs @@ -28,3 +28,8 @@ fn test_hostname_full() { .succeeds() .stdout_contains(ls_short_res.stdout_str().trim()); } + +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} diff --git a/tests/by-util/test_id.rs b/tests/by-util/test_id.rs index b791dbfd0..b7b36c58d 100644 --- a/tests/by-util/test_id.rs +++ b/tests/by-util/test_id.rs @@ -9,6 +9,11 @@ use crate::common::util::*; const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31 +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] #[cfg(unix)] fn test_id_no_specified_user() { diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index 3b68eb38c..252aeb1b7 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -9,6 +9,11 @@ use std::process::Command; #[cfg(any(target_os = "linux", target_os = "android"))] use std::thread::sleep; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_install_basic() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_join.rs b/tests/by-util/test_join.rs index d5da873f6..10af26ec5 100644 --- a/tests/by-util/test_join.rs +++ b/tests/by-util/test_join.rs @@ -8,6 +8,11 @@ use std::{ffi::OsStr, os::unix::ffi::OsStrExt}; #[cfg(windows)] use std::{ffi::OsString, os::windows::ffi::OsStringExt}; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn empty_files() { new_ucmd!() diff --git a/tests/by-util/test_kill.rs b/tests/by-util/test_kill.rs index 7581086a0..43e281155 100644 --- a/tests/by-util/test_kill.rs +++ b/tests/by-util/test_kill.rs @@ -45,6 +45,11 @@ impl Drop for Target { } } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_kill_list_all_signals() { // Check for a few signals. Do not try to be comprehensive. diff --git a/tests/by-util/test_link.rs b/tests/by-util/test_link.rs index 9f6a2ee5f..a1f4f2c3f 100644 --- a/tests/by-util/test_link.rs +++ b/tests/by-util/test_link.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[cfg(not(target_os = "android"))] #[test] fn test_link_existing_file() { diff --git a/tests/by-util/test_ln.rs b/tests/by-util/test_ln.rs index 74af0acc6..cb4729adf 100644 --- a/tests/by-util/test_ln.rs +++ b/tests/by-util/test_ln.rs @@ -1,6 +1,11 @@ use crate::common::util::*; use std::path::PathBuf; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_symlink_existing_file() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_logname.rs b/tests/by-util/test_logname.rs index 0e8125191..43fce6851 100644 --- a/tests/by-util/test_logname.rs +++ b/tests/by-util/test_logname.rs @@ -1,6 +1,11 @@ use crate::common::util::*; use std::env; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_normal() { let result = new_ucmd!().run(); diff --git a/tests/by-util/test_mkdir.rs b/tests/by-util/test_mkdir.rs index be7a95af2..0a9d9f4d4 100644 --- a/tests/by-util/test_mkdir.rs +++ b/tests/by-util/test_mkdir.rs @@ -20,6 +20,11 @@ static TEST_DIR11: &str = "mkdir_test11/.."; #[cfg(not(windows))] static TEST_DIR12: &str = "mkdir_test12"; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_mkdir_mkdir() { new_ucmd!().arg(TEST_DIR1).succeeds(); diff --git a/tests/by-util/test_mkfifo.rs b/tests/by-util/test_mkfifo.rs index 318a2ea5d..18d1d53d1 100644 --- a/tests/by-util/test_mkfifo.rs +++ b/tests/by-util/test_mkfifo.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_create_fifo_missing_operand() { new_ucmd!().fails().stderr_is("mkfifo: missing operand"); diff --git a/tests/by-util/test_mknod.rs b/tests/by-util/test_mknod.rs index 3b22ef835..291b56b72 100644 --- a/tests/by-util/test_mknod.rs +++ b/tests/by-util/test_mknod.rs @@ -1,5 +1,11 @@ use crate::common::util::*; +#[test] +#[cfg(not(windows))] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[cfg(not(windows))] #[test] fn test_mknod_help() { diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index f22c8f7ca..a171b6ba9 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -4,6 +4,11 @@ extern crate time; use self::filetime::*; use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_mv_rename_dir() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_nl.rs b/tests/by-util/test_nl.rs index 1ed46c313..cd59a745c 100644 --- a/tests/by-util/test_nl.rs +++ b/tests/by-util/test_nl.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_stdin_no_newline() { new_ucmd!() diff --git a/tests/by-util/test_nohup.rs b/tests/by-util/test_nohup.rs index 8d848131c..8ef0bc9c9 100644 --- a/tests/by-util/test_nohup.rs +++ b/tests/by-util/test_nohup.rs @@ -5,6 +5,11 @@ use std::thread::sleep; // because stdin/stdout is not attached to a TTY. // All that can be tested is the side-effects. +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(125); +} + #[test] #[cfg(any( target_os = "linux", diff --git a/tests/by-util/test_nproc.rs b/tests/by-util/test_nproc.rs index 330f327cb..3260e46e7 100644 --- a/tests/by-util/test_nproc.rs +++ b/tests/by-util/test_nproc.rs @@ -1,6 +1,11 @@ // spell-checker:ignore incorrectnumber use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_nproc() { let nproc: u8 = new_ucmd!().succeeds().stdout_str().trim().parse().unwrap(); diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index 721e3e5a4..b12ea2d50 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -2,6 +2,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_should_not_round_floats() { new_ucmd!() diff --git a/tests/by-util/test_od.rs b/tests/by-util/test_od.rs index e68881309..a5dc49554 100644 --- a/tests/by-util/test_od.rs +++ b/tests/by-util/test_od.rs @@ -24,6 +24,11 @@ static ALPHA_OUT: &str = " // XXX We could do a better job of ensuring that we have a fresh temp dir to ourselves, // not a general one full of other process leftovers. +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + // Test that od can read one file and dump with default format #[test] fn test_file() { diff --git a/tests/by-util/test_paste.rs b/tests/by-util/test_paste.rs index b4d23868a..088a27eae 100644 --- a/tests/by-util/test_paste.rs +++ b/tests/by-util/test_paste.rs @@ -128,6 +128,11 @@ static EXAMPLE_DATA: &[TestData] = &[ }, ]; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_combine_pairs_of_lines() { for s in ["-s", "--serial"] { diff --git a/tests/by-util/test_pathchk.rs b/tests/by-util/test_pathchk.rs index 8ba3b9033..9b16fe738 100644 --- a/tests/by-util/test_pathchk.rs +++ b/tests/by-util/test_pathchk.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_default_mode() { // test the default mode diff --git a/tests/by-util/test_pinky.rs b/tests/by-util/test_pinky.rs index 1da93ee42..26af822cd 100644 --- a/tests/by-util/test_pinky.rs +++ b/tests/by-util/test_pinky.rs @@ -12,6 +12,11 @@ use self::uucore::entries::{Locate, Passwd}; extern crate pinky; pub use self::pinky::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_capitalize() { assert_eq!("Zbnmasd", "zbnmasd".capitalize()); // spell-checker:disable-line diff --git a/tests/by-util/test_ptx.rs b/tests/by-util/test_ptx.rs index 75c96e42e..7372bb5cc 100644 --- a/tests/by-util/test_ptx.rs +++ b/tests/by-util/test_ptx.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn gnu_ext_disabled_rightward_no_ref() { new_ucmd!() diff --git a/tests/by-util/test_pwd.rs b/tests/by-util/test_pwd.rs index 950a148a3..0ae63c895 100644 --- a/tests/by-util/test_pwd.rs +++ b/tests/by-util/test_pwd.rs @@ -4,6 +4,11 @@ use std::path::PathBuf; use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_default() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_readlink.rs b/tests/by-util/test_readlink.rs index 5707913b2..2bc983b02 100644 --- a/tests/by-util/test_readlink.rs +++ b/tests/by-util/test_readlink.rs @@ -8,6 +8,11 @@ static NOT_A_DIRECTORY: &str = "Not a directory"; #[cfg(windows)] static NOT_A_DIRECTORY: &str = "The directory name is invalid."; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_resolve() { let scene = TestScenario::new(util_name!()); diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index c5c150371..472d12bed 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_rm_one_file() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_rmdir.rs b/tests/by-util/test_rmdir.rs index c8f22aa6c..4cee34bf8 100644 --- a/tests/by-util/test_rmdir.rs +++ b/tests/by-util/test_rmdir.rs @@ -20,6 +20,11 @@ const NOT_A_DIRECTORY: &str = "The directory name is invalid."; #[cfg(not(windows))] const NOT_A_DIRECTORY: &str = "Not a directory"; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_rmdir_empty_directory_no_parents() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index a18cbc2ad..c3ca61081 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -2,6 +2,11 @@ use crate::common::util::*; use std::io::Read; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_hex_rejects_sign_after_identifier() { new_ucmd!() diff --git a/tests/by-util/test_shred.rs b/tests/by-util/test_shred.rs index b29b9bfec..0780411f6 100644 --- a/tests/by-util/test_shred.rs +++ b/tests/by-util/test_shred.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_shred_remove() { let scene = TestScenario::new(util_name!()); diff --git a/tests/by-util/test_shuf.rs b/tests/by-util/test_shuf.rs index 682b0dab6..39a7a640b 100644 --- a/tests/by-util/test_shuf.rs +++ b/tests/by-util/test_shuf.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_output_is_random_permutation() { let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 854225d18..c57e6bd6e 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -119,6 +119,11 @@ impl RandomFile { } } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_split_default() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_stat.rs b/tests/by-util/test_stat.rs index 92af7118d..365ac3df3 100644 --- a/tests/by-util/test_stat.rs +++ b/tests/by-util/test_stat.rs @@ -10,6 +10,11 @@ use crate::common::util::*; extern crate stat; pub use self::stat::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_scanners() { assert_eq!(Some((-5, 2)), "-5zxc".scan_num::()); diff --git a/tests/by-util/test_stty.rs b/tests/by-util/test_stty.rs index 730ccdf37..d15052591 100644 --- a/tests/by-util/test_stty.rs +++ b/tests/by-util/test_stty.rs @@ -2,6 +2,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] #[ignore = "Fails because cargo test does not run in a tty"] fn runs() { diff --git a/tests/by-util/test_sum.rs b/tests/by-util/test_sum.rs index 0248c05cf..68432a647 100644 --- a/tests/by-util/test_sum.rs +++ b/tests/by-util/test_sum.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_bsd_single_file() { new_ucmd!() diff --git a/tests/by-util/test_sync.rs b/tests/by-util/test_sync.rs index 033651910..97259cdda 100644 --- a/tests/by-util/test_sync.rs +++ b/tests/by-util/test_sync.rs @@ -3,6 +3,11 @@ extern crate tempfile; use std::fs; use tempfile::tempdir; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_sync_default() { new_ucmd!().succeeds(); diff --git a/tests/by-util/test_tac.rs b/tests/by-util/test_tac.rs index 323aa5149..6f8a72989 100644 --- a/tests/by-util/test_tac.rs +++ b/tests/by-util/test_tac.rs @@ -1,6 +1,11 @@ // spell-checker:ignore axxbxx bxxaxx axxx axxxx xxaxx xxax xxxxa axyz zyax zyxa use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_stdin_default() { new_ucmd!() diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index 442c07979..cbb05ba9d 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -30,6 +30,11 @@ static FOLLOW_NAME_SHORT_EXP: &str = "follow_name_short.expected"; #[cfg(target_os = "linux")] static FOLLOW_NAME_EXP: &str = "follow_name.expected"; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] #[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android fn test_stdin_default() { diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index 7fd4d77b0..54b77d3b4 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -6,6 +6,11 @@ use crate::common::util::*; // spell-checker:ignore nopipe +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_tee_processing_multiple_operands() { // POSIX says: "Processing of at least 13 file operands shall be supported." diff --git a/tests/by-util/test_timeout.rs b/tests/by-util/test_timeout.rs index 5d77e1fa0..2dc8da8fe 100644 --- a/tests/by-util/test_timeout.rs +++ b/tests/by-util/test_timeout.rs @@ -1,6 +1,11 @@ // spell-checker:ignore dont use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(125); +} + // FIXME: this depends on the system having true and false in PATH // the best solution is probably to generate some test binaries that we can call for any // utility that requires executing another program (kill, for instance) diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index bdef1e1e5..a89e808de 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -59,6 +59,11 @@ fn str_to_filetime(format: &str, s: &str) -> FileTime { FileTime::from_unix_time(offset_dt.unix_timestamp(), tm.nanosecond()) } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_touch_default() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index bf550a109..7f60f88a1 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -1,6 +1,11 @@ // spell-checker:ignore aabbaa aabbcc aabc abbb abcc abcdefabcdef abcdefghijk abcdefghijklmn abcdefghijklmnop ABCDEFGHIJKLMNOPQRS abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFZZ abcxyz ABCXYZ abcxyzabcxyz ABCXYZABCXYZ acbdef alnum amzamz AMZXAMZ bbbd cclass cefgm cntrl compl dabcdef dncase Gzabcdefg PQRST upcase wxyzz xdigit xycde xyyye xyyz xyzzzzxyzzzz ZABCDEF Zamz Cdefghijkl Cdefghijklmn use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_to_upper() { new_ucmd!() diff --git a/tests/by-util/test_tsort.rs b/tests/by-util/test_tsort.rs index 0da6f44e4..e424fe651 100644 --- a/tests/by-util/test_tsort.rs +++ b/tests/by-util/test_tsort.rs @@ -1,5 +1,9 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} #[test] fn test_sort_call_graph() { new_ucmd!() diff --git a/tests/by-util/test_uname.rs b/tests/by-util/test_uname.rs index 5e78ddc13..7cd165d0f 100644 --- a/tests/by-util/test_uname.rs +++ b/tests/by-util/test_uname.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_uname() { new_ucmd!().succeeds(); diff --git a/tests/by-util/test_unexpand.rs b/tests/by-util/test_unexpand.rs index c208b624c..1639ee1bc 100644 --- a/tests/by-util/test_unexpand.rs +++ b/tests/by-util/test_unexpand.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn unexpand_init_0() { new_ucmd!() diff --git a/tests/by-util/test_uniq.rs b/tests/by-util/test_uniq.rs index 5b22622d3..22a56c0e2 100644 --- a/tests/by-util/test_uniq.rs +++ b/tests/by-util/test_uniq.rs @@ -9,6 +9,11 @@ static SKIP_CHARS: &str = "skip-chars.txt"; static SKIP_FIELDS: &str = "skip-fields.txt"; static SORTED_ZERO_TERMINATED: &str = "sorted-zero-terminated.txt"; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_stdin_default() { new_ucmd!() diff --git a/tests/by-util/test_unlink.rs b/tests/by-util/test_unlink.rs index 6b4fc41da..38b1cf2ba 100644 --- a/tests/by-util/test_unlink.rs +++ b/tests/by-util/test_unlink.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_unlink_file() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_uptime.rs b/tests/by-util/test_uptime.rs index 4dc90eb31..946bb30fa 100644 --- a/tests/by-util/test_uptime.rs +++ b/tests/by-util/test_uptime.rs @@ -2,6 +2,11 @@ extern crate regex; use self::regex::Regex; use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_uptime() { TestScenario::new(util_name!()) diff --git a/tests/by-util/test_users.rs b/tests/by-util/test_users.rs index c074f3e40..747995d99 100644 --- a/tests/by-util/test_users.rs +++ b/tests/by-util/test_users.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_users_no_arg() { new_ucmd!().succeeds(); diff --git a/tests/by-util/test_wc.rs b/tests/by-util/test_wc.rs index d9166cb92..9b4f053ac 100644 --- a/tests/by-util/test_wc.rs +++ b/tests/by-util/test_wc.rs @@ -2,6 +2,11 @@ use crate::common::util::*; // spell-checker:ignore (flags) lwmcL clmwL ; (path) bogusfile emptyfile manyemptylines moby notrailingnewline onelongemptyline onelongword weirdchars +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_count_bytes_large_stdin() { for n in [ diff --git a/tests/by-util/test_who.rs b/tests/by-util/test_who.rs index 580d9ea6f..1f0554f92 100644 --- a/tests/by-util/test_who.rs +++ b/tests/by-util/test_who.rs @@ -7,6 +7,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[cfg(unix)] #[test] #[ignore = "issue #3219"] diff --git a/tests/by-util/test_whoami.rs b/tests/by-util/test_whoami.rs index 340c1434f..a64dbb7cd 100644 --- a/tests/by-util/test_whoami.rs +++ b/tests/by-util/test_whoami.rs @@ -5,6 +5,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] #[cfg(unix)] fn test_normal() { diff --git a/tests/by-util/test_yes.rs b/tests/by-util/test_yes.rs index 20561ced6..dd455a933 100644 --- a/tests/by-util/test_yes.rs +++ b/tests/by-util/test_yes.rs @@ -28,6 +28,11 @@ fn run(args: &[&str], expected: &[u8]) { assert_eq!(buf.as_slice(), expected); } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_simple() { run(&[], b"y\ny\ny\ny\n");