Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for multiple yaml files in command line arguments #7

Merged
merged 2 commits into from
Sep 25, 2017
Merged

Adding support for multiple yaml files in command line arguments #7

merged 2 commits into from
Sep 25, 2017

Conversation

bubbleattic
Copy link
Contributor

Adding support for multiple yaml files in command line arguments.

Tested all result in same output:

Recursive merge two json files using jq (1.5)

jq -s '.[0] * .[1]' a.json b.json

Recursive merge two json files using yq

yq -s '.[0] * .[1]' a.json b.json

Recursive merge two yaml files using yq

yq -s '.[0] * .[1]' a.yml b.yml

NOTE:
The line "jq.stdin.write('\n')" was added in to work around bug with current version of jq where the following commands were generating different results.
echo -n '{"b": {"c": 3}, "a": 2}{"b": {"e": 4}, "d": 3}' | jq -s '.'
echo '{"b": {"c": 3}, "a": 2}{"b": {"e": 4}, "d": 3}' | jq -s '.'

Since adding newline after json documents makes sense any way, workaround not that big of deal.

@codecov-io
Copy link

codecov-io commented Sep 24, 2017

Codecov Report

Merging #7 into master will increase coverage by 0.7%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master       #7     +/-   ##
=========================================
+ Coverage   83.58%   84.28%   +0.7%     
=========================================
  Files           2        2             
  Lines          67       70      +3     
=========================================
+ Hits           56       59      +3     
  Misses         11       11
Impacted Files Coverage Δ
yq/__init__.py 84.05% <100%> (+0.72%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d89088e...468188c. Read the comment docs.

@kislyuk
Copy link
Owner

kislyuk commented Sep 25, 2017

Thanks! This needs a test, but I can add one.

@kislyuk kislyuk merged commit 71b4fb6 into kislyuk:master Sep 25, 2017
@kislyuk
Copy link
Owner

kislyuk commented Sep 26, 2017

Released in v2.3.1.

Please note, I have removed your printing of an extra newline. I don't consider it appropriate to put workarounds for jq bugs in this package. If you wish to put it back in, please provide a more thorough rationale/use case, and also a link to the corresponding issue filed with https://github.com/stedolan/jq.

@bubbleattic
Copy link
Contributor Author

bubbleattic commented Sep 26, 2017

I created bug to jq: jqlang/jq#1486

FYI if '-y' specified yq is already adding in newlines.
input_payload = "\n".join(json.dumps(doc, cls=JSONDateTimeEncoder) for doc in input_docs)

maybe just use exact same code if -y not specified that way its not workaround its consistent.

input_payload = "\n".join(json.dumps(doc, cls=JSONDateTimeEncoder) for doc in input_docs)
jq_out, jq_err = jq.communicate(input_payload)
sys.stdout.write(jq_out)

None of examples i listed above will work due to jq bug. (Examples will work though if use -y flag since in that case newlines added in).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants