anesis 0.9.1

CLI for scaffolding projects from remote templates and extending them with project addons
Documentation
use std::path::Path;

use anyhow::Result;

use crate::addons::manifest::DeleteStep;

use super::{Rollback, resolve_target};

pub fn execute_delete(step: &DeleteStep, project_root: &Path) -> Result<Vec<Rollback>> {
  let paths = resolve_target(&step.target, project_root)?;
  let mut rollbacks = Vec::new();

  for path in paths {
    if path.exists() {
      let original = std::fs::read(&path)?;
      rollbacks.push(Rollback::RestoreFile {
        path: path.clone(),
        original,
      });
      std::fs::remove_file(&path)?;
    }
  }

  Ok(rollbacks)
}