提交 aa17e4d3 编写于 作者: B Benjamin Sago

Make a common module of exit statuses

上级 e4e603b4
......@@ -5,6 +5,7 @@ use std::env::args_os;
use std::io::{stdout, stderr, Write, ErrorKind};
use std::process::exit;
fn main() {
let args = args_os().skip(1);
match Exa::new(args, &mut stdout()) {
......@@ -13,10 +14,10 @@ fn main() {
Ok(exit_status) => exit(exit_status),
Err(e) => {
match e.kind() {
ErrorKind::BrokenPipe => exit(0),
ErrorKind::BrokenPipe => exit(exits::SUCCESS),
_ => {
writeln!(stderr(), "{}", e).unwrap();
exit(1);
exit(exits::RUNTIME_ERROR);
},
};
}
......@@ -25,12 +26,23 @@ fn main() {
Err(ref e) if e.is_error() => {
writeln!(stderr(), "{}", e).unwrap();
exit(3);
exit(exits::OPTIONS_ERROR);
},
Err(ref e) => {
writeln!(stdout(), "{}", e).unwrap();
exit(0);
exit(exits::SUCCESS);
},
};
}
extern crate libc;
#[allow(trivial_numeric_casts)]
mod exits {
use libc::{self, c_int};
pub const SUCCESS: c_int = libc::EXIT_SUCCESS;
pub const RUNTIME_ERROR: c_int = libc::EXIT_FAILURE;
pub const OPTIONS_ERROR: c_int = 3 as c_int;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册