mise 2026.9.3

Dev tools, env vars, and tasks in one CLI
use eyre::Result;

use crate::system::history::replay::{self, UndoRequest};

/// Reverse the tracked-file changes from an operation
///
/// Restores exactly the paths that operation changed from the protective
/// checkpoint it took, leaving everything else as it is now. Without a
/// reference, the newest operation not yet undone is reversed.
/// Bootstrap, captured commands, rollback, undo, and pull are supported.
/// Package installations, service state, and untracked files are not reversed.
#[derive(Debug, usage_rs::Args)]
#[usage(verbatim_doc_comment)]
pub(crate) struct DotfilesUndo {
    /// The operation's checkpoint: numeric ID, `latest`, `latest~N`, or `commit:<sha>`
    #[usage(value_name = "REF")]
    reference: Option<String>,

    /// Show the plan without changing anything
    #[usage(long, short = 'n')]
    dry_run: bool,

    /// Apply without prompting
    #[usage(long, short)]
    yes: bool,
}

impl DotfilesUndo {
    pub(crate) async fn run(self) -> Result<()> {
        replay::undo(UndoRequest {
            reference: self.reference,
            dry_run: self.dry_run,
            yes: self.yes,
        })
        .await
    }
}