diff options
Diffstat (limited to '')
| -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 |
4 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?, 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 |
