diff --git a/src/env_validator.rs b/src/env_validator.rs index d31c71c..656ee86 100644 --- a/src/env_validator.rs +++ b/src/env_validator.rs @@ -1,5 +1,9 @@ use regex::Regex; use std::collections::HashSet; +use std::collections::HashMap; +use std::fs; +use std::io; + pub fn extract_env_variables(source: &str) -> Vec { @@ -29,4 +33,54 @@ pub fn extract_env_variables(source: &str) -> Vec { let mut result: Vec = vars.into_iter().collect(); result.sort(); result +} + +pub fn parse_env_file(path: &str) -> io::Result> { + let content = fs::read_to_string(path)?; + let mut vars = HashMap::new(); + + for line in content.lines() { + let line = line.trim(); + + if line.is_empty() || line.starts_with('#') { + continue; + } + + if let Some((key, value)) = line.split_once('=') { + vars.insert( + key.trim().to_string(), + value.trim().to_string(), + ); + } + } + + Ok(vars) +} + +pub fn validate_env( + extracted: &[String], + env: &HashMap, +) { + println!("Validation Report"); + + println!("\nMissing Variables:"); + for var in extracted { + if !env.contains_key(var) { + println!("- {}", var); + } + } + + println!("\nUnused Variables:"); + for key in env.keys() { + if !extracted.contains(key) { + println!("- {}", key); + } + } + + println!("\nEmpty Variables:"); + for (key, value) in env { + if value.trim().is_empty() { + println!("- {}", key); + } + } } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index f52a3f9..224d42e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ mod env_validator; fn main() { - println!("issue 4!!!"); + println!("issue 4/5/6 solution"); } \ No newline at end of file