diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-01 16:26:21 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-01 16:26:21 +0100 |
| commit | a036e7eb46886ff7fe88255ae26c327f63ec4bfa (patch) | |
| tree | 494911ce0d394041c00eff276632e4f5f48f3fb5 /src/bin/client/repl.rs | |
| parent | v3.2.0: straight and split bets anywhere on the felt; add history command (diff) | |
| download | zagan-bet-a036e7eb46886ff7fe88255ae26c327f63ec4bfa.tar.gz zagan-bet-a036e7eb46886ff7fe88255ae26c327f63ec4bfa.zip | |
v3.3.0: keep client.db in the XDG data dir, add -d/--data-dir
Diffstat (limited to '')
| -rw-r--r-- | src/bin/client/repl.rs | 12 |
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 | ||
| 45 | impl ClientState { | 45 | impl 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) { |
