mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 00:47:53 +00:00
CLI option for port number
This commit is contained in:
1 parent
44dae5d64a
commit
4ac33dcef0
3 files changed
+58
-4
No files matched your search
Generated
+27
@@ -2,6 +2,7 @@
|
||||
name = "trumpet"
|
||||
version = "0.0.2"
|
||||
dependencies = [
|
||||
"clap 1.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hound 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"iron 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -22,6 +23,11 @@ dependencies = [
|
||||
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "0.3.3"
|
||||
@@ -38,6 +44,17 @@ dependencies = [
|
||||
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "1.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ansi_term 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strsim 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"vec_map 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "conduit-mime-types"
|
||||
version = "0.7.3"
|
||||
@@ -358,6 +375,11 @@ dependencies = [
|
||||
"log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "tempdir"
|
||||
version = "0.3.4"
|
||||
@@ -454,6 +476,11 @@ dependencies = [
|
||||
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.5"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
name = "trumpet"
|
||||
|
||||
[dependencies]
|
||||
clap = "1.5.*" # CLI parsing.
|
||||
#cpal = "*" # Hardware audio output (for testing); works well with Hound.
|
||||
hound = "1.1.0" # WAV codec.
|
||||
hyper = "0.7.*"
|
||||
|
||||
+30
-4
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2015 Brandon Thomas <bt@brand.io>
|
||||
|
||||
extern crate clap;
|
||||
extern crate crypto;
|
||||
extern crate hound;
|
||||
extern crate iron;
|
||||
@@ -14,6 +15,7 @@ pub mod handlers;
|
||||
pub mod logger;
|
||||
pub mod words;
|
||||
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use iron::prelude::*;
|
||||
use router::Router;
|
||||
|
||||
@@ -25,10 +27,34 @@ use logger::SimpleLogger;
|
||||
|
||||
fn main() {
|
||||
SimpleLogger::init().unwrap();
|
||||
start_server();
|
||||
|
||||
let matches = App::new("trumpet")
|
||||
.arg(Arg::with_name("PORT")
|
||||
.short("p")
|
||||
.long("port")
|
||||
.help("Sets the port the server listens on.")
|
||||
.takes_value(true)
|
||||
.required(false))
|
||||
.get_matches();
|
||||
|
||||
let port = get_port(&matches, 9000);
|
||||
|
||||
start_server(port);
|
||||
}
|
||||
|
||||
fn start_server() {
|
||||
fn get_port(matches: &ArgMatches, default_port: u16) -> u16 {
|
||||
match matches.value_of("PORT") {
|
||||
None => default_port,
|
||||
Some(port) => {
|
||||
match port.parse::<u16>() {
|
||||
Err(_) => default_port,
|
||||
Ok(p) => p,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn start_server(port: u16) {
|
||||
let audio_path = "./sounds/trump";
|
||||
let file_path = "./web";
|
||||
let index = "index.html";
|
||||
@@ -44,7 +70,7 @@ fn start_server() {
|
||||
router.get("/", FileServerHandler::new(file_path, index));
|
||||
router.get("/assets/:filename", FileServerHandler::new(file_path, index));
|
||||
|
||||
info!("Starting server...");
|
||||
Iron::new(router).http("0.0.0.0:9000").unwrap();
|
||||
info!("Starting server on port {}...", port);
|
||||
Iron::new(router).http(("0.0.0.0", port)).unwrap();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user