on master help sign in
Add new '--blank' option for 'bat cache --init'

closes #206

commit2df3305b94ff85878b61415d6136c8a5b2d3e439 authorsharkdp <davidpeter@web.de> dateMon 20 Aug 2018, 21:12 (8 years ago) parent6882fc1
4 files changed+30−4
assets/create.sh+1−1 src/app.rs+6 src/assets.rs+20−2 src/main.rs+3−1
assets/create.sh+1−1
@@ -2,4 +2,4 @@
22
33ASSET_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44
5−bat cache --init --source="$ASSET_DIR" --target="$ASSET_DIR"
5+bat cache --init --blank --source="$ASSET_DIR" --target="$ASSET_DIR"
src/app.rs+6
@@ -210,6 +210,12 @@ impl App {
210210 .help(
211211 "Use a different directory to store the cached syntax and theme set",
212212 ),
213+ ).arg(
214+ Arg::with_name("blank")
215+ .long("blank")
216+ .requires("init")
217+ .help("Create completely new syntax and theme sets \
218+ (instead of appending to the default sets")
213219 ),
214220 ).help_message("Print this help message.")
215221 .version_message("Show version information.")
src/assets.rs+20−2
@@ -1,6 +1,7 @@
11use directories::ProjectDirs;
22use errors::*;
33use std::borrow::Cow;
4+use std::collections::BTreeMap;
45use std::fs::{self, File};
56use std::path::{Path, PathBuf};
67use syntect::dumps::{dump_to_file, from_binary, from_reader};
@@ -25,10 +26,27 @@ impl HighlightingAssets {
2526 Self::from_cache().unwrap_or_else(|_| Self::from_binary())
2627 }
2728
28− pub fn from_files(dir: Option<&Path>) -> Result<Self> {
29+ fn empty() -> Self {
30+ let mut syntax_set = SyntaxSet::new();
31+ syntax_set.load_plain_text_syntax();
32+
33+ let theme_set = ThemeSet {
34+ themes: BTreeMap::new(),
35+ };
36+ HighlightingAssets {
37+ syntax_set,
38+ theme_set,
39+ }
40+ }
41+
42+ pub fn from_files(dir: Option<&Path>, start_empty: bool) -> Result<Self> {
2943 let source_dir = dir.unwrap_or_else(|| PROJECT_DIRS.config_dir());
3044
31− let mut assets = Self::from_binary_unlinked();
45+ let mut assets = if start_empty {
46+ Self::empty()
47+ } else {
48+ Self::from_binary_unlinked()
49+ };
3250
3351 let theme_dir = source_dir.join("themes");
3452
src/main.rs+3−1
@@ -73,7 +73,9 @@ fn run() -> Result<bool> {
7373 let source_dir = cache_matches.value_of("source").map(Path::new);
7474 let target_dir = cache_matches.value_of("target").map(Path::new);
7575
76− let assets = HighlightingAssets::from_files(source_dir)?;
76+ let blank = cache_matches.is_present("blank");
77+
78+ let assets = HighlightingAssets::from_files(source_dir, blank)?;
7779 assets.save(target_dir)?;
7880 } else if cache_matches.is_present("clear") {
7981 clear_assets();