Skip to content

Commit 0549678

Browse files
reuse zenoh-examples common arguments parsing in zenoh-ext examples (#1679)
1 parent 9640d22 commit 0549678

File tree

4 files changed

+4
-64
lines changed

4 files changed

+4
-64
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ zenoh-link-commons = { version = "1.0.0-dev", path = "io/zenoh-link-commons" }
223223
zenoh = { version = "1.0.0-dev", path = "zenoh", default-features = false }
224224
zenoh-runtime = { version = "1.0.0-dev", path = "commons/zenoh-runtime" }
225225
zenoh-task = { version = "1.0.0-dev", path = "commons/zenoh-task" }
226+
zenoh-examples = { version = "1.0.0-dev", path = "examples" }
226227

227228
[profile.dev]
228229
debug = true

zenoh-ext/examples/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ futures = { workspace = true }
3737
zenoh = { workspace = true, features = ["unstable", "internal_config"], default-features = false }
3838
clap = { workspace = true, features = ["derive"] }
3939
zenoh-ext = { workspace = true, features = ["unstable"] }
40+
zenoh-examples = { workspace = true }
4041

4142
[dev-dependencies]
4243
zenoh-config = { workspace = true }

zenoh-ext/examples/src/lib.rs

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,4 @@
22
//! See the code in ../examples/
33
//! Check ../README.md for usage.
44
//!
5-
use zenoh::{config::WhatAmI, Config};
6-
7-
#[derive(clap::ValueEnum, Clone, Copy, PartialEq, Eq, Hash, Debug)]
8-
pub enum Wai {
9-
Peer,
10-
Client,
11-
Router,
12-
}
13-
impl core::fmt::Display for Wai {
14-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15-
core::fmt::Debug::fmt(&self, f)
16-
}
17-
}
18-
#[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)]
19-
pub struct CommonArgs {
20-
#[arg(short, long)]
21-
/// A configuration file.
22-
config: Option<String>,
23-
#[arg(short, long)]
24-
/// The Zenoh session mode [default: peer].
25-
mode: Option<Wai>,
26-
#[arg(short = 'e', long)]
27-
/// Endpoints to connect to.
28-
connect: Vec<String>,
29-
#[arg(short, long)]
30-
/// Endpoints to listen on.
31-
listen: Vec<String>,
32-
}
33-
34-
impl From<CommonArgs> for Config {
35-
fn from(value: CommonArgs) -> Self {
36-
(&value).into()
37-
}
38-
}
39-
impl From<&CommonArgs> for Config {
40-
fn from(value: &CommonArgs) -> Self {
41-
let mut config = match &value.config {
42-
Some(path) => Config::from_file(path).unwrap(),
43-
None => Config::default(),
44-
};
45-
match value.mode {
46-
Some(Wai::Peer) => config.set_mode(Some(WhatAmI::Peer)),
47-
Some(Wai::Client) => config.set_mode(Some(WhatAmI::Client)),
48-
Some(Wai::Router) => config.set_mode(Some(WhatAmI::Router)),
49-
None => Ok(None),
50-
}
51-
.unwrap();
52-
if !value.connect.is_empty() {
53-
config
54-
.connect
55-
.endpoints
56-
.set(value.connect.iter().map(|v| v.parse().unwrap()).collect())
57-
.unwrap();
58-
}
59-
if !value.listen.is_empty() {
60-
config
61-
.listen
62-
.endpoints
63-
.set(value.listen.iter().map(|v| v.parse().unwrap()).collect())
64-
.unwrap();
65-
}
66-
config
67-
}
68-
}
5+
pub use zenoh_examples::CommonArgs;

0 commit comments

Comments
 (0)