From cf2cbd23f03286e8e7d12f47fec1023dd119106c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Chocholat=C3=BD?= Date: Wed, 21 Feb 2024 17:27:08 +0100 Subject: [PATCH] refactor(alias): Clarify operation result for working with aliases (#1748) --- atuin/src/command/client/config/alias.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/atuin/src/command/client/config/alias.rs b/atuin/src/command/client/config/alias.rs index 56f24c12..77dc8123 100644 --- a/atuin/src/command/client/config/alias.rs +++ b/atuin/src/command/client/config/alias.rs @@ -19,10 +19,10 @@ impl Cmd { let found: Vec = aliases.into_iter().filter(|a| a.name == name).collect(); if found.is_empty() { - println!("Aliasing {name}={value}"); + println!("Aliasing '{name}={value}'."); } else { println!( - "Overwriting alias {name}={} with {name}={value}", + "Overwriting alias '{name}={}' with '{name}={value}'.", found[0].value ); } @@ -43,16 +43,13 @@ impl Cmd { } async fn delete(&self, store: AliasStore, name: String) -> Result<()> { - let aliases = store.aliases().await?; - let found = aliases.into_iter().any(|a| a.name == name); - - if !found { - eprintln!("Alias not found - \"{name}\" - could not delete"); - return Ok(()); - } - - store.delete(&name).await?; - + let mut aliases = store.aliases().await?.into_iter(); + if let Some(alias) = aliases.find(|alias| alias.name == name) { + println!("Deleting '{name}={}'.", alias.value); + store.delete(&name).await?; + } else { + eprintln!("Cannot delete '{name}': Alias not set."); + }; Ok(()) }