Skip to content

Commit 0a3d769

Browse files
committed
coreutils: --list arg and no args should fail
1 parent 5dcde30 commit 0a3d769

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

src/bin/coreutils.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use coreutils::validation;
88
use itertools::Itertools as _;
99
use std::cmp;
1010
use std::ffi::OsString;
11-
use std::io::{self, Write};
11+
use std::io::{self, Write, stderr};
1212
use std::process;
1313
use uucore::Args;
1414

@@ -76,19 +76,18 @@ fn main() {
7676

7777
match util {
7878
"--list" => {
79-
// If --help is also present, show usage instead of list
80-
if args.any(|arg| arg == "--help" || arg == "-h") {
81-
usage(&utils, binary_as_util);
82-
process::exit(0);
79+
// GNU does not like lax options https://github.com/uutils/coreutils/issues/11383#issuecomment-4082564058
80+
if args.next().is_some() {
81+
let _ = writeln!(stderr(), "coreutils: invalid sub-command");
82+
process::exit(1);
8383
}
84-
let utils: Vec<_> = utils.keys().collect();
85-
for util in utils {
84+
for util in utils.keys() {
8685
println!("{util}");
8786
}
8887
process::exit(0);
8988
}
9089
"--version" | "-V" => {
91-
println!("{binary_as_util} {VERSION} (multi-call binary)");
90+
println!("coreutils {VERSION} (multi-call binary)");
9291
process::exit(0);
9392
}
9493
// Not a special command: fallthrough to calling a util
@@ -138,7 +137,9 @@ fn main() {
138137
}
139138
} else {
140139
// no arguments provided
141-
usage(&utils, binary_as_util);
142-
process::exit(0);
140+
let _ = writeln!(stderr(), "coreutils: missing argument");
141+
// GNU exit(1), but busybox tests needs exit(0)
142+
// todo: patch the test suite instead.
143+
process::exit(!binary_as_util.ends_with("box") as i32);
143144
}
144145
}

0 commit comments

Comments
 (0)