tether_utils/tether_topics/
mod.rs

1use clap::Args;
2
3pub mod agent_tree;
4pub mod insights;
5pub mod sampler;
6
7#[derive(Args, Clone)]
8pub struct TopicOptions {
9    #[arg(long = "topic", default_value_t=String::from("#"))]
10    pub topic: String,
11
12    /// Sampler interval, in milliseconds
13    #[arg(long = "sampler.interval", default_value_t = 1000)]
14    pub sampler_interval: u64,
15
16    /// Whether to print message rate and activity graph to the terminal;
17    /// some terminals might break
18    #[arg(long = "graph.enable")]
19    pub graph_enable: bool,
20}
21
22impl Default for TopicOptions {
23    fn default() -> Self {
24        TopicOptions {
25            topic: "#".into(),
26            sampler_interval: 1000,
27            graph_enable: false,
28        }
29    }
30}
31
32pub fn parse_plug_name(topic: &str) -> Option<&str> {
33    let parts: Vec<&str> = topic.split('/').collect();
34    match parts.get(2) {
35        Some(s) => Some(*s),
36        None => None,
37    }
38}
39
40pub fn parse_agent_id(topic: &str) -> Option<&str> {
41    let parts: Vec<&str> = topic.split('/').collect();
42    match parts.get(1) {
43        Some(s) => Some(*s),
44        None => None,
45    }
46}
47
48pub fn parse_agent_role(topic: &str) -> Option<&str> {
49    let parts: Vec<&str> = topic.split('/').collect();
50    match parts.first() {
51        Some(s) => Some(*s),
52        None => None,
53    }
54}