atuin/src/command/client.rs
Patrick Decat ed394afa82
Allow overriding filter and search modes from CLI (#635)
* Allow overriding filter and search modes from CLI arguments

* Use session filter mode for bash up key binding

* We precisely do not want to add quotes here so that all arguments are properly passed

* Add --shell-up-key-binding hidden command argument and filter_mode_shell_up_key_binding configuration option to allow customizing the filter mode used when atuin is invoked from a shell up-key binding

* Correct up binding for zsh

Co-authored-by: Ellie Huxtable <ellie@elliehuxtable.com>
2022-12-18 18:26:09 +00:00

61 lines
1.5 KiB
Rust

use std::path::PathBuf;
use clap::Subcommand;
use eyre::{Result, WrapErr};
use atuin_client::{database::Sqlite, settings::Settings};
use env_logger::Builder;
#[cfg(feature = "sync")]
mod sync;
mod history;
mod import;
mod search;
mod stats;
#[derive(Subcommand)]
#[command(infer_subcommands = true)]
pub enum Cmd {
/// Manipulate shell history
#[command(subcommand)]
History(history::Cmd),
/// Import shell history from file
#[command(subcommand)]
Import(import::Cmd),
/// Calculate statistics for your history
Stats(stats::Cmd),
/// Interactive history search
Search(search::Cmd),
#[cfg(feature = "sync")]
#[command(flatten)]
Sync(sync::Cmd),
}
impl Cmd {
#[tokio::main(flavor = "current_thread")]
pub async fn run(self) -> Result<()> {
Builder::new()
.filter_level(log::LevelFilter::Off)
.parse_env("ATUIN_LOG")
.init();
let mut settings = Settings::new().wrap_err("could not load client settings")?;
let db_path = PathBuf::from(settings.db_path.as_str());
let mut db = Sqlite::new(db_path).await?;
match self {
Self::History(history) => history.run(&settings, &mut db).await,
Self::Import(import) => import.run(&mut db).await,
Self::Stats(stats) => stats.run(&mut db, &settings).await,
Self::Search(search) => search.run(&mut db, &mut settings).await,
#[cfg(feature = "sync")]
Self::Sync(sync) => sync.run(settings, &mut db).await,
}
}
}