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/client/sync.rs | |
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/client/sync.rs')
-rw-r--r-- | src/command/client/sync.rs | 59 |
1 files changed, 54 insertions, 5 deletions
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?, |