1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#![feature(io_error_more)] use std::{io::ErrorKind, process::ExitCode}; macro_rules! fail { () => { fail!("<infile>") }; ($usage:literal) => {{ eprintln!(concat!("usage: erad ", comat::comat!($usage))); return ExitCode::FAILURE; }}; } fn main() -> ExitCode { let Some(out) = std::env::args().nth(1) else { fail!(); }; println!( "{:?}", match std::fs::read(out).map_err(|e| e.kind()) { Err(ErrorKind::IsADirectory) => fail!("<valid {red}{italic}file{reset}>"), Err(ErrorKind::PermissionDenied) => fail!("<{red}readable filename{reset}>"), Err(_) => fail!("<{red}infile{reset}>"), Ok(x) => x, } ); ExitCode::SUCCESS }