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,
ctx: &tera::Context,
) -> Result<Vec<Rollback>> {
let paths = resolve_target(&step.target, project_root, ctx)?;
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)
}