Skip to content

Commit a23816f

Browse files
committed
feat: refactor conditional printing api docs urls
1 parent 1280603 commit a23816f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/fastapi_cli/cli.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ def _run(
126126

127127
module_data = import_data.module_data
128128
import_string = import_data.import_string
129+
openapi_url = import_data.openapi_url
130+
docs_url = import_data.docs_url
131+
redoc_url = import_data.redoc_url
129132

130133
toolkit.print(f"Importing from {module_data.extra_sys_path}")
131134
toolkit.print_line()
@@ -152,15 +155,30 @@ def _run(
152155
)
153156

154157
url = f"http://{host}:{port}"
155-
url_docs = f"{url}/docs"
158+
docs_str = ""
159+
160+
if openapi_url and (docs_url or redoc_url):
161+
if docs_url:
162+
docs_str += f"[link={url}{docs_url}]{url}{docs_url}[/]"
163+
164+
if docs_url and redoc_url:
165+
docs_str += " or "
166+
167+
if redoc_url:
168+
docs_str += f"[link={url}{redoc_url}]{url}{redoc_url}[/]"
156169

157170
toolkit.print_line()
158171
toolkit.print(
159172
f"Server started at [link={url}]{url}[/]",
160-
f"Documentation at [link={url_docs}]{url_docs}[/]",
161173
tag="server",
162174
)
163175

176+
if docs_str:
177+
toolkit.print(
178+
f"Documentation at {docs_str}",
179+
tag="server",
180+
)
181+
164182
if command == "dev":
165183
toolkit.print_line()
166184
toolkit.print(

0 commit comments

Comments
 (0)