Coverage for /usr/local/lib/python3.12/site-packages/prefect/cli/dashboard.py: 62%

14 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 10:48 +0000

1import webbrowser 1a

2 

3from prefect.cli._types import PrefectTyper 1a

4from prefect.cli._utilities import exit_with_error, exit_with_success 1a

5from prefect.cli.root import app 1a

6from prefect.settings import get_current_settings 1a

7from prefect.utilities.asyncutils import run_sync_in_worker_thread 1a

8 

9dashboard_app: PrefectTyper = PrefectTyper( 1a

10 name="dashboard", 

11 help="Commands for interacting with the Prefect UI.", 

12) 

13app.add_typer(dashboard_app) 1a

14 

15 

16@dashboard_app.command() 1a

17async def open() -> None: 1a

18 """ 

19 Open the Prefect UI in the browser. 

20 """ 

21 

22 if not (ui_url := get_current_settings().ui_url): 

23 exit_with_error( 

24 "`PREFECT_UI_URL` must be set to the URL of a running Prefect server or Prefect Cloud workspace." 

25 ) 

26 

27 await run_sync_in_worker_thread(webbrowser.open_new_tab, ui_url) 

28 

29 exit_with_success(f"Opened {ui_url!r} in browser.")