1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Merge pull request #3012 from shoriminimoe/2951-truncate

truncate: change cli error return code
This commit is contained in:
Sylvestre Ledru 2022-02-03 10:43:16 +01:00 committed by GitHub
commit 2d3b8db9ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View file

@ -115,7 +115,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app()
.override_usage(&usage[..])
.after_help(&long_usage[..])
.get_matches_from(args);
.try_get_matches_from(args)
.map_err(|e| {
e.print().expect("Error writing clap::Error");
match e.kind {
clap::ErrorKind::DisplayHelp | clap::ErrorKind::DisplayVersion => 0,
_ => 1,
}
})?;
let files: Vec<String> = matches
.values_of(options::ARG_FILES)

View file

@ -250,11 +250,24 @@ fn test_size_and_reference() {
#[test]
fn test_error_filename_only() {
// truncate: you must specify either '--size' or '--reference'
new_ucmd!().args(&["file"]).fails().stderr_contains(
"error: The following required arguments were not provided:
new_ucmd!()
.args(&["file"])
.fails()
.code_is(1)
.stderr_contains(
"error: The following required arguments were not provided:
--reference <RFILE>
--size <SIZE>",
);
);
}
#[test]
fn test_invalid_option() {
// truncate: cli parsing error returns 1
new_ucmd!()
.args(&["--this-arg-does-not-exist"])
.fails()
.code_is(1);
}
#[test]