diff --git a/pyproject.toml b/pyproject.toml index 49c170a..bd65445 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,8 @@ dependencies = [ "ty>=0.0.1a9", "pytest-env>=1.1.5", "pydantic-settings>=2.12.0", + "requests>=2.31.0", + "typer[all]>=0.12.3", ] readme = "README.md" requires-python = ">= 3.12" @@ -35,7 +37,10 @@ build-backend = "hatchling.build" allow-direct-references = true [tool.hatch.build.targets.wheel] -packages = ["src/python_template"] +packages = ["src"] + +[project.scripts] +eito = "src.cli.main:app" [tool.vulture] exclude = [ diff --git a/src/cli/main.py b/src/cli/main.py new file mode 100644 index 0000000..639f8e2 --- /dev/null +++ b/src/cli/main.py @@ -0,0 +1,19 @@ +import typer +import requests + +app = typer.Typer() + +@app.command() +def run(): + """ + Pings app.eito.me/ping and prints the response. + """ + try: + response = requests.get("https://app.eito.me/ping") + response.raise_for_status() # Raise an exception for bad status codes + print(response.text) + except requests.exceptions.RequestException as e: + print(f"Error: {e}") + +if __name__ == "__main__": + app() diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..0c4de03 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,18 @@ +import pytest +from src.cli.main import run +from unittest.mock import patch, MagicMock + +@patch('requests.get') +def test_cli_run(mock_get, capsys): + """ + Tests that the eito run command works with typer. + """ + mock_response = MagicMock() + mock_response.status_code = 200 + mock_response.text = "pong" + mock_get.return_value = mock_response + + run() + + captured = capsys.readouterr() + assert "pong" in captured.out