Skip to main content

zoi_cli/cmd/
info.rs

1//! Command for displaying system and configuration information.
2
3use anyhow::Result;
4use colored::Colorize;
5
6use crate::{pkg, utils};
7
8/// Runs the 'info' command.
9///
10/// Displays detailed information about the system, platform,
11/// package managers, and Zoi configuration.
12///
13/// # Errors
14///
15/// Returns an error if the platform information or configuration cannot be
16/// retrieved.
17pub fn run(
18    branch: &str,
19    status: &str,
20    number: &str,
21    commit: &str
22) -> Result<()> {
23    let branch_short = if branch == "Production" {
24        "Prod."
25    } else if branch == "Development" {
26        "Dev."
27    } else if branch == "Public" {
28        "Pub."
29    } else if branch == "Special" {
30        "Spec."
31    } else {
32        branch
33    };
34
35    println!("{} System information", "::".bold().blue());
36
37    let platform = crate::pkg::utils::get_platform()?;
38    let parts: Vec<&str> = platform.split('-').collect();
39    let os = parts.first().copied().unwrap_or("unknown");
40    let arch = parts.get(1).copied().unwrap_or("unknown");
41
42    utils::print_aligned_info("OS", os);
43    utils::print_aligned_info("Architecture", arch);
44
45    if os == "linux"
46        && let Some(dist) = crate::pkg::utils::get_linux_distribution()
47    {
48        utils::print_aligned_info("Distribution", &dist);
49    }
50
51    let config = pkg::config::read_config()?;
52    let native_pm = config.native_package_manager;
53    let all_pms = config.package_managers.unwrap_or_default();
54
55    if all_pms.is_empty() {
56        utils::print_aligned_info(
57            "Package Managers",
58            "Not available (run 'zoi sync')"
59        );
60    } else {
61        let pm_list: Vec<String> = all_pms
62            .into_iter()
63            .map(|pm| {
64                if Some(pm.clone()) == native_pm {
65                    format!("{} (native)", pm.green())
66                } else {
67                    pm
68                }
69            })
70            .collect();
71        let pm_list_str = pm_list.join(", ");
72        utils::print_aligned_info("Package Managers", &pm_list_str);
73    }
74
75    let tel = if config.telemetry_enabled {
76        "Enabled".green()
77    } else {
78        "Disabled".yellow()
79    };
80    utils::print_aligned_info("Telemetry", &tel.to_string());
81
82    let key_with_colon = format!("{}:", "Version");
83    println!(
84        "{:<18}{} {} {} {}",
85        key_with_colon.cyan(),
86        branch_short,
87        status,
88        number,
89        commit.green()
90    );
91    Ok(())
92}