2017-10-27 07:08:24 +00:00
|
|
|
import click
|
2017-11-04 23:53:50 +00:00
|
|
|
from click_default_group import DefaultGroup
|
2017-11-10 19:05:57 +00:00
|
|
|
from .app import Datasette, ensure_build_metadata
|
2017-10-27 07:08:24 +00:00
|
|
|
|
2017-11-04 23:53:50 +00:00
|
|
|
|
|
|
|
@click.group(cls=DefaultGroup, default='serve', default_if_no_args=True)
|
2017-10-27 07:08:24 +00:00
|
|
|
def cli():
|
|
|
|
"""
|
2017-11-10 18:38:35 +00:00
|
|
|
Datasette!
|
2017-10-27 07:08:24 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
2017-11-06 02:24:43 +00:00
|
|
|
@click.argument('files', type=click.Path(exists=True), nargs=-1)
|
|
|
|
def build(files):
|
|
|
|
ensure_build_metadata(files, True)
|
2017-10-27 07:08:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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)
|
2017-11-09 13:46:16 +00:00
|
|
|
@click.option('--reload', is_flag=True)
|
|
|
|
def serve(files, host, port, debug, reload):
|
2017-11-04 23:53:50 +00:00
|
|
|
"""Serve up specified database files with a web UI"""
|
2017-11-09 13:46:16 +00:00
|
|
|
if reload:
|
|
|
|
import hupper
|
2017-11-10 18:38:35 +00:00
|
|
|
hupper.start_reloader('datasette.cli.serve')
|
2017-11-09 13:46:16 +00:00
|
|
|
|
2017-10-27 07:08:24 +00:00
|
|
|
click.echo('Serve! files={} on port {}'.format(files, port))
|
2017-11-10 20:26:37 +00:00
|
|
|
app = Datasette(files, cache_headers=not debug and not reload).app()
|
2017-10-27 07:08:24 +00:00
|
|
|
app.run(host=host, port=port, debug=debug)
|