Skip to content

Commit

Permalink
Merge 02b86d8 into 26b8f51
Browse files Browse the repository at this point in the history
  • Loading branch information
severen committed Apr 18, 2016
2 parents 26b8f51 + 02b86d8 commit b0c3ca2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use curl::http;
use walkdir::{WalkDir, WalkDirIterator, DirEntry};
use time;

use error::TldrError::{self, CacheError, UpdateError};
use error::TealdeerError::{self, CacheError, UpdateError};
use types::OsType;

#[derive(Debug)]
Expand All @@ -30,17 +30,17 @@ impl Cache {
}

/// Return the path to the cache directory.
fn get_cache_dir(&self) -> Result<PathBuf, TldrError> {
fn get_cache_dir(&self) -> Result<PathBuf, TealdeerError> {
// Allow overriding the cache directory by setting the
// $TLDR_RS_CACHE_DIR env variable.
if let Ok(value) = env::var("TLDR_RS_CACHE_DIR") {
// $TEALDEER_CACHE_DIR env variable.
if let Ok(value) = env::var("TEALDEER_CACHE_DIR") {
let path = PathBuf::from(value);

if path.exists() && path.is_dir() {
return Ok(path)
} else {
return Err(CacheError(
"Path specified by $TLDR_RS_CACHE_DIR \
"Path specified by $TEALDEER_CACHE_DIR \
does not exist or is not a directory.".into()
));
}
Expand All @@ -55,7 +55,7 @@ impl Cache {
}

/// Download the archive
fn download(&self) -> Result<http::Response, TldrError> {
fn download(&self) -> Result<http::Response, TealdeerError> {
let resp = try!(
http::handle()
.follow_location(1)
Expand All @@ -66,13 +66,13 @@ impl Cache {
}

/// Decompress and open the archive
fn decompress<R: Read>(&self, reader: R) -> Result<Archive<GzDecoder<R>>, TldrError> {
fn decompress<R: Read>(&self, reader: R) -> Result<Archive<GzDecoder<R>>, TealdeerError> {
let decoder = try!(GzDecoder::new(reader).map_err(|_| UpdateError("Could not decode gzip data".into())));
Ok(Archive::new(decoder))
}

/// Update the pages cache.
pub fn update(&self) -> Result<(), TldrError> {
pub fn update(&self) -> Result<(), TealdeerError> {
// First, download the compressed data
let response = try!(self.download());

Expand Down Expand Up @@ -162,7 +162,7 @@ impl Cache {
}

/// Return the available pages.
pub fn list_pages(&self) -> Result<Vec<String>, TldrError> {
pub fn list_pages(&self) -> Result<Vec<String>, TealdeerError> {
// Determine platforms directory and platform
let cache_dir = try!(self.get_cache_dir());
let platforms_dir = cache_dir.join("tldr-master").join("pages");
Expand Down Expand Up @@ -211,7 +211,7 @@ impl Cache {
}

/// Delete the cache directory.
pub fn clear(&self) -> Result<(), TldrError> {
pub fn clear(&self) -> Result<(), TealdeerError> {
let path = try!(self.get_cache_dir());
if path.exists() && path.is_dir() {
try!(fs::remove_dir_all(&path).map_err(|_| {
Expand Down
8 changes: 4 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use curl::ErrCode;

#[derive(Debug)]
pub enum TldrError {
pub enum TealdeerError {
CacheError(String),
UpdateError(String),
}

impl From<ErrCode> for TldrError {
fn from(err: ErrCode) -> TldrError {
TldrError::UpdateError(err.to_string())
impl From<ErrCode> for TealdeerError {
fn from(err: ErrCode) -> TealdeerError {
TealdeerError::UpdateError(err.to_string())
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod error;

use tokenizer::Tokenizer;
use cache::Cache;
use error::TldrError::{UpdateError, CacheError};
use error::TealdeerError::{UpdateError, CacheError};
use formatter::print_lines;
use types::OsType;

Expand Down
6 changes: 1 addition & 5 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::process::Command;

use tempdir::TempDir;


struct TestEnv {
cache_dir: TempDir,
bin_path: PathBuf,
Expand All @@ -33,13 +32,11 @@ impl TestEnv {
/// Return a new Command instance with the base binary and env vars set.
fn cmd(&self) -> Command {
let mut cmd = Command::new(&self.bin_path);
cmd.env("TLDR_RS_CACHE_DIR", self.cache_dir.path());
cmd.env("TEALDEER_CACHE_DIR", self.cache_dir.path());
cmd
}

}


#[test]
fn test_missing_cache() {
let testenv = TestEnv::new();
Expand All @@ -53,7 +50,6 @@ fn test_missing_cache() {
assert_eq!(stdout, "Cache not found. Please run `tldr --update`.\n");
}


#[test]
fn test_update_cache() {
let testenv = TestEnv::new();
Expand Down

0 comments on commit b0c3ca2

Please sign in to comment.