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