Skip to content

Commit

Permalink
Add atuin status (atuinsh#830)
Browse files Browse the repository at this point in the history
Useful for debugging, checking the state of things, and for if you
forget your username!
  • Loading branch information
ellie authored Mar 30, 2023
1 parent ca5e58a commit 0d16a11
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions atuin-common/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub struct IndexResponse {
#[derive(Debug, Serialize, Deserialize)]
pub struct StatusResponse {
pub count: i64,
pub username: String,
pub deleted: Vec<String>,
}

Expand Down
6 changes: 5 additions & 1 deletion atuin-server/src/handlers/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ pub async fn status<DB: Database>(
},
};

Ok(Json(StatusResponse { count, deleted }))
Ok(Json(StatusResponse {
count,
deleted,
username: user.username,
}))
}
4 changes: 4 additions & 0 deletions src/command/client/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -32,6 +33,8 @@ pub enum Cmd {
#[arg(long)]
base64: bool,
},

Status,
}

impl Cmd {
Expand All @@ -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")?;
Expand Down
35 changes: 35 additions & 0 deletions src/command/client/sync/status.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit 0d16a11

Please sign in to comment.