There’s more to erroneousness than an exit code

This commit is contained in:
Benjamin Sago 2017-06-23 22:12:21 +01:00
parent a060782312
commit e4e603b4ee
2 changed files with 11 additions and 11 deletions

View File

@ -1,5 +1,5 @@
extern crate exa; extern crate exa;
use exa::{Exa, Misfire}; use exa::Exa;
use std::env::args_os; use std::env::args_os;
use std::io::{stdout, stderr, Write, ErrorKind}; use std::io::{stdout, stderr, Write, ErrorKind};
@ -23,14 +23,14 @@ fn main() {
}; };
}, },
Err(e@Misfire::Help(_)) | Err(e@Misfire::Version) => { Err(ref e) if e.is_error() => {
writeln!(stdout(), "{}", e).unwrap(); writeln!(stderr(), "{}", e).unwrap();
exit(e.error_code()); exit(3);
}, },
Err(e) => { Err(ref e) => {
writeln!(stderr(), "{}", e).unwrap(); writeln!(stdout(), "{}", e).unwrap();
exit(e.error_code()); exit(0);
}, },
}; };
} }

View File

@ -54,11 +54,11 @@ pub enum Misfire {
impl Misfire { impl Misfire {
/// The OS return code this misfire should signify. /// The OS return code this misfire should signify.
pub fn error_code(&self) -> i32 { pub fn is_error(&self) -> bool {
match *self { match *self {
Misfire::Help(_) => 0, Misfire::Help(_) => false,
Misfire::Version => 0, Misfire::Version => false,
_ => 3, _ => true,
} }
} }