Add beginning of web server for the serve subcommand (#159)
This commit is contained in:
parent
b11b9b909c
commit
71a30fe69f
2 changed files with 18 additions and 7 deletions
|
@ -4,8 +4,9 @@ version = "0.4.0"
|
||||||
authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexander@mozilla.com>"]
|
authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexander@mozilla.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rusqlite = "0.8.0"
|
|
||||||
clap = "2.19.3"
|
clap = "2.19.3"
|
||||||
|
nickel = "0.9.0"
|
||||||
|
rusqlite = "0.8.0"
|
||||||
|
|
||||||
[dependencies.edn]
|
[dependencies.edn]
|
||||||
path = "edn"
|
path = "edn"
|
||||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -9,9 +9,15 @@
|
||||||
// specific language governing permissions and limitations under the License.
|
// specific language governing permissions and limitations under the License.
|
||||||
|
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
#[macro_use] extern crate nickel;
|
||||||
|
|
||||||
|
use nickel::{Nickel, HttpRouter};
|
||||||
|
|
||||||
use clap::{App, Arg, SubCommand, AppSettings};
|
use clap::{App, Arg, SubCommand, AppSettings};
|
||||||
|
|
||||||
|
use std::u16;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = App::new("Mentat").setting(AppSettings::ArgRequiredElseHelp);
|
let app = App::new("Mentat").setting(AppSettings::ArgRequiredElseHelp);
|
||||||
let matches = app.subcommand(SubCommand::with_name("serve")
|
let matches = app.subcommand(SubCommand::with_name("serve")
|
||||||
|
@ -24,7 +30,7 @@ fn main() {
|
||||||
.long("database")
|
.long("database")
|
||||||
.value_name("FILE")
|
.value_name("FILE")
|
||||||
.help("Path to the Mentat database to serve")
|
.help("Path to the Mentat database to serve")
|
||||||
.default_value("temp.db")
|
.default_value("")
|
||||||
.takes_value(true))
|
.takes_value(true))
|
||||||
.arg(Arg::with_name("port")
|
.arg(Arg::with_name("port")
|
||||||
.short("p")
|
.short("p")
|
||||||
|
@ -36,10 +42,14 @@ fn main() {
|
||||||
.get_matches();
|
.get_matches();
|
||||||
if let Some(ref matches) = matches.subcommand_matches("serve") {
|
if let Some(ref matches) = matches.subcommand_matches("serve") {
|
||||||
let debug = matches.is_present("debug");
|
let debug = matches.is_present("debug");
|
||||||
println!("This doesn't work yet, but it will eventually serve the following database: {} \
|
let port = u16::from_str(matches.value_of("port").unwrap()).expect("Port must be an integer");
|
||||||
on port: {}. Debugging={}",
|
if debug {
|
||||||
matches.value_of("database").unwrap(),
|
println!("This doesn't do anything yet, but it will eventually serve up the following database: {}",
|
||||||
matches.value_of("port").unwrap(),
|
matches.value_of("database").unwrap());
|
||||||
debug);
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue