From 0d16a113c5fc9da7bb75f8c771714f4e00449f19 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Thu, 30 Mar 2023 06:45:49 +0100 Subject: Add `atuin status` (#830) Useful for debugging, checking the state of things, and for if you forget your username! --- src/command/client/sync.rs | 4 ++++ src/command/client/sync/status.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/command/client/sync/status.rs (limited to 'src/command') diff --git a/src/command/client/sync.rs b/src/command/client/sync.rs index c485e240..419177a5 100644 --- a/src/command/client/sync.rs +++ b/src/command/client/sync.rs @@ -6,6 +6,7 @@ use atuin_client::{database::Database, settings::Settings}; mod login; mod logout; mod register; +mod status; #[derive(Subcommand)] #[command(infer_subcommands = true)] @@ -32,6 +33,8 @@ pub enum Cmd { #[arg(long)] base64: bool, }, + + Status, } impl Cmd { @@ -41,6 +44,7 @@ impl Cmd { Self::Login(l) => l.run(&settings).await, Self::Logout => logout::run(&settings), Self::Register(r) => r.run(&settings).await, + Self::Status => status::run(&settings, db).await, Self::Key { base64 } => { use atuin_client::encryption::{encode_key, load_key}; let key = load_key(&settings).wrap_err("could not load encryption key")?; diff --git a/src/command/client/sync/status.rs b/src/command/client/sync/status.rs new file mode 100644 index 00000000..b3e73e8e --- /dev/null +++ b/src/command/client/sync/status.rs @@ -0,0 +1,35 @@ +use atuin_client::{ + api_client, database::Database, encryption::load_encoded_key, settings::Settings, +}; +use colored::Colorize; +use eyre::Result; + +pub async fn run(settings: &Settings, db: &impl Database) -> Result<()> { + let client = api_client::Client::new( + &settings.sync_address, + &settings.session_token, + load_encoded_key(settings)?, + )?; + + let status = client.status().await?; + let last_sync = Settings::last_sync()?; + let local_count = db.history_count().await?; + + println!("{}", "[Local]".green()); + + if settings.auto_sync { + println!("Sync frequency: {}", settings.sync_frequency); + println!("Last sync: {last_sync}"); + } + + println!("History count: {local_count}\n"); + + if settings.auto_sync { + println!("{}", "[Remote]".green()); + println!("Address: {}", settings.sync_address); + println!("Username: {}", status.username); + println!("History count: {}", status.count); + } + + Ok(()) +} -- cgit v1.3.1