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.
iTi-Flask/iti/cli.py

39 lines
1.2 KiB
Python

import click
from iti.config import get_config
@click.group()
def iti_cli() -> None:
"""iTi-Flask framework commands."""
@iti_cli.command("config")
@click.option("--env", "env_name", default=None, help="Config environment name.")
def show_config(env_name: str | None) -> None:
config = get_config(env_name)
click.echo(f"app_env={config.app_env}")
click.echo(f"database_url={config.database_url}")
click.echo(f"health_enabled={config.health_enabled}")
click.echo(f"ready_check_db={config.ready_check_db}")
@iti_cli.command("routes")
@click.argument("app_import")
def list_routes(app_import: str) -> None:
app = _load_app(app_import)
for route in app.routes:
methods = ",".join(sorted(getattr(route, "methods", []) or []))
path = getattr(route, "path", "")
name = getattr(route, "name", "")
click.echo(f"{methods:20} {path:40} {name}")
def _load_app(app_import: str):
module_name, _, attr_name = app_import.partition(":")
if not module_name or not attr_name:
raise click.ClickException("app import must use module:attribute")
module = __import__(module_name, fromlist=[attr_name])
app = getattr(module, attr_name)
return app() if callable(app) else app