0k / shyaml

YAML for command line
BSD 2-Clause "Simplified" License
767 stars 57 forks source link

get-value matching nodes with having certain child nodes #19

Open CodeCommander opened 8 years ago

CodeCommander commented 8 years ago

Google Cloud outputs yaml like this for meta data:

commonInstanceMetadata:
  fingerprint: ..
  items:
  - key: SQL_INSTANCE_IP
    value: 123.45.6.78
  - key: SQL_INSTANCE_NAME
    value: database-server

Is there any way to use shyaml get-value to get the value of the "value" key on a node having a "key" matching a specified string? e.g. something like:

gcloud compute project-info describe | shyaml get-value commonInstanceMetadata.items[key=SQL_INSTANCE_IP].value

Right now I'm doing:

gcloud compute project-info describe | shyaml get-value commonInstanceMetadata.items | grep -A1 SQL_INSTANCE_IP | shyaml get-value 0.value

which seems to work, but I'm wondering if there is a better way without using grep?

vaab commented 8 years ago

That's a great idea, this is going towards xpath way, and you should know that parsing such a string is not trivial. Any PR is welcome though.