Skip to content

Commit eed75f6

Browse files
committed
Added passthrough for reload_dir option to uvicorn
1 parent 9a47418 commit eed75f6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/fastapi_cli/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _run(
8686
command: str,
8787
app: Union[str, None] = None,
8888
proxy_headers: bool = False,
89+
reload_dir: Union[str, None] = None,
8990
) -> None:
9091
with get_rich_toolkit() as toolkit:
9192
server_type = "development" if command == "dev" else "production"
@@ -167,6 +168,7 @@ def _run(
167168
workers=workers,
168169
root_path=root_path,
169170
proxy_headers=proxy_headers,
171+
reload_dir=reload_dir.split(",") if reload_dir else None,
170172
log_config=get_uvicorn_log_config(),
171173
)
172174

@@ -216,6 +218,12 @@ def dev(
216218
help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info."
217219
),
218220
] = True,
221+
reload_dir: Annotated[
222+
Union[str, None],
223+
typer.Option(
224+
help="Comma separated list of directories to watch for changes in. If not provided, by default the whole current directory will be watched."
225+
),
226+
] = None,
219227
) -> Any:
220228
"""
221229
Run a [bold]FastAPI[/bold] app in [yellow]development[/yellow] mode. 🧪
@@ -251,6 +259,7 @@ def dev(
251259
app=app,
252260
command="dev",
253261
proxy_headers=proxy_headers,
262+
reload_dir=reload_dir,
254263
)
255264

256265

tests/test_cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_dev() -> None:
3030
"workers": None,
3131
"root_path": "",
3232
"proxy_headers": True,
33+
"reload_dir": None,
3334
"log_config": get_uvicorn_log_config(),
3435
}
3536
assert "Using import string: single_file_app:app" in result.output
@@ -94,6 +95,8 @@ def test_dev_args() -> None:
9495
"--app",
9596
"api",
9697
"--no-proxy-headers",
98+
"--reload-dir",
99+
"api,config",
97100
],
98101
)
99102
assert result.exit_code == 0, result.output
@@ -107,6 +110,7 @@ def test_dev_args() -> None:
107110
"workers": None,
108111
"root_path": "/api",
109112
"proxy_headers": False,
113+
"reload_dir": "api,config",
110114
"log_config": get_uvicorn_log_config(),
111115
}
112116
assert "Using import string: single_file_app:api" in result.output

0 commit comments

Comments
 (0)