ecg

Gem Version Build Status Maintainability Test Coverage

ecg is an ERB(eRuby) based, simple and powerful configration file generator for general purpose.

Requirements

Ruby: 2.5 or higher

Install

gem install ecg

Usage

See also ecg --help

Simple example

ecg --values name=epaew --values email="[email protected]" < template.json.erb
{
  "type": "user",
  "name": "epaew",
  "email": "[email protected]"
}

or

ecg config.yml < template.json.erb
{
  "type": "user",
  "name": "epaew",
  "email": "[email protected]"
}

with

  • template.json.erb json { "type": "user", "name": "<%= name %>", "email": "<%= email %>" }
  • config.yml yaml name: epaew email: [email protected]

Using nested keys

ecg --values user.name=epaew --values user.email="[email protected]" < template.json.erb
{
  "user": {
    "name": "epaew",
    "email": "[email protected]"
  }
}

or

ecg config.yml < template.json.erb
{
  "user": {
    "name": "epaew",
    "email": "[email protected]"
  }
}

with

  • template.json.erb json { "user": { "name": "<%= user.name %>", "email": "<%= user.email %>" } }
  • config.yml yaml user: name: epaew email: [email protected]

Using array (JSON and YAML only)

ecg config.yml < template.json.erb
{
  "user": [
    {
      "name": "Kurimu"
    },
    {
      "name": "Chizuru"
    },
    {
      "name": "Minatsu"
    },
    {
      "name": "Mahuyu"
    }
  ]
}

with

  • template.json.erb json { "user": [ <% users.each_with_index do |user, i| %> { "name": "<%= user.name %>" <% unless i == users.count - 1 %> }, <% else %> } <% end %> <% end %> ] }
  • config.yml yaml users: - name: Kurimu - name: Chizuru - name: Minatsu - name: Mahuyu

License

MIT