mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
sort: allow --check=<value> syntax
* --check=silent and --check=quiet, which are equivalent to -C. * --check=diagnose-first, which is the same as --check We also allow -c=<value>, which confuses GNU sort.
This commit is contained in:
parent
cc0df6ea43
commit
fb035aa049
2 changed files with 47 additions and 24 deletions
|
@ -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 DICTIONARY_ORDER: &str = "dictionary-order";
|
||||||
pub const MERGE: &str = "merge";
|
pub const MERGE: &str = "merge";
|
||||||
pub const CHECK: &str = "check";
|
|
||||||
pub const CHECK_SILENT: &str = "check-silent";
|
|
||||||
pub const DEBUG: &str = "debug";
|
pub const DEBUG: &str = "debug";
|
||||||
pub const IGNORE_CASE: &str = "ignore-case";
|
pub const IGNORE_CASE: &str = "ignore-case";
|
||||||
pub const IGNORE_BLANKS: &str = "ignore-blanks";
|
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"),
|
.help("merge already sorted files; do not sort"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::CHECK)
|
Arg::with_name(options::check::CHECK)
|
||||||
.short("c")
|
.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"),
|
.help("check for sorted input; do not sort"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::CHECK_SILENT)
|
Arg::with_name(options::check::CHECK_SILENT)
|
||||||
.short("C")
|
.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."),
|
.help("exit successfully if the given file is already sorted, and exit with status 1 otherwise."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -1220,9 +1234,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
settings.zero_terminated = matches.is_present(options::ZERO_TERMINATED);
|
settings.zero_terminated = matches.is_present(options::ZERO_TERMINATED);
|
||||||
settings.merge = matches.is_present(options::MERGE);
|
settings.merge = matches.is_present(options::MERGE);
|
||||||
|
|
||||||
settings.check = matches.is_present(options::CHECK);
|
settings.check = matches.is_present(options::check::CHECK);
|
||||||
if matches.is_present(options::CHECK_SILENT) {
|
if matches.is_present(options::check::CHECK_SILENT)
|
||||||
settings.check_silent = matches.is_present(options::CHECK_SILENT);
|
|| matches!(
|
||||||
|
matches.value_of(options::check::CHECK),
|
||||||
|
Some(options::check::SILENT) | Some(options::check::QUIET)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
settings.check_silent = true;
|
||||||
settings.check = true;
|
settings.check = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -717,26 +717,30 @@ fn test_pipe() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_check() {
|
fn test_check() {
|
||||||
new_ucmd!()
|
for diagnose_arg in &["-c", "--check", "--check=diagnose-first"] {
|
||||||
.arg("-c")
|
new_ucmd!()
|
||||||
.arg("check_fail.txt")
|
.arg(diagnose_arg)
|
||||||
.fails()
|
.arg("check_fail.txt")
|
||||||
.stdout_is("sort: check_fail.txt:6: disorder: 5\n");
|
.fails()
|
||||||
|
.stdout_is("sort: check_fail.txt:6: disorder: 5\n");
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.arg("-c")
|
.arg(diagnose_arg)
|
||||||
.arg("multiple_files.expected")
|
.arg("multiple_files.expected")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is("");
|
.stdout_is("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_check_silent() {
|
fn test_check_silent() {
|
||||||
new_ucmd!()
|
for silent_arg in &["-C", "--check=silent", "--check=quiet"] {
|
||||||
.arg("-C")
|
new_ucmd!()
|
||||||
.arg("check_fail.txt")
|
.arg(silent_arg)
|
||||||
.fails()
|
.arg("check_fail.txt")
|
||||||
.stdout_is("");
|
.fails()
|
||||||
|
.stdout_is("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue