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