anesis 0.12.4

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.is_dir() {
      eprintln!(
        "Warning: skipping '{}': deleting directories is not supported",
        path.display()
      );
      continue;
    }
    if !path.exists() {
      eprintln!(
        "Warning: delete target '{}' does not exist; skipping",
        path.display()
      );
      continue;
    }
    let original = std::fs::read(&path)?;
    rollbacks.push(Rollback::RestoreFile {
      path: path.clone(),
      original,
    });
    std::fs::remove_file(&path)?;
  }

  Ok(rollbacks)
}