Yarp

YAml for gReP - yarp

yarp transforms a subset of YAML into discrete assignments to make it easier to grep for what you want and see the absolute ‘path’ to it. It eases the parsing of YAML documents from bash.

Example

$ cat file.yml | yarp | grep "commit.author"
code[0].commit.author =
code[0].commit.author.date = 2016-07-02T10:51:21Z
code[0].commit.author.email = mail@tomnomnom.com
code[0].commit.author.name = Tom Hudson

Supported Yaml features

  • Mappings: key:

  • Mappings with values: key: value

  • Sequences: - value

  • And nested combinations of the above.

  • A form of multiline values where the lines end in \

Note

Limited support of comments. Entire commented lines are removed from the output, but lines ending with a comment will not have the comments removed from the final output. This should have minimal side effects when grepping.

What is not supported

  • Multiple documents: ---/...

  • Key names with colons or quotes

  • ? multiline keys

  • Streams (So no % tags)

  • Type tags !!

  • Binary fields !!binary

  • Sets ?

  • Anchors &

  • Labels *

  • | multiline

  • > multiline

  • Collapsed nested sequence indicators - -

  • And any other YAML features

The supported subset is enough to handle the output of docker compose config. docker compose’s config command will parse anchors, multilines, and remove comments.

yarp
Arguments:
  • stdin - Yaml file in

Output:

stdout - greppable version out

Bash CLI version of yarp

yarp
Arguments:
  • stdin - Yaml file in

Output:

stdout - greppable version out