Alek Petuskey преди 1 година
родител
ревизия
f5e9debe4f
променени са 3 файла, в които са добавени 78 реда и са изтрити 30 реда
  1. 77 29
      reflex/reflex.py
  2. 1 1
      reflex/testing.py
  3. 0 0
      requirements.txt

+ 77 - 29
reflex/reflex.py

@@ -65,20 +65,12 @@ def main(
     pass
 
 
-@cli.command()
-def init(
-    name: str = typer.Option(
-        None, metavar="APP_NAME", help="The name of the app to initialize."
-    ),
-    template: constants.Templates.Kind = typer.Option(
-        constants.Templates.Kind.BASE.value,
-        help="The template to initialize the app with.",
-    ),
-    loglevel: constants.LogLevel = typer.Option(
-        config.loglevel, help="The log level to use."
-    ),
+def _init(
+    name: str,
+    template: constants.Templates.Kind,
+    loglevel: constants.LogLevel,
 ):
-    """Initialize a new Reflex app in the current directory."""
+    """Initialize a new Reflex app in the given directory."""
     # Set the log level.
     console.set_log_level(loglevel)
 
@@ -114,28 +106,32 @@ def init(
 
 
 @cli.command()
-def run(
-    env: constants.Env = typer.Option(
-        constants.Env.DEV, help="The environment to run the app in."
-    ),
-    frontend: bool = typer.Option(
-        False, "--frontend-only", help="Execute only frontend."
-    ),
-    backend: bool = typer.Option(False, "--backend-only", help="Execute only backend."),
-    frontend_port: str = typer.Option(
-        config.frontend_port, help="Specify a different frontend port."
-    ),
-    backend_port: str = typer.Option(
-        config.backend_port, help="Specify a different backend port."
+def init(
+    name: str = typer.Option(
+        None, metavar="APP_NAME", help="The name of the app to initialize."
     ),
-    backend_host: str = typer.Option(
-        config.backend_host, help="Specify the backend host."
+    template: constants.Templates.Kind = typer.Option(
+        constants.Templates.Kind.BASE.value,
+        help="The template to initialize the app with.",
     ),
     loglevel: constants.LogLevel = typer.Option(
         config.loglevel, help="The log level to use."
     ),
 ):
-    """Run the app in the current directory."""
+    """Initialize a new Reflex app in the current directory."""
+    _init(name, template, loglevel)
+
+
+def _run(
+    env: constants.Env,
+    frontend: bool = True,
+    backend: bool = True,
+    frontend_port: str = str(get_config().frontend_port),
+    backend_port: str = str(get_config().backend_port),
+    backend_host: str = config.backend_host,
+    loglevel: constants.LogLevel = config.loglevel,
+):
+    """Run the app in the given directory."""
     # Set the log level.
     console.set_log_level(loglevel)
 
@@ -219,6 +215,32 @@ def run(
             backend_cmd(backend_host, int(backend_port))
 
 
+@cli.command()
+def run(
+    env: constants.Env = typer.Option(
+        constants.Env.DEV, help="The environment to run the app in."
+    ),
+    frontend: bool = typer.Option(
+        False, "--frontend-only", help="Execute only frontend."
+    ),
+    backend: bool = typer.Option(False, "--backend-only", help="Execute only backend."),
+    frontend_port: str = typer.Option(
+        config.frontend_port, help="Specify a different frontend port."
+    ),
+    backend_port: str = typer.Option(
+        config.backend_port, help="Specify a different backend port."
+    ),
+    backend_host: str = typer.Option(
+        config.backend_host, help="Specify the backend host."
+    ),
+    loglevel: constants.LogLevel = typer.Option(
+        config.loglevel, help="The log level to use."
+    ),
+):
+    """Run the app in the current directory."""
+    _run(env, frontend, backend, frontend_port, backend_port, backend_host, loglevel)
+
+
 @cli.command()
 def deploy_legacy(
     dry_run: bool = typer.Option(False, help="Whether to run a dry run."),
@@ -677,6 +699,32 @@ def deploy(
     console.warn(f"For logs: `reflex deployments logs {key}`")
 
 
+@cli.command()
+def demo(
+    frontend_port: str = typer.Option(
+        "3001", help="Specify a different frontend port."
+    ),
+    backend_port: str = typer.Option("8001", help="Specify a different backend port."),
+):
+    """Run the demo app."""
+    with tempfile.TemporaryDirectory() as tmp_dir:
+        os.chdir(tmp_dir)
+        _init(
+            name="reflex_demo",
+            template=constants.Templates.Kind.BASE,
+            loglevel=constants.LogLevel.ERROR,
+        )
+        _run(
+            env=constants.Env.DEV,
+            frontend=True,
+            backend=True,
+            frontend_port=frontend_port,
+            backend_port=backend_port,
+            backend_host="localhost",
+            loglevel=constants.LogLevel.ERROR,
+        )
+
+
 deployments_cli = typer.Typer()
 
 

+ 1 - 1
reflex/testing.py

@@ -152,7 +152,7 @@ class AppHarness:
                 "".join(inspect.getsource(self.app_source).splitlines(True)[1:]),
             )
             with chdir(self.app_path):
-                reflex.reflex.init(
+                reflex.reflex._init(
                     name=self.app_name,
                     template=reflex.constants.Templates.Kind.BLANK,
                     loglevel=reflex.constants.LogLevel.INFO,

+ 0 - 0
requirements.txt