qudag_cli/
output.rs

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