diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 11fd05c4e..1156a9437 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -79,10 +79,16 @@ mod options { ]; } + pub mod check { + pub const CHECK: &str = "check"; + pub const CHECK_SILENT: &str = "check-silent"; + pub const SILENT: &str = "silent"; + pub const QUIET: &str = "quiet"; + pub const DIAGNOSE_FIRST: &str = "diagnose-first"; + } + pub const DICTIONARY_ORDER: &str = "dictionary-order"; pub const MERGE: &str = "merge"; - pub const CHECK: &str = "check"; - pub const CHECK_SILENT: &str = "check-silent"; pub const DEBUG: &str = "debug"; pub const IGNORE_CASE: &str = "ignore-case"; pub const IGNORE_BLANKS: &str = "ignore-blanks"; @@ -994,15 +1000,23 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .help("merge already sorted files; do not sort"), ) .arg( - Arg::with_name(options::CHECK) + Arg::with_name(options::check::CHECK) .short("c") - .long(options::CHECK) + .long(options::check::CHECK) + .takes_value(true) + .require_equals(true) + .min_values(0) + .possible_values(&[ + options::check::SILENT, + options::check::QUIET, + options::check::DIAGNOSE_FIRST, + ]) .help("check for sorted input; do not sort"), ) .arg( - Arg::with_name(options::CHECK_SILENT) + Arg::with_name(options::check::CHECK_SILENT) .short("C") - .long(options::CHECK_SILENT) + .long(options::check::CHECK_SILENT) .help("exit successfully if the given file is already sorted, and exit with status 1 otherwise."), ) .arg( @@ -1220,9 +1234,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 { settings.zero_terminated = matches.is_present(options::ZERO_TERMINATED); settings.merge = matches.is_present(options::MERGE); - settings.check = matches.is_present(options::CHECK); - if matches.is_present(options::CHECK_SILENT) { - settings.check_silent = matches.is_present(options::CHECK_SILENT); + settings.check = matches.is_present(options::check::CHECK); + if matches.is_present(options::check::CHECK_SILENT) + || matches!( + matches.value_of(options::check::CHECK), + Some(options::check::SILENT) | Some(options::check::QUIET) + ) + { + settings.check_silent = true; settings.check = true; }; diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 7a0143b43..1624c2caf 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -717,26 +717,30 @@ fn test_pipe() { #[test] fn test_check() { - new_ucmd!() - .arg("-c") - .arg("check_fail.txt") - .fails() - .stdout_is("sort: check_fail.txt:6: disorder: 5\n"); + for diagnose_arg in &["-c", "--check", "--check=diagnose-first"] { + new_ucmd!() + .arg(diagnose_arg) + .arg("check_fail.txt") + .fails() + .stdout_is("sort: check_fail.txt:6: disorder: 5\n"); - new_ucmd!() - .arg("-c") - .arg("multiple_files.expected") - .succeeds() - .stdout_is(""); + new_ucmd!() + .arg(diagnose_arg) + .arg("multiple_files.expected") + .succeeds() + .stdout_is(""); + } } #[test] fn test_check_silent() { - new_ucmd!() - .arg("-C") - .arg("check_fail.txt") - .fails() - .stdout_is(""); + for silent_arg in &["-C", "--check=silent", "--check=quiet"] { + new_ucmd!() + .arg(silent_arg) + .arg("check_fail.txt") + .fails() + .stdout_is(""); + } } #[test]