gisaf-backend/src/gisaf/cli.py
2025-06-28 04:41:57 +02:00

50 lines
1 KiB
Python

#!/usr/bin/env python
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.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:
from gisaf import __version__
typer.echo(__version__)
raise typer.Exit()
@cli.callback()
def main(
version: Annotated[bool | None, typer.Option("--version", callback=version_callback)] = None,
):
pass
if __name__ == "__main__":
cli()