webmetro/src/main.rs

61 lines
1.6 KiB
Rust
Raw Normal View History

2018-04-11 05:39:28 +00:00
#[macro_use] extern crate clap;
extern crate futures;
2018-09-18 06:15:02 +00:00
extern crate http;
extern crate hyper;
2018-09-21 00:58:51 +00:00
extern crate tokio_codec;
extern crate tokio_io;
2018-04-11 05:39:28 +00:00
extern crate webmetro;
mod commands;
use clap::{App, AppSettings};
use futures::prelude::*;
use hyper::rt;
use webmetro::error::WebmetroError;
use commands::{
relay,
2018-04-12 06:03:46 +00:00
filter,
2018-04-15 05:43:23 +00:00
send,
dump
};
2018-04-11 05:50:18 +00:00
fn options() -> App<'static, 'static> {
App::new("webmetro")
.version(crate_version!())
.about("Utilities for broadcasting & relaying live WebM video/audio streams")
2018-04-15 05:43:23 +00:00
.setting(AppSettings::DisableHelpSubcommand)
.setting(AppSettings::VersionlessSubcommands)
2018-04-11 05:50:18 +00:00
.subcommand(relay::options())
2018-04-12 06:03:46 +00:00
.subcommand(filter::options())
2018-04-15 05:43:23 +00:00
.subcommand(send::options())
.subcommand(dump::options())
2018-04-11 05:50:18 +00:00
}
fn main() {
let args = options().get_matches();
match args.subcommand() {
("filter", Some(sub_args)) => { tokio_run(filter::run(sub_args)); },
("relay", Some(sub_args)) => { relay::run(sub_args).unwrap_or_else(handle_error); },
("send", Some(sub_args)) => { tokio_run(send::run(sub_args)); },
("dump", Some(sub_args)) => { dump::run(sub_args).unwrap_or_else(handle_error); },
_ => {
2018-04-11 05:50:18 +00:00
options().print_help().unwrap();
2018-04-11 23:45:02 +00:00
println!("");
}
};
}
fn handle_error(err: WebmetroError) {
eprintln!("Error: {}", err);
}
fn tokio_run<T: IntoFuture<Item=(), Error=WebmetroError> + Send>(task: T)
where T::Future: Send + 'static {
rt::run(task.into_future().map_err(|err| {
handle_error(err);
::std::process::exit(1);
}));
}