53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
#!/usr/bin/env python
|
|
from importlib.metadata import version as importlib_version
|
|
from sqlalchemy.engine import create
|
|
from typing_extensions import Annotated
|
|
import typer
|
|
|
|
|
|
cli = typer.Typer(no_args_is_help=True, help="Gisaf GIS backend")
|
|
|
|
|
|
@cli.command()
|
|
def create_db():
|
|
"""Populate the database with a functional empty structure"""
|
|
from gisaf.application import app
|
|
from gisaf.database import create_db
|
|
from asyncio import run
|
|
|
|
print(f"Create DB...")
|
|
run(create_db())
|
|
|
|
|
|
@cli.command()
|
|
def serve(host: str = "localhost", port: int = 8000):
|
|
"""
|
|
Run the uvicorn server.
|
|
|
|
Use yaml config files or environment variables for configuration.
|
|
Note that you can also run gisaf with:
|
|
uvicorn src.gisaf.application:app
|
|
"""
|
|
from uvicorn import run
|
|
from gisaf.application import app
|
|
|
|
run(app, host=host, port=port)
|
|
|
|
|
|
def version_callback(show_version: bool):
|
|
if show_version:
|
|
print(importlib_version("gisaf-backend"))
|
|
raise typer.Exit()
|
|
|
|
|
|
@cli.callback()
|
|
def main(
|
|
version: Annotated[
|
|
bool | None, typer.Option("--version", callback=version_callback)
|
|
] = None
|
|
):
|
|
pass
|
|
|
|
|
|
if __name__ == "__main__":
|
|
cli()
|