2021-02-14 11:00:41 -07:00
|
|
|
use eyre::Result;
|
2021-02-14 10:18:02 -07:00
|
|
|
use structopt::StructOpt;
|
2021-02-14 11:00:41 -07:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
2021-02-15 02:07:49 -07:00
|
|
|
use crate::local::database::Database;
|
2021-03-10 14:24:08 -07:00
|
|
|
use crate::settings::Settings;
|
2021-02-14 10:18:02 -07:00
|
|
|
|
2021-03-19 18:50:31 -06:00
|
|
|
mod event;
|
2021-02-14 10:18:02 -07:00
|
|
|
mod history;
|
|
|
|
mod import;
|
2021-02-15 16:33:30 -07:00
|
|
|
mod init;
|
2021-04-13 12:14:07 -06:00
|
|
|
mod login;
|
|
|
|
mod register;
|
2021-03-19 18:50:31 -06:00
|
|
|
mod search;
|
2021-02-14 10:18:02 -07:00
|
|
|
mod server;
|
2021-02-14 15:12:35 -07:00
|
|
|
mod stats;
|
2021-04-13 12:14:07 -06:00
|
|
|
mod sync;
|
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),
|
|
|
|
|
2021-02-14 15:12:35 -07:00
|
|
|
#[structopt(about = "calculate statistics for your history")]
|
|
|
|
Stats(stats::Cmd),
|
|
|
|
|
2021-02-15 16:33:30 -07:00
|
|
|
#[structopt(about = "output shell setup")]
|
|
|
|
Init,
|
|
|
|
|
2021-02-14 10:18:02 -07:00
|
|
|
#[structopt(about = "generates a UUID")]
|
|
|
|
Uuid,
|
2021-03-19 18:50:31 -06:00
|
|
|
|
|
|
|
#[structopt(about = "interactive history search")]
|
|
|
|
Search { query: Vec<String> },
|
2021-04-13 12:14:07 -06:00
|
|
|
|
|
|
|
#[structopt(about = "sync with the configured server")]
|
|
|
|
Sync {
|
|
|
|
#[structopt(long, short, about = "force re-download everything")]
|
|
|
|
force: bool,
|
|
|
|
},
|
|
|
|
|
|
|
|
#[structopt(about = "login to the configured server")]
|
|
|
|
Login(login::Cmd),
|
|
|
|
|
|
|
|
#[structopt(about = "register with the configured server")]
|
|
|
|
Register(register::Cmd),
|
|
|
|
|
|
|
|
#[structopt(about = "print the encryption key for transfer to another machine")]
|
|
|
|
Key,
|
2021-02-14 10:18:02 -07:00
|
|
|
}
|
2021-02-14 11:00:41 -07:00
|
|
|
|
2021-02-14 11:40:51 -07:00
|
|
|
pub fn uuid_v4() -> String {
|
|
|
|
Uuid::new_v4().to_simple().to_string()
|
|
|
|
}
|
|
|
|
|
2021-02-14 11:00:41 -07:00
|
|
|
impl AtuinCmd {
|
2021-04-20 10:07:11 -06:00
|
|
|
pub async fn run<T: Database + Send>(self, db: &mut T, settings: &Settings) -> Result<()> {
|
2021-02-14 11:00:41 -07:00
|
|
|
match self {
|
2021-04-20 10:07:11 -06:00
|
|
|
Self::History(history) => history.run(settings, db).await,
|
2021-02-14 11:00:41 -07:00
|
|
|
Self::Import(import) => import.run(db),
|
2021-04-20 10:07:11 -06:00
|
|
|
Self::Server(server) => server.run(settings).await,
|
2021-03-10 14:24:08 -07:00
|
|
|
Self::Stats(stats) => stats.run(db, settings),
|
2021-02-15 16:33:30 -07:00
|
|
|
Self::Init => init::init(),
|
2021-03-19 18:50:31 -06:00
|
|
|
Self::Search { query } => search::run(&query, db),
|
2021-02-14 11:00:41 -07:00
|
|
|
|
2021-04-20 10:07:11 -06:00
|
|
|
Self::Sync { force } => sync::run(settings, force, db).await,
|
2021-04-13 12:14:07 -06:00
|
|
|
Self::Login(l) => l.run(settings),
|
|
|
|
Self::Register(r) => register::run(
|
|
|
|
settings,
|
|
|
|
r.username.as_str(),
|
|
|
|
r.email.as_str(),
|
|
|
|
r.password.as_str(),
|
|
|
|
),
|
|
|
|
Self::Key => {
|
|
|
|
let key = std::fs::read(settings.local.key_path.as_str())?;
|
|
|
|
println!("{}", base64::encode(key));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-02-14 11:00:41 -07:00
|
|
|
Self::Uuid => {
|
2021-02-14 11:40:51 -07:00
|
|
|
println!("{}", uuid_v4());
|
2021-02-14 11:00:41 -07:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|