From 54143d1403b79ac1e28ef5c693ecb3e320601892 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Thu, 7 Feb 2019 21:19:20 +0100 Subject: [PATCH] Add --cache-dir option --- src/assets.rs | 4 ++++ src/clap_app.rs | 7 ++++++- src/main.rs | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/assets.rs b/src/assets.rs index ab9f0e4a..ffbc32b9 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -216,6 +216,10 @@ pub fn config_dir() -> Cow<'static, str> { PROJECT_DIRS.config_dir().to_string_lossy() } +pub fn cache_dir() -> Cow<'static, str> { + PROJECT_DIRS.cache_dir().to_string_lossy() +} + pub fn clear_assets() { print!("Clearing theme set cache ... "); fs::remove_file(theme_set_path()).ok(); diff --git a/src/clap_app.rs b/src/clap_app.rs index abecb68a..0cdba9f2 100644 --- a/src/clap_app.rs +++ b/src/clap_app.rs @@ -374,9 +374,14 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { .short("d") .help("Show bat's configuration directory."), ) + .arg( + Arg::with_name("cache-dir") + .long("cache-dir") + .help("Show bat's cache directory."), + ) .group( ArgGroup::with_name("cache-actions") - .args(&["init", "clear", "config-dir"]) + .args(&["init", "clear", "config-dir", "cache-dir"]) .required(arg_group_required), ) .arg( diff --git a/src/main.rs b/src/main.rs index 610a8f7a..6a80c87d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ use ansi_term::Colour::Green; use ansi_term::Style; use app::{App, Config}; -use assets::{clear_assets, config_dir, HighlightingAssets}; +use assets::{cache_dir, clear_assets, config_dir, HighlightingAssets}; use config::config_file; use controller::Controller; use inputfile::InputFile; @@ -98,6 +98,8 @@ fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> { clear_assets(); } else if matches.is_present("config-dir") { writeln!(io::stdout(), "{}", config_dir())?; + } else if matches.is_present("cache-dir") { + writeln!(io::stdout(), "{}", cache_dir())?; } Ok(())