From 27057e0a39c7cf50b9b503c6468d25e0af4925ff Mon Sep 17 00:00:00 2001 From: Sergey Motornyuk Date: Fri, 13 Dec 2019 16:48:20 +0200 Subject: [PATCH] IClick support --- ckanext/spatial/cli.py | 32 ++++++++++++-------------- ckanext/spatial/plugin/flask_plugin.py | 11 +++++++++ setup.py | 4 ---- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/ckanext/spatial/cli.py b/ckanext/spatial/cli.py index 2cef239..7be5a0b 100644 --- a/ckanext/spatial/cli.py +++ b/ckanext/spatial/cli.py @@ -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() diff --git a/ckanext/spatial/plugin/flask_plugin.py b/ckanext/spatial/plugin/flask_plugin.py index 3108d65..3c77fe0 100644 --- a/ckanext/spatial/plugin/flask_plugin.py +++ b/ckanext/spatial/plugin/flask_plugin.py @@ -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) diff --git a/setup.py b/setup.py index 9aee440..a98871c 100644 --- a/setup.py +++ b/setup.py @@ -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 """, )