From a2041a3d337afdc236d3c323957c0d581d32234a Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 24 Aug 2026 18:39:12 +0200 Subject: Add hosts command, info shows current host+fingerprint, disconnect-before-connect, default port 11525 --- src/bin/client/database.rs | 12 ++++++++++++ src/bin/client/repl.rs | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'src/bin/client') diff --git a/src/bin/client/database.rs b/src/bin/client/database.rs index 55051fb..e1fa42d 100644 --- a/src/bin/client/database.rs +++ b/src/bin/client/database.rs @@ -104,3 +104,15 @@ pub fn forget_host(conn: &Connection, host: &str) -> Result<(), rusqlite::Error> conn.execute("DELETE FROM credentials WHERE host = ?1", [host])?; Ok(()) } + +/// List all remembered hosts with their fingerprints. +pub fn get_all_hosts(conn: &Connection) -> Vec<(String, Option)> { + let mut stmt = conn + .prepare("SELECT host, fingerprint FROM hosts ORDER BY last_used DESC") + .unwrap(); + let rows = stmt.query_map([], |row| { + Ok((row.get(0)?, row.get(1)?)) + }) + .unwrap(); + rows.filter_map(|r| r.ok()).collect() +} diff --git a/src/bin/client/repl.rs b/src/bin/client/repl.rs index 40b267e..dd55acc 100644 --- a/src/bin/client/repl.rs +++ b/src/bin/client/repl.rs @@ -273,11 +273,15 @@ impl ClientState { } } "connect" => { + if self.stream.is_some() { + println!("\nAlready connected. Disconnect first."); + continue 'outer; + } let addr_str = if parts.len() < 2 { if let Some(h) = &self.addr { h.clone() } else { - println!("\nNo host specified and no previous connection. Usage: connect :"); + println!("\nNo host specified. Usage: connect :"); continue 'outer; } } else { @@ -590,6 +594,20 @@ impl ClientState { ), Err(e) => println!("\nFailed to forget host: {}", e), } + } + "hosts" => { + let hosts = database::get_all_hosts(&self.conn); + if hosts.is_empty() { + println!("\nNo remembered hosts."); + } else { + println!("\nRemembered hosts:"); + for (host, fp) in &hosts { + match fp { + Some(fp) => println!(" {} - {}", host, fp), + None => println!(" {} - (no fingerprint)", host), + } + } + } } _ => help(), } @@ -752,6 +770,7 @@ fn get_commands() -> Vec { "help".to_string(), "quit".to_string(), "forget-host".to_string(), + "hosts".to_string(), ] } -- cgit v1.2.3