Write settings back to `.gemini/settings.json`.
(
settings_path: &Path,
raw: &serde_json::Map<String, serde_json::Value>,
)
| 343 | |
| 344 | /// Write settings back to `.gemini/settings.json`. |
| 345 | fn write_settings( |
| 346 | settings_path: &Path, |
| 347 | raw: &serde_json::Map<String, serde_json::Value>, |
| 348 | ) -> AgentResult<()> { |
| 349 | // Ensure parent directory exists |
| 350 | if let Some(parent) = settings_path.parent() { |
| 351 | if !parent.exists() { |
| 352 | std::fs::create_dir_all(parent).map_err(|e| AgentError::ConfigError { |
| 353 | operation: "create directory".to_string(), |
| 354 | path: parent.to_path_buf(), |
| 355 | reason: e.to_string(), |
| 356 | })?; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | let content = serde_json::to_string_pretty(raw).map_err(|e| AgentError::ConfigError { |
| 361 | operation: "serialize".to_string(), |
| 362 | path: settings_path.to_path_buf(), |
| 363 | reason: e.to_string(), |
| 364 | })?; |
| 365 | |
| 366 | std::fs::write(settings_path, content.as_bytes()).map_err(|e| AgentError::ConfigError { |
| 367 | operation: "write".to_string(), |
| 368 | path: settings_path.to_path_buf(), |
| 369 | reason: e.to_string(), |
| 370 | })?; |
| 371 | |
| 372 | Ok(()) |
| 373 | } |
| 374 | |
| 375 | /// Install hooks into a settings file (project or global). |
| 376 | fn install_to(settings_path: &Path, force: bool) -> AgentResult<usize> { |