summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs
index 68d83f7..49f110e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,18 +14,29 @@ fn main() {
let matches = App::new("linoquotes")
.version("3.0.0")
.author("Kjetil Ørbekk")
- .about("Quote db for #linux.no. Run with \
- RUST_LOG=linoquotes_gamma=info to enable logging.")
- .arg(Arg::with_name("port")
- .short("p").long("port").takes_value(true)
- .help("Port to serve on"))
- .arg(Arg::with_name("db_file")
- .long("db_file").takes_value(true)
- .help("Path to sqlite database (use in-memory test \
- database if unset)"))
- .arg(Arg::with_name("use_test_db")
- .long("use_test_db")
- .help("Use in-memory test database"))
+ .about(
+ "Quote db for #linux.no. Run with \
+ RUST_LOG=linoquotes_gamma=info to enable logging.",
+ )
+ .arg(
+ Arg::with_name("port")
+ .short("p")
+ .long("port")
+ .takes_value(true)
+ .help("Port to serve on"),
+ )
+ .arg(
+ Arg::with_name("db_file")
+ .long("db_file")
+ .takes_value(true)
+ .help(
+ "Path to sqlite database (use in-memory test \
+ database if unset)",
+ ),
+ )
+ .arg(Arg::with_name("use_test_db").long("use_test_db").help(
+ "Use in-memory test database",
+ ))
.get_matches();
let port = matches
@@ -36,20 +47,21 @@ fn main() {
let use_test_db = matches.is_present("use_test_db");
let db_file = matches.value_of("db_file");
- let connection = match db_file {
- None => {
- assert!(use_test_db, "--db_file or --use_test_db must be set");
- rusqlite::Connection::open_in_memory().unwrap()
- },
- Some(ref path) => rusqlite::Connection::open(path).unwrap()
+ let state = linoquotes_gamma::server::State {
+ connection: match db_file {
+ None => {
+ assert!(use_test_db, "--db_file or --use_test_db must be set");
+ rusqlite::Connection::open_in_memory().unwrap()
+ }
+ Some(ref path) => rusqlite::Connection::open(path).unwrap(),
+ },
};
- linoquotes_gamma::data::init(&connection).unwrap();
+ linoquotes_gamma::data::init(&state.connection).unwrap();
if use_test_db {
- linoquotes_gamma::data::populate_test_db(&connection).unwrap();
+ linoquotes_gamma::data::populate_test_db(&state.connection).unwrap();
}
- info!("Starting");
- linoquotes_gamma::server::serve(port);
+ linoquotes_gamma::server::serve(state, port);
}