Skip to content

Commit

Permalink
Add long list for identity (#18)
Browse files Browse the repository at this point in the history
* Add list_identities_long in config/locator.rs

* Add a long ls option to config identity command

* Add -l to docs
  • Loading branch information
elizabethengelman authored Nov 22, 2023
1 parent 5b3cc5f commit 3349f04
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cmd/soroban-cli/src/commands/config/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ impl Args {
.collect())
}

pub fn list_identities_long(&self) -> Result<Vec<(String, String)>, Error> {
Ok(KeyType::Identity
.list_paths(&self.local_and_global()?)
.into_iter()
.flatten()
.map(|(name, location)| {
let path = match location {
Location::Local(path) | Location::Global(path) => path,
};
(name, format!("{}", path.display()))
})
.collect())
}

pub fn list_networks(&self) -> Result<Vec<String>, Error> {
Ok(KeyType::Network
.list_paths(&self.local_and_global()?)
Expand Down
19 changes: 18 additions & 1 deletion cmd/soroban-cli/src/commands/identity/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,28 @@ pub enum Error {
pub struct Cmd {
#[command(flatten)]
pub config_locator: locator::Args,

#[arg(long, short = 'l')]
pub long: bool,
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
println!("{}", self.config_locator.list_identities()?.join("\n"));
let res = if self.long { self.ls_l() } else { self.ls() }?.join("\n");
println!("{res}");
Ok(())
}

pub fn ls(&self) -> Result<Vec<String>, Error> {
Ok(self.config_locator.list_identities()?)
}

pub fn ls_l(&self) -> Result<Vec<String>, Error> {
Ok(self
.config_locator
.list_identities_long()?
.into_iter()
.map(|(name, location)| format!("{location}\nName: {name}\n"))
.collect::<Vec<String>>())
}
}
1 change: 1 addition & 0 deletions docs/soroban-cli-full-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ List identities

* `--global` — Use global config
* `--config-dir <CONFIG_DIR>`
* `-l`, `--long`



Expand Down

0 comments on commit 3349f04

Please sign in to comment.