Browse Source

Add --port flag to pc run (#313)

Francesco Ambrosini 2 năm trước cách đây
mục cha
commit
8068d5f176
2 tập tin đã thay đổi với 8 bổ sung7 xóa
  1. 2 2
      pynecone/pc.py
  2. 6 5
      pynecone/utils.py

+ 2 - 2
pynecone/pc.py

@@ -57,6 +57,7 @@ def run(
     loglevel: constants.LogLevel = typer.Option(
     loglevel: constants.LogLevel = typer.Option(
         constants.LogLevel.ERROR, help="The log level to use."
         constants.LogLevel.ERROR, help="The log level to use."
     ),
     ),
+    port: str = typer.Option(None, help="Specify a different port."),
 ):
 ):
     """Run the app in the current directory."""
     """Run the app in the current directory."""
     # Check that the app is initialized.
     # Check that the app is initialized.
@@ -87,7 +88,7 @@ def run(
 
 
     # Run the frontend and backend.
     # Run the frontend and backend.
     if frontend:
     if frontend:
-        frontend_cmd(app.app, Path.cwd())
+        frontend_cmd(app.app, Path.cwd(), port)
     if backend:
     if backend:
         backend_cmd(app.__name__, loglevel=loglevel)
         backend_cmd(app.__name__, loglevel=loglevel)
 
 
@@ -146,6 +147,5 @@ def export():
 
 
 main = cli
 main = cli
 
 
-
 if __name__ == "__main__":
 if __name__ == "__main__":
     main()
     main()

+ 6 - 5
pynecone/utils.py

@@ -48,7 +48,6 @@ if TYPE_CHECKING:
     from pynecone.event import Event, EventHandler, EventSpec
     from pynecone.event import Event, EventHandler, EventSpec
     from pynecone.var import Var
     from pynecone.var import Var
 
 
-
 # Shorthand for join.
 # Shorthand for join.
 join = os.linesep.join
 join = os.linesep.join
 
 
@@ -512,12 +511,13 @@ def setup_frontend(root: Path):
     )
     )
 
 
 
 
-def run_frontend(app: App, root: Path):
+def run_frontend(app: App, root: Path, port: str):
     """Run the frontend.
     """Run the frontend.
 
 
     Args:
     Args:
         app: The app.
         app: The app.
         root: root path of the project.
         root: root path of the project.
+        port: port of the app.
     """
     """
     # Set up the frontend.
     # Set up the frontend.
     setup_frontend(root)
     setup_frontend(root)
@@ -527,7 +527,7 @@ def run_frontend(app: App, root: Path):
 
 
     # Run the frontend in development mode.
     # Run the frontend in development mode.
     console.rule("[bold green]App Running")
     console.rule("[bold green]App Running")
-    os.environ["PORT"] = get_config().port
+    os.environ["PORT"] = get_config().port if port is None else port
 
 
     subprocess.Popen(
     subprocess.Popen(
         [get_package_manager(), "run", "next", "telemetry", "disable"],
         [get_package_manager(), "run", "next", "telemetry", "disable"],
@@ -542,12 +542,13 @@ def run_frontend(app: App, root: Path):
     )
     )
 
 
 
 
-def run_frontend_prod(app: App, root: Path):
+def run_frontend_prod(app: App, root: Path, port: str):
     """Run the frontend.
     """Run the frontend.
 
 
     Args:
     Args:
         app: The app.
         app: The app.
         root: root path of the project.
         root: root path of the project.
+        port: port of the app.
     """
     """
     # Set up the frontend.
     # Set up the frontend.
     setup_frontend(root)
     setup_frontend(root)
@@ -555,7 +556,7 @@ def run_frontend_prod(app: App, root: Path):
     # Export the app.
     # Export the app.
     export_app(app)
     export_app(app)
 
 
-    os.environ["PORT"] = get_config().port
+    os.environ["PORT"] = get_config().port if port is None else port
 
 
     # Run the frontend in production mode.
     # Run the frontend in production mode.
     subprocess.Popen(
     subprocess.Popen(