mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
I now call a factory function to construct the Sanic app:
app = app_factory(files)
This allows me to pass additional arguments to it, e.g. the files to serve.
Also refactored my class-based views to accept jinja as an argument, e.g:
app.add_route(
TableView.as_view(jinja),
'/<db_name:[^/]+>/<table:[^/]+?><as_json:(.jsono?)?$>'
)
27 lines
738 B
Python
27 lines
738 B
Python
import click
|
|
from click_default_group import DefaultGroup
|
|
from .app import app_factory, ensure_build_metadata
|
|
|
|
|
|
@click.group(cls=DefaultGroup, default='serve', default_if_no_args=True)
|
|
def cli():
|
|
"""
|
|
Datasite!
|
|
"""
|
|
|
|
|
|
@cli.command()
|
|
def build():
|
|
ensure_build_metadata(True)
|
|
|
|
|
|
@cli.command()
|
|
@click.argument('files', type=click.Path(exists=True), nargs=-1)
|
|
@click.option('-h', '--host', default='0.0.0.0')
|
|
@click.option('-p', '--port', default=8001)
|
|
@click.option('--debug', is_flag=True)
|
|
def serve(files, host, port, debug):
|
|
"""Serve up specified database files with a web UI"""
|
|
click.echo('Serve! files={} on port {}'.format(files, port))
|
|
app = app_factory(files)
|
|
app.run(host=host, port=port, debug=debug)
|