config: add support for Matcher::Exactly and Action::Set

This commit is contained in:
Harsh Shandilya 2022-01-23 14:35:52 +05:30
parent a357b02712
commit 51e7c4a74c
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80

View file

@ -29,10 +29,14 @@ pub enum Matcher<'config> {
Contains { substring: &'config str }, Contains { substring: &'config str },
#[serde(rename = "regex")] #[serde(rename = "regex")]
Regex { pattern: &'config str }, Regex { pattern: &'config str },
#[serde(rename = "exactly")]
Exactly { content: &'config str },
} }
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
pub enum Action<'config> { pub enum Action<'config> {
#[serde(rename = "set")]
Set { content: &'config str },
#[serde(rename = "replace")] #[serde(rename = "replace")]
Replace { Replace {
from: &'config str, from: &'config str,
@ -62,6 +66,7 @@ impl Match for Matcher<'_> {
let regex = Regex::from_str(pattern).expect("Failed to parse regex"); let regex = Regex::from_str(pattern).expect("Failed to parse regex");
regex.is_match(string) regex.is_match(string)
} }
Matcher::Exactly { content } => string == content,
} }
} }
} }
@ -72,6 +77,7 @@ impl Act for Action<'_> {
Action::Replace { from, to } => input.replace(from, to), Action::Replace { from, to } => input.replace(from, to),
Action::Prefix { prefix } => format!("{}{}", prefix, input), Action::Prefix { prefix } => format!("{}{}", prefix, input),
Action::Suffix { suffix } => format!("{}{}", input, suffix), Action::Suffix { suffix } => format!("{}{}", input, suffix),
Action::Set { content } => content.to_owned(),
}; };
} }
} }