Add beginning of web server for the serve subcommand (#159)

This commit is contained in:
Brian Grinstead 2017-01-13 11:46:00 -08:00 committed by GitHub
parent b11b9b909c
commit 71a30fe69f
2 changed files with 18 additions and 7 deletions

View file

@ -4,8 +4,9 @@ version = "0.4.0"
authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexander@mozilla.com>"]
[dependencies]
rusqlite = "0.8.0"
clap = "2.19.3"
nickel = "0.9.0"
rusqlite = "0.8.0"
[dependencies.edn]
path = "edn"

View file

@ -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");
}
}