import subprocess

import typer

from remotivelabs.cli.topology.cli.run_in_docker import run_topology_cli_in_docker


def run_topology_cli(ctx: typer.Context, args: list[str]) -> None:
    if ctx.obj["topology_cmd"] is None:
        run_topology_cli_in_docker(ctx, args)
    else:
        cmd = [ctx.obj["topology_cmd"]] + args
        try:
            subprocess.run(cmd, check=True)
        except subprocess.CalledProcessError as e:
            raise typer.Exit(code=e.returncode)
