From 0ebe1529a67e6395307415fa0fbf69b761ac69d4 Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Fri, 28 Jul 2023 12:30:39 -0700 Subject: [PATCH] Update version flag (#1452) --- pyproject.toml | 2 +- reflex/reflex.py | 36 +++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9d1d60318..96824e344 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,7 @@ pre-commit = {version = "^3.2.1", python = ">=3.8,<4.0"} selenium = "^4.10.0" [tool.poetry.scripts] -reflex = "reflex.reflex:main" +reflex = "reflex.reflex:cli" [build-system] requires = ["poetry-core>=1.5.1"] diff --git a/reflex/reflex.py b/reflex/reflex.py index 81b563c8b..d8937c2cc 100644 --- a/reflex/reflex.py +++ b/reflex/reflex.py @@ -18,10 +18,33 @@ from reflex.utils import build, console, exec, prerequisites, processes, telemet cli = typer.Typer() -@cli.command() -def version(): - """Get the Reflex version.""" - console.print(constants.VERSION) +def version(value: bool): + """Get the Reflex version. + + Args: + value: Whether the version flag was passed. + + Raises: + typer.Exit: If the version flag was passed. + """ + if value: + console.print(constants.VERSION) + raise typer.Exit() + + +@cli.callback() +def main( + version: bool = typer.Option( + None, + "--version", + "-v", + callback=version, + help="Get the Reflex version.", + is_eager=True, + ), +): + """Reflex CLI global configuration.""" + pass @cli.command() @@ -306,8 +329,7 @@ def makemigrations( ) -cli.add_typer(db_cli, name="db", help="Subcommands for managing the database schema") -main = cli +cli.add_typer(db_cli, name="db", help="Subcommands for managing the database schema.") if __name__ == "__main__": - main() + cli()