Skip to content

Commit 5ba00b5

Browse files
committed
Add version flag
1 parent 2d3354f commit 5ba00b5

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

ape_linux.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22

33
import os
44
import subprocess
5+
from importlib.metadata import version
56
from typing import Annotated
67

78
import openai
89
import rich.console
910
import typer
1011

12+
__version__ = version("ape_linux")
13+
1114
app = typer.Typer(add_completion=False, pretty_exceptions_enable=False)
1215

1316

17+
def version_callback(value: bool) -> None:
18+
if value:
19+
typer.echo(__version__)
20+
raise typer.Exit()
21+
22+
1423
def call_llm(
1524
api_key: str, model: str, system_prompt: str, user_prompt: str
1625
) -> str | None:
@@ -49,6 +58,16 @@ def main(
4958
help="Run the command if suggested. Dangerous!",
5059
),
5160
] = False,
61+
version: Annotated[
62+
bool | None,
63+
typer.Option(
64+
"--version",
65+
"-v",
66+
callback=version_callback,
67+
help="Show the version and exit.",
68+
is_eager=True,
69+
),
70+
] = None,
5271
):
5372
"""Suggest a command for a Linux task described in QUERY.
5473

tests/test_app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ def test_app_for_suggestion_with_execute(mockenv, monkeypatch):
5252
assert result.stdout == "ls\n" # careful, this will actually run
5353
assert result.stderr == ""
5454
assert result.exit_code == 0
55+
56+
57+
def test_app_for_version(mockenv):
58+
result = runner.invoke(ape_linux.app, ["--version"])
59+
assert result.stdout == f"{ape_linux.__version__}\n"
60+
assert result.stderr == ""
61+
assert result.exit_code == 0

0 commit comments

Comments
 (0)