Coverage for src/fastapi_cloud_cli/commands/domains/list.py: 100%

29 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-11-09 00:25 +0000

1from typing import Annotated, Any 1abcdefg

2 

3import typer 1abcdefg

4from pydantic import BaseModel 1abcdefg

5from rich_toolkit import RichToolkit 1abcdefg

6 

7from fastapi_cloud_cli.api import APIClient, CustomDomain 1abcdefg

8from fastapi_cloud_cli.commands._auth import UserCommand, get_user_command_context 1abcdefg

9from fastapi_cloud_cli.commands.domains._app import domains_app 1abcdefg

10from fastapi_cloud_cli.commands.domains.rendering import get_custom_domains_table 1abcdefg

11from fastapi_cloud_cli.utils.apps import resolve_app_id_or_fail 1abcdefg

12from fastapi_cloud_cli.utils.execution import JsonOutputOption 1abcdefg

13 

14 

15class CustomDomainsListOutput(BaseModel): 1abcdefg

16 app_id: str 1abcdefg

17 domains: list[CustomDomain] 1abcdefg

18 total_count: int 1abcdefg

19 

20 

21def _render_custom_domains_list_output( 1abjcdkefgl

22 data: CustomDomainsListOutput, 

23 toolkit: RichToolkit, 

24) -> None: 

25 toolkit.print_title("custom domains") 1hmnjotpkiqrusl

26 toolkit.print_line() 1hmnjotpkiqrusl

27 

28 if not data.domains: 1hmnjotpkiqrusl

29 toolkit.print("No custom domains found.", bullet=False) 1hnopirs

30 return 1hnopirs

31 

32 toolkit.print(get_custom_domains_table(data.domains), bullet=False) 1mjtkqul

33 

34 

35@domains_app.command("list", cls=UserCommand) 1abcdefg

36def list_domains( 1abXcdYefgZ

37 ctx: typer.Context, 

38 app_id: Annotated[ 

39 str | None, 

40 typer.Option( 

41 "--app-id", 

42 help="ID of the app whose custom domains should be listed.", 

43 ), 

44 ] = None, 

45 json_output: JsonOutputOption = False, 

46) -> Any: 

47 """ 

48 List custom domains for an app. 

49 """ 

50 toolkit = get_user_command_context(ctx).toolkit 1hQvxymnRzGHjoSAIJtpTBKLkiUwCDqrVEMNusWFOPl

51 app_id = resolve_app_id_or_fail(toolkit, app_id=app_id) 1hQvxymnRzGHjoSAIJtpTBKLkiUwCDqrVEMNusWFOPl

52 

53 with APIClient() as client: 1hvxymnzGHjoAIJtpBKLkiwCDqrEMNusFOPl

54 with ( 1hvxymiwCDq

55 toolkit.progress( 

56 title="Fetching custom domains", 

57 transient=True, 

58 ) as progress, 

59 client.handle_http_errors( 

60 progress, 

61 default_message=( 

62 "Error fetching custom domains. Please try again later." 

63 ), 

64 not_found_message="App not found.", 

65 toolkit=toolkit, 

66 ), 

67 ): 

68 response = client.get_custom_domains(app_id=app_id) 1hvxymnzGHjoAIJtpBKLkiwCDqrEMNusFOPl

69 

70 toolkit.success( 1hvmnzjoAtpBkiwqrEusFl

71 CustomDomainsListOutput( 

72 app_id=app_id, 

73 domains=response.data, 

74 total_count=response.count, 

75 ), 

76 render_output=_render_custom_domains_list_output, 

77 )