1use crate::models::Feature;
2use colored::*;
3
4pub fn print_features(features: &[Feature], indent: usize, show_description: bool) {
5 let prefix = " ".repeat(indent);
6
7 for feature in features {
8 let is_deprecated = feature
9 .meta
10 .get("deprecated")
11 .and_then(|v| v.as_bool())
12 .unwrap_or(false);
13
14 let feature_name = if is_deprecated {
15 feature.name.truecolor(255, 165, 0).bold()
16 } else {
17 feature.name.bold()
18 };
19
20 println!(
21 "{}{} {} -> {}",
22 prefix,
23 feature_name,
24 format!("[{}]", feature.owner).blue(),
25 feature.path.dimmed()
26 );
27
28 if let Some(stats) = &feature.stats
30 && let Some(coverage) = &stats.coverage
31 {
32 let coverage_color = if coverage.line_coverage_percent >= 80.0 {
33 "green"
34 } else if coverage.line_coverage_percent >= 60.0 {
35 "yellow"
36 } else {
37 "red"
38 };
39
40 let coverage_str = format!(
41 " {}Coverage: {:.1}% lines ({}/{})",
42 prefix,
43 coverage.line_coverage_percent,
44 coverage.lines_covered,
45 coverage.lines_total
46 );
47
48 println!("{}", coverage_str.color(coverage_color));
49
50 if let Some(branch_percent) = coverage.branch_coverage_percent {
51 let branch_str = format!(
52 " {} {:.1}% branches ({}/{})",
53 prefix,
54 branch_percent,
55 coverage.branches_covered.unwrap_or(0),
56 coverage.branches_total.unwrap_or(0)
57 );
58 println!("{}", branch_str.color(coverage_color));
59 }
60 }
61
62 if show_description {
63 println!("{}Description: {}", prefix, feature.description);
64 }
65
66 if !feature.features.is_empty() {
68 print_features(&feature.features, indent + 1, show_description);
69 }
70 }
71}