Loads configuration from an explicit config path while preserving the project root used for default config values.
(project_root: &Path, config_path: &Path)
| 414 | /// Loads configuration from an explicit config path while preserving the |
| 415 | /// project root used for default config values. |
| 416 | pub fn load_config_from_path(project_root: &Path, config_path: &Path) -> Result<TraceDecayConfig> { |
| 417 | if !config_path.exists() { |
| 418 | return Ok(TraceDecayConfig { |
| 419 | root_dir: project_root.to_string_lossy().to_string(), |
| 420 | ..TraceDecayConfig::default() |
| 421 | }); |
| 422 | } |
| 423 | |
| 424 | let contents = fs::read_to_string(config_path).map_err(|e| TraceDecayError::Config { |
| 425 | message: format!( |
| 426 | "failed to read config file '{}': {}", |
| 427 | config_path.display(), |
| 428 | e |
| 429 | ), |
| 430 | })?; |
| 431 | |
| 432 | let config: TraceDecayConfig = |
| 433 | serde_json::from_str(&contents).map_err(|e| TraceDecayError::Config { |
| 434 | message: format!( |
| 435 | "failed to parse config file '{}': {}", |
| 436 | config_path.display(), |
| 437 | e |
| 438 | ), |
| 439 | })?; |
| 440 | |
| 441 | Ok(config) |
| 442 | } |
| 443 | |
| 444 | /// Saves the configuration to disk using an atomic write. |
| 445 | /// |
no test coverage detected