From 42ac13e0bd24c2775874cac891826024054e4e3c Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 17 Nov 2023 17:56:24 -0800 Subject: [PATCH] feat(config): autopopulate matcher for exes This commit updates the fmt-asc command to automatically populate unset matching strategies for Exe matching rules to be "Equals" --- komorebi-core/src/config_generation.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/komorebi-core/src/config_generation.rs b/komorebi-core/src/config_generation.rs index 9566bf51..65ff989b 100644 --- a/komorebi-core/src/config_generation.rs +++ b/komorebi-core/src/config_generation.rs @@ -98,6 +98,20 @@ pub struct ApplicationConfiguration { pub float_identifiers: Option>, } +impl ApplicationConfiguration { + pub fn populate_default_matching_strategies(&mut self) { + if self.identifier.matching_strategy.is_none() { + match self.identifier.kind { + ApplicationIdentifier::Exe => { + self.identifier.matching_strategy = Option::from(MatchingStrategy::Equals); + } + ApplicationIdentifier::Class => {} + ApplicationIdentifier::Title => {} + } + } + } +} + #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] pub struct ApplicationConfigurationGenerator; @@ -108,6 +122,10 @@ impl ApplicationConfigurationGenerator { pub fn format(content: &str) -> Result { let mut cfgen = Self::load(content)?; + for cfg in &mut cfgen { + cfg.populate_default_matching_strategies(); + } + cfgen.sort_by(|a, b| a.name.cmp(&b.name)); Ok(serde_yaml::to_string(&cfgen)?) }