From 0dd2326baba954f4fd5f6d3e5fa2d95b3d361d17 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 27 Jun 2021 13:19:04 -0700 Subject: [PATCH] wire up cli functionality --- requirements.txt | 2 +- xmrbackers/cli.py | 33 +++++++-------------------------- xmrbackers/factory.py | 7 +++---- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/requirements.txt b/requirements.txt index d170a84..d2c404b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ Flask Flask-SQLAlchemy Flask-WTF flask-login -gunicorn +hypercorn Pillow psycopg2-binary python-dotenv diff --git a/xmrbackers/cli.py b/xmrbackers/cli.py index b088b3b..6a8cbe1 100644 --- a/xmrbackers/cli.py +++ b/xmrbackers/cli.py @@ -1,30 +1,11 @@ import click -from quart import Blueprint, current_app -from xmrbackers.models import Creator -from xmrbackers.factory import db +def cli(app): + @app.cli.command('init') + def init(): + import xmrbackers.models + from xmrbackers.factory import db + db.create_all() -bp = Blueprint('cli', 'cli') - -@bp.cli.command('init') -def init(): - import app.models - db.create_all() - -@bp.cli.command('delete') -@click.argument('thing_id') -def delete(thing_id): - thing = Creator.query.get(thing_id) - if thing: - db.session.delete(thing) - db.session.commit() - click.echo(f'Creator {thing.id} was deleted') - else: - click.echo('Creator ID does not exist') - -@bp.cli.command('list') -def list_things(): - thing = Creator.query.all() - for i in thing: - click.echo(i.id) + return app diff --git a/xmrbackers/factory.py b/xmrbackers/factory.py index df9a439..93a48c6 100644 --- a/xmrbackers/factory.py +++ b/xmrbackers/factory.py @@ -2,6 +2,7 @@ import quart.flask_patch from quart import Quart from flask_sqlalchemy import SQLAlchemy +from xmrbackers.cli import cli from xmrbackers import config @@ -22,16 +23,14 @@ async def _setup_db(app: Quart): def create_app(): app = Quart(__name__) app.config.from_envvar('QUART_SECRETS') - - + app = cli(app) @app.before_serving async def startup(): from xmrbackers.routes import meta, api - from xmrbackers import filters, cli + from xmrbackers import filters await _setup_db(app) app.register_blueprint(meta.bp) app.register_blueprint(api.bp) app.register_blueprint(filters.bp) - app.register_blueprint(cli.bp) return app