From 20cb64970dae30bacc58fa7af8ded258142e316a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 13 Nov 2020 18:33:41 +0100 Subject: Make highlighting optional Signed-off-by: Matthias Beyer --- src/config/not_validated.rs | 29 +++++++++++++++-------------- src/config/util.rs | 4 ---- 2 files changed, 15 insertions(+), 18 deletions(-) (limited to 'src/config') diff --git a/src/config/not_validated.rs b/src/config/not_validated.rs index 456cc2a..87bb816 100644 --- a/src/config/not_validated.rs +++ b/src/config/not_validated.rs @@ -24,9 +24,8 @@ pub struct NotValidatedConfiguration { #[getset(get = "pub")] package_print_format: String, - #[serde(default = "default_script_highlight_theme")] #[getset(get = "pub")] - script_highlight_theme: String, + script_highlight_theme: Option, #[serde(rename = "releases")] releases_directory: String, @@ -71,18 +70,20 @@ pub struct NotValidatedConfiguration { impl<'reg> NotValidatedConfiguration { pub fn validate(self) -> Result> { // TODO: Implement proper validation - let allowed_theme_present = [ - "base16-ocean.dark", - "base16-eighties.dark", - "base16-mocha.dark", - "base16-ocean.light", - "InspiredGitHub", - "Solarized (dark)", - "Solarized (light)", - ].into_iter().any(|allowed_theme| self.script_highlight_theme == *allowed_theme); - - if !allowed_theme_present { - return Err(anyhow!("Theme not known: {}", self.script_highlight_theme)) + if let Some(configured_theme) = self.script_highlight_theme.as_ref() { + let allowed_theme_present = [ + "base16-ocean.dark", + "base16-eighties.dark", + "base16-mocha.dark", + "base16-ocean.light", + "InspiredGitHub", + "Solarized (dark)", + "Solarized (light)", + ].into_iter().any(|allowed_theme| configured_theme == *allowed_theme); + + if !allowed_theme_present { + return Err(anyhow!("Theme not known: {}", configured_theme)) + } } let hb = { diff --git a/src/config/util.rs b/src/config/util.rs index 38939f0..17aeadf 100644 --- a/src/config/util.rs +++ b/src/config/util.rs @@ -15,7 +15,3 @@ pub fn default_package_print_format() -> String { "#)) } -pub fn default_script_highlight_theme() -> String { - String::from("base16-ocean.dark") -} - -- cgit v1.2.3