(path: String)
| 280 | } |
| 281 | |
| 282 | pub fn indent_file(path: String) -> Result<String, CommandError> { |
| 283 | let file = OpenOptions::new().read(true).open(path.as_str()).map_err(|e| { |
| 284 | CommandError::new(format!("Unable to open YAML backup file {path}."), Some(e.to_string()), None) |
| 285 | })?; |
| 286 | |
| 287 | let file_content = BufReader::new(file.try_clone().unwrap()) |
| 288 | .lines() |
| 289 | .map(|line| line.unwrap()) |
| 290 | .collect::<Vec<String>>(); |
| 291 | |
| 292 | let content = file_content.iter().map(|line| line[2..].to_string()).join("\n"); |
| 293 | |
| 294 | let mut file = OpenOptions::new() |
| 295 | .write(true) |
| 296 | .truncate(true) |
| 297 | .open(path.as_str()) |
| 298 | .map_err(|e| { |
| 299 | CommandError::new(format!("Unable to edit YAML backup file {path}."), Some(e.to_string()), None) |
| 300 | })?; |
| 301 | |
| 302 | match file.write_all(content.as_bytes()) { |
| 303 | Err(e) => Err(CommandError::new( |
| 304 | format!("Unable to edit YAML backup file {path}."), |
| 305 | Some(e.to_string()), |
| 306 | None, |
| 307 | )), |
| 308 | Ok(_) => Ok(path), |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | pub fn create_yaml_file_from_secret<P>(working_root_dir: P, secret: SecretItem) -> Result<String, CommandError> |
| 313 | where |
no test coverage detected