| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- extern crate exa;
- use exa::Exa;
- use std::ffi::OsString;
- use std::env::args_os;
- use std::io::{stdout, stderr, Write, ErrorKind};
- use std::process::exit;
- fn main() {
- let args: Vec<OsString> = args_os().skip(1).collect();
- match Exa::new(args.iter(), &mut stdout()) {
- Ok(mut exa) => {
- match exa.run() {
- Ok(exit_status) => exit(exit_status),
- Err(e) => {
- match e.kind() {
- ErrorKind::BrokenPipe => exit(exits::SUCCESS),
- _ => {
- writeln!(stderr(), "{}", e).unwrap();
- exit(exits::RUNTIME_ERROR);
- },
- };
- }
- };
- },
- Err(ref e) if e.is_error() => {
- writeln!(stderr(), "{}", e).unwrap();
- exit(exits::OPTIONS_ERROR);
- },
- Err(ref e) => {
- writeln!(stdout(), "{}", e).unwrap();
- 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;
- }
|