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

Exiting with error code 2 when help argument passed #180

Closed
fredrb opened this issue May 16, 2017 · 3 comments
Closed

Exiting with error code 2 when help argument passed #180

fredrb opened this issue May 16, 2017 · 3 comments
Assignees
Milestone

Comments

@fredrb
Copy link

fredrb commented May 16, 2017

> exa --help
...
> echo $?
2
> exa --version
...
> echo $?
3

Shouldn't it be 0 for both, like ls?

I understand how help and version are treated as errors so they can have an early return. But the error code is explicitly set here:

    /// The OS return code this misfire should signify.
    pub fn error_code(&self) -> i32 {
        if let Misfire::Help(_) = *self { 2 }
                                   else { 3 }
    }
@ogham
Copy link
Owner

ogham commented May 16, 2017

That function only actually exists so --help gets its own error code!

I don't know, it felt right to me to treat things like --help and --version as their own categories, separate from both success and failure. Success means that exa has listed some files, failure meant that an error occurred meaning it crashed or couldn't list files, but help? There's no error, so it's not 1, but it didn't list any files either, so it's not 0.

I can see the argument in favour of returning 0 here, because it was able to display the help correctly... but would anyone really use --help or --version in a script? Is there a use case that I'm not seeing?

@ogham ogham self-assigned this May 16, 2017
@fredrb
Copy link
Author

fredrb commented May 16, 2017

I don't see any real script that would depend on --help. I know this looks like a nitpick to you. But for instance piping exa --help with something else would break, like: exa --help | grep git. Help text will not be piped to grep because the command failed from shell's point of view.

@ogham ogham added this to the v0.6.0 milestone May 17, 2017
@ogham
Copy link
Owner

ogham commented May 17, 2017

I tried running that command in my shell and it still worked (though --help does go to stderr). But I can see that sort of thing happening. Also, I can’t find any other examples of other programs using different exit codes for --help and --version! So I’m going to change it.

@ogham ogham closed this as completed in 510d2f7 May 17, 2017
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

No branches or pull requests

2 participants