2022-04-28 11:53:59 -06:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2022-09-25 04:15:33 -06:00
|
|
|
use clap::Subcommand;
|
2022-04-21 03:12:56 -06:00
|
|
|
use eyre::{Result, WrapErr};
|
|
|
|
|
2022-04-28 11:53:59 -06:00
|
|
|
use atuin_client::{database::Sqlite, settings::Settings};
|
2022-12-16 11:37:45 -07:00
|
|
|
use env_logger::Builder;
|
2022-04-21 03:12:56 -06:00
|
|
|
|
2022-04-22 14:14:23 -06:00
|
|
|
#[cfg(feature = "sync")]
|
|
|
|
mod sync;
|
|
|
|
|
2022-04-21 03:12:56 -06:00
|
|
|
mod history;
|
|
|
|
mod import;
|
|
|
|
mod search;
|
|
|
|
mod stats;
|
2022-04-22 14:14:23 -06:00
|
|
|
|
2022-04-21 03:12:56 -06:00
|
|
|
#[derive(Subcommand)]
|
2022-10-18 02:50:22 -06:00
|
|
|
#[command(infer_subcommands = true)]
|
2022-04-21 03:12:56 -06:00
|
|
|
pub enum Cmd {
|
|
|
|
/// Manipulate shell history
|
2022-10-18 02:50:22 -06:00
|
|
|
#[command(subcommand)]
|
2022-04-21 03:12:56 -06:00
|
|
|
History(history::Cmd),
|
|
|
|
|
|
|
|
/// Import shell history from file
|
2022-10-18 02:50:22 -06:00
|
|
|
#[command(subcommand)]
|
2022-04-21 03:12:56 -06:00
|
|
|
Import(import::Cmd),
|
|
|
|
|
|
|
|
/// Calculate statistics for your history
|
|
|
|
Stats(stats::Cmd),
|
|
|
|
|
|
|
|
/// Interactive history search
|
|
|
|
Search(search::Cmd),
|
|
|
|
|
2022-04-22 14:14:23 -06:00
|
|
|
#[cfg(feature = "sync")]
|
2022-10-18 02:50:22 -06:00
|
|
|
#[command(flatten)]
|
2022-04-22 14:14:23 -06:00
|
|
|
Sync(sync::Cmd),
|
2022-04-21 03:12:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Cmd {
|
2022-05-09 00:46:52 -06:00
|
|
|
#[tokio::main(flavor = "current_thread")]
|
2022-04-21 03:12:56 -06:00
|
|
|
pub async fn run(self) -> Result<()> {
|
2022-12-16 11:37:45 -07:00
|
|
|
Builder::new()
|
|
|
|
.filter_level(log::LevelFilter::Off)
|
|
|
|
.parse_env("ATUIN_LOG")
|
|
|
|
.init();
|
2022-04-21 03:12:56 -06:00
|
|
|
|
2022-12-18 11:26:09 -07:00
|
|
|
let mut settings = Settings::new().wrap_err("could not load client settings")?;
|
2022-04-21 03:12:56 -06:00
|
|
|
|
|
|
|
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,
|
2022-12-18 11:26:09 -07:00
|
|
|
Self::Search(search) => search.run(&mut db, &mut settings).await,
|
2022-04-22 14:14:23 -06:00
|
|
|
#[cfg(feature = "sync")]
|
|
|
|
Self::Sync(sync) => sync.run(settings, &mut db).await,
|
2022-04-21 03:12:56 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|