use std::{env, fmt, error, result}; use std::process::exit; use std::io; use colored::*; use lazy_static::lazy_static; mod cache; pub use cache::Cache; lazy_static! { pub static ref GIT_DIR: String = { match env::var("GCLONE_PATH") { Ok(d) => d, Err(e) => { let e: Error = e.into(); eprintln!("{}", e); exit(1); }, } }; } macro_rules! impl_from_error { ($type: ty, $variant: path, $from: ty) => { impl From<$from> for $type { fn from(e: $from) -> $type { $variant(e) } } } } #[derive(Debug)] pub enum Error { NoGclonePath(env::VarError), IoError(io::Error), } impl_from_error!(Error, Error::NoGclonePath, env::VarError); impl_from_error!(Error, Error::IoError, io::Error); impl fmt::Display for Error { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match self { Error::NoGclonePath(e) => write!(fmt, "{} {} {}", "error:".bold().red(), "couldn't read environment variable GCLONE_PATH".bold(), e), Error::IoError(e) => write!(fmt, "{} {} {}", "error:".bold().red(), "couldn't read or write cache:".bold(), e), } } } impl error::Error for Error {} pub type Result = result::Result;