feat(tht): schema columns reader (name/description/type/pk) from catalog
This commit is contained in:
@@ -156,3 +156,43 @@ def render_cmd(
|
||||
typer.secho(f"OK: scritto {output}", fg=typer.colors.GREEN)
|
||||
else:
|
||||
typer.echo(out)
|
||||
|
||||
|
||||
@schema_app.command("columns")
|
||||
def columns_cmd(
|
||||
table: str = typer.Argument(..., help="Nome tabella (chiave in physical.yaml)."),
|
||||
json_out: bool = typer.Option(False, "--json", help="Emetti JSON puro su stdout."),
|
||||
config: Path = CONFIG_OPT,
|
||||
) -> None:
|
||||
"""Elenca nome/descrizione/tipo/pk delle colonne di una tabella dal catalogo."""
|
||||
import json as _json
|
||||
|
||||
from tht.mschema.models import PhysicalSchema
|
||||
|
||||
cfg = _load_config_or_exit(config)
|
||||
phys_file = physical_path(cfg)
|
||||
if not phys_file.exists():
|
||||
typer.secho(
|
||||
f"ERRORE: {phys_file} non trovato. Esegui prima `tht schema introspect`.",
|
||||
fg=typer.colors.RED, err=True,
|
||||
)
|
||||
raise typer.Exit(code=1)
|
||||
physical = PhysicalSchema.from_yaml(phys_file)
|
||||
tbl = physical.tables.get(table)
|
||||
if tbl is None:
|
||||
typer.secho(f"ERRORE: tabella non nel catalogo: {table}", fg=typer.colors.RED, err=True)
|
||||
raise typer.Exit(code=1)
|
||||
payload = {
|
||||
"table": table,
|
||||
"description": tbl.comment,
|
||||
"columns": [
|
||||
{"name": name, "description": col.comment, "type": col.type, "pk": col.pk}
|
||||
for name, col in tbl.columns.items()
|
||||
],
|
||||
}
|
||||
if json_out:
|
||||
typer.echo(_json.dumps(payload, ensure_ascii=False))
|
||||
return
|
||||
typer.echo(f"{table}: {tbl.comment}")
|
||||
for c in payload["columns"]:
|
||||
typer.echo(f" {'*' if c['pk'] else ' '} {c['name']} ({c['type']}) — {c['description']}")
|
||||
|
||||
Reference in New Issue
Block a user