Skip to content

Commit 282a3d0

Browse files
committed
Added cli options
1 parent 7c19558 commit 282a3d0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ env_logger = "0.7"
1111
futures = "0.3.1"
1212
tokio = { version="0.2", features=["full"] }
1313
actix-cors="0.2.0"
14+
clap = "2.33.3"
1415

1516
[dependencies.serde]
1617
version = "1.0"

src/main.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::task::{Context, Poll};
1616
use actix_cors::Cors;
1717
use actix_web::web::{Bytes, Data, Path};
1818
use actix_web::{get, post, web, App, Error, HttpResponse, HttpServer, Responder};
19+
use clap::{crate_version, clap_app};
1920
use futures::Stream;
2021
use serde::{Deserialize, Serialize};
2122
use tokio::sync::broadcast::{channel, Receiver, Sender};
@@ -25,8 +26,17 @@ use tokio::sync::broadcast::{channel, Receiver, Sender};
2526
async fn main() -> std::io::Result<()> {
2627
env_logger::init();
2728

29+
let matches = clap_app!(myapp =>
30+
(version: crate_version!())
31+
(author: "Ronak B.")
32+
(about: "A sse-based pubsub with different channels")
33+
(@arg HOST: --host +takes_value "Address to host on")
34+
(@arg PORT: --port +takes_value "Port to host on")
35+
).get_matches();
36+
2837
let data = BroadcasterMap::create();
2938

39+
3040
HttpServer::new(move || {
3141
App::new()
3242
.wrap(
@@ -39,7 +49,9 @@ async fn main() -> std::io::Result<()> {
3949
.service(new_client)
4050
.service(broadcast)
4151
})
42-
.bind("127.0.0.1:8080")?
52+
.bind(format!("{}:{}",
53+
matches.value_of("HOST").unwrap_or("127.0.0.1"),
54+
matches.value_of("PORT").unwrap_or("8080")))?
4355
.run()
4456
.await
4557
}

0 commit comments

Comments
 (0)