Coverage for src/fastapi_cloud_cli/utils/teams.py: 100%
31 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-11-09 00:25 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-11-09 00:25 +0000
1from pathlib import Path 1hijklmn
3from pydantic import BaseModel 1hijklmn
4from rich_toolkit.menu import Option 1hijklmn
6from fastapi_cloud_cli.api import APIClient 1hijklmn
7from fastapi_cloud_cli.utils.apps import get_app_config 1hijklmn
8from fastapi_cloud_cli.utils.cli import FastAPIRichToolkit 1hijklmn
11class Team(BaseModel): 1hijklmn
12 id: str 1hijklmn
13 slug: str 1hijklmn
14 name: str 1hijklmn
17def get_teams(client: APIClient) -> list[Team]: 1hijklmn
18 response = client.get("/teams/") 1aovwxbpyzAcqBCDdrEFGesHIJftKLMguNOP
19 response.raise_for_status() 1aovwxbpyzAcqBCDdrEFGesHIJftKLMguNOP
21 return [Team.model_validate(team) for team in response.json()["data"]] 1aovwxbpyzAcqBCDdrEFGesHIJftKLMguNOP
24def select_team( 1hijklmn
25 toolkit: FastAPIRichToolkit,
26 client: APIClient,
27 *,
28 empty_hint: str,
29) -> Team:
30 with toolkit.progress( 1aovwxbpyzAcqBCDdrEFGesHIJftKLMguNOP
31 title="Fetching teams",
32 transient=True,
33 ) as progress:
34 with client.handle_http_errors( 1aovwxbpyzAcqBCDdrEFGesHIJftKLMguNOP
35 progress,
36 default_message="Error fetching teams. Please try again later.",
37 toolkit=toolkit,
38 ):
39 teams = get_teams(client) 1aovwxbpyzAcqBCDdrEFGesHIJftKLMguNOP
41 if not teams: 1aovwxbpyzAcqBCDdrEFGesHIJftKLMguNOP
42 toolkit.fail( 1oxpAqDrGsJtMuP
43 "missing_required_input",
44 "No teams found.",
45 hint=empty_hint,
46 )
48 return toolkit.ask( 1avwbyzcBCdEFeHIfKLgNO
49 "Select the team:",
50 options=[
51 Option({"name": team.name, "value": team})
52 for team in sorted(teams, key=lambda team: team.name.lower())
53 ],
54 allow_filtering=True,
55 bullet=False,
56 )
59def resolve_team_id( 1hijklmn
60 toolkit: FastAPIRichToolkit,
61 client: APIClient,
62 *,
63 team_id: str | None = None,
64 path: Path | None = None,
65 empty_hint: str,
66) -> str:
67 if team_id is not None: 145Q6aoX78R9bpY!#S$cqZ%'T(dr0)*U+es1,-V.ft2/:W;gu3
68 return team_id 1456789!#$%'()*+,-./:;
70 if app_config := get_app_config(path or Path.cwd()): 1QaoXRbpYScqZTdr0Ues1Vft2Wgu3
71 return app_config.team_id 1XYZ0123
73 if toolkit.mode == "json": 1QaoRbpScqTdrUesVftWgu
74 toolkit.fail( 1QRSTUVW
75 "missing_required_input",
76 "Team ID is required.",
77 hint="Pass --team-id or run the command from a linked app.",
78 )
80 team = select_team(toolkit, client, empty_hint=empty_hint) 1aobpcqdresftgu
81 toolkit.print_line() 1abcdefg
83 return team.id 1abcdefg