ic-query-cli 0.98.0

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
//! Module: nns::topology::gaps
//!
//! Responsibility: render NNS topology gap reports as text.
//! Does not own: gap detection, source reads, or JSON output.
//! Boundary: formats known topology relation gaps for human inspection.

use crate::presentation::text_value::table;
use ic_host_text::table::Alignment;

use ic_query::nns::topology::NnsTopologyGapRow;
use ic_query::nns::topology::NnsTopologyGapsReport;

#[must_use]
/// Render the NNS topology gaps report as human-facing text.
pub fn nns_topology_gaps_report_text(report: &NnsTopologyGapsReport) -> String {
    if report.gaps.is_empty() {
        return render_gaps_status_table(report);
    }
    render_gaps_table(&report.gaps)
}

fn render_gaps_status_table(report: &NnsTopologyGapsReport) -> String {
    let headers = ["STATUS", "DETAIL"];
    let rows = [[
        report.status.as_str().to_string(),
        "no topology join gaps".to_string(),
    ]];
    let alignments = [Alignment::Left; 2];
    table(&headers, &rows, &alignments)
}

fn render_gaps_table(rows: &[NnsTopologyGapRow]) -> String {
    let headers = [
        "SUBJECT_KIND",
        "SUBJECT",
        "MISSING_RELATION",
        "REFERENCED_ID",
    ];
    let rows = rows
        .iter()
        .map(|row| {
            [
                row.subject_kind.as_str().to_string(),
                row.subject.clone(),
                row.missing_relation.as_str().to_string(),
                row.referenced_id.clone(),
            ]
        })
        .collect::<Vec<_>>();
    let alignments = [Alignment::Left; 4];
    table(&headers, &rows, &alignments)
}