From a036e7eb46886ff7fe88255ae26c327f63ec4bfa Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 1 Nov 2026 16:26:21 +0100 Subject: v3.3.0: keep client.db in the XDG data dir, add -d/--data-dir --- src/bin/client/repl.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/bin/client/repl.rs') diff --git a/src/bin/client/repl.rs b/src/bin/client/repl.rs index bf02c8d..1debff1 100644 --- a/src/bin/client/repl.rs +++ b/src/bin/client/repl.rs @@ -43,11 +43,9 @@ pub struct ClientState { } impl ClientState { - pub fn new() -> Self { - let conn = rusqlite::Connection::open( - std::env::var("CLIENT_DB").unwrap_or_else(|_| "client.db".to_string()), - ) - .unwrap(); + pub fn new(db_path: &std::path::Path) -> Result { + let conn = rusqlite::Connection::open(db_path) + .map_err(|error| format!("cannot open {}: {error}", db_path.display()))?; database::init_db(&conn); let default_ip = "127.0.0.1".to_string(); let default_port = 11525; @@ -55,7 +53,7 @@ impl ClientState { let default_host = format!("{}:{}", default_ip, default_port); let addr = last_host.or(Some(default_host)); - Self { + Ok(Self { stream: None, conn, addr, @@ -66,7 +64,7 @@ impl ClientState { prompt_text: String::new(), terminal_size: crossterm::terminal::size().unwrap_or((MIN_COLUMNS, MIN_ROWS)), size_warned: None, - } + }) } pub fn connect_to(&mut self, addr: &str) { -- cgit v1.2.3