mielin_cli/commands/
mesh.rs1use crate::output::{render_output, OutputFormat};
4use crate::types::{MeshStatus, OperationResult, PeerInfo, PeerList};
5use anyhow::Result;
6use clap::Subcommand;
7
8#[derive(Subcommand)]
9pub enum MeshCommands {
10 #[command(aliases = ["st", "stat"])]
12 Status,
13 #[command(aliases = ["ls", "list"])]
15 Peers,
16 Gossip,
18 Dht,
20}
21
22pub async fn handle_mesh_command(action: MeshCommands, format: OutputFormat) -> Result<()> {
23 match action {
24 MeshCommands::Status => {
25 let data = mock_mesh_status();
26 println!("{}", render_output(&data, format)?);
27 }
28 MeshCommands::Peers => {
29 let data = mock_peer_list();
30 println!("{}", render_output(&data, format)?);
31 }
32 MeshCommands::Gossip => {
33 let result = OperationResult {
34 success: true,
35 message: "Gossip protocol status: Active".to_string(),
36 id: None,
37 };
38 println!("{}", render_output(&result, format)?);
39 }
40 MeshCommands::Dht => {
41 let result = OperationResult {
42 success: true,
43 message: "DHT status: 256 entries, 15 buckets".to_string(),
44 id: None,
45 };
46 println!("{}", render_output(&result, format)?);
47 }
48 }
49 Ok(())
50}
51
52fn mock_mesh_status() -> MeshStatus {
53 MeshStatus {
54 state: "Healthy".to_string(),
55 local_node: "a1b2c3d4-e5f6-7890-abcd-ef1234567890".to_string(),
56 connected_peers: 3,
57 total_agents: 7,
58 gossip_round: 1542,
59 dht_entries: 256,
60 }
61}
62
63fn mock_peer_list() -> PeerList {
64 PeerList {
65 peers: vec![
66 PeerInfo {
67 id: "peer-001-uuid-here-1234567890ab".to_string(),
68 address: "192.168.1.101:9000".to_string(),
69 latency_ms: 2.3,
70 state: "Connected".to_string(),
71 last_seen: "2s ago".to_string(),
72 },
73 PeerInfo {
74 id: "peer-002-uuid-here-abcdef123456".to_string(),
75 address: "192.168.1.102:9000".to_string(),
76 latency_ms: 5.1,
77 state: "Connected".to_string(),
78 last_seen: "5s ago".to_string(),
79 },
80 ],
81 total: 2,
82 }
83}