from pathlib import Path import subprocess import typer from l4d2host.instances import delete_instance, initialize_instance, start_instance, stop_instance from l4d2host.steam_install import SteamInstaller app = typer.Typer(no_args_is_help=True) def _exit_from_subprocess_error(exc: subprocess.CalledProcessError) -> None: if exc.stderr: typer.echo(exc.stderr, err=True) raise typer.Exit(code=exc.returncode) @app.command() def install() -> None: try: SteamInstaller().install_or_update(passthrough=True) except subprocess.CalledProcessError as exc: _exit_from_subprocess_error(exc) @app.command() def initialize(name: str, spec: Path = typer.Option(..., "-f")) -> None: try: initialize_instance(name, spec, passthrough=True) except subprocess.CalledProcessError as exc: _exit_from_subprocess_error(exc) @app.command() def start(name: str) -> None: try: start_instance(name, passthrough=True) except subprocess.CalledProcessError as exc: _exit_from_subprocess_error(exc) @app.command() def stop(name: str) -> None: try: stop_instance(name, passthrough=True) except subprocess.CalledProcessError as exc: _exit_from_subprocess_error(exc) @app.command() def delete(name: str) -> None: try: delete_instance(name, passthrough=True) except subprocess.CalledProcessError as exc: _exit_from_subprocess_error(exc)