soroban_cli/commands/keys/
ls.rs1use super::super::config::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
15 #[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 let list = self.config_locator.list_identities()?;
28 Ok(list)
29 }
30
31 pub fn ls_l(&self) -> Result<Vec<String>, Error> {
32 Ok(self
33 .config_locator
34 .list_identities_long()?
35 .into_iter()
36 .map(|(name, location)| format!("{location}\nName: {name}\n"))
37 .collect::<Vec<String>>())
38 }
39}