Fix naming of validators in CLI (#1332)

## Issue Addressed

NA

## Proposed Changes

- Adds a `lighthouse account validator list` command, to list all known validators.
- Fixes the validator names; previously they were using a full path (e.g., `"/home/paul/.lighthouse/validators/0x8ce25415d078bdc83133758604578ba51707a55965eeca8982f44695db7432d6ff1c23529020a971faa68ab60baf3118"` but now we only use the final directory name (e.g., `0x8ce25415d078bdc83133758604578ba51707a55965eeca8982f44695db7432d6ff1c23529020a971faa68ab60baf3118`).
This commit is contained in:
Paul Hauner
2020-07-27 01:25:20 +00:00
parent a413b43fed
commit 5680355b31
3 changed files with 40 additions and 5 deletions

View File

@@ -164,10 +164,12 @@ impl Manager {
///
/// Returns an error if a directory is unable to be read.
pub fn directory_names(&self) -> Result<HashMap<String, PathBuf>, Error> {
Ok(HashMap::from_iter(
self.iter_dir()?
.into_iter()
.map(|path| (format!("{:?}", path), path)),
))
Ok(HashMap::from_iter(self.iter_dir()?.into_iter().filter_map(
|path| {
path.file_name()
.and_then(|os_string| os_string.to_str().map(|s| s.to_string()))
.map(|filename| (filename, path))
},
)))
}
}