summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2023-03-30 06:45:49 +0100
committerGitHub <noreply@github.com>2023-03-30 06:45:49 +0100
commit0d16a113c5fc9da7bb75f8c771714f4e00449f19 (patch)
tree87e7bb841f5e9cc2ffa0dd3d5492c0a4648b4db7
parentca5e58ad0191fed6000433c1e56f7d0c555653e6 (diff)
Add `atuin status` (#830)
Useful for debugging, checking the state of things, and for if you forget your username!
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml1
-rw-r--r--atuin-common/src/api.rs1
-rw-r--r--atuin-server/src/handlers/status.rs6
-rw-r--r--src/command/client/sync.rs4
-rw-r--r--src/command/client/sync/status.rs35
6 files changed, 58 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index faa08cfd..264648bb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -80,6 +80,7 @@ dependencies = [
"chrono",
"clap",
"clap_complete",
+ "colored",
"crossbeam-channel",
"crossterm",
"directories",
@@ -384,6 +385,17 @@ dependencies = [
]
[[package]]
+name = "colored"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
+dependencies = [
+ "atty",
+ "lazy_static",
+ "winapi",
+]
+
+[[package]]
name = "config"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 27adc77d..af3867b7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -75,6 +75,7 @@ tiny-bip39 = "1"
futures-util = "0.3"
ratatui = "0.20.1"
fuzzy-matcher = "0.3.7"
+colored = "2.0.0"
[dependencies.tracing-subscriber]
version = "0.3"
diff --git a/atuin-common/src/api.rs b/atuin-common/src/api.rs
index 6f18d18c..e9809329 100644
--- a/atuin-common/src/api.rs
+++ b/atuin-common/src/api.rs
@@ -69,6 +69,7 @@ pub struct IndexResponse {
#[derive(Debug, Serialize, Deserialize)]
pub struct StatusResponse {
pub count: i64,
+ pub username: String,
pub deleted: Vec<String>,
}
diff --git a/atuin-server/src/handlers/status.rs b/atuin-server/src/handlers/status.rs
index 090d2c3d..351c2dd2 100644
--- a/atuin-server/src/handlers/status.rs
+++ b/atuin-server/src/handlers/status.rs
@@ -31,5 +31,9 @@ pub async fn status<DB: Database>(
},
};
- Ok(Json(StatusResponse { count, deleted }))
+ Ok(Json(StatusResponse {
+ count,
+ deleted,
+ username: user.username,
+ }))
}
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(())
+}