Fix CLI registration for module command groups

This commit is contained in:
Chase Sterling 2016-07-10 17:47:43 -04:00
parent 0b931d1a05
commit 57e98cdd9d
4 changed files with 30 additions and 32 deletions

View file

@ -1,3 +1,4 @@
import functools
import sys import sys
# Set default encoding to UTF-8 # Set default encoding to UTF-8
@ -75,7 +76,9 @@ class Application(Flask):
# Click # Click
if hasattr(sources, 'commands'): if hasattr(sources, 'commands'):
cli.add_command(sources.commands.cli, name=module_name) if sources.commands.cli.name == 'cli':
sources.commands.cli.name = module_name
cli.add_command(sources.commands.cli)
# Hooks # Hooks
if hasattr(sources, 'hooks'): if hasattr(sources, 'hooks'):
@ -287,9 +290,8 @@ class AppGroup(click.Group):
kwargs.setdefault('cls', AppGroup) kwargs.setdefault('cls', AppGroup)
return click.Group.group(self, *args, **kwargs) return click.Group.group(self, *args, **kwargs)
flask_cli = AppGroup() cli = AppGroup()
# Decorator to be used in modules instead of click.group
cli_group = functools.partial(click.group, cls=AppGroup)
@flask_cli.group()
def cli():
pass

View file

@ -1,4 +1,4 @@
from realms import config, create_app, db, __version__, flask_cli as cli, cache from realms import config, create_app, db, __version__, cli, cache
from realms.lib.util import random_string, in_virtualenv, green, yellow, red from realms.lib.util import random_string, in_virtualenv, green, yellow, red
from subprocess import call, Popen from subprocess import call, Popen
from multiprocessing import cpu_count from multiprocessing import cpu_count

View file

@ -2,10 +2,10 @@ import click
from realms.lib.util import random_string from realms.lib.util import random_string
from realms.modules.auth.local.models import User from realms.modules.auth.local.models import User
from realms.lib.util import green, red, yellow from realms.lib.util import green, red, yellow
from realms import flask_cli from realms import cli_group
@flask_cli.group(short_help="Auth Module") @cli_group(short_help="Auth Module")
def cli(): def cli():
pass pass

View file

@ -1,10 +1,10 @@
import click import click
from realms import create_app, search, flask_cli from flask import current_app
from realms import search, cli_group
from realms.modules.wiki.models import Wiki from realms.modules.wiki.models import Wiki
from realms.lib.util import filename_to_cname
@flask_cli.group(short_help="Search Module") @cli_group(short_help="Search Module")
def cli(): def cli():
pass pass
@ -13,27 +13,23 @@ def cli():
def rebuild_index(): def rebuild_index():
""" Rebuild search index """ Rebuild search index
""" """
app = create_app() if current_app.config.get('SEARCH_TYPE') == 'simple':
if app.config.get('SEARCH_TYPE') == 'simple':
click.echo("Search type is simple, try using elasticsearch.") click.echo("Search type is simple, try using elasticsearch.")
return return
with app.app_context(): # Wiki
# Wiki search.delete_index('wiki')
search.delete_index('wiki') wiki = Wiki(current_app.config['WIKI_PATH'])
wiki = Wiki(app.config['WIKI_PATH']) for entry in wiki.get_index():
for entry in wiki.get_index(): page = wiki.get_page(entry['name'])
page = wiki.get_page(entry['name']) if not page:
if not page: # Some non-markdown files may have issues
# Some non-markdown files may have issues continue
continue # TODO add email?
name = filename_to_cname(page['path']) body = dict(name=page.name,
# TODO add email? content=page.data,
body = dict(name=name, message=page.info['message'],
content=page.data, username=page.info['author'],
message=page.info['message'], updated_on=entry['mtime'],
username=page.info['author'], created_on=entry['ctime'])
updated_on=entry['mtime'], search.index_wiki(name, body)
created_on=entry['ctime'])
search.index_wiki(name, body)