# -*- coding: utf-8 -*-

import click
from ckan.lib.cli import click_config_option

import ckanext.xroad_integration.utils as utils

def get_commands():
    return [xroad]


@click.group()
def xroad():
    """X-Road related commands.
    """
    pass


@xroad.command()
def init_db():
    """Creates the necessary tables in the database.
    """
    utils.init_db()
    click.secho(u"DB tables created", fg=u"green")

@xroad.command(
    u'update_xroad_organizations',
    help='Updates harvested organizations\' metadata'
)
@click_config_option
@click.pass_context
def update_xroad_organizations(ctx, config):
    flask_app = ctx.meta["flask_app"]
    with flask_app.test_request_context():
        utils.update_xroad_organization()

@xroad.command(
    u'fetch_errors',
    help='Fetches error log from catalog lister'
)
@click_config_option
@click.pass_context
def fetch_errors(ctx, config):
    flask_app = ctx.meta["flask_app"]
    with flask_app.test_request_context():
        utils.fetch_errors()

@xroad.command(
    u'fetch_stats',
    help='Fetches X-Road stats from catalog lister'
)
@click_config_option
@click.pass_context
@click.option(u'--days', type=int)
def fetch_stats(ctx, config, days):

    flask_app = ctx.meta["flask_app"]
    with flask_app.test_request_context():
        utils.fetch_stats(days)

@xroad.command(
    u'fetch_service_list',
    help='Fetches X-Road services from catalog lister'
)
@click_config_option
@click.pass_context
@click.option(u'--days', type=int)
def fetch_service_list(ctx, config, days):

    flask_app = ctx.meta["flask_app"]
    with flask_app.test_request_context():
        utils.fetch_service_list(days)
@@ -34,53 +34,8 @@
 lick
-%0Afrom ckan.lib.cli import click_config_option
 %0A%0Aim
@@ -473,37 +473,16 @@
 data'%0A)%0A
-@click_config_option%0A
 @click.p
@@ -750,37 +750,16 @@
 ster'%0A)%0A
-@click_config_option%0A
 @click.p
@@ -1002,37 +1002,16 @@
 ster'%0A)%0A
-@click_config_option%0A
 @click.p
@@ -1310,31 +1310,10 @@
 er'%0A
+
 )%0A
-@click_config_option%0A
 @cli

remove click_config_option from new cli