syncable_cli/handlers/
analyze.rs

1use crate::{
2    analyzer::analyze_monorepo,
3    analyzer::display::{
4        ColorScheme as DisplayColorScheme, DisplayMode, display_analysis_with_return,
5        init_color_adapter,
6    },
7    cli::{ColorScheme, DisplayFormat},
8};
9
10pub fn handle_analyze(
11    path: std::path::PathBuf,
12    json: bool,
13    detailed: bool,
14    display: Option<DisplayFormat>,
15    _only: Option<Vec<String>>,
16    color_scheme: Option<ColorScheme>,
17) -> crate::Result<String> {
18    // Initialize color adapter based on user preference
19    if let Some(scheme) = color_scheme {
20        let display_scheme = match scheme {
21            ColorScheme::Auto => {
22                // Let the color adapter auto-detect
23                DisplayColorScheme::Dark // This will be overridden by auto-detection in ColorAdapter::new()
24            }
25            ColorScheme::Dark => DisplayColorScheme::Dark,
26            ColorScheme::Light => DisplayColorScheme::Light,
27        };
28
29        // Only initialize if not auto - auto-detection happens by default
30        if !matches!(scheme, ColorScheme::Auto) {
31            init_color_adapter(display_scheme);
32        }
33    }
34
35    println!("🔍 Analyzing project: {}", path.display());
36
37    let monorepo_analysis = analyze_monorepo(&path)?;
38
39    let output = if json {
40        display_analysis_with_return(&monorepo_analysis, DisplayMode::Json)
41    } else {
42        // Determine display mode
43        let mode = if detailed {
44            // Legacy flag for backward compatibility
45            DisplayMode::Detailed
46        } else {
47            match display {
48                Some(DisplayFormat::Matrix) | None => DisplayMode::Matrix,
49                Some(DisplayFormat::Detailed) => DisplayMode::Detailed,
50                Some(DisplayFormat::Summary) => DisplayMode::Summary,
51            }
52        };
53
54        display_analysis_with_return(&monorepo_analysis, mode)
55    };
56
57    Ok(output)
58}