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

View File

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