import click

from rapt.connection import get_vr
from rapt.models import query
from rapt.util import dump_yaml, load_yaml, edit_yaml


@click.command()
@click.option('--name', '-n')
def ingredients(name, verbose):
    """List builds.
    """
    vr = get_vr()

    q = {}
    if name:
        q['name'] = name

    # add filters if we need to be...
    for i, ingredient in enumerate(query('Ingredient', vr, q)):
        click.echo(ingredient.name)


@click.command()
@click.argument('name')
def ingredient(name):
    """View a complete ingredient config."""
    vr = get_vr()
    q = {'name': name}
    ingredient = query('Ingredient', vr, q).next()

    doc = {
        'config': load_yaml(ingredient.config_yaml),
        'env': load_yaml(ingredient.env_yaml),
    }

    config = edit_yaml(dump_yaml(doc))

    if not config:
        click.echo('No changes')
        return

    ingredient.config_yaml = dump_yaml(config['config'])
    ingredient.env_yaml = dump_yaml(config['env'])
    ingredient.save()

@@ -485,16 +485,122 @@
 'name')%0A
+@click.option('--read', '-r', is_flag=True,%0A              help='Read the config elements', default=False)%0A
 def ingr
@@ -610,16 +610,22 @@
 ent(name
+, read
 ):%0A    %22
@@ -876,16 +876,80 @@
 %0A    %7D%0A%0A
+    if read:%0A        click.echo(dump_yaml(doc))%0A        return%0A%0A
     conf

Support reading the config.