summaryrefslogtreecommitdiffstats
path: root/src/bin/client/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/client/main.rs')
-rw-r--r--src/bin/client/main.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/bin/client/main.rs b/src/bin/client/main.rs
index 9018026..3407380 100644
--- a/src/bin/client/main.rs
+++ b/src/bin/client/main.rs
@@ -5,10 +5,21 @@ mod repl;
5mod tls; 5mod tls;
6 6
7use repl::ClientState; 7use repl::ClientState;
8use zagan_bet::client::paths::{database_path, default_data_dir, parse_args, USAGE};
8 9
9fn main() { 10fn main() {
10 let args: Vec<String> = std::env::args().collect(); 11 let args = match parse_args(std::env::args().skip(1)) {
11 let unsafe_mode = args.iter().any(|arg| arg == "--unsafe"); 12 Ok(args) => args,
13 Err(message) => {
14 eprintln!("{message}");
15 std::process::exit(2);
16 }
17 };
18
19 if args.help {
20 println!("{USAGE}");
21 return;
22 }
12 23
13 // Every game board is drawn in place, so refuse a terminal that cannot fit 24 // Every game board is drawn in place, so refuse a terminal that cannot fit
14 // them before touching the network or the terminal mode. 25 // them before touching the network or the terminal mode.
@@ -25,19 +36,33 @@ fn main() {
25 std::process::exit(1); 36 std::process::exit(1);
26 } 37 }
27 38
28 if unsafe_mode { 39 if args.unsafe_mode {
29 println!("WARNING: Running in UNSAFE mode - certificate verification disabled!"); 40 println!("WARNING: Running in UNSAFE mode - certificate verification disabled!");
30 } 41 }
31 42
32 connection::set_unsafe_mode(unsafe_mode); 43 connection::set_unsafe_mode(args.unsafe_mode);
33 44
34 let mut state = ClientState::new(); 45 let data_dir = args.data_dir.unwrap_or_else(default_data_dir);
46 if let Err(error) = std::fs::create_dir_all(&data_dir) {
47 eprintln!("Cannot create {}: {error}", data_dir.display());
48 std::process::exit(1);
49 }
50 let db_path = database_path(&data_dir);
51
52 let mut state = match ClientState::new(&db_path) {
53 Ok(state) => state,
54 Err(error) => {
55 eprintln!("{error}");
56 std::process::exit(1);
57 }
58 };
35 if let Some(host) = state.addr.clone() { 59 if let Some(host) = state.addr.clone() {
36 state.connect_to(&host); 60 state.connect_to(&host);
37 } 61 }
38 62
39 println!("Welcome to Zagan-Bet Client!"); 63 println!("Welcome to Zagan-Bet Client!");
40 println!("Type 'help' for available commands."); 64 println!("Type 'help' for available commands.");
65 println!("Data: {}", db_path.display());
41 66
42 state.run(); 67 state.run();
43} 68}