nedots 0.1.2

A tool to manage configuration files/(ne)dots.
#[derive(Debug, clap::Args)]
/// Clean up `dots` & `backups`. Example: `nedots clean -db` to clean both.
pub(crate) struct CleanCmd {
    #[arg(short, long)]
    /// Clean up `dots`.
    dots: bool,

    #[arg(short, long)]
    /// Clean up `backups`.
    backups: bool,
}

impl super::Command for CleanCmd {
    fn run(
        &self,
        _: &super::nedots::RootCmd,
        config: &crate::config::Config,
    ) -> Result<(), super::CommandError> {
        if self.dots {
            if dialoguer::Confirm::new()
                .with_prompt("Cleaning dots. Continue?")
                .interact()?
            {
                let dir = &config.dots_dir;
                trash::delete(dir)?;
                std::fs::create_dir_all(dir)?;
            }
        }

        if self.backups {
            if dialoguer::Confirm::new()
                .with_prompt("Cleaning backups. Continue?")
                .interact()?
            {
                let dir = &config.root.join("backups");
                trash::delete(dir)?;
                std::fs::create_dir_all(dir)?;
            }
        }

        Ok(())
    }
}