coreutils: output proper error for unrecognized options (#9869)

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
Chris Dryden
2026-02-04 22:14:27 +01:00
committed by GitHub
co-authored by Sylvestre Ledru
parent c9c78b2415
commit e7f82473a8
2 changed files with 18 additions and 0 deletions
+8
View File
@@ -75,6 +75,11 @@ fn main() {
match util {
"--list" => {
// If --help is also present, show usage instead of list
if args.any(|arg| arg == "--help" || arg == "-h") {
usage(&utils, binary_as_util);
process::exit(0);
}
let mut utils: Vec<_> = utils.keys().collect();
utils.sort();
for util in utils {
@@ -123,6 +128,9 @@ fn main() {
}
usage(&utils, binary_as_util);
process::exit(0);
} else if util.starts_with('-') {
// Argument looks like an option but wasn't recognized
validation::unrecognized_option(binary_as_util, &util_os);
} else {
validation::not_found(&util_os);
}
+10
View File
@@ -29,6 +29,16 @@ pub fn not_found(util: &OsStr) -> ! {
process::exit(1);
}
/// Prints an "unrecognized option" error and exits
pub fn unrecognized_option(binary_name: &str, option: &OsStr) -> ! {
eprintln!(
"{}: unrecognized option '{}'",
binary_name,
option.to_string_lossy()
);
process::exit(1);
}
/// Sets up localization for a utility with proper error handling
pub fn setup_localization_or_exit(util_name: &str) {
let util_name = get_canonical_util_name(util_name);