iroh_node_util/cli/
node.rs1use clap::Subcommand;
3
4use crate::rpc::client::node;
5
6#[derive(Subcommand, Debug, Clone)]
8#[allow(clippy::large_enum_variant)]
9pub enum NodeCommands {
10 Stats,
12 Status,
14 Shutdown {
16 #[clap(long, default_value_t = false)]
21 force: bool,
22 },
23}
24
25impl NodeCommands {
26 pub async fn run(self, node: &node::Client) -> anyhow::Result<()> {
28 match self {
29 Self::Stats => {
30 let stats = node.stats().await?;
31 for (name, details) in stats.iter() {
32 println!(
33 "{:23} : {:>6} ({})",
34 name, details.value, details.description
35 );
36 }
37 Ok(())
38 }
39 Self::Shutdown { force } => {
40 node.shutdown(force).await?;
41 Ok(())
42 }
43 Self::Status => {
44 let response = node.status().await?;
45 println!("Listening addresses: {:#?}", response.listen_addrs);
46 println!("Node ID: {}", response.addr.node_id);
47 println!("Version: {}", response.version);
48 if let Some(addr) = response.rpc_addr {
49 println!("RPC Addr: {}", addr);
50 }
51 Ok(())
52 }
53 }
54 }
55}