mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
coreutils: output proper error for unrecognized options (#9869)
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
co-authored by
Sylvestre Ledru
parent
c9c78b2415
commit
e7f82473a8
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user