Skip to content

Commit

Permalink
✨ Add option --version
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelWO committed Dec 24, 2024
1 parent 763b671 commit 348d28a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions pirel/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.2.1"
17 changes: 17 additions & 0 deletions pirel/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import typer
from rich.console import Console

import pirel

from .logging import setup_logging
from .python_cli import get_active_python_info
from .releases import load_releases
Expand All @@ -29,6 +31,12 @@ def logging_callback(ctx: typer.Context, verbosity: int) -> Optional[int]:
return verbosity


def version_callback(value: bool) -> None:
if value:
print(f"pirel {pirel.__version__}")
raise typer.Exit()


VERBOSE_OPTION = Annotated[
int,
typer.Option(
Expand All @@ -54,6 +62,15 @@ def print_releases() -> None:
def main(
ctx: typer.Context,
verbose: VERBOSE_OPTION = 0,
version: Annotated[
Optional[bool],
typer.Option(
"--version",
help="Dispay the version of pirel",
callback=version_callback,
is_eager=True,
),
] = None,
) -> None:
"""The Python release cycle in your terminal."""
if not ctx.invoked_subcommand:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from rich.console import Console
from typer.testing import CliRunner

import pirel
from pirel.cli import app
from pirel.python_cli import PythonVersion

Expand Down Expand Up @@ -130,3 +131,9 @@ def test_pirel_check_no_interpreter():
# Call CLI
result = runner.invoke(app, "check")
assert result.exit_code == 2, result.stdout


def test_pirel_version():
result = runner.invoke(app, "--version")
assert result.exit_code == 0
assert result.stdout.strip() == f"pirel {pirel.__version__}"

0 comments on commit 348d28a

Please sign in to comment.