this repo has no description
1use anyhow::{anyhow, Context, Result};
2use supercell::matcher::Matcher;
3use supercell::matcher::RhaiMatcher;
4
5fn main() -> Result<()> {
6 let mut rhai_input_path: Option<String> = None;
7 let mut json_input_path: Option<String> = None;
8 for arg in std::env::args_os().skip(1) {
9 let arg = arg.to_string_lossy();
10 if arg.ends_with(".rhai") {
11 rhai_input_path = Some(arg.to_string());
12 } else if arg.ends_with(".json") {
13 json_input_path = Some(arg.to_string());
14 }
15 }
16
17 if rhai_input_path.is_none() {
18 return Err(anyhow!("No rhai input file provided"));
19 }
20 let rhai_input_path = rhai_input_path.unwrap();
21
22 if json_input_path.is_none() {
23 return Err(anyhow!("No json input file provided"));
24 }
25 let json_input_path = json_input_path.unwrap();
26
27 let json_content = std::fs::read(json_input_path)
28 .map_err(|err| anyhow::Error::new(err).context(anyhow!("reading input_json failed")))?;
29 let value: serde_json::Value =
30 serde_json::from_slice(&json_content).context("parsing input_json failed")?;
31
32 let matcher = RhaiMatcher::new(&rhai_input_path).context("could not construct matcher")?;
33 let result = matcher.matches(&value)?;
34
35 let result = result.ok_or(anyhow!("no matches found"))?;
36
37 println!("{:?} {}", result.0, result.1);
38
39 Ok(())
40}