From eec5df3ff33525aba6e3fceff981721376cdc38c Mon Sep 17 00:00:00 2001 From: DustInDark Date: Sun, 26 Jun 2022 12:16:27 +0900 Subject: [PATCH] adjusted default value when level-tuning option is not defined --- src/detections/configs.rs | 3 +-- src/main.rs | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/detections/configs.rs b/src/detections/configs.rs index ecc2e028..657183ca 100644 --- a/src/detections/configs.rs +++ b/src/detections/configs.rs @@ -191,11 +191,10 @@ pub struct Config { /// Tune alert levels (default: ./rules/config/level_tuning.txt) #[clap( long = "level-tuning", - default_value = "./rules/config/level_tuning.txt", hide_default_value = true, value_name = "LEVEL_TUNING_FILE" )] - pub level_tuning: PathBuf, + pub level_tuning: Option>, /// Quiet mode: do not display the launch banner #[clap(short, long)] diff --git a/src/main.rs b/src/main.rs index 7cb27c64..1414321b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -251,18 +251,18 @@ impl App { } else if configs::CONFIG.read().unwrap().args.contributors { self.print_contributors(); return; - } else if std::env::args() - .into_iter() - .any(|arg| arg.contains("level-tuning")) + } else if configs::CONFIG.read().unwrap().args.level_tuning.is_some() { - let level_tuning_config_path = configs::CONFIG - .read() - .unwrap() - .args - .level_tuning - .as_path() - .display() - .to_string(); + let level_tuning_val = &configs::CONFIG + .read() + .unwrap() + .args + .level_tuning.clone().unwrap(); + let level_tuning_config_path = match level_tuning_val { + Some (path) => path.to_owned(), + _ => "./rules/config/level_tuning.txt".to_string(), + }; + if Path::new(&level_tuning_config_path).exists() { if let Err(err) = LevelTuning::run(