From 97d2b30838dd3a837d82dafbf3d00d5e33924a07 Mon Sep 17 00:00:00 2001 From: Wytamma Wirth Date: Fri, 26 Apr 2024 10:57:04 +1000 Subject: [PATCH] :art: check for port use before starting server --- backend/beastiary/cli.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/beastiary/cli.py b/backend/beastiary/cli.py index fc00378..bb1230a 100644 --- a/backend/beastiary/cli.py +++ b/backend/beastiary/cli.py @@ -32,7 +32,7 @@ def main( ), token: str = typer.Option(str(uuid.uuid4()), "--token", "-t"), host: str = typer.Option("127.0.0.1", "--host"), - port: str = typer.Option(5000, "--port"), + port: int = typer.Option(5000, "--port"), share: bool = typer.Option( False, "--share", help="Create a publicly shareable link." ), @@ -55,6 +55,12 @@ def main( if version: typer.echo(f"Beastiary {pkg_resources.get_distribution('beastiary').version}") return typer.Exit() + if not address_is_available(host, port): + typer.secho( + f"Address {host}:{port} is already in use. Please choose another address.", + fg=typer.colors.RED, + ) + return typer.Exit(1) msg = typer.style("STARTING BEASTIARY", fg=typer.colors.BLUE, bold=True) typer.echo(f"\nšŸ™šŸ {msg} šŸšŸ™\n") if log_files: @@ -86,12 +92,6 @@ def main( log_level = "debug" if testing: return typer.Exit() - if not address_is_available(host, port): - typer.secho( - f"Address {host}:{port} is already in use. Please choose another address.", - fg=typer.colors.RED, - ) - return typer.Exit(1) if share: typer.echo("Creating public shareable link...") with cloudflared(port=port) as cloudflared_url: