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