biojppm / c4conf

YAML-based configuration data trees, with override facilities including command line arguments.
MIT License
19 stars 2 forks source link

Filtering and parsing facilities #1

Open captain-yoshi opened 2 years ago

captain-yoshi commented 2 years ago

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
biojppm commented 2 years ago

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!