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:
commit
2d3b8db9ed
2 changed files with 24 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue