oxide_cli/addons/steps/
move_step.rs1use std::path::Path;
2
3use anyhow::{anyhow, Result};
4
5use crate::addons::manifest::MoveStep;
6
7use super::Rollback;
8
9pub fn execute_move(
10 step: &MoveStep,
11 project_root: &Path,
12 ctx: &tera::Context,
13) -> Result<Vec<Rollback>> {
14 let rendered_from = super::render_string(&step.from, ctx)?;
15 let rendered_to = super::render_string(&step.to, ctx)?;
16 let from = super::safe_join(project_root, &rendered_from, "move source")?;
17 let to = super::safe_join(project_root, &rendered_to, "move destination")?;
18
19 if !from.exists() {
20 return Err(anyhow!("{} does not exist", from.display()));
21 }
22 if to.exists() {
23 return Err(anyhow!("{} already exists", to.display()));
24 }
25
26 if let Some(parent) = to.parent() {
27 std::fs::create_dir_all(parent)?;
28 }
29 std::fs::rename(&from, &to)?;
30
31 Ok(vec![Rollback::RenameFile { from: to, to: from }])
32}
33