Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ape_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

import os
import subprocess
from importlib.metadata import version
from typing import Annotated

import openai
import rich.console
import typer

__version__ = version("ape_linux")

app = typer.Typer(add_completion=False, pretty_exceptions_enable=False)


def version_callback(value: bool) -> None:
if value:
typer.echo(__version__)
raise typer.Exit()


def call_llm(
api_key: str, model: str, system_prompt: str, user_prompt: str
) -> str | None:
Expand Down Expand Up @@ -49,6 +58,16 @@ def main(
help="Run the command if suggested. Dangerous!",
),
] = False,
version: Annotated[
bool | None,
typer.Option(
"--version",
"-v",
callback=version_callback,
help="Show the version and exit.",
is_eager=True,
),
] = None,
):
"""Suggest a command for a Linux task described in QUERY.

Expand Down
7 changes: 7 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ def test_app_for_suggestion_with_execute(mockenv, monkeypatch):
assert result.stdout == "ls\n" # careful, this will actually run
assert result.stderr == ""
assert result.exit_code == 0


def test_app_for_version(mockenv):
result = runner.invoke(ape_linux.app, ["--version"])
assert result.stdout == f"{ape_linux.__version__}\n"
assert result.stderr == ""
assert result.exit_code == 0