wire up cli functionality

main
lza_menace 3 years ago
parent a3fda7c4ed
commit 0dd2326bab

@ -2,7 +2,7 @@ Flask
Flask-SQLAlchemy
Flask-WTF
flask-login
gunicorn
hypercorn
Pillow
psycopg2-binary
python-dotenv

@ -1,30 +1,11 @@
import click
from quart import Blueprint, current_app
from xmrbackers.models import Creator
from xmrbackers.factory import db
bp = Blueprint('cli', 'cli')
@bp.cli.command('init')
def cli(app):
@app.cli.command('init')
def init():
import app.models
import xmrbackers.models
from xmrbackers.factory import db
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

@ -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

Loading…
Cancel
Save