MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / update_config

Function update_config

crates/opencode-config/src/loader.rs:1340–1359  ·  view source on GitHub ↗

Update project-level config by merging a patch.

(project_dir: &Path, patch: &Config)

Source from the content-addressed store, hash-verified

1338
1339/// Update project-level config by merging a patch.
1340pub fn update_config(project_dir: &Path, patch: &Config) -> Result<()> {
1341 let config_path = project_dir.join("opencode.json");
1342
1343 let existing = if config_path.exists() {
1344 let content = fs::read_to_string(&config_path)?;
1345 parse_jsonc(&content).unwrap_or_default()
1346 } else {
1347 Config::default()
1348 };
1349
1350 let mut merged = existing;
1351 merged.merge(patch.clone());
1352
1353 let json =
1354 serde_json::to_string_pretty(&merged).with_context(|| "Failed to serialize config")?;
1355 fs::write(&config_path, json)
1356 .with_context(|| format!("Failed to write config to {:?}", config_path))?;
1357
1358 Ok(())
1359}
1360
1361/// Update global config by merging a patch.
1362pub fn update_global_config(patch: &Config) -> Result<()> {

Callers 1

test_update_configFunction · 0.85

Calls 4

parse_jsoncFunction · 0.85
existsMethod · 0.80
mergeMethod · 0.45
cloneMethod · 0.45

Tested by 1

test_update_configFunction · 0.68