winbrew_app\operations/
report.rs1use anyhow::Result;
2
3use crate::core::paths::ResolvedPaths;
4use crate::models::domains::reporting::{ReportSection, RuntimeReport};
5use crate::models::domains::shared::ConfigSection;
6
7pub fn runtime_report(
8 sections: &[ConfigSection],
9 resolved_paths: &ResolvedPaths,
10) -> Result<RuntimeReport> {
11 let core_section = section(sections, "Core")?;
12
13 let sections = vec![
14 ReportSection {
15 title: "Paths".to_string(),
16 entries: vec![
17 (
18 "Database".to_string(),
19 resolved_paths.db.to_string_lossy().to_string(),
20 ),
21 (
22 "Catalog DB".to_string(),
23 resolved_paths.catalog_db.to_string_lossy().to_string(),
24 ),
25 (
26 "Config file".to_string(),
27 resolved_paths.config.to_string_lossy().to_string(),
28 ),
29 (
30 "Log file".to_string(),
31 resolved_paths.log.to_string_lossy().to_string(),
32 ),
33 (
34 "Install root".to_string(),
35 resolved_paths.root.to_string_lossy().to_string(),
36 ),
37 (
38 "Packages dir".to_string(),
39 resolved_paths.packages.to_string_lossy().to_string(),
40 ),
41 (
42 "Cache dir".to_string(),
43 resolved_paths.cache.to_string_lossy().to_string(),
44 ),
45 ],
46 },
47 render_section(core_section),
48 ];
49
50 Ok(RuntimeReport::new(sections))
51}
52
53fn section<'a>(sections: &'a [ConfigSection], title: &str) -> Result<&'a ConfigSection> {
54 sections
55 .iter()
56 .find(|section| section.title == title)
57 .ok_or_else(|| anyhow::anyhow!("missing config section: {title}"))
58}
59
60fn render_section(section: &ConfigSection) -> ReportSection {
61 let mut entries = Vec::with_capacity(section.entries.len());
62
63 for (key, file_value) in §ion.entries {
64 entries.push((key.clone(), file_value.clone()));
65 }
66
67 ReportSection {
68 title: section.title.clone(),
69 entries,
70 }
71}