From 55a773304461a2c261823c6d4bab38b66e95dc07 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 17 Jun 2017 10:17:31 -0400 Subject: Add port number flag. --- Cargo.lock | 1 + Cargo.toml | 1 + src/bin/main.rs | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a2aac1e..bd8c576 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,6 +3,7 @@ name = "systemhttp" version = "0.1.0" dependencies = [ "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.24.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "horrorshow 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "iron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index e19c8c2..2109fef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ regex = "*" sqlite = "*" rust-crypto = "*" base64 = "*" +clap = "*" diff --git a/src/bin/main.rs b/src/bin/main.rs index b54c4c0..94bdd71 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -4,9 +4,22 @@ extern crate log; extern crate systemhttp; extern crate env_logger; +#[macro_use] +extern crate clap; fn main() { + let matches = clap_app!( + systemhttpd => + (version: "0.1") + (author: "Kjetil Ørbekk") + (about: "A systemd web frontend") + (@arg PORT: -p --port +takes_value "Port to serve on")) + .get_matches(); + + let port = matches.value_of("PORT").unwrap_or("8080") + .parse::().expect("port number"); + env_logger::init().unwrap(); - let _server = systemhttp::server::serve(8080).unwrap(); - println!("Serving on {}", 8080); + let _server = systemhttp::server::serve(port).unwrap(); + println!("Serving on {}", port); } -- cgit v1.2.3