aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/mod.rs
diff options
context:
space:
mode:
authorEllie Huxtable <e@elm.sh>2021-04-20 21:53:07 +0100
committerGitHub <noreply@github.com>2021-04-20 20:53:07 +0000
commita21737e2b7f8d1e426726bdd7536033f299d476a (patch)
treee940afdff9c145d25d9a2895fd44a77d70719a2e /src/command/mod.rs
parentSwitch to Warp + SQLx, use async, switch to Rust stable (#36) (diff)
downloadatuin-a21737e2b7f8d1e426726bdd7536033f299d476a.zip
Use cargo workspaces (#37)
* Switch to Cargo workspaces Breaking things into "client", "server" and "common" makes managing the codebase much easier! client - anything running on a user's machine for adding history server - handles storing/syncing history and running a HTTP server common - request/response API definitions, common utils, etc * Update dockerfile
Diffstat (limited to 'src/command/mod.rs')
-rw-r--r--src/command/mod.rs40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/command/mod.rs b/src/command/mod.rs
index cd857e9f..6fd52613 100644
--- a/src/command/mod.rs
+++ b/src/command/mod.rs
@@ -1,9 +1,12 @@
+use std::path::PathBuf;
+
use eyre::Result;
use structopt::StructOpt;
-use uuid::Uuid;
-use crate::local::database::Database;
-use crate::settings::Settings;
+use atuin_client::database::Sqlite;
+use atuin_client::settings::Settings as ClientSettings;
+use atuin_common::utils::uuid_v4;
+use atuin_server::settings::Settings as ServerSettings;
mod event;
mod history;
@@ -58,30 +61,33 @@ pub enum AtuinCmd {
Key,
}
-pub fn uuid_v4() -> String {
- Uuid::new_v4().to_simple().to_string()
-}
-
impl AtuinCmd {
- pub async fn run<T: Database + Send>(self, db: &mut T, settings: &Settings) -> Result<()> {
+ pub async fn run(self) -> Result<()> {
+ let client_settings = ClientSettings::new()?;
+ let server_settings = ServerSettings::new()?;
+
+ let db_path = PathBuf::from(client_settings.db_path.as_str());
+
+ let mut db = Sqlite::new(db_path)?;
+
match self {
- Self::History(history) => history.run(settings, db).await,
- Self::Import(import) => import.run(db),
- Self::Server(server) => server.run(settings).await,
- Self::Stats(stats) => stats.run(db, settings),
+ Self::History(history) => history.run(&client_settings, &mut db).await,
+ Self::Import(import) => import.run(&mut db),
+ Self::Server(server) => server.run(&server_settings).await,
+ Self::Stats(stats) => stats.run(&mut db, &client_settings),
Self::Init => init::init(),
- Self::Search { query } => search::run(&query, db),
+ Self::Search { query } => search::run(&query, &mut db),
- Self::Sync { force } => sync::run(settings, force, db).await,
- Self::Login(l) => l.run(settings),
+ Self::Sync { force } => sync::run(&client_settings, force, &mut db).await,
+ Self::Login(l) => l.run(&client_settings),
Self::Register(r) => register::run(
- settings,
+ &client_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())?;
+ let key = std::fs::read(client_settings.key_path.as_str())?;
println!("{}", base64::encode(key));
Ok(())
}