yquery is a program which finds elements in your yaml documents using selectors. Sort of like how jquery works for css.
yquery is a command-line tool which currently accepts one file and a 'search query'. It will then search through the document looking for elements of the document which adhere to the search query. I am currently working on multi-file support so you can search directories as well.
A 'search query' consists of four parts: A parent name, an element name, a child specifier and id selection. It is given in the form <Parent>ElementA[childname=name].id
. You can have multiple occurrences of each part: (<Parent>ElementA|<Parent>ElementB)[childname=name,childage=age].(id,name)
. If only the element name part is given, the output will the entire element found, as seen in the first example below. If the id selection part is specified, you will only receive those specifically, as seen in the second example below.
Example with no id specifier
[mads@Adria][~/projects/yquery]% yquery documents/verify_apache.yaml "service"
service: { name: httpd, state: started}
service: { name: httpd, state: restarted}
Example with id specifier set
[mads@Adria][~/projects/yquery]% yquery documents/verify_apache.yaml "service.name"
httpd
httpd
Currently yquery does not reside in any package manager that I know of. So in order to install it you need to build the tool yourself.
You can also build and install from source (requires the latest stable Rust compiler.)
cargo install --git https://github.com/madsravn/yquery.git yquery
Some issues can arise from the grammar I made to parse the search query. If you are in doubt whether or not your query was understood correctly, run the program with a third parameter. Then it will output how it understands your search query.
This tool and its source is licensed under GNU GPLv3