Skip to content

Commit dd4938b

Browse files
committed
coreutils: output proper error for unrecognized options
1 parent efa1aa7 commit dd4938b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/bin/coreutils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ fn main() {
127127
}
128128
usage(&utils, binary_as_util);
129129
process::exit(0);
130+
} else if util.starts_with('-') {
131+
// Argument looks like an option but wasn't recognized
132+
validation::unrecognized_option(binary_as_util, &util_os);
130133
} else {
131134
validation::not_found(&util_os);
132135
}

src/common/validation.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ pub fn not_found(util: &OsStr) -> ! {
2929
process::exit(1);
3030
}
3131

32+
/// Prints an "unrecognized option" error and exits
33+
pub fn unrecognized_option(binary_name: &str, option: &OsStr) -> ! {
34+
eprintln!(
35+
"{}: unrecognized option '{}'",
36+
binary_name,
37+
option.to_string_lossy()
38+
);
39+
process::exit(1);
40+
}
41+
3242
/// Sets up localization for a utility with proper error handling
3343
pub fn setup_localization_or_exit(util_name: &str) {
3444
let util_name = get_canonical_util_name(util_name);

0 commit comments

Comments
 (0)