c4conf icon indicating copy to clipboard operation
c4conf copied to clipboard

Filtering and parsing facilities

Open captain-yoshi opened this issue 2 years ago • 1 comments

Is this library meant to do filtering like the YAML processor yq does ? If it does, I guess I would have to implement the filtering logic (see example below) but that would not be too complicated because of the provided parsing facilities. Speaking of facilities, do you have a function that checks if a YAML node is a subset of another node ?

# Filtering example using 'yq'
# Filters out every data sequences that does not match:
#     query.scene   == "box-1c" && 
#     query.request == "First Contact"
yq 'del(.data[] | select((.query.scene == "box-1c" and .query.request == "First Contact")|not))' < dataset.yaml

YAML file:

data:
- query:
    scene: box-1c
    request: First Contact
- query:
    scene: empty
    request: All Contact
- query:
    scene: empty
    request: First Contact
- query:
    scene: empty
    request: First Contact

After filtering:

data:
- query:
    scene: box-1c
    request: First Contact

captain-yoshi avatar Apr 03 '22 02:04 captain-yoshi

Is this library meant to do filtering like the YAML processor yq does ?

No, filtering is not the intent, and is not contemplated. In terms of importance, modification and replacement of existing nodes is the first objective, adding nodes the second, and removal of nodes is possible but just as an artifact of the first two: assigning an empty node. Selective removal is not considered.

do you have a function that checks if a YAML node is a subset of another node ?

No, sorry. Happy to accept a PR for that!

biojppm avatar Apr 05 '22 09:04 biojppm