josephburnett / jd

JSON diff and patch
MIT License
826 stars 38 forks source link

Explicitly return exit codes when differences are found. #34

Closed tmcgilchrist closed 2 years ago

tmcgilchrist commented 2 years ago

Similar to unix diff tool returning 0 for no differences and 1 if differences are found. Fixes https://github.com/josephburnett/jd/issues/33

I don't typically write Go code, so if there is a more idiomatic way to do it please let me know.

Using this locally:

$ ./jd -set ~/code/ocaml/ocaml-gitlab/_build/default/test/cases/commit_statuses/expected.json  ~/code/ocaml/ocaml-gitlab/_build/default/test/cases/commit_statuses/event.json 
@ [["set"],{}]
+ {"allow_failure":false,"author":{"avatar_url":"https://secure.gravatar.com/avatar/67afd2b4c98c9befd18c19f0ee9d94dc?s=80\u0026d=identicon","id":490393,"name":"Tim McGilchrist","state":"active","username":"tmcgilchrist","web_url":"https://gitlab.com/tmcgilchrist"},"coverage":null,"created_at":"2021-10-12T02:37:01.862Z","description":null,"finished_at":"2021-10-12T02:37:01.861Z","id":1670148491,"name":"default","ref":"master","sha":"8d97942a62c9f17dd47e23cf806221230deabaab","started_at":null,"status":"success","target_url":null}
$ echo $?
1
$ ./jd -set ~/code/ocaml/ocaml-gitlab/_build/default/test/cases/commit_statuses/expected.json  ~/code/ocaml/ocaml-gitlab/_build/default/test/cases/commit_statuses/expected.json
$ echo $?
0