Skip to content

Commit e9aeb35

Browse files
committed
Add "acidwatch list" subcommand
1 parent e3c9ece commit e9aeb35

3 files changed

Lines changed: 141 additions & 7 deletions

File tree

backend/packages/acidwatch/pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ name = "acidwatch"
33
description = "CLI for AcidWatch"
44
readme = "README.md"
55
requires-python = ">=3.12, <3.14"
6-
dependencies = []
6+
dependencies = [
7+
"httpx>=0.28.1",
8+
"pydantic>=2.13.3",
9+
"typer>=0.26.7",
10+
]
711
dynamic = ["version"]
812

913
[project.scripts]
10-
acidwatch = "acidwatch.cli:main"
14+
acidwatch = "acidwatch.cli:app"
1115

1216
[dependency-groups]
1317
dev = [
Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
1-
def main() -> None:
2-
print("Hello from acidwatch!")
1+
from __future__ import annotations
2+
from pydantic.alias_generators import to_camel
3+
4+
from typer import Typer
5+
from httpx import Client
6+
from pydantic import BaseModel, RootModel, ConfigDict
7+
from rich.console import Console
8+
from rich.table import Table
9+
10+
app = Typer()
11+
console = Console()
12+
13+
14+
API_URL = "https://backend-acidwatch-prod.radix.equinor.com"
15+
16+
17+
class Model(BaseModel):
18+
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
19+
20+
access_error: str | None
21+
model_id: str
22+
display_name: str
23+
24+
25+
@app.command("list")
26+
def list_models() -> None:
27+
with Client(base_url=API_URL) as session:
28+
response = session.get("/models")
29+
assert response.status_code == 200
30+
31+
klass = RootModel[list[Model]]
32+
33+
table = Table(title="Available AcidWatch models")
34+
table.add_column("ID")
35+
table.add_column("Name")
36+
for model in klass.model_validate_json(response.content).root:
37+
if model.access_error is not None:
38+
continue
39+
40+
table.add_row(model.model_id, model.display_name)
41+
42+
console.print(table)
43+
44+
45+
@app.command()
46+
def run() -> None:
47+
pass
348

449

550
if __name__ == "__main__":
6-
main()
51+
app()

backend/uv.lock

Lines changed: 87 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)