Add CLI demo command (#2044)
This commit is contained in:
parent
d2afaf5bb3
commit
f5e9debe4f
106
reflex/reflex.py
106
reflex/reflex.py
@ -65,20 +65,12 @@ def main(
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
def _init(
|
||||||
def init(
|
name: str,
|
||||||
name: str = typer.Option(
|
template: constants.Templates.Kind,
|
||||||
None, metavar="APP_NAME", help="The name of the app to initialize."
|
loglevel: constants.LogLevel,
|
||||||
),
|
|
||||||
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."
|
|
||||||
),
|
|
||||||
):
|
):
|
||||||
"""Initialize a new Reflex app in the current directory."""
|
"""Initialize a new Reflex app in the given directory."""
|
||||||
# Set the log level.
|
# Set the log level.
|
||||||
console.set_log_level(loglevel)
|
console.set_log_level(loglevel)
|
||||||
|
|
||||||
@ -114,28 +106,32 @@ def init(
|
|||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
def run(
|
def init(
|
||||||
env: constants.Env = typer.Option(
|
name: str = typer.Option(
|
||||||
constants.Env.DEV, help="The environment to run the app in."
|
None, metavar="APP_NAME", help="The name of the app to initialize."
|
||||||
),
|
),
|
||||||
frontend: bool = typer.Option(
|
template: constants.Templates.Kind = typer.Option(
|
||||||
False, "--frontend-only", help="Execute only frontend."
|
constants.Templates.Kind.BASE.value,
|
||||||
),
|
help="The template to initialize the app with.",
|
||||||
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(
|
loglevel: constants.LogLevel = typer.Option(
|
||||||
config.loglevel, help="The log level to use."
|
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.
|
# Set the log level.
|
||||||
console.set_log_level(loglevel)
|
console.set_log_level(loglevel)
|
||||||
|
|
||||||
@ -219,6 +215,32 @@ def run(
|
|||||||
backend_cmd(backend_host, int(backend_port))
|
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()
|
@cli.command()
|
||||||
def deploy_legacy(
|
def deploy_legacy(
|
||||||
dry_run: bool = typer.Option(False, help="Whether to run a dry run."),
|
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}`")
|
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()
|
deployments_cli = typer.Typer()
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ class AppHarness:
|
|||||||
"".join(inspect.getsource(self.app_source).splitlines(True)[1:]),
|
"".join(inspect.getsource(self.app_source).splitlines(True)[1:]),
|
||||||
)
|
)
|
||||||
with chdir(self.app_path):
|
with chdir(self.app_path):
|
||||||
reflex.reflex.init(
|
reflex.reflex._init(
|
||||||
name=self.app_name,
|
name=self.app_name,
|
||||||
template=reflex.constants.Templates.Kind.BLANK,
|
template=reflex.constants.Templates.Kind.BLANK,
|
||||||
loglevel=reflex.constants.LogLevel.INFO,
|
loglevel=reflex.constants.LogLevel.INFO,
|
||||||
|
Loading…
Reference in New Issue
Block a user