diff options
author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-02-21 11:54:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-21 11:54:46 +0000 |
commit | 6a885cf4abaf03ab9bf235db498e11499a153747 (patch) | |
tree | 67da19d12a7688fd8eea34abd1b4e99f89ad2b43 | |
parent | 21fee97a62c2ceb19bf36cfb7ae6f13771ec6e3a (diff) |
feat: add alias feedback and list command (#1747)
-rw-r--r-- | atuin/src/command/client/config/alias.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/atuin/src/command/client/config/alias.rs b/atuin/src/command/client/config/alias.rs index 9d34d84a..56f24c12 100644 --- a/atuin/src/command/client/config/alias.rs +++ b/atuin/src/command/client/config/alias.rs @@ -3,23 +3,54 @@ use eyre::{Context, Result}; use atuin_client::{encryption, record::sqlite_store::SqliteStore, settings::Settings}; -use atuin_config::store::AliasStore; +use atuin_config::{shell::Alias, store::AliasStore}; #[derive(Subcommand, Debug)] #[command(infer_subcommands = true)] pub enum Cmd { Set { name: String, value: String }, Delete { name: String }, + List, } impl Cmd { async fn set(&self, store: AliasStore, name: String, value: String) -> Result<()> { + let aliases = store.aliases().await?; + let found: Vec<Alias> = aliases.into_iter().filter(|a| a.name == name).collect(); + + if found.is_empty() { + println!("Aliasing {name}={value}"); + } else { + println!( + "Overwriting alias {name}={} with {name}={value}", + found[0].value + ); + } + store.set(&name, &value).await?; Ok(()) } + async fn list(&self, store: AliasStore) -> Result<()> { + let aliases = store.aliases().await?; + + for i in aliases { + println!("{}={}", i.name, i.value); + } + + Ok(()) + } + 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?; Ok(()) @@ -35,8 +66,8 @@ impl Cmd { match self { Self::Set { name, value } => self.set(alias_store, name.clone(), value.clone()).await, - Self::Delete { name } => self.delete(alias_store, name.clone()).await, + Self::List => self.list(alias_store).await, } } } |