soroban_cli/commands/network/
ls.rs

1use clap::command;
2
3use super::locator;
4
5#[derive(thiserror::Error, Debug)]
6pub enum Error {
7    #[error(transparent)]
8    Config(#[from] locator::Error),
9}
10
11#[derive(Debug, clap::Parser, Clone)]
12#[group(skip)]
13pub struct Cmd {
14    #[command(flatten)]
15    pub config_locator: locator::Args,
16    /// Get more info about the networks
17    #[arg(long, short = 'l')]
18    pub long: bool,
19}
20
21impl Cmd {
22    pub fn run(&self) -> Result<(), Error> {
23        let res = if self.long { self.ls_l() } else { self.ls() }?.join("\n");
24        println!("{res}");
25        Ok(())
26    }
27
28    pub fn ls(&self) -> Result<Vec<String>, Error> {
29        Ok(self.config_locator.list_networks()?)
30    }
31
32    pub fn ls_l(&self) -> Result<Vec<String>, Error> {
33        Ok(self
34            .config_locator
35            .list_networks_long()?
36            .iter()
37            .filter_map(|(name, network, location)| {
38                (!self.config_locator.global || location == "Global")
39                    .then(|| Some(format!("{location}\nName: {name}\n{network:#?}\n")))?
40            })
41            .collect())
42    }
43}