Skip to main content

omni_dev/cli/git/
amend.rs

1//! Amend command — applies commit message amendments from a YAML file.
2
3use anyhow::{Context, Result};
4use clap::Parser;
5
6/// Amend command options.
7#[derive(Parser)]
8pub struct AmendCommand {
9    /// YAML file containing commit amendments.
10    #[arg(value_name = "YAML_FILE")]
11    pub yaml_file: String,
12}
13
14impl AmendCommand {
15    /// Executes the amend command.
16    ///
17    /// `repo` is the repository location resolved at the CLI boundary
18    /// (`None` = current working directory).
19    pub fn execute(self, repo: Option<&std::path::Path>) -> Result<()> {
20        use crate::git::AmendmentHandler;
21
22        // Resolve the repo root once; the preflight checks and the amendment
23        // handler (including all its `git` subprocesses) anchor to it.
24        let repo_root = match repo {
25            Some(p) => p.to_path_buf(),
26            None => std::env::current_dir().context("Failed to determine current directory")?,
27        };
28
29        // Preflight checks: validate prerequisites before any processing
30        crate::utils::check_git_repository_at(&repo_root)?;
31        crate::utils::check_working_directory_clean_at(&repo_root)?;
32
33        println!("🔄 Starting commit amendment process...");
34        println!("📄 Loading amendments from: {}", self.yaml_file);
35
36        // Create amendment handler and apply amendments
37        let handler =
38            AmendmentHandler::new(&repo_root).context("Failed to initialize amendment handler")?;
39
40        handler
41            .apply_amendments(&self.yaml_file)
42            .context("Failed to apply amendments")?;
43
44        Ok(())
45    }
46}