1use ic_host_text::escape::terminal_text;
4
5#[cfg(feature = "nns-host")]
6use crate::text_value::yes_no;
7
8#[must_use]
9pub fn compact_text(value: &str, chars: usize) -> String {
10 crate::text_value::compact_text(value, chars)
11}
12
13#[must_use]
14pub fn text_or_dash(value: Option<&str>) -> String {
15 crate::text_value::text_or_dash(value.unwrap_or_default())
16}
17
18#[must_use]
19pub fn optional_f32_text(value: Option<f32>) -> String {
20 value.map_or_else(|| "-".to_string(), |value| value.to_string())
21}
22
23#[must_use]
24pub fn optional_node_count_text(value: Option<u32>) -> String {
25 value.map_or_else(|| "unknown".to_string(), |count| count.to_string())
26}
27
28#[cfg(feature = "nns-host")]
29#[must_use]
30pub fn nns_inventory_refresh_report_text(report: &crate::nns::NnsInventoryRefreshReport) -> String {
32 let mut lines = vec![
33 format!("network: {}", terminal_text(&report.provenance.network)),
34 format!("cache_path: {}", terminal_text(&report.cache_path)),
35 format!(
36 "refresh_lock_path: {}",
37 terminal_text(&report.refresh_lock_path)
38 ),
39 ];
40 if let Some(governance_canister_id) = &report.governance_canister_id {
41 lines.push(format!(
42 "governance_canister_id: {}",
43 terminal_text(governance_canister_id)
44 ));
45 }
46 lines.extend([
47 format!(
48 "registry_canister_id: {}",
49 report.provenance.registry_canister_id
50 ),
51 format!("registry_version: {}", report.provenance.registry_version),
52 format!(
53 "fetched_at: {}",
54 terminal_text(&report.provenance.fetched_at)
55 ),
56 format!(
57 "source_endpoint: {}",
58 terminal_text(&report.provenance.source_endpoint)
59 ),
60 format!(
61 "fetched_by: {}",
62 terminal_text(&report.provenance.fetched_by)
63 ),
64 format!("dry_run: {}", yes_no(report.dry_run)),
65 format!("wrote_cache: {}", yes_no(report.wrote_cache)),
66 format!(
67 "replaced_existing_cache: {}",
68 yes_no(report.replaced_existing_cache)
69 ),
70 format!("collection: {}", terminal_text(&report.collection)),
71 format!("row_count: {}", report.row_count),
72 ]);
73 lines.join("\n")
74}
75
76#[must_use]
77pub(super) fn registry_provenance_lines(
78 provenance: &super::registry::NnsRegistryInventoryProvenance,
79) -> [String; 6] {
80 [
81 format!("registry_canister_id: {}", provenance.registry_canister_id),
82 format!("registry_version: {}", provenance.registry_version),
83 format!("network: {}", terminal_text(&provenance.network)),
84 format!("fetched_at: {}", terminal_text(&provenance.fetched_at)),
85 format!(
86 "source_endpoint: {}",
87 terminal_text(&provenance.source_endpoint)
88 ),
89 format!("fetched_by: {}", terminal_text(&provenance.fetched_by)),
90 ]
91}