mirror of
https://github.com/uutils/coreutils
synced 2025-01-06 02:09:15 +00:00
uniq
: print version and help on stdout again (#6123)
* uniq: print version and help on stdout again * uniq: format test * uniq: replace redundant closure with fn --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
parent
e4a1455af5
commit
d060134d97
2 changed files with 17 additions and 3 deletions
|
@ -518,7 +518,7 @@ fn handle_extract_obs_skip_chars(
|
||||||
/// Unfortunately these overrides are necessary, since several GNU tests
|
/// Unfortunately these overrides are necessary, since several GNU tests
|
||||||
/// for `uniq` hardcode and require the exact wording of the error message
|
/// for `uniq` hardcode and require the exact wording of the error message
|
||||||
/// and it is not compatible with how Clap formats and displays those error messages.
|
/// and it is not compatible with how Clap formats and displays those error messages.
|
||||||
fn map_clap_errors(clap_error: &Error) -> Box<dyn UError> {
|
fn map_clap_errors(clap_error: Error) -> Box<dyn UError> {
|
||||||
let footer = "Try 'uniq --help' for more information.";
|
let footer = "Try 'uniq --help' for more information.";
|
||||||
let override_arg_conflict =
|
let override_arg_conflict =
|
||||||
"--group is mutually exclusive with -c/-d/-D/-u\n".to_string() + footer;
|
"--group is mutually exclusive with -c/-d/-D/-u\n".to_string() + footer;
|
||||||
|
@ -547,7 +547,7 @@ fn map_clap_errors(clap_error: &Error) -> Box<dyn UError> {
|
||||||
{
|
{
|
||||||
override_all_repeated_badoption
|
override_all_repeated_badoption
|
||||||
}
|
}
|
||||||
_ => clap_error.to_string(),
|
_ => return clap_error.into(),
|
||||||
};
|
};
|
||||||
USimpleError::new(1, error_message)
|
USimpleError::new(1, error_message)
|
||||||
}
|
}
|
||||||
|
@ -558,7 +558,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
|
||||||
let matches = uu_app()
|
let matches = uu_app()
|
||||||
.try_get_matches_from(args)
|
.try_get_matches_from(args)
|
||||||
.map_err(|e| map_clap_errors(&e))?;
|
.map_err(map_clap_errors)?;
|
||||||
|
|
||||||
let files = matches.get_many::<OsString>(ARG_FILES);
|
let files = matches.get_many::<OsString>(ARG_FILES);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,20 @@ fn test_invalid_arg() {
|
||||||
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_help_and_version_on_stdout() {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("--help")
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr()
|
||||||
|
.stdout_contains("Usage");
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("--version")
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr()
|
||||||
|
.stdout_contains("uniq");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stdin_default() {
|
fn test_stdin_default() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Reference in a new issue