summaryrefslogtreecommitdiffstats
path: root/src/bin/client/repl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/client/repl.rs')
-rw-r--r--src/bin/client/repl.rs12
1 files changed, 5 insertions, 7 deletions
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 {
43} 43}
44 44
45impl ClientState { 45impl ClientState {
46 pub fn new() -> Self { 46 pub fn new(db_path: &std::path::Path) -> Result<Self, String> {
47 let conn = rusqlite::Connection::open( 47 let conn = rusqlite::Connection::open(db_path)
48 std::env::var("CLIENT_DB").unwrap_or_else(|_| "client.db".to_string()), 48 .map_err(|error| format!("cannot open {}: {error}", db_path.display()))?;
49 )
50 .unwrap();
51 database::init_db(&conn); 49 database::init_db(&conn);
52 let default_ip = "127.0.0.1".to_string(); 50 let default_ip = "127.0.0.1".to_string();
53 let default_port = 11525; 51 let default_port = 11525;
@@ -55,7 +53,7 @@ impl ClientState {
55 let default_host = format!("{}:{}", default_ip, default_port); 53 let default_host = format!("{}:{}", default_ip, default_port);
56 let addr = last_host.or(Some(default_host)); 54 let addr = last_host.or(Some(default_host));
57 55
58 Self { 56 Ok(Self {
59 stream: None, 57 stream: None,
60 conn, 58 conn,
61 addr, 59 addr,
@@ -66,7 +64,7 @@ impl ClientState {
66 prompt_text: String::new(), 64 prompt_text: String::new(),
67 terminal_size: crossterm::terminal::size().unwrap_or((MIN_COLUMNS, MIN_ROWS)), 65 terminal_size: crossterm::terminal::size().unwrap_or((MIN_COLUMNS, MIN_ROWS)),
68 size_warned: None, 66 size_warned: None,
69 } 67 })
70 } 68 }
71 69
72 pub fn connect_to(&mut self, addr: &str) { 70 pub fn connect_to(&mut self, addr: &str) {