Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

truncate: change cli error return code #3012

Merged
merged 5 commits into from
Feb 3, 2022

Conversation

shoriminimoe
Copy link
Contributor

Exit with status code 1 for argument parsing errors in truncate. When clap encounters an error during argument parsing, it exits with status code 2. This causes some GNU tests to fail since they expect status code 1.

Closes #2951

Exit with status code 1 for argument parsing errors in `truncate`. When
`clap` encounters an error during argument parsing, it exits with status
code 2. This causes some GNU tests to fail since they expect status code
1.
@shoriminimoe shoriminimoe changed the title [truncate] change cli error return code truncate: change cli error return code Feb 1, 2022
Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good! Could you add a small test for this behaviour? Just testing that truncate --this-arg-does-not-exist returns 1 is fine.

e.print().expect("Error writing clap::Error");
match e.kind {
clap::ErrorKind::DisplayHelp | clap::ErrorKind::DisplayVersion => {
std::process::exit(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit to make it a bit cleaner using UResult and so that we don't have to call std::process:exit:

.map_err(|e| {
    e.print().expect("Error writing clap::Error");
    match e.kind {
        clap::ErrorKind::DisplayHelp | clap::ErrorKind::DisplayVersion => 0,
        _ => 1,
    }
})?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it. Working on it now.

@sylvestre sylvestre merged commit 2d3b8db into uutils:main Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

truncate: exit status should be 1, not 2, on invalid arguments
3 participants