atuin/src/command/mod.rs

52 lines
1.1 KiB
Rust
Raw Normal View History

use eyre::Result;
2021-02-14 10:18:02 -07:00
use structopt::StructOpt;
use uuid::Uuid;
use crate::local::database::Database;
2021-02-14 10:18:02 -07:00
mod history;
mod import;
mod server;
mod stats;
2021-02-14 10:18:02 -07:00
#[derive(StructOpt)]
pub enum AtuinCmd {
#[structopt(
about="manipulate shell history",
aliases=&["h", "hi", "his", "hist", "histo", "histor"],
)]
History(history::Cmd),
#[structopt(about = "import shell history from file")]
Import(import::Cmd),
#[structopt(about = "start an atuin server")]
Server(server::Cmd),
#[structopt(about = "calculate statistics for your history")]
Stats(stats::Cmd),
2021-02-14 10:18:02 -07:00
#[structopt(about = "generates a UUID")]
Uuid,
}
pub fn uuid_v4() -> String {
Uuid::new_v4().to_simple().to_string()
}
impl AtuinCmd {
pub fn run(self, db: &mut impl Database) -> Result<()> {
match self {
Self::History(history) => history.run(db),
Self::Import(import) => import.run(db),
Self::Server(server) => server.run(),
Self::Stats(stats) => stats.run(db),
Self::Uuid => {
println!("{}", uuid_v4());
Ok(())
}
}
}
}