from __future__ import annotations

import typer

from flow_xhs.cli.spec.runtime_contracts import command_description, command_summary
from flow_xhs.services.init_runtime import execute_runtime_init
from flow_xhs.cli.context import CliContext
from flow_xhs.cli.runtime import run_sync_command

app = typer.Typer(
    help=command_summary(("init",)),
    no_args_is_help=False,
    options_metavar="[OPTIONS]",
    subcommand_metavar="",
)

def _run_init_command(ctx: typer.Context, *, command_name: str) -> None:
    cli_ctx: CliContext = ctx.obj
    run_sync_command(ctx=cli_ctx, command=command_name, func=execute_runtime_init)


@app.callback(invoke_without_command=True)
def init(ctx: typer.Context):
    if ctx.invoked_subcommand:
        return
    _run_init_command(ctx, command_name="init")


init.__doc__ = command_description(("init",))
