leo_lang/cli/commands/query/
peers.rs

1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use super::*;
18
19use crate::cli::context::Context;
20use clap::Parser;
21
22// Query information about network peers.
23#[derive(Parser, Debug)]
24pub struct LeoPeers {
25    #[arg(short, long, help = "Get all peer metrics", default_value = "false", conflicts_with("count"))]
26    pub(crate) metrics: bool,
27    #[arg(
28        short,
29        long,
30        help = "Get the count of all participating peers",
31        default_value = "false",
32        conflicts_with("metrics")
33    )]
34    pub(crate) count: bool,
35}
36
37impl Command for LeoPeers {
38    type Input = ();
39    type Output = String;
40
41    fn log_span(&self) -> Span {
42        tracing::span!(tracing::Level::INFO, "Leo")
43    }
44
45    fn prelude(&self, _context: Context) -> Result<Self::Input> {
46        Ok(())
47    }
48
49    fn apply(self, _context: Context, _input: Self::Input) -> Result<Self::Output> {
50        // Build custom url to fetch from based on the flags and user's input.
51        let url = if self.metrics {
52            "peers/all/metrics".to_string()
53        } else if self.count {
54            "peers/count".to_string()
55        } else {
56            "peers/all".to_string()
57        };
58
59        Ok(url)
60    }
61}