comby
comby copied to clipboard
Support for YAML
Describe the bug Does Comby support YAML file. Can it parse it and do search and replace. Only yaml tool that is out there that can do this is python ruamel which also supports comment https://pypi.org/project/ruamel.yaml/
It would be a great feature for this tool
Between love your work. This is a great tool
Thanks for your enthusiasm! You can run comby
on YAML files, but it won't respect indentation for matching blocks, which is the big missing thing. Supporting indentation is something I've wanted to handle for a while (so that there's also a convenient way to match Python code). I've been doing some refactors to make implementing that a bit easier. I might have a chance in the next month or two? It's a bit difficult to predict when I'll have spare cycles for this, but I'm moving towards it :-)
Thank you @rvantonder for quick response. I just did some test and found few issues when trying to parse
Issue 1:
bit.ly/3dA3hDr
I am trying to replace my_tag: 03.01.10 &tags #this is comment
to my_tag: zzzz &tags #this is comment
it works when i do
my_tag: :[1] :[2\n]
but there will be cases where there wont be comments or anchor, eg: my_tag: 03.01.10
. In this case, I want it to do my_tag: zzzz
but it replaces newline and breaks yaml format.
Issue 2:
How do you perform search and replace in file without fileextension. I have file that doesn't have extension like Jenkinsfile
How do you find and filter this file. i tried comby 'my_tag: :[1] :[2\n]' 'my_tag: zzzz :[2\n]' Jenkinsfile
which didn't work.
@rvantonder any thought on this issue
Issue 1: how about using a regular expression with lookahead to stop scanning before the newline? Here's an example
Issue 2: You can use -matcher <language>
, like -matcher .json
, and it will parse your Jenkinsfile in whatever language you feel is the right choice. You can run comby -list
to get the list of languages. There isn't anything for Jenkinsfile specifically. By default comby
chooses -matcher .generic
, but it sounds like that option doesn't work for you. Is there a language closer to Jenkinsfile
that might? If there is something specific about Jenkinsfile
I can add it too.
By the way, the Gitter channel is a good choice to ask question so that I don't lose track of them like this one. The GH issues are fine but I might forget to respond.
@rvantonder Issue 1: I was trying to get result like this. This is a very normal use case for YAML. As it supports anchors and scalars. https://docs.ansible.com/ansible/latest/user_guide/playbooks_advanced_syntax.html#yaml-anchors-and-aliases-sharing-variable-values
my_tag: zzzz
my_tag: zzzz &tags
In your example, i can see it prints out
my_tag: zzzz is_enabled: false
my_tag: zzzz &tags
That is not correct.
Issue 2:
Jenkinsfile is in groovy format. I dont see groovy as an option in the list. Also we have file ABC
without any extension and it is in YAML format.
Thanks in advance