mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
fix(Error Status): fixes bug where --help and --version return non-zero exit code
This commit is contained in:
parent
c748cef855
commit
89b51fdf8b
1 changed files with 13 additions and 2 deletions
|
@ -267,8 +267,19 @@ pub struct ClapError {
|
|||
impl ClapError {
|
||||
/// Prints the error to `stderr` and exits with a status of `1`
|
||||
pub fn exit(&self) -> ! {
|
||||
wlnerr!("{}", self.error);
|
||||
process::exit(1);
|
||||
if self.use_stderr() {
|
||||
wlnerr!("{}", self.error);
|
||||
process::exit(1);
|
||||
}
|
||||
println!("{}", self.error);
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
fn use_stderr(&self) -> bool {
|
||||
match self.error_type {
|
||||
ClapErrorType::HelpDisplayed | ClapErrorType::VersionDisplayed => false,
|
||||
_ => true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue