use crate::types::Config;
use anyhow::{Context, Result};
use std::collections::HashMap;
use std::fs;
use std::path::Path;
pub fn load_config(config_path: &str) -> Result<Config> {
if !Path::new(config_path).exists() {
eprintln!("Warning: Config file '{config_path}' not found. No command mappings will be applied.");
return Ok(Config {
commands: HashMap::new(),
semantic_directories: HashMap::new(),
command_history: None,
});
}
let content = fs::read_to_string(config_path)
.with_context(|| format!("Failed to read config file: {config_path}"))?;
let config: Config = toml::from_str(&content)
.with_context(|| format!("Failed to parse config file: {config_path}"))?;
Ok(config)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config_loading_missing_file() {
let result = load_config("non-existent-file.toml");
assert!(result.is_ok()); let config = result.unwrap();
assert!(config.commands.is_empty());
}
}