Browse Source

Update pc run backend/frontend only flags (#800)

Milo Chen 2 years ago
parent
commit
adf2b8d395
1 changed files with 16 additions and 10 deletions
  1. 16 10
      pynecone/pc.py

+ 16 - 10
pynecone/pc.py

@@ -61,15 +61,14 @@ def run(
         constants.Env.DEV, help="The environment to run the app in."
     ),
     frontend: bool = typer.Option(
-        True, "--no-frontend", help="Disable frontend execution."
-    ),
-    backend: bool = typer.Option(
-        True, "--no-backend", help="Disable backend execution."
+        False, "--frontend-only", help="Execute only frontend."
     ),
+    backend: bool = typer.Option(False, "--backend-only", help="Execute only backend."),
     loglevel: constants.LogLevel = typer.Option(
         constants.LogLevel.ERROR, help="The log level to use."
     ),
-    port: str = typer.Option(None, help="Specify a different port."),
+    port: str = typer.Option(None, help="Specify a different frontend port."),
+    backend_port: str = typer.Option(None, help="Specify a different backend port."),
 ):
     """Run the app in the current directory."""
     if platform.system() == "Windows":
@@ -78,13 +77,18 @@ def run(
         )
 
     frontend_port = get_config().port if port is None else port
-    backend_port = get_config().backend_port
+    backend_port = get_config().backend_port if backend_port is None else backend_port
+
+    # If --no-frontend-only and no --backend-only, then turn on frontend and backend both
+    if not frontend and not backend:
+        frontend = True
+        backend = True
 
     # If something is running on the ports, ask the user if they want to kill or change it.
-    if 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")
 
-    if 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")
 
     # Check that the app is initialized.
@@ -123,8 +127,10 @@ def run(
         if backend:
             backend_cmd(app.__name__, port=int(backend_port), loglevel=loglevel)
     finally:
-        processes.kill_process_on_port(frontend_port)
-        processes.kill_process_on_port(backend_port)
+        if frontend:
+            processes.kill_process_on_port(frontend_port)
+        if backend:
+            processes.kill_process_on_port(backend_port)
 
 
 @cli.command()