Move relay_server into a subcommand

This commit is contained in:
Tangent 128 2018-04-11 01:39:28 -04:00
parent f3aa76243f
commit 98f7f446f9
3 changed files with 24 additions and 9 deletions

1
src/commands/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod relay;

View File

@ -1,8 +1,3 @@
extern crate futures;
extern crate hyper;
extern crate webmetro;
use std::env::args;
use std::io::ErrorKind;
use std::net::ToSocketAddrs;
use std::sync::{
@ -10,6 +5,7 @@ use std::sync::{
Mutex
};
use clap::{App, Arg, ArgMatches, SubCommand};
use futures::{
Future,
Stream,
@ -112,8 +108,19 @@ impl Service for RelayServer {
}
}
pub fn main() {
pub fn args() -> App<'static, 'static> {
SubCommand::with_name("relay")
.about("Hosts an HTTP-based relay server")
.arg(Arg::with_name("listen")
.help("The address:port to listen to")
.required(true))
}
pub fn run(args: &ArgMatches) {
let single_channel = Channel::new();
let addr = args().nth(1).expect("Need binding address+port").to_socket_addrs().unwrap().next().unwrap();
let addr_str = args.value_of("listen").unwrap();
let addr = addr_str.to_socket_addrs().expect("parsing bind address").next().expect("resolving bind address");
Http::new().bind(&addr, move || Ok(RelayServer(single_channel.clone()))).unwrap().run().unwrap();
}

View File

@ -1,7 +1,12 @@
#[macro_use]
extern crate clap;
#[macro_use] extern crate clap;
extern crate futures;
extern crate hyper;
extern crate webmetro;
mod commands;
use clap::{App, AppSettings};
use commands::{relay};
fn main() {
let args = App::new("webmetro")
@ -9,9 +14,11 @@ fn main() {
.about("Utilities for broadcasting & relaying live WebM video/audio streams")
.setting(AppSettings::SubcommandRequired)
.setting(AppSettings::VersionlessSubcommands)
.subcommand(relay::args())
.get_matches();
match args.subcommand() {
("relay", Some(sub_args)) => relay::run(sub_args),
_ => {}
}
}