Skip to content

Commit 5df54f4

Browse files
committed
coreutils: --help args is same with --help
1 parent 59288a7 commit 5df54f4

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

src/bin/coreutils.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use coreutils::validation;
88
use itertools::Itertools as _;
99
use std::cmp;
1010
use std::ffi::OsString;
11-
use std::io::{self, Write};
1211
use std::process;
1312
use uucore::Args;
1413

@@ -106,33 +105,10 @@ fn main() {
106105
process::exit(uumain(vec![util_os].into_iter().chain(args)));
107106
}
108107
None => {
108+
// GNU coreutils --help string shows help for coreutils
109109
if util == "--help" || util == "-h" {
110-
// see if they want help on a specific util
111-
if let Some(util_os) = args.next() {
112-
let Some(util) = util_os.to_str() else {
113-
validation::not_found(&util_os)
114-
};
115-
116-
match utils.get(util) {
117-
Some(&(uumain, _)) => {
118-
let code = uumain(
119-
vec![util_os, OsString::from("--help")]
120-
.into_iter()
121-
.chain(args),
122-
);
123-
io::stdout().flush().expect("could not flush stdout");
124-
process::exit(code);
125-
}
126-
None => validation::not_found(&util_os),
127-
}
128-
}
129110
usage(&utils, binary_as_util);
130111
process::exit(0);
131-
} else if util.starts_with('-') {
132-
// Argument looks like an option but wasn't recognized
133-
validation::unrecognized_option(binary_as_util, &util_os);
134-
} else {
135-
validation::not_found(&util_os);
136112
}
137113
}
138114
}

tests/test_util_name.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ fn init() {
2626
eprintln!("Setting UUTESTS_BINARY_PATH={TESTS_BINARY}");
2727
}
2828

29+
#[test]
30+
fn test_coreutils_help_ignore_args() {
31+
use std::process::Command;
32+
33+
let scenario = TestScenario::new("help_ignoring_args");
34+
if !scenario.bin_path.exists() {
35+
return;
36+
}
37+
38+
let output = Command::new(&scenario.bin_path)
39+
.arg("--help")
40+
.arg("---")
41+
.output()
42+
.unwrap();
43+
44+
assert_eq!(output.status.code(), Some(0));
45+
}
46+
2947
#[test]
3048
#[cfg(feature = "ls")]
3149
fn execution_phrase_double() {

util/fetch-gnu.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ repo=https://github.com/coreutils/coreutils
44
curl -L "${repo}/releases/download/v${ver}/coreutils-${ver}.tar.xz" | tar --strip-components=1 -xJf -
55

66
# TODO stop backporting tests from master at GNU coreutils > $ver
7-
# backport = ()
8-
# for f in ${backport[@]}
9-
# do curl -L ${repo}/raw/refs/heads/master/tests/$f > tests/$f
10-
# done
7+
backport=(
8+
misc/coreutils.sh
9+
)
10+
for f in "${backport[@]}"
11+
do curl -L ${repo}/raw/refs/heads/master/tests/$f > tests/$f
12+
done

0 commit comments

Comments
 (0)