From 20b36a00ed258fa5a3245df41a7d80cd3e747824 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Tue, 21 Oct 2025 17:46:15 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20get=5Frules=5Ffrom()?= =?UTF-8?q?=20to=20load=20rules=20from=20custom=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add get_rules_from(path) function that accepts optional custom path - Keep get_rules() as backward-compatible wrapper - Automatically create and save default rules to custom path if not found --- src/cli/rules_cli.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/cli/rules_cli.rs b/src/cli/rules_cli.rs index 6e4e3bb..7876ec5 100644 --- a/src/cli/rules_cli.rs +++ b/src/cli/rules_cli.rs @@ -102,6 +102,7 @@ //! - **Logging system**: Comprehensive operation tracking use clap::{Parser, Subcommand}; +use std::path::Path; mod config_cli; mod run_cli; @@ -327,13 +328,27 @@ impl RulesCli { /// - **Rules CLI**: To load rules before configuration or execution /// - **Main CLI**: For default rule execution when no subcommand is specified /// - **Validation systems**: To verify rule configuration integrity +/// Loads rules from the default location. pub fn get_rules() -> Result { - match Rules::load() { + get_rules_from(None) +} + +/// Loads rules from a specified path, or the default location if None. +/// +/// # Arguments +/// +/// * `path` - Optional path to the rules file +/// +/// # Returns +/// +/// Returns the loaded rules, or creates and saves default rules if not found. +pub fn get_rules_from(path: Option<&Path>) -> Result { + match Rules::load_from(path) { Ok(c) => Ok(c), Err(_) => { log::warn!("Configuration not found, creating default config."); let rules = Rules::new(); - rules.save()?; + rules.save_to(path)?; Ok(rules) } }