andywerner/yaml_cli

Add option to get a value?

gbl opened this issue · 0 comments

gbl commented

I'd really like to see an option that outputs a list of subkeys of a key, or the value of a (sub)key.

For a yaml file that looks like this:

`root:
    elem1:
        something: 'value`'
         otherthing: 'value'
    elem2:
        something: 'value'

I'd like to be able to call

yaml_cli -g root                                        <== outputs "elem1 elem2"
yaml_cli -g root:elem1                             <== outputs "something otherthing"
yaml_cli -g root.elem1.something           <== outputs "value"

That would allow me to write a shell script like

for i in $(yaml_cli -g root); do yaml_cli -s root:$i:something newval; done
to set all somethings to a value, regardless of which elements exist.