diff options
author | Conrad Ludgate <conrad.ludgate@truelayer.com> | 2022-04-22 21:14:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-22 20:14:23 +0000 |
commit | 7436e4ff651b64d4019a59d04c30c414ae220403 (patch) | |
tree | 3d5e35df1bce075ae04be63d76f9edc8cc17c6cb /src/command | |
parent | 508d4f476157384b0d454bee3dd6e9256560561b (diff) |
feature-flags (#328)
* use feature flags
* fmt
* fix features
* update ci
* fmt
Co-authored-by: Ellie Huxtable <ellie@elliehuxtable.com>
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/client.rs | 44 | ||||
-rw-r--r-- | src/command/client/history.rs | 11 | ||||
-rw-r--r-- | src/command/client/sync.rs | 59 | ||||
-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.rs | 4 |
7 files changed, 77 insertions, 41 deletions
diff --git a/src/command/client.rs b/src/command/client.rs index fd65345c8..4858e2ba1 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 994cbfd55..4f96c444b 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 f8bfd5e26..8e80310a6 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 efc9c5903..efc9c5903 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 a7e9541d8..a7e9541d8 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 2c60a2e98..2c60a2e98 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 3a3ed393d..953b76bad 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, } } |