added feature to automatically change port (#2867)
This commit is contained in:
parent
8a2b92f2e9
commit
15dc7f4552
@ -169,10 +169,10 @@ def _run(
|
|||||||
|
|
||||||
# If something is running on the ports, ask the user if they want to kill or change it.
|
# If something is running on the ports, ask the user if they want to kill or change it.
|
||||||
if frontend and processes.is_process_on_port(frontend_port):
|
if frontend and processes.is_process_on_port(frontend_port):
|
||||||
frontend_port = processes.change_or_terminate_port(frontend_port, "frontend")
|
frontend_port = processes.change_port(frontend_port, "frontend")
|
||||||
|
|
||||||
if backend and processes.is_process_on_port(backend_port):
|
if backend and processes.is_process_on_port(backend_port):
|
||||||
backend_port = processes.change_or_terminate_port(backend_port, "backend")
|
backend_port = processes.change_port(backend_port, "backend")
|
||||||
|
|
||||||
# Apply the new ports to the config.
|
# Apply the new ports to the config.
|
||||||
if frontend_port != str(config.frontend_port):
|
if frontend_port != str(config.frontend_port):
|
||||||
|
@ -87,41 +87,24 @@ def kill_process_on_port(port):
|
|||||||
get_process_on_port(port).kill() # type: ignore
|
get_process_on_port(port).kill() # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def change_or_terminate_port(port, _type) -> str:
|
def change_port(port: str, _type: str) -> str:
|
||||||
"""Terminate or change the port.
|
"""Change the port.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
port: The port.
|
port: The port.
|
||||||
_type: The type of the port.
|
_type: The type of the port.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The new port or the current one.
|
The new port.
|
||||||
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
Exit: If the user wants to exit.
|
|
||||||
"""
|
"""
|
||||||
|
new_port = str(int(port) + 1)
|
||||||
|
if is_process_on_port(new_port):
|
||||||
|
return change_port(new_port, _type)
|
||||||
console.info(
|
console.info(
|
||||||
f"Something is already running on port [bold underline]{port}[/bold underline]. This is the port the {_type} runs on."
|
f"The {_type} will run on port [bold underline]{new_port}[/bold underline]."
|
||||||
)
|
)
|
||||||
frontend_action = console.ask("Kill or change it?", choices=["k", "c", "n"])
|
return new_port
|
||||||
if frontend_action == "k":
|
|
||||||
kill_process_on_port(port)
|
|
||||||
return port
|
|
||||||
elif frontend_action == "c":
|
|
||||||
new_port = console.ask("Specify the new port")
|
|
||||||
|
|
||||||
# Check if also the new port is used
|
|
||||||
if is_process_on_port(new_port):
|
|
||||||
return change_or_terminate_port(new_port, _type)
|
|
||||||
else:
|
|
||||||
console.info(
|
|
||||||
f"The {_type} will run on port [bold underline]{new_port}[/bold underline]."
|
|
||||||
)
|
|
||||||
return new_port
|
|
||||||
else:
|
|
||||||
console.log("Exiting...")
|
|
||||||
raise typer.Exit()
|
|
||||||
|
|
||||||
|
|
||||||
def new_process(args, run: bool = False, show_logs: bool = False, **kwargs):
|
def new_process(args, run: bool = False, show_logs: bool = False, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user