Update project-level config by merging a patch.
(project_dir: &Path, patch: &Config)
| 1338 | |
| 1339 | /// Update project-level config by merging a patch. |
| 1340 | pub 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. |
| 1362 | pub fn update_global_config(patch: &Config) -> Result<()> { |