Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/bin/coreutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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 {
Expand Down Expand Up @@ -127,6 +132,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);
}
Expand Down
10 changes: 10 additions & 0 deletions src/common/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 '{}'",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use translate!()

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);
Expand Down
Loading