From 5df3d4888d0b696dd666ce2de8f2b6a11c74a0ff Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 19 Oct 2017 23:43:45 +0200 Subject: [PATCH] Turn homeserver url and room into command line params for hello_world examples --- examples/hello_world.rs | 17 ++++++++++++++--- examples/hello_world_await.rs | 18 +++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index dc62b7a2..e444eeee 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -9,6 +9,8 @@ extern crate tokio_core; extern crate url; use std::convert::TryFrom; +use std::env; +use std::process::exit; use futures::Future; use ruma_client::Client; @@ -41,12 +43,13 @@ macro_rules! clone { fn hello_world( tokio_handle: &Handle, homeserver_url: Url, + room: String, ) -> impl Future + 'static { let client = Client::https(tokio_handle, homeserver_url, None).unwrap(); client.register_guest().and_then(clone!(client => move |_| { r0::alias::get_alias::call(client, r0::alias::get_alias::Request { - room_alias: RoomAliasId::try_from("#ruma-client-test:matrix.org").unwrap(), + room_alias: RoomAliasId::try_from(&room[..]).unwrap(), }) })).and_then(clone!(client => move |response| { let room_id = response.room_id; @@ -69,9 +72,17 @@ fn hello_world( } fn main() { + let (homeserver_url, room) = match (env::args().nth(1), env::args().nth(2)) { + (Some(a), Some(b)) => (a, b), + _ => { + eprintln!("Usage: {} ", env::args().next().unwrap()); + exit(1) + } + }; + let mut core = Core::new().unwrap(); let handle = core.handle(); - let server = Url::parse("https://matrix.org/").unwrap(); + let server = Url::parse(&homeserver_url).unwrap(); - core.run(hello_world(&handle, server)).unwrap(); + core.run(hello_world(&handle, server, room)).unwrap(); } diff --git a/examples/hello_world_await.rs b/examples/hello_world_await.rs index b0167d64..cd5dd3f5 100644 --- a/examples/hello_world_await.rs +++ b/examples/hello_world_await.rs @@ -11,6 +11,8 @@ extern crate tokio_core; extern crate url; use std::convert::TryFrom; +use std::env; +use std::process::exit; use futures::prelude::*; use ruma_client::Client; @@ -24,6 +26,7 @@ use url::Url; fn hello_world( tokio_handle: &Handle, homeserver_url: Url, + room: String, ) -> impl Future + 'static { let client = Client::https(tokio_handle, homeserver_url, None).unwrap(); @@ -33,7 +36,7 @@ fn hello_world( let response = await!(r0::alias::get_alias::call( client.clone(), r0::alias::get_alias::Request { - room_alias: RoomAliasId::try_from("#ruma-client-test:matrix.org").unwrap(), + room_alias: RoomAliasId::try_from(&room[..]).unwrap(), } ))?; @@ -65,9 +68,18 @@ fn hello_world( } fn main() { + let (homeserver_url, room) = match (env::args().nth(1), env::args().nth(2)) { + (Some(a), Some(b)) => (a, b), + _ => { + eprintln!("Usage: {} ", env::args().next().unwrap()); + exit(1) + } + }; + + let mut core = Core::new().unwrap(); let handle = core.handle(); - let server = Url::parse("https://matrix.org/").unwrap(); + let server = Url::parse(&homeserver_url).unwrap(); - core.run(hello_world(&handle, server)).unwrap(); + core.run(hello_world(&handle, server, room)).unwrap(); }