update
This commit is contained in:
parent
e76f1e4419
commit
526b699845
2 changed files with 40 additions and 0 deletions
22
README.md
Normal file
22
README.md
Normal file
|
@ -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] <file> <file2>
|
||||
|
||||
Arguments:
|
||||
<file> First File
|
||||
<file2> 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 <key> <val> Add test case to json patch
|
||||
-x, --exclude <JSONPATH> Exclude json path from diff
|
||||
-k, --keys <JSONPATH> Only include the specified json paths in diff
|
||||
```
|
18
src/main.rs
18
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::<String>("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::<String>("exclude") {
|
||||
let excludes: Vec<String> = excludes.cloned().collect();
|
||||
diff = exclude_json_paths(&diff, &excludes);
|
||||
|
|
Loading…
Add table
Reference in a new issue