1use serde::Serialize;
2use std::io;
3
4#[derive(Debug, Clone, Copy)]
6pub enum OutputFormat {
7 Text,
9 Json,
11 Table,
13}
14
15pub struct Formatter {
17 format: OutputFormat,
18}
19
20impl Formatter {
21 pub fn new(format: OutputFormat) -> Self {
23 Self { format }
24 }
25
26 pub fn write<T: Serialize>(&self, value: &T) -> io::Result<()> {
28 match self.format {
29 OutputFormat::Text => {
30 println!("{}", serde_json::to_string_pretty(value)?);
31 }
32 OutputFormat::Json => {
33 println!("{}", serde_json::to_string(value)?);
34 }
35 OutputFormat::Table => {
36 println!("{}", serde_json::to_string_pretty(value)?);
38 }
39 }
40 Ok(())
41 }
42}
43
44#[derive(Debug, Serialize)]
46pub struct StatusOutput {
47 pub node_id: String,
49 pub version: String,
51 pub uptime: u64,
53 pub peers: Vec<PeerOutput>,
55 pub dag_stats: DagStats,
57}
58
59#[derive(Debug, Serialize)]
61pub struct PeerOutput {
62 pub id: String,
64 pub address: String,
66 pub connected: u64,
68}
69
70#[derive(Debug, Serialize)]
72pub struct DagStats {
73 pub vertex_count: usize,
75 pub tip_count: usize,
77 pub finalized_height: u64,
79}