Skip to content
Draft
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
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = [
Expand Down
19 changes: 19 additions & 0 deletions src/cli/main.py
Original file line number Diff line number Diff line change
@@ -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()
18 changes: 18 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -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
Loading