You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.1 KiB
Python

6 years ago
import click
from molten.contrib.sqlalchemy import EngineData
from {{cookiecutter.project_slug}}.index import create_app
_, app = create_app()
6 years ago
@click.group()
def cli():
pass
@cli.command()
@click.option("--host", "-h", default="0.0.0.0", help="A hostname or IP address")
@click.option(
"--port", "-p", default=8000, help="Port number to bind to development server"
)
def runserver(host, port):
"""
Runs a Werkzueg development server. Do no use for production.
"""
from werkzeug.serving import run_simple
run_simple(
hostname=host, port=port, application=app, use_debugger=True, use_reloader=True
)
@cli.command()
def shell():
"""
Enters an interactive shell with an app instance and dependency resolver.
"""
import rlcompleter
6 years ago
import readline
from code import InteractiveConsole
helpers = {"app": app, "resolver": app.injector.get_resolver()}
readline.parse_and_bind("tab: complete")
6 years ago
interpreter = InteractiveConsole(helpers)
interpreter.interact(f"Instances in scope: {', '.join(helpers)}.", "")
6 years ago
@cli.command()
def initdb():
"""
Initialize database
"""
click.echo("This feature has been commented out. Please use alembic to manage your database initialization and changes.")
# from {{cookiecutter.project_slug}}.db import Base
#
# def _init(engine_data: EngineData):
# Base.metadata.create_all(bind=engine_data.engine)
#
# click.echo("Creating database")
# app.injector.get_resolver().resolve(_init)()
# click.echo("Database created")
6 years ago
@cli.command()
def dropdb():
"""
Drop all tables in database
"""
from {{cookiecutter.project_slug}}.db import Base
def _drop(engine_data: EngineData):
Base.metadata.drop_all(bind=engine_data.engine)
6 years ago
click.echo("Are you sure you would like to drop the database?: [Y/N]")
response = input()
if response.lower() == "y":
app.injector.get_resolver().resolve(_drop)()
6 years ago
click.echo("Database dropped")
else:
click.echo("Database drop aborted")
if __name__ == "__main__":
cli()