Skip to content

Commit 9ae1420

Browse files
Refactor/cleanup
1 parent 4b5f79c commit 9ae1420

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

cmd/soroban-cli/src/commands/keys/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Cmd {
7575
Cmd::Fund(cmd) => cmd.run().await?,
7676
Cmd::Generate(cmd) => cmd.run(global_args).await?,
7777
Cmd::Ls(cmd) => cmd.run()?,
78-
Cmd::Rm(cmd) => cmd.run()?,
78+
Cmd::Rm(cmd) => cmd.run(global_args)?,
7979
Cmd::Show(cmd) => cmd.run()?,
8080
Cmd::Default(cmd) => cmd.run(global_args)?,
8181
};

cmd/soroban-cli/src/commands/keys/rm.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use clap::command;
22

3+
use crate::commands::global;
4+
35
use super::super::config::locator;
46

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

2123
impl Cmd {
22-
pub fn run(&self) -> Result<(), Error> {
23-
Ok(self.config.remove_identity(&self.name)?)
24+
pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
25+
Ok(self.config.remove_identity(&self.name, global_args)?)
2426
}
2527
}

cmd/soroban-cli/src/config/locator.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use std::{
1313
use stellar_strkey::{Contract, DecodeError};
1414

1515
use crate::{
16-
commands::HEADING_GLOBAL,
16+
commands::{global, HEADING_GLOBAL},
17+
print::Print,
1718
signer::{self, keyring::StellarEntry},
1819
utils::find_config_dir,
1920
Pwd,
@@ -260,19 +261,21 @@ impl Args {
260261
res
261262
}
262263

263-
pub fn remove_identity(&self, name: &str) -> Result<(), Error> {
264+
pub fn remove_identity(&self, name: &str, global_args: &global::Args) -> Result<(), Error> {
265+
let printer = Print::new(global_args.quiet);
264266
let identity = self.read_identity(name)?;
265267
match identity {
266268
Secret::SecureStore { entry_name } => {
267269
let entry = StellarEntry::new(&entry_name)?;
268-
let _ = entry.delete_password().map_err(|e| {
269-
if e.to_string() == keyring::Error::NoEntry.to_string() {
270-
println!("This key was already removed from the secure store. Removing the config file");
271-
return Ok(());
272-
} else {
273-
Err(Error::Keyring(e))
270+
match entry.delete_password() {
271+
Ok(_) => {}
272+
Err(e) if e.to_string() == keyring::Error::NoEntry.to_string() => {
273+
printer.infoln("This key was already removed from the secure store. Removing the config file.");
274274
}
275-
});
275+
Err(e) => {
276+
return Err(Error::Keyring(e));
277+
}
278+
}
276279
}
277280
_ => {}
278281
}

0 commit comments

Comments
 (0)