IClick support

This commit is contained in:
Sergey Motornyuk 2019-12-13 16:48:20 +02:00
parent 93951db642
commit 27057e0a39
3 changed files with 26 additions and 21 deletions

View File

@ -1,47 +1,45 @@
# encoding: utf-8
import click
import logging
from ckan.cli import click_config_option
from ckan.cli.cli import CkanCommand
import ckanext.spatial.util as util
log = logging.getLogger(__name__)
@click.group(short_help=u"Validation commands")
@click.help_option(u"-h", u"--help")
@click_config_option
@click.pass_context
def validation(ctx, config, *args, **kwargs):
ctx.obj = CkanCommand(config)
def get_commands():
return [
spatial,
spatial_validation
]
@validation.command()
@click.group(u"spatial-validation", short_help=u"Validation commands")
def spatial_validation():
pass
@spatial_validation.command()
@click.argument('pkg', required=False)
def report(pkg):
return util.report(pkg)
@validation.command('report-csv')
@spatial_validation.command('report-csv')
@click.argument('filepath')
def report_csv(filepath):
return util.report_csv(filepath)
@validation.command('file')
@spatial_validation.command('file')
@click.argument('filepath')
def validate_file(filepath):
return util.validate_file(filepath)
@click.group(short_help=u"Performs spatially related operations.")
@click.help_option(u"-h", u"--help")
@click_config_option
@click.pass_context
def spatial(ctx, config, *args, **kwargs):
ctx.obj = CkanCommand(config)
def spatial():
pass
@spatial.command()

View File

@ -1,14 +1,25 @@
# -*- coding: utf-8 -*-
import ckan.plugins as p
import ckanext.spatial.views as blueprints
from ckanext.spatial.cli import get_commands
class SpatialQueryMixin(p.SingletonPlugin):
p.implements(p.IBlueprint)
p.implements(p.IClick)
# IBlueprint
def get_blueprint(self):
return [blueprints.api]
# IClick
def get_commands(self):
return get_commands()
class HarvestMetadataApiMixin(p.SingletonPlugin):
p.implements(p.IBlueprint)

View File

@ -45,9 +45,5 @@ setup(
[ckan.test_plugins]
test_spatial_plugin = ckanext.spatial.tests.test_plugin.plugin:TestSpatialPlugin
[console_scripts]
spatial = ckanext.spatial.cli:spatial
validation = ckanext.spatial.cli:validation
""",
)