import typer
from importlib.metadata import version as get_package_version

from iac.cli.apps.run import app as run_app
from iac.cli.apps.list import app as list_app
from iac.cli.apps.get import app as get_app
from iac.cli.apps.check import app as check_app
from iac.cli.apps.deps import app as deps_app
from iac.cli.apps.init import app as init_app

app = typer.Typer(
    add_completion=False,
    help="Infrastructure as Code",
    no_args_is_help=True,
)

app.add_typer(run_app, name="run", help="execute commands, books, and steps")
app.add_typer(list_app, name="list", help="list available books, steps, and modules")
app.add_typer(init_app, name="init", help="scaffold books")
app.add_typer(check_app, name="check", help="check dependency requirements")
app.add_typer(deps_app, name="deps", help="dependency install helpers")
app.add_typer(
    get_app, name="get", help="get details for a book, step, or module (no execution)"
)


@app.command()
def version() -> None:
    """show the iac version"""
    typer.echo(f"iac version: {get_package_version('iac')}")
    raise typer.Exit(code=0)
