Writes the Selenium LLM rules file to the given path, creating parent directories as needed. # Arguments `path` - Destination file path (e.g. `rules/selenium.md`) `log` - Logger instance # Errors Returns an error if the file already exists or cannot be written.
(path: &Path, log: &Logger)
| 32 | /// # Errors |
| 33 | /// Returns an error if the file already exists or cannot be written. |
| 34 | pub fn write_rules_file(path: &Path, log: &Logger) -> Result<(), Error> { |
| 35 | log.debug(format!("Creating rules file at: {}", path.display())); |
| 36 | if path.exists() { |
| 37 | return Err(anyhow!( |
| 38 | "The file {} already exists. Please remove it or choose a different location.", |
| 39 | path.display() |
| 40 | )); |
| 41 | } |
| 42 | if let Some(parent) = path.parent() { |
| 43 | if !parent.exists() { |
| 44 | log.debug(format!("Creating directory: {}", parent.display())); |
| 45 | std::fs::create_dir_all(parent)?; |
| 46 | } |
| 47 | } |
| 48 | let mut file = OpenOptions::new().write(true).create_new(true).open(path)?; |
| 49 | file.write_all(RULES_CONTENT.as_bytes())?; |
| 50 | Ok(()) |
| 51 | } |