"""Typer CLI for CDIF profile code generation, inspection, and validation."""
from __future__ import annotations
from pathlib import Path
from typing import Annotated
import typer
from dartfx.cdif.codegen import generate_all
from dartfx.cdif.registry import DEFAULT_REGISTRY, detect_profiles, load_cdif
app = typer.Typer(
name="cdif",
help="CLI utilities for Cross-Domain Interoperability Framework (CDIF) profiles and Pydantic RDF models.",
no_args_is_help=True,
)
[docs]
@app.command("codegen")
def codegen_cmd(
cdif_root: Annotated[
Path | None,
typer.Option("--cdif-root", help="Path to the local git-cdif repositories directory."),
] = None,
output_dir: Annotated[
Path | None,
typer.Option("--output-dir", help="Destination directory for generated model files."),
] = None,
) -> None:
"""Regenerate CDIF Pydantic + RDF models from upstream JSON Schemas and vocabularies."""
written = generate_all(cdif_root=cdif_root, output_dir=output_dir)
typer.echo(f"Generated {len(written)} files:")
for path in written:
typer.echo(f" {path}")
[docs]
@app.command("profiles")
def profiles_cmd() -> None:
"""List registered CDIF profiles, model classes, and canonical URIs."""
for info in DEFAULT_REGISTRY.list_profiles():
model_name = info.model_class.__name__ if info.model_class is not None else "(component-only)"
typer.echo(f"{info.key}: {model_name}")
for uri in info.uris:
typer.echo(f" - {uri}")
[docs]
@app.command("validate")
def validate_cmd(
path: Annotated[Path, typer.Argument(help="Path to a CDIF JSON-LD or RDF file.")],
profile: Annotated[
str | None,
typer.Option("--profile", "-p", help="Explicit profile key or URI (auto-detected if omitted)."),
] = None,
rdf_format: Annotated[
str | None,
typer.Option("--format", "-f", help="Input RDF serialization format (e.g. json-ld, turtle)."),
] = None,
) -> None:
"""Load a CDIF metadata file into its Pydantic model and run conformance checks."""
if not path.is_file():
typer.echo(f"File not found: {path}", err=True)
raise typer.Exit(code=1)
model = load_cdif(path, profile=profile, rdf_format=rdf_format)
detected = detect_profiles(model)
profile_keys = ", ".join(p.key for p in detected)
typer.echo(f"Model: {type(model).__name__} (detected profiles: {profile_keys})")
violations = model.validate_conformance(strict=False)
if violations:
typer.echo("Conformance issues found:", err=True)
for v in violations:
typer.echo(f" - {v}", err=True)
raise typer.Exit(code=1)
typer.echo("Conformance check passed.")
if __name__ == "__main__":
app()