mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-09 09:49:10 +02:00
Implement --clear-cache flag
This commit is contained in:
parent
5eb44dd708
commit
55bbd78360
2 changed files with 23 additions and 3 deletions
15
src/cache.rs
15
src/cache.rs
|
|
@ -127,4 +127,19 @@ impl Cache {
|
|||
}
|
||||
}
|
||||
|
||||
/// Delete the cache directory.
|
||||
pub fn clear(&self) -> Result<(), TldrError> {
|
||||
let path = try!(self.get_cache_dir());
|
||||
if path.exists() && path.is_dir() {
|
||||
try!(fs::remove_dir_all(&path).map_err(|_| {
|
||||
CacheError(format!("Could not remove cache directory ({}).", path.display()))
|
||||
}));
|
||||
} else if path.exists() {
|
||||
return Err(CacheError(format!("Cache path ({}) is not a directory.", path.display())));
|
||||
} else {
|
||||
return Err(CacheError(format!("Cache path ({}) does not exist.", path.display())));
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
11
src/main.rs
11
src/main.rs
|
|
@ -124,8 +124,13 @@ fn main() {
|
|||
|
||||
// Clear cache, pass through
|
||||
if args.flag_clear_cache {
|
||||
println!("Flag --clear-cache not yet implemented.");
|
||||
process::exit(1);
|
||||
cache.clear().unwrap_or_else(|e| {
|
||||
match e {
|
||||
UpdateError(msg) | CacheError(msg) => println!("Could not delete cache: {}", msg),
|
||||
};
|
||||
process::exit(1);
|
||||
});
|
||||
println!("Successfully deleted cache.");
|
||||
}
|
||||
|
||||
// Update cache, pass through
|
||||
|
|
@ -196,7 +201,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// Some flags can be run without a command.
|
||||
if !args.flag_update {
|
||||
if !(args.flag_update || args.flag_clear_cache) {
|
||||
println!("{}", USAGE);
|
||||
process::exit(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue