import typer

import uv_go
from uv_go.manager import UvRunManager

cli = typer.Typer(help='uv-go CLI')


def version_callback(value: bool):
    if value:
        print(f'Version of uv-go is {uv_go.__version__}')
        raise typer.Exit(0)


@cli.callback(invoke_without_command=True)
def callback(  # noqa: C901
    #
    version: bool = typer.Option(
        False,
        '--version',
        callback=version_callback,
        help='Print version of uv-go.',
        is_eager=True,
    ),
    script: str = typer.Argument(help='Script in format module:function.method'),
    verbose: bool = typer.Option(
        False,
        '--verbose',
        '-v',
        help='Run with verbose',
    ),
):
    manager = UvRunManager(script, verbose=verbose)
    manager.run()


@cli.command('nothing', hidden=True)
def nothing_command():
    """Plug."""
    pass
