josephburnett / jd

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

Cannot directly apply json6902 patch. #52

Closed matthewhembree closed 1 year ago

matthewhembree commented 1 year ago

In the CLI, a json6902 patch cannot be directly applied. This works in the webUI. I can translate with patch2jd as an interim step.

Intended:

jd -p --yaml -f patch patches/template-patch.json templates/original-vendored-template.yaml
2023/01/24 14:19:39 invalid diff at line 1. Unexpected [. Expecteding @.

Workaround:

jd -t patch2jd patches/template-patch.json > patches/template-patch.jd
jd --yaml -p patches/template-patch.jd templates/original-vendored-template.yaml > templates/vendored-template.yaml

I might do a PR, but I figured I'd log the issue as anyone else could get something out faster than I would be able to.

Great tool. Nothing else does what this does from the CLI. Libraries, yes; compiled CLI tool no.

Thanks!

josephburnett commented 1 year ago

Thanks for the feedback. I've marked this as a feature request because the CLI is working as intended. The default is to read the patch in jd format. It doesn't try to interpret the file in different formats. The web UI does a little bit of that to translate JSON to YAML for convenience (e.g. when you have put in data and then change the format). However for a CLI, it's best to have more predictable behavior and less magic.

I think the feature request here is to respect the -f flag when patching. It was just never implemented here: https://github.com/josephburnett/jd/blob/7a5a7d6ba3605a6498e578f46571f682380da51e/main.go#L268

josephburnett commented 1 year ago

This should do it: https://github.com/josephburnett/jd/commit/3db3045c763410732e19985fdce781fcf1a2e7a0

josephburnett commented 1 year ago

I've rolled this and a few other changes into a new release: https://github.com/josephburnett/jd/releases/tag/v1.7.0 so you should be able to do this now!