Add debug CLI districts subcommand
This commit is contained in:
parent
df0fa41586
commit
7a35489f35
1 changed files with 41 additions and 0 deletions
41
cli/districts.py
Normal file
41
cli/districts.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
"""Debug CLI — district commands."""
|
||||
import click
|
||||
import httpx
|
||||
|
||||
from cli._context import CliContext, get_http_headers, output, error_output
|
||||
from services import district_service
|
||||
|
||||
|
||||
@click.group("districts")
|
||||
def districts_group() -> None:
|
||||
"""District management commands."""
|
||||
pass
|
||||
|
||||
|
||||
@districts_group.command("list")
|
||||
@click.pass_context
|
||||
def list_districts(ctx: click.Context) -> None:
|
||||
"""List all available districts."""
|
||||
cli_ctx: CliContext = ctx.obj["cli_ctx"]
|
||||
|
||||
try:
|
||||
if cli_ctx.use_http:
|
||||
resp = httpx.get(
|
||||
f"{cli_ctx.api_base_url}/api/get_districts",
|
||||
headers=get_http_headers(cli_ctx.user_email),
|
||||
)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
else:
|
||||
data = district_service.get_all_districts()
|
||||
|
||||
if cli_ctx.json_output:
|
||||
output(data, json_mode=True)
|
||||
else:
|
||||
print(f"Available districts ({len(data)}):")
|
||||
for name in sorted(data.keys()):
|
||||
print(f" {name}: {data[name]}")
|
||||
except httpx.HTTPStatusError as e:
|
||||
error_output(f"HTTP {e.response.status_code}: {e.response.text}", cli_ctx.json_output)
|
||||
except Exception as e:
|
||||
error_output(str(e), cli_ctx.json_output)
|
||||
Loading…
Add table
Add a link
Reference in a new issue