cargo-mate 1.8.0

Rust development companion that enhances cargo with intelligent workflows, state management, performance optimization, and comprehensive project monitoring.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
use super::{Tool, Result, ToolError, common_options, parse_output_format, OutputFormat};
use clap::{Arg, ArgMatches, Command};
use colored::*;
use std::path::Path;
use std::fs;
use std::env;
use std::process::Command as ProcessCommand;
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
pub struct EnvCheckTool;
#[derive(Debug, Clone, Serialize, Deserialize)]
struct EnvironmentReport {
    overall_status: String,
    checks_passed: usize,
    checks_failed: usize,
    checks_warning: usize,
    rust_toolchain: RustToolchainInfo,
    system_info: SystemInfo,
    dependencies: DependencyStatus,
    configuration: ConfigStatus,
    recommendations: Vec<String>,
    issues: Vec<EnvironmentIssue>,
    timestamp: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct RustToolchainInfo {
    version: String,
    channel: String,
    target: String,
    components: Vec<String>,
    is_compatible: bool,
    issues: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct SystemInfo {
    os: String,
    arch: String,
    memory_gb: u64,
    available_disk_gb: u64,
    cpu_cores: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct DependencyStatus {
    required_tools: HashMap<String, ToolStatus>,
    optional_tools: HashMap<String, ToolStatus>,
    rust_components: HashMap<String, ComponentStatus>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct ConfigStatus {
    cargo_config_exists: bool,
    rustfmt_config_exists: bool,
    clippy_config_exists: bool,
    environment_variables: HashMap<String, EnvVarStatus>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct ToolStatus {
    installed: bool,
    version: Option<String>,
    required_version: Option<String>,
    status: String,
    path: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct ComponentStatus {
    installed: bool,
    status: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct EnvVarStatus {
    set: bool,
    value: Option<String>,
    required: bool,
    masked: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
struct EnvironmentIssue {
    severity: String,
    category: String,
    message: String,
    solution: String,
    command: Option<String>,
}
impl EnvCheckTool {
    pub fn new() -> Self {
        Self
    }
    fn check_rust_toolchain(&self) -> Result<RustToolchainInfo> {
        let mut issues = Vec::new();
        let version_output = ProcessCommand::new("rustc")
            .arg("--version")
            .output()
            .map_err(|_| ToolError::ExecutionFailed("rustc not found".to_string()))?;
        let version_str = String::from_utf8_lossy(&version_output.stdout);
        let version = version_str
            .split_whitespace()
            .nth(1)
            .unwrap_or("unknown")
            .to_string();
        let is_compatible = self.is_rust_version_compatible(&version);
        if !is_compatible {
            issues.push(format!("Rust version {} may be outdated", version));
        }
        let channel = if version.contains("nightly") {
            "nightly".to_string()
        } else if version.contains("beta") {
            "beta".to_string()
        } else {
            "stable".to_string()
        };
        let target_output = ProcessCommand::new("rustc")
            .args(&["--print", "target-list"])
            .output()
            .ok();
        let target = target_output
            .and_then(|output| {
                String::from_utf8_lossy(&output.stdout)
                    .lines()
                    .next()
                    .map(|s| s.to_string())
            })
            .unwrap_or_else(|| "unknown".to_string());
        let components = self.check_rust_components()?;
        Ok(RustToolchainInfo {
            version,
            channel,
            target,
            components,
            is_compatible,
            issues,
        })
    }
    fn is_rust_version_compatible(&self, version: &str) -> bool {
        if let Some(version_part) = version.split('+').next() {
            let parts: Vec<&str> = version_part.split('.').collect();
            if parts.len() >= 2 {
                if let (Ok(major), Ok(minor)) = (
                    parts[0].parse::<u32>(),
                    parts[1].parse::<u32>(),
                ) {
                    return major > 1 || (major == 1 && minor >= 70);
                }
            }
        }
        false
    }
    fn check_rust_components(&self) -> Result<Vec<String>> {
        let output = ProcessCommand::new("rustup")
            .args(&["component", "list", "--installed"])
            .output()
            .map_err(|_| ToolError::ExecutionFailed("rustup not found".to_string()))?;
        let components = String::from_utf8_lossy(&output.stdout)
            .lines()
            .map(|line| line.trim().to_string())
            .filter(|line| !line.is_empty())
            .collect();
        Ok(components)
    }
    fn check_system_info(&self) -> Result<SystemInfo> {
        let os = env::consts::OS.to_string();
        let arch = env::consts::ARCH.to_string();
        let memory_gb = self.get_memory_info();
        let available_disk_gb = self.get_disk_info();
        let cpu_cores = self.get_cpu_cores_fallback();
        Ok(SystemInfo {
            os,
            arch,
            memory_gb,
            available_disk_gb,
            cpu_cores,
        })
    }
    fn get_memory_info(&self) -> u64 {
        if cfg!(target_os = "linux") {
            if let Ok(contents) = fs::read_to_string("/proc/meminfo") {
                for line in contents.lines() {
                    if line.starts_with("MemTotal:") {
                        if let Some(kb_str) = line.split_whitespace().nth(1) {
                            if let Ok(kb) = kb_str.parse::<u64>() {
                                return kb / 1024 / 1024;
                            }
                        }
                    }
                }
            }
        }
        0
    }
    fn get_disk_info(&self) -> u64 {
        if let Ok(stat) = fs::metadata(".") { 100 } else { 0 }
    }
    fn get_cpu_cores_fallback(&self) -> usize {
        if cfg!(target_os = "linux") {
            if let Ok(contents) = fs::read_to_string("/proc/cpuinfo") {
                let processor_count = contents
                    .lines()
                    .filter(|line| line.starts_with("processor"))
                    .count();
                if processor_count > 0 {
                    return processor_count;
                }
            }
        } else if cfg!(target_os = "macos") {
            if let Ok(output) = ProcessCommand::new("sysctl")
                .args(&["-n", "hw.ncpu"])
                .output()
            {
                if let Ok(core_str) = String::from_utf8(output.stdout) {
                    if let Ok(cores) = core_str.trim().parse::<usize>() {
                        return cores;
                    }
                }
            }
        }
        4
    }
    fn check_dependencies(&self) -> Result<DependencyStatus> {
        let mut required_tools = HashMap::new();
        let mut optional_tools = HashMap::new();
        let mut rust_components = HashMap::new();
        let required = vec!["cargo", "rustc", "rustup", "git"];
        for tool in required {
            required_tools.insert(tool.to_string(), self.check_tool(tool)?);
        }
        let optional = vec!["docker", "node", "npm", "yarn", "python", "python3"];
        for tool in optional {
            optional_tools.insert(tool.to_string(), self.check_tool(tool)?);
        }
        let components = vec!["rustfmt", "clippy", "rust-docs", "rust-analyzer"];
        for component in components {
            rust_components
                .insert(component.to_string(), self.check_rust_component(component)?);
        }
        Ok(DependencyStatus {
            required_tools,
            optional_tools,
            rust_components,
        })
    }
    fn check_tool(&self, tool: &str) -> Result<ToolStatus> {
        let output = ProcessCommand::new(tool).arg("--version").output();
        match output {
            Ok(result) => {
                if result.status.success() {
                    let version = String::from_utf8_lossy(&result.stdout)
                        .lines()
                        .next()
                        .unwrap_or("unknown")
                        .to_string();
                    let path_output = ProcessCommand::new("which")
                        .arg(tool)
                        .output()
                        .ok();
                    let path = path_output
                        .and_then(|p| {
                            if p.status.success() {
                                String::from_utf8_lossy(&p.stdout).trim().to_string().into()
                            } else {
                                None
                            }
                        });
                    Ok(ToolStatus {
                        installed: true,
                        version: Some(version),
                        required_version: None,
                        status: "ok".to_string(),
                        path,
                    })
                } else {
                    Ok(ToolStatus {
                        installed: false,
                        version: None,
                        required_version: None,
                        status: "not_found".to_string(),
                        path: None,
                    })
                }
            }
            Err(_) => {
                Ok(ToolStatus {
                    installed: false,
                    version: None,
                    required_version: None,
                    status: "not_found".to_string(),
                    path: None,
                })
            }
        }
    }
    fn check_rust_component(&self, component: &str) -> Result<ComponentStatus> {
        let output = ProcessCommand::new("rustup")
            .args(&["component", "list", "--installed"])
            .output()
            .map_err(|_| ToolError::ExecutionFailed("rustup not found".to_string()))?;
        let installed_components = String::from_utf8_lossy(&output.stdout);
        let installed = installed_components.contains(component);
        Ok(ComponentStatus {
            installed,
            status: if installed { "ok".to_string() } else { "missing".to_string() },
        })
    }
    fn check_configuration(&self) -> Result<ConfigStatus> {
        let cargo_config_exists = Path::new("Cargo.toml").exists();
        let rustfmt_config_exists = Path::new(".rustfmt.toml").exists()
            || Path::new("rustfmt.toml").exists();
        let clippy_config_exists = Path::new(".clippy.toml").exists()
            || Path::new("clippy.toml").exists();
        let env_vars = vec!["RUST_BACKTRACE", "CARGO_HOME", "RUSTUP_HOME", "PATH"];
        let mut environment_variables = HashMap::new();
        for var in env_vars {
            let value = env::var(var).ok();
            let set = value.is_some();
            let required = matches!(var, "PATH");
            let masked = matches!(var, "RUST_BACKTRACE" | "CARGO_HOME" | "RUSTUP_HOME");
            environment_variables
                .insert(
                    var.to_string(),
                    EnvVarStatus {
                        set,
                        value: if masked {
                            Some("***masked***".to_string())
                        } else {
                            value
                        },
                        required,
                        masked,
                    },
                );
        }
        Ok(ConfigStatus {
            cargo_config_exists,
            rustfmt_config_exists,
            clippy_config_exists,
            environment_variables,
        })
    }
    fn analyze_issues(&self, report: &EnvironmentReport) -> Vec<EnvironmentIssue> {
        let mut issues = Vec::new();
        if !report.rust_toolchain.is_compatible {
            issues
                .push(EnvironmentIssue {
                    severity: "warning".to_string(),
                    category: "rust_toolchain".to_string(),
                    message: format!(
                        "Rust version {} may be outdated", report.rust_toolchain.version
                    ),
                    solution: "Update Rust to version 1.70.0 or later".to_string(),
                    command: Some("rustup update stable".to_string()),
                });
        }
        for (tool, status) in &report.dependencies.required_tools {
            if !status.installed {
                issues
                    .push(EnvironmentIssue {
                        severity: "error".to_string(),
                        category: "dependencies".to_string(),
                        message: format!("Required tool '{}' is not installed", tool),
                        solution: format!(
                            "Install {} using your system package manager", tool
                        ),
                        command: None,
                    });
            }
        }
        for (component, status) in &report.dependencies.rust_components {
            if !status.installed {
                issues
                    .push(EnvironmentIssue {
                        severity: "warning".to_string(),
                        category: "rust_components".to_string(),
                        message: format!(
                            "Rust component '{}' is not installed", component
                        ),
                        solution: format!(
                            "Install with: rustup component add {}", component
                        ),
                        command: Some(format!("rustup component add {}", component)),
                    });
            }
        }
        if report.system_info.memory_gb < 4 {
            issues
                .push(EnvironmentIssue {
                    severity: "warning".to_string(),
                    category: "system".to_string(),
                    message: format!(
                        "Low memory: {}GB available", report.system_info.memory_gb
                    ),
                    solution: "Consider upgrading to at least 8GB RAM for better Rust compilation performance"
                        .to_string(),
                    command: None,
                });
        }
        issues
    }
    fn generate_recommendations(&self, report: &EnvironmentReport) -> Vec<String> {
        let mut recommendations = Vec::new();
        recommendations
            .push("đŸŽ¯ Keep Rust updated to the latest stable version".to_string());
        recommendations
            .push(
                "📚 Install rustfmt and clippy for code formatting and linting"
                    .to_string(),
            );
        recommendations
            .push(
                "🔧 Set RUST_BACKTRACE=1 for better error messages during development"
                    .to_string(),
            );
        if !report
            .dependencies
            .optional_tools
            .get("docker")
            .map_or(false, |t| t.installed)
        {
            recommendations
                .push(
                    "đŸŗ Consider installing Docker for integration testing".to_string(),
                );
        }
        if !report.configuration.rustfmt_config_exists {
            recommendations
                .push(
                    "📝 Create .rustfmt.toml for consistent code formatting"
                        .to_string(),
                );
        }
        if !report.configuration.clippy_config_exists {
            recommendations
                .push("🔍 Create .clippy.toml to configure linting rules".to_string());
        }
        recommendations
    }
    fn determine_overall_status(&self, report: &EnvironmentReport) -> String {
        let critical_issues = report
            .issues
            .iter()
            .filter(|i| i.severity == "error")
            .count();
        let warning_issues = report
            .issues
            .iter()
            .filter(|i| i.severity == "warning")
            .count();
        if critical_issues > 0 {
            "❌ Issues Found".to_string()
        } else if warning_issues > 0 {
            "âš ī¸  Needs Attention".to_string()
        } else {
            "✅ All Good".to_string()
        }
    }
}
impl Tool for EnvCheckTool {
    fn name(&self) -> &'static str {
        "env-check"
    }
    fn description(&self) -> &'static str {
        "Validate development environment and provide setup recommendations"
    }
    fn command(&self) -> Command {
        Command::new(self.name())
            .about(self.description())
            .long_about(
                "Comprehensive development environment validation for Rust projects. Checks Rust toolchain, system resources, required tools, and provides actionable recommendations for optimizing your development setup.",
            )
            .args(
                &[
                    Arg::new("detailed")
                        .long("detailed")
                        .short('d')
                        .help("Show detailed system information")
                        .action(clap::ArgAction::SetTrue),
                    Arg::new("fix")
                        .long("fix")
                        .help("Attempt to automatically fix issues")
                        .action(clap::ArgAction::SetTrue),
                    Arg::new("export")
                        .long("export")
                        .help("Export environment report to file")
                        .value_name("FILE"),
                    Arg::new("check-only")
                        .long("check-only")
                        .help("Only run checks, don't provide recommendations")
                        .action(clap::ArgAction::SetTrue),
                ],
            )
            .args(&common_options())
    }
    fn execute(&self, matches: &ArgMatches) -> Result<()> {
        let detailed = matches.get_flag("detailed");
        let fix = matches.get_flag("fix");
        let export_file = matches.get_one::<String>("export");
        let check_only = matches.get_flag("check-only");
        let dry_run = matches.get_flag("dry-run");
        let verbose = matches.get_flag("verbose");
        let output_format = parse_output_format(matches);
        println!(
            "🔍 {} - {}", "CargoMate EnvCheck".bold().blue(), self.description().cyan()
        );
        if verbose {
            println!("   📊 Analyzing development environment...");
        }
        let rust_toolchain = self.check_rust_toolchain()?;
        let system_info = self.check_system_info()?;
        let dependencies = self.check_dependencies()?;
        let configuration = self.check_configuration()?;
        let mut report = EnvironmentReport {
            overall_status: String::new(),
            checks_passed: 0,
            checks_failed: 0,
            checks_warning: 0,
            rust_toolchain,
            system_info,
            dependencies,
            configuration,
            recommendations: Vec::new(),
            issues: Vec::new(),
            timestamp: chrono::Utc::now().to_rfc3339(),
        };
        report.issues = self.analyze_issues(&report);
        report.recommendations = if check_only {
            Vec::new()
        } else {
            self.generate_recommendations(&report)
        };
        report.checks_passed = report
            .dependencies
            .required_tools
            .values()
            .filter(|t| t.installed)
            .count()
            + report.dependencies.optional_tools.values().filter(|t| t.installed).count()
            + report
                .dependencies
                .rust_components
                .values()
                .filter(|c| c.installed)
                .count();
        report.checks_failed = report
            .issues
            .iter()
            .filter(|i| i.severity == "error")
            .count();
        report.checks_warning = report
            .issues
            .iter()
            .filter(|i| i.severity == "warning")
            .count();
        report.overall_status = self.determine_overall_status(&report);
        if fix && !dry_run {
            self.apply_fixes(&report.issues)?;
        }
        if let Some(file_path) = export_file {
            if !dry_run {
                let json_report = serde_json::to_string_pretty(&report)?;
                fs::write(file_path, json_report)?;
                println!("  💾 Report exported to: {}", file_path.cyan());
            }
        }
        match output_format {
            OutputFormat::Human => {
                self.display_human_report(&report, detailed, check_only);
            }
            OutputFormat::Json => {
                let json_report = serde_json::to_string_pretty(&report)?;
                println!("{}", json_report);
            }
            OutputFormat::Table => {
                self.display_table_report(&report);
            }
        }
        if report.checks_failed > 0 {
            println!(
                "\n❌ Environment check failed - {} critical issues found", report
                .checks_failed
            );
            std::process::exit(1);
        } else if report.checks_warning > 0 {
            println!(
                "\nâš ī¸  Environment check completed with {} warnings", report
                .checks_warning
            );
        } else {
            println!("\n✅ Environment check passed - all systems go!");
        }
        Ok(())
    }
}
impl EnvCheckTool {
    fn display_human_report(
        &self,
        report: &EnvironmentReport,
        detailed: bool,
        check_only: bool,
    ) {
        println!("\n📊 {}", "Environment Report".bold().underline());
        println!("Status: {}", report.overall_status);
        println!("Timestamp: {}", report.timestamp);
        println!(
            "Checks: ✅ {} passed, ❌ {} failed, âš ī¸  {} warnings", report
            .checks_passed, report.checks_failed, report.checks_warning
        );
        println!("\nđŸĻ€ {}", "Rust Toolchain".bold());
        println!("   Version: {}", report.rust_toolchain.version);
        println!("   Channel: {}", report.rust_toolchain.channel);
        println!("   Target: {}", report.rust_toolchain.target);
        println!(
            "   Compatible: {}", if report.rust_toolchain.is_compatible { "✅ Yes" }
            else { "❌ No" }
        );
        if detailed {
            println!("   Components: {}", report.rust_toolchain.components.join(", "));
        }
        if !report.rust_toolchain.issues.is_empty() {
            for issue in &report.rust_toolchain.issues {
                println!("   âš ī¸  {}", issue.yellow());
            }
        }
        if detailed {
            println!("\nđŸ’ģ {}", "System Information".bold());
            println!("   OS: {} {}", report.system_info.os, report.system_info.arch);
            println!("   Memory: {} GB", report.system_info.memory_gb);
            println!(
                "   Disk Space: {} GB available", report.system_info.available_disk_gb
            );
            println!("   CPU Cores: {}", report.system_info.cpu_cores);
        }
        println!("\nđŸ“Ļ {}", "Dependencies".bold());
        println!("   {}", "Required Tools:".underline());
        for (tool, status) in &report.dependencies.required_tools {
            let status_icon = if status.installed { "✅" } else { "❌" };
            let version = status
                .version
                .as_ref()
                .map(|v| format!(" ({})", v))
                .unwrap_or_default();
            println!("     {} {} {}", status_icon, tool, version);
        }
        if detailed {
            println!("   {}", "Optional Tools:".underline());
            for (tool, status) in &report.dependencies.optional_tools {
                let status_icon = if status.installed { "✅" } else { "âšĒ" };
                let version = status
                    .version
                    .as_ref()
                    .map(|v| format!(" ({})", v))
                    .unwrap_or_default();
                println!("     {} {} {}", status_icon, tool, version);
            }
            println!("   {}", "Rust Components:".underline());
            for (component, status) in &report.dependencies.rust_components {
                let status_icon = if status.installed { "✅" } else { "❌" };
                println!("     {} {}", status_icon, component);
            }
        }
        println!("\nâš™ī¸  {}", "Configuration".bold());
        println!(
            "   Cargo.toml: {}", if report.configuration.cargo_config_exists {
            "✅ Found" } else { "❌ Missing" }
        );
        println!(
            "   Rustfmt config: {}", if report.configuration.rustfmt_config_exists {
            "✅ Found" } else { "❌ Missing" }
        );
        println!(
            "   Clippy config: {}", if report.configuration.clippy_config_exists {
            "✅ Found" } else { "❌ Missing" }
        );
        if detailed {
            println!("   {}", "Environment Variables:".underline());
            for (var, status) in &report.configuration.environment_variables {
                let status_icon = if status.set { "✅" } else { "❌" };
                let default_value = "not set".to_string();
                let value = status.value.as_ref().unwrap_or(&default_value);
                let required = if status.required { " (required)" } else { "" };
                println!("     {} {} = {}{}", status_icon, var, value, required);
            }
        }
        if !report.issues.is_empty() {
            println!("\n🚨 {}", "Issues Found".bold());
            for issue in &report.issues {
                let severity_icon = match issue.severity.as_str() {
                    "error" => "❌",
                    "warning" => "âš ī¸ ",
                    _ => "â„šī¸ ",
                };
                println!("   {} {}", severity_icon, issue.message);
                println!("      💡 Solution: {}", issue.solution);
                if let Some(cmd) = &issue.command {
                    println!("      đŸ› ī¸  Command: {}", cmd.cyan());
                }
                println!();
            }
        }
        if !check_only && !report.recommendations.is_empty() {
            println!("\n💡 {}", "Recommendations".bold());
            for recommendation in &report.recommendations {
                println!("   â€ĸ {}", recommendation);
            }
        }
    }
    fn display_table_report(&self, report: &EnvironmentReport) {
        println!(
            "{:<25} {:<12} {:<12} {:<12}", "Category", "Status", "Passed", "Issues"
        );
        println!("{}", "─".repeat(70));
        let rust_status = if report.rust_toolchain.is_compatible {
            "✅ OK"
        } else {
            "âš ī¸  WARN"
        };
        println!(
            "{:<25} {:<12} {:<12} {:<12}", "Rust Toolchain", rust_status, "1/1", "0"
        );
        let deps_passed = report
            .dependencies
            .required_tools
            .values()
            .filter(|t| t.installed)
            .count();
        let deps_total = report.dependencies.required_tools.len();
        let deps_status = if deps_passed == deps_total { "✅ OK" } else { "❌ FAIL" };
        println!(
            "{:<25} {:<12} {:<12} {:<12}", "Required Tools", deps_status,
            format!("{}/{}", deps_passed, deps_total), "0"
        );
        let comp_passed = report
            .dependencies
            .rust_components
            .values()
            .filter(|c| c.installed)
            .count();
        let comp_total = report.dependencies.rust_components.len();
        let comp_status = if comp_passed == comp_total {
            "✅ OK"
        } else {
            "âš ī¸  WARN"
        };
        println!(
            "{:<25} {:<12} {:<12} {:<12}", "Rust Components", comp_status,
            format!("{}/{}", comp_passed, comp_total), "0"
        );
    }
    fn apply_fixes(&self, issues: &[EnvironmentIssue]) -> Result<()> {
        println!("\n🔧 {}", "Applying Automatic Fixes".bold());
        for issue in issues {
            if let Some(command) = &issue.command {
                println!("   đŸ› ī¸  Running: {}", command.cyan());
                let output = ProcessCommand::new("sh").arg("-c").arg(command).output();
                match output {
                    Ok(result) => {
                        if result.status.success() {
                            println!("      ✅ Success");
                        } else {
                            println!(
                                "      ❌ Failed: {}", String::from_utf8_lossy(& result
                                .stderr)
                            );
                        }
                    }
                    Err(e) => {
                        println!("      ❌ Error: {}", e);
                    }
                }
            }
        }
        Ok(())
    }
}
impl Default for EnvCheckTool {
    fn default() -> Self {
        Self::new()
    }
}