From 526b699845da3e3f50e0ca982fe47e4cbfefb9b3 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Mon, 6 Nov 2023 09:36:42 +0100 Subject: [PATCH] update --- README.md | 22 ++++++++++++++++++++++ src/main.rs | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..90a38be --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# mddiff + +mddiff is a tool for comparing the frontmatter of two markdown files and generating a [JSON patch](https://jsonpatch.com/) file. + +## Usage + +``` +Usage: mddiff [OPTIONS] + +Arguments: + First File + Second File + +Options: + -p, --pretty Output formatted json patch + -a, --add Only output add operations + -m, --modify Only output modify operations + -d, --delete Only output delete operations + -t, --test Add test case to json patch + -x, --exclude Exclude json path from diff + -k, --keys Only include the specified json paths in diff +``` \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 44025b6..c774d43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,6 +149,24 @@ fn main() { let mut diff = serde_json::to_value(diff).unwrap(); + if let Some(test_cases) = args.get_many::("test") { + // TODO : Multiple test arguments + let test_cases: Vec<_> = test_cases.collect(); + + let path = test_cases.get(0).unwrap(); + let val = test_cases.get(1).unwrap(); + + diff.as_array_mut().unwrap().insert(0, + serde_json::json!( + { + "op": "test", + "path": path, + "value": val + } + ) + ); + } + if let Some(excludes) = args.get_many::("exclude") { let excludes: Vec = excludes.cloned().collect(); diff = exclude_json_paths(&diff, &excludes);