mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-29 03:34:44 +01:00
feat: add alias feedback and list command (#1747)
This commit is contained in:
parent
21fee97a62
commit
6a885cf4ab
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user