syncable_cli/analyzer/tool_management/installers/
java.rs1use crate::analyzer::tool_management::ToolDetector;
2use crate::error::Result;
3use super::common::InstallationUtils;
4use std::collections::HashMap;
5use log::{info, warn};
6
7pub fn install_grype(
9 tool_detector: &mut ToolDetector,
10 installed_tools: &mut HashMap<String, bool>,
11) -> Result<()> {
12 if tool_detector.detect_tool("grype").available {
13 return Ok(());
14 }
15
16 info!("🔧 Installing grype for vulnerability scanning...");
17
18 let os = std::env::consts::OS;
20
21 match os {
22 "macos" => {
23 if InstallationUtils::is_command_available("brew") {
24 let success = InstallationUtils::execute_command("brew", &["install", "grype"])?;
25 if success {
26 info!("✅ grype installed successfully via Homebrew");
27 installed_tools.insert("grype".to_string(), true);
28 tool_detector.clear_cache();
29 return Ok(());
30 }
31 }
32 }
33 "linux" => {
34 if InstallationUtils::is_command_available("snap") {
36 let success = InstallationUtils::execute_command("snap", &["install", "grype"])?;
37 if success {
38 info!("✅ grype installed successfully via snap");
39 installed_tools.insert("grype".to_string(), true);
40 tool_detector.clear_cache();
41 return Ok(());
42 }
43 }
44 }
45 _ => {}
46 }
47
48 warn!("❌ Automatic installation failed. Please install manually:");
49 if cfg!(windows) {
50 warn!(" • Download from: https://github.com/anchore/grype/releases");
51 warn!(" • Or use: scoop install grype (if you have Scoop)");
52 } else {
53 warn!(" • macOS: brew install grype");
54 warn!(" • Linux: snap install grype");
55 warn!(" • Download: https://github.com/anchore/grype/releases");
56 }
57
58 Ok(())
59}