1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use serde::Serialize;
use std::io;
/// Output format
#[derive(Debug, Clone, Copy)]
pub enum OutputFormat {
/// Plain text output
Text,
/// JSON output
Json,
/// Table output
Table,
}
/// Output formatter
pub struct Formatter {
format: OutputFormat,
}
impl Formatter {
/// Create new formatter
pub fn new(format: OutputFormat) -> Self {
Self { format }
}
/// Write formatted output
pub fn write<T: Serialize>(&self, value: &T) -> io::Result<()> {
match self.format {
OutputFormat::Text => {
println!("{}", serde_json::to_string_pretty(value)?);
}
OutputFormat::Json => {
println!("{}", serde_json::to_string(value)?);
}
OutputFormat::Table => {
// TODO: Implement table formatting
println!("{}", serde_json::to_string_pretty(value)?);
}
}
Ok(())
}
}
/// Status output
#[derive(Debug, Serialize)]
pub struct StatusOutput {
/// Node ID
pub node_id: String,
/// Node version
pub version: String,
/// Uptime in seconds
pub uptime: u64,
/// Connected peers
pub peers: Vec<PeerOutput>,
/// DAG statistics
pub dag_stats: DagStats,
}
/// Peer information
#[derive(Debug, Serialize)]
pub struct PeerOutput {
/// Peer ID
pub id: String,
/// Peer address
pub address: String,
/// Connection duration
pub connected: u64,
}
/// DAG statistics
#[derive(Debug, Serialize)]
pub struct DagStats {
/// Total vertices
pub vertex_count: usize,
/// Number of tips
pub tip_count: usize,
/// Finalized height
pub finalized_height: u64,
}