Skip to content

Commit

Permalink
Fix -c usage
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Jan 16, 2020
1 parent 3b8e223 commit cab09be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
23 changes: 22 additions & 1 deletion ckan/cli/__init__.py
Expand Up @@ -6,19 +6,40 @@
import logging
from logging.config import fileConfig as loggingFileConfig

import ckan.plugins as p
from ckan.config.middleware import make_app


log = logging.getLogger(__name__)


def error_shout(exception):
click.secho(str(exception), fg=u'red', err=True)


class CkanCommand(object):

def __init__(self, conf=None):
self.config = load_config(conf)
self.app = make_app(self.config.global_conf, **self.config.local_conf)


def _init_ckan_config(ctx, param, value):
ctx.obj = CkanCommand(value)
for plugin in p.PluginImplementations(p.IClick):
for cmd in plugin.get_commands():
cmd._ckanext = plugin.name
ctx.command.add_command(cmd)


click_config_option = click.option(
u'-c',
u'--config',
default=None,
metavar=u'CONFIG',
help=u'Config file to use (default: development.ini)'
help=u'Config file to use (default: development.ini)',
is_eager=True,
callback=_init_ckan_config
)


Expand Down
23 changes: 5 additions & 18 deletions ckan/cli/cli.py
Expand Up @@ -3,14 +3,13 @@
import logging
from collections import defaultdict

import ckan.plugins as p
import click
from ckan.cli import config_tool
from ckan.cli import (
jobs,
datapusher,
front_end_build,
click_config_option, db, load_config, search_index, server,
click_config_option, db, search_index, server,
profile,
asset,
datastore,
Expand All @@ -27,7 +26,6 @@
user
)

from ckan.config.middleware import make_app
from ckan.cli import seed

log = logging.getLogger(__name__)
Expand All @@ -37,7 +35,7 @@ class CustomGroup(click.Group):
def get_command(self, ctx, name):
cmd = super(CustomGroup, self).get_command(ctx, name)
if not cmd:
ctx.invoke(self)
ctx.forward(self)
cmd = super(CustomGroup, self).get_command(ctx, name)
return cmd

Expand All @@ -60,23 +58,12 @@ def format_commands(self, ctx, formatter):
formatter.write_dl(rows)


class CkanCommand(object):

def __init__(self, conf=None):
self.config = load_config(conf)
self.app = make_app(self.config.global_conf, **self.config.local_conf)


@click.group(cls=CustomGroup)
@click.help_option(u'-h', u'--help')
@click_config_option
@click.pass_context
def ckan(ctx, config, *args, **kwargs):
ctx.obj = CkanCommand(config)
for plugin in p.PluginImplementations(p.IClick):
for cmd in plugin.get_commands():
cmd._ckanext = plugin.name
ckan.add_command(cmd)
# @click.pass_context
def ckan(config, *args, **kwargs):
pass


ckan.add_command(jobs.jobs)
Expand Down

0 comments on commit cab09be

Please sign in to comment.