config: store and parse 'filter' as regex
This commit is contained in:
parent
54f67887aa
commit
ad420dc874
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -66,6 +66,15 @@ dependencies = [
|
|||
"opaque-debug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.12.1"
|
||||
|
@ -132,7 +141,9 @@ dependencies = [
|
|||
"clap",
|
||||
"futures",
|
||||
"matrix-sdk",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_regex",
|
||||
"serde_yaml",
|
||||
"systemd",
|
||||
"thiserror",
|
||||
|
@ -1439,7 +1450,10 @@ version = "1.4.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
"thread_local",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1774,6 +1788,16 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_regex"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8136f1a4ea815d7eac4101cfd0b16dc0cb5e1fe1b8609dfd728058656b7badf"
|
||||
dependencies = [
|
||||
"regex",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.0"
|
||||
|
|
|
@ -10,9 +10,11 @@ edition = "2018"
|
|||
anyhow = "1.0"
|
||||
clap = "3.0.0-beta.2"
|
||||
futures = "0.3"
|
||||
regex = "1"
|
||||
tokio = { version = "1", features = [ "full" ] }
|
||||
tracing-subscriber = "0.2"
|
||||
url = { version = "2.2", features = [ "serde" ] }
|
||||
serde_regex = "1"
|
||||
serde_yaml = "0.8"
|
||||
serde = "1.0"
|
||||
systemd = "0.8"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use matrix_sdk::identifiers::RoomId;
|
||||
use regex::Regex;
|
||||
use serde::de::{self, MapAccess, Visitor};
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use std::fmt;
|
||||
|
@ -27,15 +28,24 @@ pub struct Config {
|
|||
}
|
||||
|
||||
/// Holds a single unit's configuration.
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(from = "SerializedUnit")]
|
||||
pub struct Unit {
|
||||
/// Can be serialized from a string only instead of a map.
|
||||
pub name: String,
|
||||
/// Regex to filter each line read from the unit's logs.
|
||||
pub filter: Option<String>, // FIXME: regex
|
||||
#[serde(with = "serde_regex")]
|
||||
pub filter: Option<Regex>,
|
||||
}
|
||||
|
||||
impl PartialEq for Unit {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for Unit {}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
struct SerializedUnit(#[serde(deserialize_with = "unit_name_or_struct")] Unit);
|
||||
|
|
Loading…
Reference in a new issue