zoi/cmd/
check.rs

1use crate::utils;
2use anyhow::{Result, anyhow};
3use colored::*;
4use std::io::{Write, stdout};
5
6pub fn run() -> Result<()> {
7    println!("{}", "--- Checking for Essential Tools ---".yellow().bold());
8
9    let essential_tools = ["git"];
10    let mut all_essential_found = true;
11
12    for tool in essential_tools {
13        print!("Checking for {}... ", tool.cyan());
14        let _ = stdout().flush();
15
16        if utils::command_exists(tool) {
17            println!("{}", "OK".green());
18        } else {
19            println!("{}", "MISSING".red());
20            all_essential_found = false;
21        }
22    }
23
24    if !all_essential_found {
25        return Err(anyhow!(
26            "One or more essential tools are missing. Please install them."
27        ));
28    }
29
30    println!(
31        "
32{}",
33        "--- Checking for Recommended Tools ---".yellow().bold()
34    );
35    let recommended_tools = ["less", "gpg"];
36    for tool in recommended_tools {
37        print!("Checking for {}... ", tool.cyan());
38        let _ = stdout().flush();
39
40        if utils::command_exists(tool) {
41            println!("{}", "OK".green());
42        } else {
43            println!("{}", "Not Found".yellow());
44        }
45    }
46
47    println!();
48
49    println!("{}", "All essential tools are installed.".green());
50    Ok(())
51}