aboutsummaryrefslogtreecommitdiff
path: root/src/barbfile.rs
diff options
context:
space:
mode:
authorGuillaume Pasquet <dev@etenil.net>2022-02-27 22:46:50 +0000
committerGuillaume Pasquet <dev@etenil.net>2022-02-27 23:01:17 +0000
commit8e3fde02d8878ba1734305394c63eb841440a327 (patch)
treed0dc799bc5b6b6b00efa6e5dcf7bf915d873c0f8 /src/barbfile.rs
parent8a5c6db3159cdc9f350f9083ae7d190c050b76be (diff)
Fix #9: Extract filter output for reuse in vars
Diffstat (limited to 'src/barbfile.rs')
-rw-r--r--src/barbfile.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/barbfile.rs b/src/barbfile.rs
index 35b0224..91ffd0a 100644
--- a/src/barbfile.rs
+++ b/src/barbfile.rs
@@ -2,6 +2,7 @@ use regex::Regex;
use std::str::FromStr;
use std::string::ToString;
use std::{error::Error, fmt};
+use jq_rs;
#[derive(Debug)]
pub struct BarbParseError {}
@@ -126,6 +127,12 @@ impl BarbFilter {
pub fn filter(&self) -> &String {
&self.filter
}
+
+ pub fn apply(&self, body: &String) -> Result<String, String> {
+ jq_rs::run(self.filter.as_str(), body.as_str())
+ .map_err(|x| x.to_string())
+ .map(|x| String::from(x.trim().trim_matches('"')))
+ }
}
struct BarbPreamble {