diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 383115baa82..4c45d124711 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -8,7 +8,6 @@ use coreutils::validation; use itertools::Itertools as _; use std::cmp; use std::ffi::OsString; -use std::io::{self, Write}; use std::process; use uucore::Args; @@ -125,26 +124,8 @@ fn main() { process::exit(uumain(vec![util_os].into_iter().chain(args))); } None => { + // GNU coreutils --help string shows help for coreutils if util == "--help" || util == "-h" { - // see if they want help on a specific util - if let Some(util_os) = args.next() { - let Some(util) = util_os.to_str() else { - validation::not_found(&util_os) - }; - - match utils.get(util) { - Some(&(uumain, _)) => { - let code = uumain( - vec![util_os, OsString::from("--help")] - .into_iter() - .chain(args), - ); - io::stdout().flush().expect("could not flush stdout"); - process::exit(code); - } - None => validation::not_found(&util_os), - } - } usage(&utils, binary_as_util); process::exit(0); } else if util.starts_with('-') { diff --git a/tests/test_util_name.rs b/tests/test_util_name.rs index 17b9dc36e5e..57fcd777c08 100644 --- a/tests/test_util_name.rs +++ b/tests/test_util_name.rs @@ -26,6 +26,24 @@ fn init() { eprintln!("Setting UUTESTS_BINARY_PATH={TESTS_BINARY}"); } +#[test] +fn test_coreutils_help_ignore_args() { + use std::process::Command; + + let scenario = TestScenario::new("help_ignoring_args"); + if !scenario.bin_path.exists() { + return; + } + + let output = Command::new(&scenario.bin_path) + .arg("--help") + .arg("---") + .output() + .unwrap(); + + assert_eq!(output.status.code(), Some(0)); +} + #[test] #[cfg(feature = "ls")] fn execution_phrase_double() {