| 36 | } |
| 37 | |
| 38 | pub fn load_from_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()> { |
| 39 | let path = path.as_ref(); |
| 40 | if !path.exists() { |
| 41 | return Ok(()); |
| 42 | } |
| 43 | |
| 44 | let content = fs::read_to_string(path) |
| 45 | .with_context(|| format!("Failed to read config file: {:?}", path))?; |
| 46 | |
| 47 | // Apply {env:VAR} substitution |
| 48 | let content = substitute_env_vars(&content); |
| 49 | |
| 50 | // Apply {file:path} substitution |
| 51 | let base_dir = path.parent().unwrap_or(Path::new(".")); |
| 52 | let content = resolve_file_references(&content, base_dir) |
| 53 | .with_context(|| format!("Failed to resolve file references in: {:?}", path))?; |
| 54 | |
| 55 | let config: Config = parse_jsonc(&content) |
| 56 | .with_context(|| format!("Failed to parse config file: {:?}", path))?; |
| 57 | |
| 58 | self.config.merge(config); |
| 59 | self.config_paths.push(path.to_path_buf()); |
| 60 | Ok(()) |
| 61 | } |
| 62 | |
| 63 | pub fn load_global(&mut self) -> Result<()> { |
| 64 | let global_config_path = get_global_config_path(); |