diff --git a/src/lib.rs b/src/lib.rs index 0fd70ff..666cee5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,8 @@ pub fn read_env_vars(file_path: &str) -> Result, std::io let contents = fs::read_to_string(path)?; Ok(parse_env_content(&contents)) } else { + // Create an empty .env file if it doesn't exist + fs::write(path, "")?; Ok(HashMap::new()) } } diff --git a/src/main.rs b/src/main.rs index 1d0e804..e47e0e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -161,17 +161,10 @@ fn main() { if !new_vars.is_empty() { should_print = false; // Don't print all vars when setting new ones - let mut env_vars = match read_env_vars(&cli.file) { - Ok(result) => result, - Err(e) => { - if e.kind() == std::io::ErrorKind::NotFound { - HashMap::new() - } else { - eprintln!("Error reading .env file: {}", e); - process::exit(1); - } - } - }; + let mut env_vars = read_env_vars(&cli.file).unwrap_or_else(|e| { + eprintln!("Error reading .env file: {}", e); + process::exit(1); + }); env_vars.extend(new_vars);