From 205343bc0a81b75d767cea511b54ddba837726ae Mon Sep 17 00:00:00 2001 From: Ivan Ogasawara Date: Sat, 23 Dec 2023 07:39:36 -0400 Subject: [PATCH] feat(cli): Implement --version flag to CLI --- src/envers/cli.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/envers/cli.py b/src/envers/cli.py index aa29baa..7182d6f 100644 --- a/src/envers/cli.py +++ b/src/envers/cli.py @@ -5,13 +5,36 @@ import typer +from typer import Context, Option from typing_extensions import Annotated +from envers import __version__ from envers.core import Envers app = typer.Typer() +@app.callback(invoke_without_command=True) +def main( + ctx: Context, + version: bool = Option( + None, + "--version", + "-v", + is_flag=True, + help="Show the version and exit.", + ), +) -> None: + """Process envers for specific flags, otherwise show the help menu.""" + if version: + typer.echo(f"Version: {__version__}") + raise typer.Exit() + + if ctx.invoked_subcommand is None: + typer.echo(ctx.get_help()) + raise typer.Exit(0) + + @app.command() def init(path: str = ".") -> None: """