MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / load_config_from_path

Function load_config_from_path

src/config.rs:416–442  ·  view source on GitHub ↗

Loads configuration from an explicit config path while preserving the project root used for default config values.

(project_root: &Path, config_path: &Path)

Source from the content-addressed store, hash-verified

414/// Loads configuration from an explicit config path while preserving the
415/// project root used for default config values.
416pub 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///

Callers 4

load_configFunction · 0.85
open_with_optionsMethod · 0.85

Calls 1

existsMethod · 0.80

Tested by

no test coverage detected