Introducing YAML-CLI: A YAML Command Line Processor
YAML is our favorite data format. Well, it’s my favorite data format, anyway. Popularized by Ruby and Rails, YAML is powerful and expressive. Consequently, it’s seeing increasing adoption, everywhere from dev ops tools, such as Docker or Ansible, to static site generators.
So it was surprising to discover the relative paucity of tools for processing YAML from the command-line. The few that do exist didn’t meet our needs, so we wrote our own.
One of the features is template processing. You can apply YAML data to an arbitrary template. One of the reasons, we wanted this was to instantiate Dockerfile templates based on configuration data stored in YAML files.
Consider the following Dockerfile for running Nginx with a static Web site.
FROM nginx
COPY www /usr/share/nginx/html
Suppose we want to make the document root folder configurable. We’d end up with a Dockerfile template.
FROM nginx
COPY {{root}} /usr/share/nginx/html
We can now instantiate that template using a Dockerfile
with a root
property.
root: "build"
And use our YAML CLI tool to generate a real Dockerfile.
$ yaml template config.yaml Dockerfile.template > Dockerfile
Pretty cool, right? You can learn more from the Web site or the GitHub page. Or just install it and use the builtin help.
$ npm install -g yaml-cli
Let us know what you think! Check out the issues list and up-vote your favorites or open your own feature requests.