diff --git a/cmd/soroban-cli/src/commands/keys/mod.rs b/cmd/soroban-cli/src/commands/keys/mod.rs index b3309fa02..4d44c081f 100644 --- a/cmd/soroban-cli/src/commands/keys/mod.rs +++ b/cmd/soroban-cli/src/commands/keys/mod.rs @@ -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)?, }; diff --git a/cmd/soroban-cli/src/commands/keys/rm.rs b/cmd/soroban-cli/src/commands/keys/rm.rs index df48108d3..c551d05e8 100644 --- a/cmd/soroban-cli/src/commands/keys/rm.rs +++ b/cmd/soroban-cli/src/commands/keys/rm.rs @@ -1,5 +1,7 @@ use clap::command; +use crate::commands::global; + use super::super::config::locator; #[derive(thiserror::Error, Debug)] @@ -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)?) } } diff --git a/cmd/soroban-cli/src/config/locator.rs b/cmd/soroban-cli/src/config/locator.rs index c33646938..a0450e5a0 100644 --- a/cmd/soroban-cli/src/config/locator.rs +++ b/cmd/soroban-cli/src/config/locator.rs @@ -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, @@ -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)); + } + } } _ => {} }