diff --git a/Cargo.toml b/Cargo.toml index ce71e598..ed3d80f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,9 @@ version = "0.4.0" authors = ["Richard Newman ", "Nicholas Alexander "] [dependencies] -rusqlite = "0.8.0" clap = "2.19.3" +nickel = "0.9.0" +rusqlite = "0.8.0" [dependencies.edn] path = "edn" diff --git a/src/main.rs b/src/main.rs index fdbbf515..ebf34784 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,9 +9,15 @@ // specific language governing permissions and limitations under the License. extern crate clap; +#[macro_use] extern crate nickel; + +use nickel::{Nickel, HttpRouter}; use clap::{App, Arg, SubCommand, AppSettings}; +use std::u16; +use std::str::FromStr; + fn main() { let app = App::new("Mentat").setting(AppSettings::ArgRequiredElseHelp); let matches = app.subcommand(SubCommand::with_name("serve") @@ -24,7 +30,7 @@ fn main() { .long("database") .value_name("FILE") .help("Path to the Mentat database to serve") - .default_value("temp.db") + .default_value("") .takes_value(true)) .arg(Arg::with_name("port") .short("p") @@ -36,10 +42,14 @@ fn main() { .get_matches(); if let Some(ref matches) = matches.subcommand_matches("serve") { let debug = matches.is_present("debug"); - println!("This doesn't work yet, but it will eventually serve the following database: {} \ - on port: {}. Debugging={}", - matches.value_of("database").unwrap(), - matches.value_of("port").unwrap(), - debug); + let port = u16::from_str(matches.value_of("port").unwrap()).expect("Port must be an integer"); + if debug { + println!("This doesn't do anything yet, but it will eventually serve up the following database: {}", + matches.value_of("database").unwrap()); + } + + let mut server = Nickel::new(); + server.get("/", middleware!("This doesn't do anything yet")); + server.listen(("127.0.0.1", port)).expect("Failed to launch server"); } }