Home

Awesome

Build Status Coverage Status

Yaml-tools

A set of CLI tools to manipulate YAML files (merge, delete, etc...) with comment preservation, based on ruamel.yaml

Getting Started

Prerequisites

Installation

(For development see section at the end)

$ pip install ruamel.yaml
$ export YAML_TOOLS_VERSION=0.0.6
$ sudo wget https://raw.githubusercontent.com/thecodingmachine/yaml-tools/${YAML_TOOLS_VERSION}/src/yaml_tools.py -O /usr/local/bin/yaml-tools
$ sudo chmod +x /usr/local/bin/yaml-tools

Usage

$ yaml-tools <command> [<args>] 

There are 4 commands at the moment :

1) merge

Merges two or more yaml files and preserves the comments.

$ yaml-tools merge -i INPUTS [INPUTS ...] [-o OUTPUT]

2) delete

Deletes one item/block (and its preceding comments) from the input yaml file.

$ yaml-tools delete PATH_TO_KEY -i INPUT [-o OUTPUT]

3) normalize-docker-compose

Normalize the input docker-compose file by and converting all key-value string (e.g. 'foo=bar' or '80:8080') to key-value dicts inside the services' labels and environment fields, also delete all duplicated volumes and env_file (and its preceding comments) for each services

$ yaml-tools normalize-docker-compose -i INPUT [-o OUTPUT]

4) comment (/!\ EXPERIMENTAL)

Comments one item/block from the input yaml file and preserves the comments.

/!\ There are somme issues with comments which are at the end of any intermediate level/block, and also commenting the last item from a list, so use it with caution.

$ yaml-tools comment PATH_TO_KEY -i INPUT [-o OUTPUT]

Dev

Installing

Running tests

$ cd src/tests/

$ python -m unittest discover 
or
$ coverage run --rcfile=../../.coveragerc --source=.,.. -m unittest discover && coverage report -m