feat: add alias feedback and list command (#1747)

This commit is contained in:
Ellie Huxtable 2024-02-21 11:54:46 +00:00 committed by GitHub
parent 21fee97a62
commit 6a885cf4ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,
}
}
}