lux_cli/debug/
toolchains.rs1use crate::args::OutputFormat;
2use clap::Args;
3use lux_lib::toolchains::{Tool, ToolchainReport};
4use miette::{IntoDiagnostic, Result};
5
6#[derive(Args)]
7pub struct Toolchains {
8 #[arg(long, default_value = "text", value_enum, ignore_case = true)]
10 output_format: OutputFormat,
11}
12
13impl Toolchains {
14 pub fn output_format(&self) -> OutputFormat {
15 self.output_format.clone()
16 }
17}
18
19pub fn check_toolchains(args: Toolchains) -> Result<()> {
20 let report = ToolchainReport::generate();
21
22 match args.output_format() {
23 OutputFormat::Text => print_human_readable(&report),
24 OutputFormat::Json => print_json(&report)?,
25 }
26
27 Ok(())
28}
29
30fn print_human_readable(report: &ToolchainReport) {
31 println!("Toolchains Report");
32 println!("=======================\n");
33
34 print_toolchains(report.c_compiler());
35 print_toolchains(report.make());
36 print_toolchains(report.cmake());
37 print_toolchains(report.cargo());
38 print_toolchains(report.pkg_config());
39
40 println!("\nSummary:");
41 let total = 5;
42
43 let found = [
44 report.c_compiler(),
45 report.make(),
46 report.cmake(),
47 report.cargo(),
48 report.pkg_config(),
49 ]
50 .iter()
51 .filter(|d| d.is_found())
52 .count();
53
54 println!(" Found: {}/{}", found, total);
55 println!(" Missing: {}/{}", total - found, total);
56}
57
58fn print_toolchains(dep: &Tool) {
59 match dep.info() {
60 Some(info) => {
61 print!("✓ {}: Found ({})", dep.name(), info.path().display());
62 if let Some(version) = info.version() {
63 print!(" - {}", version);
64 }
65 println!();
66 }
67 None => println!("✗ {}: Not found", dep.name()),
68 }
69}
70
71fn print_json(report: &ToolchainReport) -> Result<()> {
72 let json = serde_json::to_string_pretty(report).into_diagnostic()?;
73 println!("{}", json);
74 Ok(())
75}