diff options
Diffstat (limited to 'src/command/client')
-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 |
5 files changed, 63 insertions, 7 deletions
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 |