mntn 3.2.3

A Rust-based command-line tool for dotfiles management with profiles.
Documentation
use crate::commands::core::{Command, CommandExecutor};
use crate::profiles::{ActiveProfile, ProfileConfig};
use crate::utils::display::{green, red};

mod types;
mod utils;
mod validators;

use validators::ValidationSuite;

struct ValidateTask {
    profile: ActiveProfile,
    skip_encrypted: bool,
    ask_password: bool,
}

impl ValidateTask {
    fn new(profile: ActiveProfile, skip_encrypted: bool, ask_password: bool) -> Self {
        Self {
            profile,
            skip_encrypted,
            ask_password,
        }
    }
}

impl Command for ValidateTask {
    fn name(&self) -> &str {
        "Validate"
    }

    fn execute(&mut self) -> anyhow::Result<()> {
        println!("Validating configuration...");
        println!("   Profile: {}", self.profile);
        println!("Starting validation");

        let validator =
            ValidationSuite::new(self.profile.clone(), self.skip_encrypted, self.ask_password);
        let report = validator.run_all();
        println!();
        report.print();
        println!();
        let error_count = report.error_count();
        let warning_count = report.warning_count();
        if error_count == 0 && warning_count == 0 {
            println!("{}", green("All checks passed"));
        } else {
            eprintln!(
                "{}",
                red(&format!(
                    "Validation complete: {} error(s), {} warning(s)",
                    error_count, warning_count
                ))
            );
        }
        if error_count > 0 {
            return Err(anyhow::anyhow!(
                "Validation failed: {} error(s), {} warning(s)",
                error_count,
                warning_count
            ));
        }

        Ok(())
    }
}

pub(crate) fn run(args: crate::cli::ValidateArgs) {
    if let Ok(true) = ProfileConfig::save_default_if_missing() {
        println!("Created default profile config at ~/.mntn/profiles.json");
    }

    let profile = args.resolve_profile();
    CommandExecutor::run(&mut ValidateTask::new(
        profile,
        args.skip_encrypted,
        args.ask_password,
    ));
}