Skip to content

Commit ef1d649

Browse files
committed
feat: show app docs_url
1 parent 35c0428 commit ef1d649

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/fastapi_cli/cli.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib
12
from logging import getLogger
23
from pathlib import Path
34
from typing import Any, Union
@@ -45,6 +46,13 @@ def callback(
4546
"""
4647

4748

49+
def _get_docs_url(uvicorn_path: str) -> str:
50+
module_path, app_name = uvicorn_path.split(sep=":")
51+
module = importlib.import_module(module_path)
52+
app = getattr(module, app_name)
53+
return app.docs_url
54+
55+
4856
def _run(
4957
path: Union[Path, None] = None,
5058
*,
@@ -62,7 +70,13 @@ def _run(
6270
except FastAPICLIException as e:
6371
logger.error(str(e))
6472
raise typer.Exit(code=1) from None
65-
serving_str = f"[dim]Serving at:[/dim] [link]http://{host}:{port}[/link]\n\n[dim]API docs:[/dim] [link]http://{host}:{port}/docs[/link]"
73+
74+
docs_url = _get_docs_url(use_uvicorn_app)
75+
76+
serving_str = (
77+
f"[dim]Serving at:[/dim] [link]http://{host}:{port}[/link]\n\n[dim]"
78+
f"API docs:[/dim] [link]http://{host}:{port}{docs_url}[/link]"
79+
)
6680

6781
if command == "dev":
6882
panel = Panel(

0 commit comments

Comments
 (0)