summaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/command')
-rw-r--r--src/command/client.rs44
-rw-r--r--src/command/client/history.rs11
-rw-r--r--src/command/client/sync.rs59
-rw-r--r--src/command/client/sync/login.rs (renamed from src/command/client/login.rs)0
-rw-r--r--src/command/client/sync/logout.rs (renamed from src/command/client/logout.rs)0
-rw-r--r--src/command/client/sync/register.rs (renamed from src/command/client/register.rs)0
-rw-r--r--src/command/mod.rs4
7 files changed, 77 insertions, 41 deletions
diff --git a/src/command/client.rs b/src/command/client.rs
index fd65345c..4858e2ba 100644
--- a/src/command/client.rs
+++ b/src/command/client.rs
@@ -8,16 +8,16 @@ use atuin_client::database::Sqlite;
use atuin_client::settings::Settings;
use atuin_common::utils::uuid_v4;
+#[cfg(feature = "sync")]
+mod sync;
+
mod event;
mod history;
mod import;
mod init;
-mod login;
-mod logout;
-mod register;
mod search;
mod stats;
-mod sync;
+
use std::path::PathBuf;
#[derive(Subcommand)]
@@ -45,25 +45,6 @@ pub enum Cmd {
/// Interactive history search
Search(search::Cmd),
- /// Sync with the configured server
- Sync {
- /// Force re-download everything
- #[clap(long, short)]
- force: bool,
- },
-
- /// Login to the configured server
- Login(login::Cmd),
-
- /// Log out
- Logout,
-
- /// Register with the configured server
- Register(register::Cmd),
-
- /// Print the encryption key for transfer to another machine
- Key,
-
/// Generate shell completions
GenCompletions {
/// Set the shell for generating completions
@@ -74,6 +55,10 @@ pub enum Cmd {
#[clap(long, short)]
out_dir: Option<String>,
},
+
+ #[cfg(feature = "sync")]
+ #[clap(flatten)]
+ Sync(sync::Cmd),
}
impl Cmd {
@@ -94,17 +79,6 @@ impl Cmd {
Ok(())
}
Self::Search(search) => search.run(&mut db, &settings).await,
- Self::Sync { force } => sync::run(&settings, force, &mut db).await,
- Self::Login(l) => l.run(&settings).await,
- Self::Logout => logout::run(),
- Self::Register(r) => r.run(&settings).await,
- Self::Key => {
- use atuin_client::encryption::{encode_key, load_key};
- let key = load_key(&settings).wrap_err("could not load encryption key")?;
- let encode = encode_key(key).wrap_err("could not encode encryption key")?;
- println!("{}", encode);
- Ok(())
- }
Self::Uuid => {
println!("{}", uuid_v4());
Ok(())
@@ -128,6 +102,8 @@ impl Cmd {
Ok(())
}
+ #[cfg(feature = "sync")]
+ Self::Sync(sync) => sync.run(settings, &mut db).await,
}
}
}
diff --git a/src/command/client/history.rs b/src/command/client/history.rs
index 994cbfd5..4f96c444 100644
--- a/src/command/client/history.rs
+++ b/src/command/client/history.rs
@@ -9,6 +9,8 @@ use tabwriter::TabWriter;
use atuin_client::database::{current_context, Database};
use atuin_client::history::History;
use atuin_client::settings::Settings;
+
+#[cfg(feature = "sync")]
use atuin_client::sync;
#[derive(Subcommand)]
@@ -143,8 +145,13 @@ impl Cmd {
db.update(&h).await?;
if settings.should_sync()? {
- debug!("running periodic background sync");
- sync::sync(settings, false, db).await?;
+ #[cfg(feature = "sync")]
+ {
+ debug!("running periodic background sync");
+ sync::sync(settings, false, db).await?;
+ }
+ #[cfg(not(feature = "sync"))]
+ debug!("not compiled with sync support");
} else {
debug!("sync disabled! not syncing");
}
diff --git a/src/command/client/sync.rs b/src/command/client/sync.rs
index f8bfd5e2..8e80310a 100644
--- a/src/command/client/sync.rs
+++ b/src/command/client/sync.rs
@@ -1,15 +1,64 @@
-use eyre::Result;
-
use atuin_client::database::Database;
+use clap::Subcommand;
+use eyre::{Result, WrapErr};
+
use atuin_client::settings::Settings;
-use atuin_client::sync;
-pub async fn run(
+mod login;
+mod logout;
+mod register;
+
+#[derive(Subcommand)]
+#[clap(infer_subcommands = true)]
+pub enum Cmd {
+ /// Sync with the configured server
+ Sync {
+ /// Force re-download everything
+ #[clap(long, short)]
+ force: bool,
+ },
+
+ /// Login to the configured server
+ Login(login::Cmd),
+
+ /// Log out
+ Logout,
+
+ /// Register with the configured server
+ Register(register::Cmd),
+
+ /// Print the encryption key for transfer to another machine
+ Key,
+}
+
+impl Cmd {
+ pub async fn run(
+ self,
+ settings: Settings,
+ db: &mut (impl Database + Send + Sync),
+ ) -> Result<()> {
+ match self {
+ Self::Sync { force } => run(&settings, force, db).await,
+ Self::Login(l) => l.run(&settings).await,
+ Self::Logout => logout::run(),
+ Self::Register(r) => r.run(&settings).await,
+ Self::Key => {
+ use atuin_client::encryption::{encode_key, load_key};
+ let key = load_key(&settings).wrap_err("could not load encryption key")?;
+ let encode = encode_key(key).wrap_err("could not encode encryption key")?;
+ println!("{}", encode);
+ Ok(())
+ }
+ }
+ }
+}
+
+async fn run(
settings: &Settings,
force: bool,
db: &mut (impl Database + Send + Sync),
) -> Result<()> {
- sync::sync(settings, force, db).await?;
+ atuin_client::sync::sync(settings, force, db).await?;
println!(
"Sync complete! {} items in database, force: {}",
db.history_count().await?,
diff --git a/src/command/client/login.rs b/src/command/client/sync/login.rs
index efc9c590..efc9c590 100644
--- a/src/command/client/login.rs
+++ b/src/command/client/sync/login.rs
diff --git a/src/command/client/logout.rs b/src/command/client/sync/logout.rs
index a7e9541d..a7e9541d 100644
--- a/src/command/client/logout.rs
+++ b/src/command/client/sync/logout.rs
diff --git a/src/command/client/register.rs b/src/command/client/sync/register.rs
index 2c60a2e9..2c60a2e9 100644
--- a/src/command/client/register.rs
+++ b/src/command/client/sync/register.rs
diff --git a/src/command/mod.rs b/src/command/mod.rs
index 3a3ed393..953b76ba 100644
--- a/src/command/mod.rs
+++ b/src/command/mod.rs
@@ -2,6 +2,8 @@ use clap::Subcommand;
use eyre::Result;
mod client;
+
+#[cfg(feature = "server")]
mod server;
#[derive(Subcommand)]
@@ -11,6 +13,7 @@ pub enum AtuinCmd {
Client(client::Cmd),
/// Start an atuin server
+ #[cfg(feature = "server")]
#[clap(subcommand)]
Server(server::Cmd),
}
@@ -19,6 +22,7 @@ impl AtuinCmd {
pub async fn run(self) -> Result<()> {
match self {
Self::Client(client) => client.run().await,
+ #[cfg(feature = "server")]
Self::Server(server) => server.run().await,
}
}