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

merging 2 yaml documents with comments ? #5

Open
grosser opened this issue Sep 20, 2024 · 0 comments
Open

merging 2 yaml documents with comments ? #5

grosser opened this issue Sep 20, 2024 · 0 comments

Comments

@grosser
Copy link

grosser commented Sep 20, 2024

I want to merge some new info into a existing yaml document

gem 'psych-comments'

require "psych"
require "psych/comments"

content = ARGV.map { |f| File.read(f) }
content.unshift STDIN.read unless STDIN.tty?

asts = content.map { |c| Psych::Comments.parse_stream(c) }

asts[1...].each do |ast|
  asts[0].children[0].children.append ast.children[0].children
  asts[0].end_line += 1
end

puts Psych::Comments.emit_yaml(asts[0])

no luck though, got any hints ?

echo 'a: 1 # a' > a
echo 'b: 2 # b' > b
ruby merge a b
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

No branches or pull requests

1 participant