diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 87440b6..e1537ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,9 +38,56 @@ use crate::core::Core; use crate::flags::Flags; use std::path::PathBuf; +/// Macro used to avoid panicking when the lsd method is used with a pipe and +/// stderr close before our program. +#[macro_export] +macro_rules! print_error { + ($($arg:tt)*) => { + use std::io::Write; + + let stderr = std::io::stderr(); + + { + let mut handle = stderr.lock(); + // We can write on stderr, so we simply ignore the error and don't print + // and stop with success. + let res = handle.write_all(std::format!($($arg)*).as_bytes()); + if res.is_err() { + std::process::exit(0); + } + } + }; +} + +/// Macro used to avoid panicking when the lsd method is used with a pipe and +/// stdout close before our program. +#[macro_export] +macro_rules! print_output { + ($($arg:tt)*) => { + use std::io::Write; + + let stderr = std::io::stdout(); + + + { + let mut handle = stderr.lock(); + // We can write on stdout, so we simply ignore the error and don't print + // and stop with success. + let res = handle.write_all(std::format!($($arg)*).as_bytes()); + if res.is_err() { + std::process::exit(0); + } + } + }; +} + fn main() { let matches = app::build().get_matches_from(wild::args_os()); + // input translate glob FILE without single quote into real names + // for example: + // * to all files matched + // '*' remain as '*' let inputs = matches .values_of("FILE") .expect("failed to retrieve cli value") |