浏览代码

Update version flag (#1452)

Nikhil Rao 1 年之前
父节点
当前提交
0ebe1529a6
共有 2 个文件被更改,包括 30 次插入8 次删除
  1. 1 1
      pyproject.toml
  2. 29 7
      reflex/reflex.py

+ 1 - 1
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"]

+ 29 - 7
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()