MCPcopy Create free account
hub / github.com/Qovery/engine / indent_file

Function indent_file

lib-engine/src/fs.rs:282–310  ·  view source on GitHub ↗
(path: String)

Source from the content-addressed store, hash-verified

280}
281
282pub 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
312pub fn create_yaml_file_from_secret<P>(working_root_dir: P, secret: SecretItem) -> Result<String, CommandError>
313where

Callers 1

prepare_chart_backupFunction · 0.85

Calls 2

writeMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected