From 7991de22670799f418fdd0a806d0c98b7c2532b1 Mon Sep 17 00:00:00 2001 From: yuanyuyuan Date: Thu, 14 Sep 2023 20:36:12 +0800 Subject: [PATCH] Add missing options of z_pub_shm_thr.rs --- examples/examples/z_pub_shm_thr.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/examples/examples/z_pub_shm_thr.rs b/examples/examples/z_pub_shm_thr.rs index 44c2c1fc2b..2da0cf102c 100644 --- a/examples/examples/z_pub_shm_thr.rs +++ b/examples/examples/z_pub_shm_thr.rs @@ -47,18 +47,44 @@ fn parse_args() -> (Config, usize, usize) { Arg::from_usage("-s, --shared-memory=[MB] 'shared memory size in MBytes'") .default_value("32"), ) + .arg( + Arg::from_usage("-m, --mode=[MODE] 'The zenoh session mode (peer by default).") + .possible_values(["peer", "client"]), + ) .arg(Arg::from_usage( "-e, --connect=[ENDPOINT]... 'Endpoints to connect to.'", )) + .arg(Arg::from_usage( + "-l, --listen=[ENDPOINT]... 'Endpoints to listen on.'", + )) .arg(Arg::from_usage( "-c, --config=[FILE] 'A configuration file.'", )) .arg(Arg::from_usage( " 'Sets the size of the payload to publish'", )) + .arg(Arg::from_usage( + "--no-multicast-scouting 'Disable the multicast-based scouting mechanism.'", + )) .get_matches(); - let config = Config::default(); + let mut config = if let Some(conf_file) = args.value_of("config") { + Config::from_file(conf_file).unwrap() + } else { + Config::default() + }; + if let Some(Ok(mode)) = args.value_of("mode").map(|mode| mode.parse()) { + config.set_mode(Some(mode)).unwrap(); + } + if let Some(values) = args.values_of("connect") { + config.connect.endpoints = values.map(|v| v.parse().unwrap()).collect(); + } + if let Some(values) = args.values_of("listen") { + config.listen.endpoints = values.map(|v| v.parse().unwrap()).collect(); + } + if args.is_present("no-multicast-scouting") { + config.scouting.multicast.set_enabled(Some(false)).unwrap(); + } let sm_size = args .value_of("shared-memory") .unwrap()