Add fetch-channel command

This commit is contained in:
Tobias Reisinger 2023-11-17 17:32:15 +01:00
parent 970c1ee2c2
commit 244a7073fe
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
9 changed files with 183 additions and 54 deletions

View file

@ -18,21 +18,21 @@ pub fn parameter_find(params: &Vec<Parameter>, name: &str) -> Option<Parameter>
}
pub fn parameter_list_find(param_lists: &Vec<ParameterList>, name: &str, value: &str, strict: bool) -> Option<ParameterList> {
for params in param_lists {
for param in params {
if param.name != name {
continue;
}
if param.value != value && strict {
continue;
}
if !param.value.contains(value) && !strict {
continue;
}
if params.iter().position(|param| param.is(name, value, strict)).is_some() {
return Some(params.clone());
}
}
None
}
pub fn parameter_list_find_all(param_lists: &Vec<ParameterList>, name: &str, value: &str, strict: bool) -> Vec<ParameterList> {
let mut found = Vec::new();
for params in param_lists {
if params.iter().position(|param| param.is(name, value, strict)).is_some() {
found.push(params.clone())
}
}
found
}
pub fn parameter_parse(params_str: &str) -> ParameterList {
let parts: Vec<&str> = params_str.split(' ').collect();
@ -63,6 +63,21 @@ impl Parameter {
}
}
pub fn is(&self, name: &str, value: &str, strict: bool) -> bool {
if self.name != name {
false
}
else if self.value != value && strict {
false
}
else if !self.value.contains(value) && !strict {
false
}
else {
true
}
}
pub fn to_i32(&self, default: i32) -> i32 {
self.value.parse::<i32>().unwrap_or(default)
}