Skip to main content

lean_ctx/cli/dispatch/analytics/
mod.rs

1//! Analytics command family: gain, savings, billing, conformance and the
2//! graph tools. Split by domain (GL#439) — each submodule owns exactly one
3//! command surface; this hub re-exports the dispatch entry points.
4
5mod finops;
6mod gain;
7mod graph;
8mod learning;
9pub mod provider_run;
10mod savings;
11mod spend;
12
13pub(in crate::cli::dispatch) use finops::cmd_finops;
14pub(in crate::cli::dispatch) use gain::cmd_gain;
15pub(in crate::cli::dispatch) use graph::{cmd_compact, cmd_graph, cmd_smells};
16pub(in crate::cli::dispatch) use learning::cmd_learning;
17pub(in crate::cli::dispatch) use savings::cmd_savings;
18pub(in crate::cli::dispatch) use spend::cmd_spend;
19
20use crate::core;
21
22/// `lean-ctx conformance [--json]` — run the conformance & reproducibility
23/// scorecard (EPIC 12.17) and exit non-zero if any check fails, so CI can gate.
24pub(super) fn cmd_conformance(args: &[String]) {
25    let card = core::conformance::run();
26
27    if args.iter().any(|a| a == "--json") {
28        match serde_json::to_string_pretty(&card.to_json()) {
29            Ok(json) => println!("{json}"),
30            Err(e) => {
31                eprintln!("conformance serialization failed: {e}");
32                std::process::exit(1);
33            }
34        }
35    } else {
36        println!(
37            "Conformance scorecard ({}/{} passed)",
38            card.passed(),
39            card.total()
40        );
41        for check in &card.checks {
42            let mark = if check.passed { "ok" } else { "FAIL" };
43            let detail = if check.detail.is_empty() {
44                String::new()
45            } else {
46                format!(" — {}", check.detail)
47            };
48            println!("  [{mark}] {}/{}{detail}", check.category, check.name);
49        }
50    }
51
52    if !card.all_passed() {
53        std::process::exit(1);
54    }
55}