Skip to content

Commit

Permalink
Refactor/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Dec 3, 2024
1 parent 9482186 commit c39bf60
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Cmd {
Cmd::Fund(cmd) => cmd.run().await?,
Cmd::Generate(cmd) => cmd.run(global_args).await?,
Cmd::Ls(cmd) => cmd.run()?,
Cmd::Rm(cmd) => cmd.run()?,
Cmd::Rm(cmd) => cmd.run(global_args)?,
Cmd::Show(cmd) => cmd.run()?,
Cmd::Default(cmd) => cmd.run(global_args)?,
};
Expand Down
6 changes: 4 additions & 2 deletions cmd/soroban-cli/src/commands/keys/rm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use clap::command;

use crate::commands::global;

use super::super::config::locator;

#[derive(thiserror::Error, Debug)]
Expand All @@ -19,7 +21,7 @@ pub struct Cmd {
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
Ok(self.config.remove_identity(&self.name)?)
pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
Ok(self.config.remove_identity(&self.name, global_args)?)
}
}
21 changes: 12 additions & 9 deletions cmd/soroban-cli/src/config/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use std::{
use stellar_strkey::{Contract, DecodeError};

use crate::{
commands::HEADING_GLOBAL,
commands::{global, HEADING_GLOBAL},
print::Print,
signer::{self, keyring::StellarEntry},
utils::find_config_dir,
Pwd,
Expand Down Expand Up @@ -260,19 +261,21 @@ impl Args {
res
}

pub fn remove_identity(&self, name: &str) -> Result<(), Error> {
pub fn remove_identity(&self, name: &str, global_args: &global::Args) -> Result<(), Error> {
let printer = Print::new(global_args.quiet);
let identity = self.read_identity(name)?;
match identity {
Secret::SecureStore { entry_name } => {
let entry = StellarEntry::new(&entry_name)?;
let _ = entry.delete_password().map_err(|e| {
if e.to_string() == keyring::Error::NoEntry.to_string() {
println!("This key was already removed from the secure store. Removing the config file");
return Ok(());
} else {
Err(Error::Keyring(e))
match entry.delete_password() {
Ok(_) => {}
Err(e) if e.to_string() == keyring::Error::NoEntry.to_string() => {
printer.infoln("This key was already removed from the secure store. Removing the config file.");
}
});
Err(e) => {
return Err(Error::Keyring(e));
}
}
}
_ => {}
}
Expand Down

0 comments on commit c39bf60

Please sign in to comment.