summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 2c7905f..68d83f7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,12 +1,16 @@
+extern crate linoquotes_gamma;
+
#[macro_use]
extern crate log;
extern crate env_logger;
extern crate clap;
-extern crate linoquotes_gamma;
+extern crate rusqlite;
use clap::{App, Arg};
fn main() {
+ env_logger::init().unwrap();
+
let matches = App::new("linoquotes")
.version("3.0.0")
.author("Kjetil Ørbekk")
@@ -15,6 +19,13 @@ fn main() {
.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
@@ -23,7 +34,22 @@ fn main() {
.parse::<u16>()
.expect("port number");
- env_logger::init().unwrap();
+ 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()
+ };
+
+ linoquotes_gamma::data::init(&connection).unwrap();
+
+ if use_test_db {
+ linoquotes_gamma::data::populate_test_db(&connection).unwrap();
+ }
+
info!("Starting");
linoquotes_gamma::server::serve(port);
}