From 8480ae88f0c4b9caf98b02cd2ec02c627b67ed9b Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Tue, 12 Feb 2019 11:11:32 +0100 Subject: [PATCH] Cleaning --- src/cache.rs | 8 ++++---- src/gclone.rs | 4 ++-- src/lib.rs | 8 +++++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index 1cf0ee9..281c6e3 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use std::fs::File; use std::io::{Write, BufRead, BufReader}; use walkdir::WalkDir; -use crate::{Result, GIT_DIR}; +use crate::{Result, GCLONE_PATH}; /// The cache of gclone. /// @@ -17,7 +17,7 @@ impl Cache { /// Generates the cache by traversing the files in the git directory. pub fn generate() -> Cache { - Cache(WalkDir::new(&*GIT_DIR) + Cache(WalkDir::new(&*GCLONE_PATH) .max_depth(3) .into_iter() .filter_map(|x| x.ok()) @@ -28,7 +28,7 @@ impl Cache { /// Reads the cache file. pub fn read() -> Result { - let mut path = PathBuf::from(&*GIT_DIR); + let mut path = PathBuf::from(&*GCLONE_PATH); path.push(".cdgcache"); let file = File::open(&path)?; @@ -55,7 +55,7 @@ impl Cache { /// Writes the current content of the cache to the cache file. pub fn write(&self) -> Result<()> { - let mut path = PathBuf::from(&*GIT_DIR); + let mut path = PathBuf::from(&*GCLONE_PATH); path.push(".cdgcache"); let mut file = File::create(path)?; diff --git a/src/gclone.rs b/src/gclone.rs index 6dcf102..209ec64 100644 --- a/src/gclone.rs +++ b/src/gclone.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use colored::*; -use gclone::{GIT_DIR, Cache, Result}; +use gclone::{GCLONE_PATH, Cache, Result}; macro_rules! unwrap { ($e: expr) => { @@ -85,7 +85,7 @@ fn main() -> Result<()> { }; // Build path - let mut path = PathBuf::from(&*GIT_DIR); + let mut path = PathBuf::from(&*GCLONE_PATH); path.push(&server); path.push(&owner); path.push(&repo); diff --git a/src/lib.rs b/src/lib.rs index fee9afa..4b72e3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,8 @@ mod cache; pub use cache::Cache; lazy_static! { - pub static ref GIT_DIR: String = { + /// The directory in which the repositories will be cloned and searched. + pub static ref GCLONE_PATH: String = { match env::var("GCLONE_PATH") { Ok(d) => d, Err(e) => { @@ -32,8 +33,12 @@ macro_rules! impl_from_error { } #[derive(Debug)] +/// The error type of gclone. pub enum Error { + /// Couldn't read the GCLONE_PATH env. NoGclonePath(env::VarError), + + /// An error occured while manipulating files. IoError(io::Error), } @@ -59,5 +64,6 @@ impl fmt::Display for Error { impl error::Error for Error {} +/// The result type of gclone. pub type Result = result::Result;