winbrew_cli\commands/
info.rs

1//! Info command wrapper for runtime configuration reporting.
2//!
3//! The wrapper formats the collected runtime settings and prints the report
4//! sections in the order returned by the app layer.
5
6use anyhow::Result;
7use std::io::Write;
8
9use crate::{
10    CommandContext,
11    app::{AppContext, info},
12};
13use winbrew_app::models::domains::reporting::{InfoReport, ReportSection, RuntimeReport};
14use winbrew_ui::Ui;
15
16pub fn run(ctx: &CommandContext) -> Result<()> {
17    let mut ui = ctx.ui();
18    run_with_ui(&mut ui, ctx.app())
19}
20
21fn run_with_ui<W: Write>(ui: &mut Ui<W>, app: &AppContext) -> Result<()> {
22    let report = info::collect(&app.sections, &app.paths)?;
23    render_info_report(ui, &report);
24
25    Ok(())
26}
27
28fn render_info_report<W: Write>(ui: &mut Ui<W>, report: &InfoReport) {
29    ui.write_line(format!("WinBrew Package Manager v{}", report.version));
30    ui.write_line("Copyright (c) 2026 The WinBrew Contributors.");
31    ui.write_line("Licensed under either of MIT or Apache 2.0 at your option.");
32    ui.write_line("");
33
34    for (key, value) in &report.system {
35        ui.write_line(format!("{key}: {value}"));
36    }
37
38    ui.write_line("");
39    ui.write_line("WinBrew Paths");
40    ui.display_key_values(&runtime_section(&report.runtime, "Paths").entries);
41    ui.write_line("");
42
43    ui.write_line("WinBrew Settings");
44    ui.display_key_values(&runtime_section(&report.runtime, "Core").entries);
45}
46
47fn runtime_section<'a>(report: &'a RuntimeReport, title: &str) -> &'a ReportSection {
48    report
49        .sections
50        .iter()
51        .find(|section| section.title == title)
52        .expect("runtime report should contain the expected section")
53}
54
55#[cfg(test)]
56mod tests {
57    use super::run_with_ui;
58    use crate::app::AppContext;
59    use crate::commands::test_support::{buffer_text, buffered_ui};
60    use crate::database::Config;
61    use tempfile::tempdir;
62    use winbrew_ui::UiSettings;
63
64    #[test]
65    fn run_with_ui_renders_runtime_information() {
66        let temp_dir = tempdir().expect("temp dir");
67        let config = Config::load_at(temp_dir.path()).expect("config should load");
68        let app = AppContext::from_config(&config).expect("app context should build");
69        let (mut ui, out, err) = buffered_ui(UiSettings::default());
70
71        run_with_ui(&mut ui, &app).expect("info should succeed");
72
73        let out = buffer_text(&out);
74        let err = buffer_text(&err);
75
76        assert!(out.contains("WinBrew Package Manager v"));
77        assert!(out.contains("Copyright (c) 2026 The WinBrew Contributors."));
78        assert!(out.contains("Licensed under either of MIT or Apache 2.0 at your option."));
79        assert!(out.contains("Windows:"));
80        assert!(out.contains("System Architecture:"));
81        assert!(out.contains("WinBrew Paths"));
82        assert!(out.contains("WinBrew Settings"));
83        assert!(out.contains("Key"));
84        assert!(out.contains("Value"));
85        assert!(err.is_empty());
86    }
87}